From 7dbde4e6fba6c7653a16d9b0737d313a7f6c1d1e Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Fri, 1 Nov 2019 14:28:09 -0700 Subject: [PATCH] Make it build on windows (#5) --- .gitattributes | 8 ++++++++ .github/workflows/ci.yml | 20 +++++++++++++++----- build.rs | 39 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..8faaeb0c --- /dev/null +++ b/.gitattributes @@ -0,0 +1,8 @@ +build symlink=dir +buildtools symlink=dir +build_overrides symlink=dir +testing symlink=dir +third_party/googletest symlink=dir +third_party/jinja2 symlink=dir +third_party/llvm-build symlink=dir +third_party/markupsafe symlink=dir diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2ec91803..eb506553 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ jobs: timeout-minutes: 60 strategy: matrix: - os: [macOS-10.14, ubuntu-16.04] # TODO(ry) windows-2019 + os: [macOS-10.14, ubuntu-16.04, windows-2019] steps: - name: Configure git run: git config --global core.symlinks true @@ -30,6 +30,20 @@ jobs: with: python-version: "2.7.16" + - name: Remove unused versions of Python + # Depot_tools bootstraps its own copy of virtualenv. This fails on + # windows when multiple versions of python are in present in PATH, + # so we remove all but the first one. + # 🤯 Removing items from PATH does not seem possible on Github Actions, + # not even by using `echo ::set-env name=PATH`, so we have to rename + # or delete the actual Python directories. + if: startsWith(matrix.os, 'windows') + run: |- + $env:PATH -split ";" | + Where-Object { Test-Path "$_\python.exe" } | + Select-Object -Skip 1 | + ForEach-Object { Move-Item "$_" "$_.disabled" } + - name: Environment (common) run: | echo ::set-env name=GH_ACTIONS::1 @@ -59,13 +73,9 @@ jobs: - name: Environment (windows) if: startsWith(matrix.os, 'windows') run: | - # These appear unnecessary: - #choco install curl - #choco install archive curl -LO https://github.com/mozilla/sccache/releases/download/0.2.12/sccache-0.2.12-x86_64-pc-windows-msvc.tar.gz tar -zxvf sccache-0.2.12-x86_64-pc-windows-msvc.tar.gz echo ::add-path::$(pwd)\sccache-0.2.12-x86_64-pc-windows-msvc\ - echo ::add-path::$(pwd)\third_party\depot_tools\ - name: Start sccache env: diff --git a/build.rs b/build.rs index 7a12556f..84b4664c 100644 --- a/build.rs +++ b/build.rs @@ -7,13 +7,17 @@ use std::process::Command; use which::which; fn main() { + if cfg!(windows) { + init_depot_tools_windows(); + } if !Path::new("third_party/v8/src").is_dir() || env::var_os("GCLIENT_SYNC").is_some() { gclient_sync(); } - let mut gn_args = if cargo_gn::is_debug() { + // On windows, rustc cannot link with a V8 debug build. + let mut gn_args = if cargo_gn::is_debug() && !cfg!(target_os = "windows") { vec!["is_debug=true".to_string()] } else { vec!["is_debug=false".to_string()] @@ -46,6 +50,39 @@ fn main() { } } +fn init_depot_tools_windows() { + let depot_tools = env::current_dir() + .unwrap() + .join("third_party") + .join("depot_tools"); + // Bootstrap depot_tools. + if !depot_tools.join("git.bat").is_file() { + let status = Command::new("cmd.exe") + .arg("/c") + .arg("bootstrap\\win_tools.bat") + .current_dir(&depot_tools) + .status() + .expect("bootstrapping depot_tools failed"); + assert!(status.success()); + } + // Add third_party/depot_tools and buildtools/win to PATH. + // TODO: this should be done on all platforms. + // TODO: buildtools/win should not be added; instead, cargo_gn should invoke + // depot_tools/gn.bat. + let buildtools_win = + env::current_dir().unwrap().join("buildtools").join("win"); + // Bootstrap depot_tools. + let path = env::var_os("PATH").unwrap(); + let paths = vec![depot_tools, buildtools_win] + .into_iter() + .chain(env::split_paths(&path)) + .collect::>(); + let path = env::join_paths(paths).unwrap(); + env::set_var("PATH", &path); + // TODO: cargo_gn should do this. + env::set_var("DEPOT_TOOLS_WIN_TOOLCHAIN", "0"); +} + fn git_submodule_update() { Command::new("git") .arg("submodule")