From ba61583c7157774b164e0a45046382bd2b436c86 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Mon, 1 Jul 2019 14:46:30 -0400 Subject: [PATCH 01/16] WIP cargo_gn integration --- .appveyor.yml | 3 +++ .travis.yml | 4 +++ Cargo.lock | 20 +++++++++++++++ cli/Cargo.toml | 7 ++++++ cli/build.rs | 14 +++-------- core/Cargo.toml | 4 +++ core/build.rs | 16 ++++-------- tools/binary_downloads.py | 26 +++++++++++++++++++ tools/build_common.rs | 53 +++++++++++++++++++++++++++++++++++++++ tools/setup.py | 8 ++---- 10 files changed, 128 insertions(+), 27 deletions(-) create mode 100755 tools/binary_downloads.py create mode 100644 tools/build_common.rs diff --git a/.appveyor.yml b/.appveyor.yml index 617a5c034f2767..7e3cb494031cc3 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -23,6 +23,9 @@ environment: AWS_ACCESS_KEY_ID: AKIAIVRN52PLDBP55LBQ AWS_SECRET_ACCESS_KEY: secure: 8ybpi/y5qE2baChsCBhNHmykng3FitELAtTYOiqZd0mw38i88dzdAX8ETNtBogMV + # GN and NINJA are required by https://crates.io/crates/cargo_gn + GN: $(APPVEYOR_BUILD_FOLDER)/buildtools/win/gn.exe + NINJA: $(APPVEYOR_BUILD_FOLDER)/third_party/depot_tools/ninja.exe # Appveyor uses 7zip to pack cache directories. We use these options: diff --git a/.travis.yml b/.travis.yml index 3b389ff8f44f3f..0649339dbe1f9f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -115,6 +115,10 @@ jobs: - name: "cargo release linux x86_64" os: linux script: + # CARGO_GN_PATH and CARGO_NINJA_PATH allivate the need to build these + # tools from scratch. See docs at https://crates.io/crates/cargo_gn + - export GN=$TRAVIS_BUILD_DIR/buildtools/linux64/gn + - export NINJA=$TRAVIS_BUILD_DIR/third_party/depot_tools/ninja - ./tools/lint.py - ./tools/test_format.py - cargo build -vv --release --locked diff --git a/Cargo.lock b/Cargo.lock index cc6dde370cfb61..705ba49f4bbba4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -133,6 +133,11 @@ dependencies = [ "ppv-lite86 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "cargo_gn" +version = "0.0.13" +source = "git+https://github.com/denoland/cargo_gn#da37d12445fab1429d6d066bd407aeedc1427b9a" + [[package]] name = "cc" version = "1.0.40" @@ -255,6 +260,7 @@ dependencies = [ name = "deno" version = "0.16.0" dependencies = [ + "cargo_gn 0.0.13 (git+https://github.com/denoland/cargo_gn)", "futures 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", @@ -262,6 +268,7 @@ dependencies = [ "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", "tokio 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "which 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -270,6 +277,7 @@ version = "0.16.0" dependencies = [ "ansi_term 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", + "cargo_gn 0.0.13 (git+https://github.com/denoland/cargo_gn)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "deno 0.16.0", "dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -305,6 +313,7 @@ dependencies = [ "tokio-threadpool 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "utime 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "which 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1833,6 +1842,15 @@ dependencies = [ "nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "which" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "winapi" version = "0.2.8" @@ -1915,6 +1933,7 @@ dependencies = [ "checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" "checksum bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c" "checksum c2-chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7d64d04786e0f528460fc884753cf8dddcc466be308f6026f8e355c41a0e4101" +"checksum cargo_gn 0.0.13 (git+https://github.com/denoland/cargo_gn)" = "" "checksum cc 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)" = "b548a4ee81fccb95919d4e22cfea83c7693ebfd78f0495493178db20b3139da7" "checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33" "checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" @@ -2093,6 +2112,7 @@ dependencies = [ "checksum webpki 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d7e664e770ac0110e2384769bcc59ed19e329d81f555916a6e072714957b81b4" "checksum webpki-roots 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a262ae37dd9d60f60dd473d1158f9fbebf110ba7b6a5051c8160460f6043718b" "checksum weedle 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3bb43f70885151e629e2a19ce9e50bd730fd436cfd4b666894c9ce4de9141164" +"checksum which 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b57acb10231b9493c8472b20cb57317d0679a49e0bdbee44b3b803a6473af164" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 6fac49e3df1c00..cce4346d8a45e3 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -59,3 +59,10 @@ fwdansi = "1.0.1" [target.'cfg(unix)'.dependencies] nix = "0.14.1" + +[build-dependencies] +cargo_gn = { git = "https://github.com/denoland/cargo_gn" } +# To avoid building V8 twice, we make sure that the core crate is built before +# cli starts building. +deno = { path = "../core" } +which = "2.0.1" diff --git a/cli/build.rs b/cli/build.rs index 55451e6b73f032..60d7c179383fce 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -1,15 +1,9 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. // Run "cargo build -vv" if you want to see gn output. -mod gn { - include!("../tools/gn.rs"); -} +include!("../tools/build_common.rs"); fn main() { - let build = gn::Build::setup(); - // When RLS is running "cargo check" to analyze the source code, we're not - // trying to build a working executable, rather we're just compiling all - // rust code. - if !build.check_only { - build.run("cli:deno_deps"); - } + // TODO(ry) When running "cargo check" only build "msg_rs" + setup(); + cargo_gn::build("cli:deno_deps"); } diff --git a/core/Cargo.toml b/core/Cargo.toml index 02932df353e812..3a2239edd9b6a2 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -34,3 +34,7 @@ path = "examples/http_bench.rs" # tokio is only used for deno_core_http_bench [dev_dependencies] tokio = "0.1.18" + +[build-dependencies] +cargo_gn = { git = "https://github.com/denoland/cargo_gn" } +which = "2.0.1" diff --git a/core/build.rs b/core/build.rs index 43e993dc994a6e..0e3f84a66cec01 100644 --- a/core/build.rs +++ b/core/build.rs @@ -1,16 +1,10 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. // Run "cargo build -vv" if you want to see gn output. -mod gn { - include!("../tools/gn.rs"); -} - +include!("../tools/build_common.rs"); fn main() { - let build = gn::Build::setup(); - - println!( - "cargo:rustc-link-search=native={}/obj/core/libdeno", - build.gn_out_dir - ); + let gn_out_path = setup(); + cargo_gn::build("core:deno_core_deps"); - build.run("core:deno_core_deps"); + let d = gn_out_path.join("obj/core/libdeno/"); + println!("cargo:rustc-link-search=native={}", d.display()); } diff --git a/tools/binary_downloads.py b/tools/binary_downloads.py new file mode 100755 index 00000000000000..1fa74a8b1313f5 --- /dev/null +++ b/tools/binary_downloads.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. +# This is called from tools/setup.py in the case of a GN build or independently +# from tools/build_common.gn in the case of a cargo build. +import third_party +from util import (enable_ansi_colors, root_path) +import os +import sys +import prebuilt +import argparse + + +def binary_downloads(): + enable_ansi_colors() + os.chdir(root_path) + + print "binary download" + third_party.download_gn() + third_party.download_clang_format() + third_party.download_clang() + third_party.maybe_download_sysroot() + prebuilt.load_sccache() + + +if __name__ == '__main__': + sys.exit(binary_downloads()) diff --git a/tools/build_common.rs b/tools/build_common.rs new file mode 100644 index 00000000000000..6a29ada5b5e02a --- /dev/null +++ b/tools/build_common.rs @@ -0,0 +1,53 @@ +use cargo_gn; +use std::env; +use std::path::PathBuf; +use std::process::Command; +use which::which; + +fn binary_downloads() { + let cwd = env::current_dir().unwrap(); + let root = cwd.join(".."); + let status = Command::new("python") + .arg("tools/binary_downloads.py") + .current_dir(root) + .status() + .expect("tools/binary_downloads.py failed"); + assert!(status.success()); +} + +// This is essentially a re-write of the original tools/setup.py +// but in rust. +fn setup() -> PathBuf { + let mut debug_args = "is_debug=true\n".to_string(); + let mut release_args = "is_official_build=true\nsymbol_level=0\n".to_string(); + + if env::var_os("DENO_NO_BINARY_DOWNLOAD").is_none() { + binary_downloads(); + } + + // TODO(ry) Support prebuilt/mac/sccache + match which("sccache") { + Ok(sccache_path) => { + debug_args += &format!("cc_wrapper={:?}\n", sccache_path); + debug_args += &format!("rustc_wrapper={:?}\n", sccache_path); + + release_args += &format!("cc_wrapper={:?}\n", sccache_path); + release_args += &format!("rustc_wrapper={:?}\n", sccache_path); + } + Err(_) => {} + } + + match env::var("DENO_BUILD_ARGS") { + Ok(val) => { + for arg in val.split_whitespace() { + debug_args += arg; + debug_args += "\n"; + release_args += arg; + release_args += "\n"; + } + } + Err(_) => {} + }; + + cargo_gn::maybe_gen("..", &debug_args, &release_args) +} diff --git a/tools/setup.py b/tools/setup.py index 9f50593589dcff..e2823ba4bdff5c 100755 --- a/tools/setup.py +++ b/tools/setup.py @@ -9,6 +9,7 @@ from distutils.spawn import find_executable import prebuilt import argparse +from binary_downloads import binary_downloads parser = argparse.ArgumentParser() parser.add_argument( @@ -26,12 +27,7 @@ def main(): if args.no_binary_download: print "no binary download" else: - print "binary download" - third_party.download_gn() - third_party.download_clang_format() - third_party.download_clang() - third_party.maybe_download_sysroot() - prebuilt.load_sccache() + binary_downloads() write_lastchange() From ecbdb089193e082e94475553a5b9c4bdfdff84f7 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Thu, 18 Jul 2019 15:17:13 -0400 Subject: [PATCH 02/16] Run tests with 'cargo build' --- .travis.yml | 2 ++ cli/README.md | 4 ++++ cli/js | 1 + cli/tests | 1 + tools/target_test.py | 24 +++++++++++++++--------- 5 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 cli/README.md create mode 120000 cli/js create mode 120000 cli/tests diff --git a/.travis.yml b/.travis.yml index 0649339dbe1f9f..9f94b9cca57b0d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -123,6 +123,8 @@ jobs: - ./tools/test_format.py - cargo build -vv --release --locked - cargo clippy --all-targets --release --locked -- -D clippy::all + # TODO(ry) Warning! The following does not run libdeno_test + - ./tools/test.py --release # LSAN: We are in the process of getting a completely clean LSAN build, # but it will take some work. So for now we just run a subset of the diff --git a/cli/README.md b/cli/README.md new file mode 100644 index 00000000000000..64e186c56633f1 --- /dev/null +++ b/cli/README.md @@ -0,0 +1,4 @@ +This is the code for the main deno executable. + +The js/ and tests/ symlinks are temporarily added while we transition from +tools/build.py to cargo build. diff --git a/cli/js b/cli/js new file mode 120000 index 00000000000000..f662e4e2a017e5 --- /dev/null +++ b/cli/js @@ -0,0 +1 @@ +../js \ No newline at end of file diff --git a/cli/tests b/cli/tests new file mode 120000 index 00000000000000..6dd24e02b51335 --- /dev/null +++ b/cli/tests @@ -0,0 +1 @@ +../tests \ No newline at end of file diff --git a/tools/target_test.py b/tools/target_test.py index da1bd5537c975e..3c21eabe670f31 100644 --- a/tools/target_test.py +++ b/tools/target_test.py @@ -13,6 +13,10 @@ def check_exists(filename): print "Run ./tools/build.py" sys.exit(1) + def is_gn_build(self): + return os.path.exists( + os.path.join(self.build_dir, "cli_test" + executable_suffix)) + def test_executable_exists(self): self.check_exists(self.deno_exe) @@ -23,16 +27,18 @@ def _test(self, executable): run([bin_file], quiet=True) def test_libdeno(self): - self._test("libdeno_test") - - def test_cli(self): - self._test("cli_test") - - def test_core(self): - self._test("deno_core_test") + # TODO(ry) libdeno_test is not being run under cargo build!!! + # This must be fixed before landing. + if self.is_gn_build(): + self._test("libdeno_test") - def test_core_http_benchmark(self): - self._test("deno_core_http_bench_test") + def test_rust_unit_tests(self): + if self.is_gn_build(): + self._test("cli_test") + self._test("deno_core_test") + self._test("deno_core_http_bench_test") + else: + run(["cargo", "test", "--examples", "--all-targets"], quiet=True) def test_no_color(self): t = os.path.join(tests_path, "no_color.js") From 355a8182dcb254dce6a6aa8c644b360ec5ad4d41 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Mon, 22 Jul 2019 12:28:13 -0400 Subject: [PATCH 03/16] turn off treat_warnings_as_errors --- .gn | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.gn b/.gn index e0d902808fd888..ada9b40044f43e 100644 --- a/.gn +++ b/.gn @@ -39,7 +39,14 @@ default_args = { use_jumbo_build = true symbol_level = 1 - treat_warnings_as_errors = true + + # TODO(ry) Change this back to 'true'. This is to workaround windows error + # that is only encountered when building with cargo_gn. + # clang-cl: error: argument unused during compilation: + # '-mno-incremental-linker-compatible' + # [-Werror,-Wunused-command-line-argument] + treat_warnings_as_errors = false + rust_treat_warnings_as_errors = true # https://cs.chromium.org/chromium/src/docs/ccache_mac.md From 251a4fb1aee36ae88093b3974c4ba47cd362af00 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Mon, 22 Jul 2019 14:52:19 -0400 Subject: [PATCH 04/16] fix test --- tools/target_test.py | 6 +++++- tools/test_util.py | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/target_test.py b/tools/target_test.py index 3c21eabe670f31..6444e91233e017 100644 --- a/tools/target_test.py +++ b/tools/target_test.py @@ -38,7 +38,11 @@ def test_rust_unit_tests(self): self._test("deno_core_test") self._test("deno_core_http_bench_test") else: - run(["cargo", "test", "--examples", "--all-targets"], quiet=True) + args = ["cargo", "test", "--examples", "--all-targets", "-vv"] + from test_util import TEST_ARGS + if TEST_ARGS.release: + args += ["--release"] + run(args, quiet=True) def test_no_color(self): t = os.path.join(tests_path, "no_color.js") diff --git a/tools/test_util.py b/tools/test_util.py index 6540f37aa46ff7..afb888e5bd45ec 100644 --- a/tools/test_util.py +++ b/tools/test_util.py @@ -74,12 +74,16 @@ def create_test_arg_parser(): TestArgParser = create_test_arg_parser() +TEST_ARGS = None + def parse_test_args(argv=None): + global TEST_ARGS if argv is None: argv = sys.argv[1:] args = TestArgParser.parse_args(argv) + TEST_ARGS = args if args.executable and args.release: raise argparse.ArgumentError( From acde29aa9314c628af44c72b766255e31e3c1c56 Mon Sep 17 00:00:00 2001 From: afinch7 Date: Tue, 30 Jul 2019 10:47:14 -0400 Subject: [PATCH 05/16] update cargo_gn --- Cargo.lock | 10 +++++----- cli/Cargo.toml | 2 +- core/Cargo.toml | 2 +- tools/build_common.rs | 26 ++++++++++++++------------ 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 705ba49f4bbba4..e07c2046a9b807 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -135,8 +135,8 @@ dependencies = [ [[package]] name = "cargo_gn" -version = "0.0.13" -source = "git+https://github.com/denoland/cargo_gn#da37d12445fab1429d6d066bd407aeedc1427b9a" +version = "0.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cc" @@ -260,7 +260,7 @@ dependencies = [ name = "deno" version = "0.16.0" dependencies = [ - "cargo_gn 0.0.13 (git+https://github.com/denoland/cargo_gn)", + "cargo_gn 0.0.12 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", @@ -277,7 +277,7 @@ version = "0.16.0" dependencies = [ "ansi_term 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", - "cargo_gn 0.0.13 (git+https://github.com/denoland/cargo_gn)", + "cargo_gn 0.0.12 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "deno 0.16.0", "dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1933,7 +1933,7 @@ dependencies = [ "checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" "checksum bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c" "checksum c2-chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7d64d04786e0f528460fc884753cf8dddcc466be308f6026f8e355c41a0e4101" -"checksum cargo_gn 0.0.13 (git+https://github.com/denoland/cargo_gn)" = "" +"checksum cargo_gn 0.0.12 (registry+https://github.com/rust-lang/crates.io-index)" = "a34c50fb2ca26fb832617113c1123284ff4641be3407f60c4619876024606c5a" "checksum cc 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)" = "b548a4ee81fccb95919d4e22cfea83c7693ebfd78f0495493178db20b3139da7" "checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33" "checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index cce4346d8a45e3..5a36595e0b91e6 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -61,7 +61,7 @@ fwdansi = "1.0.1" nix = "0.14.1" [build-dependencies] -cargo_gn = { git = "https://github.com/denoland/cargo_gn" } +cargo_gn = "0.0.12" # To avoid building V8 twice, we make sure that the core crate is built before # cli starts building. deno = { path = "../core" } diff --git a/core/Cargo.toml b/core/Cargo.toml index 3a2239edd9b6a2..fc60d2a682048e 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -36,5 +36,5 @@ path = "examples/http_bench.rs" tokio = "0.1.18" [build-dependencies] -cargo_gn = { git = "https://github.com/denoland/cargo_gn" } +cargo_gn = "0.0.12" which = "2.0.1" diff --git a/tools/build_common.rs b/tools/build_common.rs index 6a29ada5b5e02a..9fad019a060d5b 100644 --- a/tools/build_common.rs +++ b/tools/build_common.rs @@ -18,8 +18,14 @@ fn binary_downloads() { // This is essentially a re-write of the original tools/setup.py // but in rust. fn setup() -> PathBuf { - let mut debug_args = "is_debug=true\n".to_string(); - let mut release_args = "is_official_build=true\nsymbol_level=0\n".to_string(); + let is_debug = cargo_gn::is_debug(); + let mut gn_args: cargo_gn::GnArgs = Vec::new(); + if is_debug { + gn_args.push(("is_debug".to_string(), "true".to_string())); + } else { + gn_args.push(("is_official_build".to_string(), "true".to_string())); + gn_args.push(("symbol_level".to_string(), "0".to_string())); + } if env::var_os("DENO_NO_BINARY_DOWNLOAD").is_none() { binary_downloads(); @@ -28,11 +34,8 @@ fn setup() -> PathBuf { // TODO(ry) Support prebuilt/mac/sccache match which("sccache") { Ok(sccache_path) => { - debug_args += &format!("cc_wrapper={:?}\n", sccache_path); - debug_args += &format!("rustc_wrapper={:?}\n", sccache_path); - - release_args += &format!("cc_wrapper={:?}\n", sccache_path); - release_args += &format!("rustc_wrapper={:?}\n", sccache_path); + gn_args.push(("cc_wapper".to_string(), format!("{:?}", sccache_path))); + gn_args.push(("rustc_wrapper".to_string(), format!("{:?}", sccache_path))); } Err(_) => {} } @@ -40,14 +43,13 @@ fn setup() -> PathBuf { match env::var("DENO_BUILD_ARGS") { Ok(val) => { for arg in val.split_whitespace() { - debug_args += arg; - debug_args += "\n"; - release_args += arg; - release_args += "\n"; + let split_pos = arg.find("=").unwrap(); + let (arg_key, arg_value) = arg.split_at(split_pos); + gn_args.push((arg_key.to_string(), arg_value.to_string())); } } Err(_) => {} }; - cargo_gn::maybe_gen("..", &debug_args, &release_args) + cargo_gn::maybe_gen("..", gn_args) } From b286ea5d19fc81cb2aff81c7de584130da441ff0 Mon Sep 17 00:00:00 2001 From: afinch7 Date: Tue, 30 Jul 2019 10:48:00 -0400 Subject: [PATCH 06/16] remove CARGO_TARGET_DIR from travis config --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9f94b9cca57b0d..c6df45242860e4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,6 @@ env: - CARGO_HOME=$TRAVIS_BUILD_DIR/third_party/rust_crates/ - RUSTUP_HOME=$HOME/.rustup/ - RUST_BACKTRACE=full - - CARGO_TARGET_DIR=$HOME/target - PATH=$TRAVIS_BUILD_DIR/third_party/llvm-build/Release+Asserts/bin:$CARGO_HOME/bin:$PATH - PYTHONPATH=third_party/python_packages - RUSTC_WRAPPER=sccache From d60e1d53d672266d94f1a67b96f0a0492be4bc2c Mon Sep 17 00:00:00 2001 From: afinch7 Date: Tue, 30 Jul 2019 10:57:46 -0400 Subject: [PATCH 07/16] fmt --- tools/build_common.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/build_common.rs b/tools/build_common.rs index 9fad019a060d5b..1da7b699f5f067 100644 --- a/tools/build_common.rs +++ b/tools/build_common.rs @@ -35,7 +35,8 @@ fn setup() -> PathBuf { match which("sccache") { Ok(sccache_path) => { gn_args.push(("cc_wapper".to_string(), format!("{:?}", sccache_path))); - gn_args.push(("rustc_wrapper".to_string(), format!("{:?}", sccache_path))); + gn_args + .push(("rustc_wrapper".to_string(), format!("{:?}", sccache_path))); } Err(_) => {} } From 3514a0eb3e040d3305a8c01d3d9e70eba6782648 Mon Sep 17 00:00:00 2001 From: afinch7 Date: Wed, 31 Jul 2019 13:29:33 -0400 Subject: [PATCH 08/16] pass custom env to ninja on windows --- Cargo.lock | 10 ++++---- cli/Cargo.toml | 2 +- cli/build.rs | 4 +-- core/Cargo.toml | 2 +- core/build.rs | 4 +-- tools/build_common.rs | 57 ++++++++++++++++++++++++++++++++++--------- 6 files changed, 57 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e07c2046a9b807..43865b8e4a2a15 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -135,8 +135,8 @@ dependencies = [ [[package]] name = "cargo_gn" -version = "0.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" +version = "0.0.13" +source = "git+https://github.com/afinch7/cargo_gn?branch=ninja_env#7639477242cbe35d2cb37a317b0ce8e2f063f246" [[package]] name = "cc" @@ -260,7 +260,7 @@ dependencies = [ name = "deno" version = "0.16.0" dependencies = [ - "cargo_gn 0.0.12 (registry+https://github.com/rust-lang/crates.io-index)", + "cargo_gn 0.0.13 (git+https://github.com/afinch7/cargo_gn?branch=ninja_env)", "futures 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", @@ -277,7 +277,7 @@ version = "0.16.0" dependencies = [ "ansi_term 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", - "cargo_gn 0.0.12 (registry+https://github.com/rust-lang/crates.io-index)", + "cargo_gn 0.0.13 (git+https://github.com/afinch7/cargo_gn?branch=ninja_env)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "deno 0.16.0", "dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1933,7 +1933,7 @@ dependencies = [ "checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" "checksum bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c" "checksum c2-chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7d64d04786e0f528460fc884753cf8dddcc466be308f6026f8e355c41a0e4101" -"checksum cargo_gn 0.0.12 (registry+https://github.com/rust-lang/crates.io-index)" = "a34c50fb2ca26fb832617113c1123284ff4641be3407f60c4619876024606c5a" +"checksum cargo_gn 0.0.13 (git+https://github.com/afinch7/cargo_gn?branch=ninja_env)" = "" "checksum cc 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)" = "b548a4ee81fccb95919d4e22cfea83c7693ebfd78f0495493178db20b3139da7" "checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33" "checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 5a36595e0b91e6..d3ee60c4c5d571 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -61,7 +61,7 @@ fwdansi = "1.0.1" nix = "0.14.1" [build-dependencies] -cargo_gn = "0.0.12" +cargo_gn = { git = "https://github.com/afinch7/cargo_gn", branch = "ninja_env" } # To avoid building V8 twice, we make sure that the core crate is built before # cli starts building. deno = { path = "../core" } diff --git a/cli/build.rs b/cli/build.rs index 60d7c179383fce..5c9fb07f562f26 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -4,6 +4,6 @@ include!("../tools/build_common.rs"); fn main() { // TODO(ry) When running "cargo check" only build "msg_rs" - setup(); - cargo_gn::build("cli:deno_deps"); + let (_, ninja_env) = setup(); + cargo_gn::build("cli:deno_deps", ninja_env); } diff --git a/core/Cargo.toml b/core/Cargo.toml index fc60d2a682048e..b3ae5a4084bb8a 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -36,5 +36,5 @@ path = "examples/http_bench.rs" tokio = "0.1.18" [build-dependencies] -cargo_gn = "0.0.12" +cargo_gn = { git = "https://github.com/afinch7/cargo_gn", branch = "ninja_env" } which = "2.0.1" diff --git a/core/build.rs b/core/build.rs index 0e3f84a66cec01..5945e4f1997459 100644 --- a/core/build.rs +++ b/core/build.rs @@ -2,8 +2,8 @@ // Run "cargo build -vv" if you want to see gn output. include!("../tools/build_common.rs"); fn main() { - let gn_out_path = setup(); - cargo_gn::build("core:deno_core_deps"); + let (gn_out_path, ninja_env) = setup(); + cargo_gn::build("core:deno_core_deps", ninja_env); let d = gn_out_path.join("obj/core/libdeno/"); println!("cargo:rustc-link-search=native={}", d.display()); diff --git a/tools/build_common.rs b/tools/build_common.rs index 1da7b699f5f067..3acfc310e27dfe 100644 --- a/tools/build_common.rs +++ b/tools/build_common.rs @@ -17,14 +17,14 @@ fn binary_downloads() { // This is essentially a re-write of the original tools/setup.py // but in rust. -fn setup() -> PathBuf { +fn setup() -> (PathBuf, cargo_gn::NinjaEnv) { let is_debug = cargo_gn::is_debug(); let mut gn_args: cargo_gn::GnArgs = Vec::new(); if is_debug { - gn_args.push(("is_debug".to_string(), "true".to_string())); + gn_args.push("is_debug=true".to_string()); } else { - gn_args.push(("is_official_build".to_string(), "true".to_string())); - gn_args.push(("symbol_level".to_string(), "0".to_string())); + gn_args.push("is_official_build=true".to_string()); + gn_args.push("symbol_level=0".to_string()); } if env::var_os("DENO_NO_BINARY_DOWNLOAD").is_none() { @@ -34,9 +34,8 @@ fn setup() -> PathBuf { // TODO(ry) Support prebuilt/mac/sccache match which("sccache") { Ok(sccache_path) => { - gn_args.push(("cc_wapper".to_string(), format!("{:?}", sccache_path))); - gn_args - .push(("rustc_wrapper".to_string(), format!("{:?}", sccache_path))); + gn_args.push(format!("cc_wrapper={:?}", sccache_path)); + gn_args.push(format!("rustc_wrapper={:?}", sccache_path)); } Err(_) => {} } @@ -44,13 +43,49 @@ fn setup() -> PathBuf { match env::var("DENO_BUILD_ARGS") { Ok(val) => { for arg in val.split_whitespace() { - let split_pos = arg.find("=").unwrap(); - let (arg_key, arg_value) = arg.split_at(split_pos); - gn_args.push((arg_key.to_string(), arg_value.to_string())); + gn_args.push(arg.to_string()); } } Err(_) => {} }; - cargo_gn::maybe_gen("..", gn_args) + let workspace_dir = env::current_dir() + .unwrap() + .join("../") + .canonicalize() + .unwrap(); + + let ninja_env: cargo_gn::NinjaEnv = if !cfg!(target_os = "windows") { + Vec::new() + } else { + // Windows needs special configuration. This is similar to the function of + // python_env() in //tools/util.py. + let mut env = Vec::new(); + let python_path: Vec = vec![ + "third_party/python_packages", + "third_party/python_packages/win32", + "third_party/python_packages/win32/lib", + "third_party/python_packages/Pythonwin", + ].into_iter() + .map(|p| { + workspace_dir + .join(p) + .into_os_string() + .into_string() + .unwrap() + }).collect(); + let orig_path = + String::from(";") + &env::var_os("PATH").unwrap().into_string().unwrap(); + let path = workspace_dir + .join("third_party/python_packages/pywin32_system32") + .into_os_string() + .into_string() + .unwrap(); + env.push(("PYTHONPATH".to_string(), python_path.join(";"))); + env.push(("PATH".to_string(), path + &orig_path)); + env.push(("DEPOT_TOOLS_WIN_TOOLCHAIN".to_string(), "0".to_string())); + env + }; + + (cargo_gn::maybe_gen("..", gn_args), ninja_env) } From 74157f0aaa568332c523fe4b7c86573df6369da5 Mon Sep 17 00:00:00 2001 From: afinch7 Date: Wed, 31 Jul 2019 14:30:59 -0400 Subject: [PATCH 09/16] update cargo_gn again and fix binary size benchmark --- tools/benchmark.py | 23 +++++++++++++++++------ tools/build_common.rs | 8 ++++---- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/tools/benchmark.py b/tools/benchmark.py index 8615a17d9864e3..47b62f5effe167 100755 --- a/tools/benchmark.py +++ b/tools/benchmark.py @@ -58,25 +58,36 @@ def import_data_from_gh_pages(): write_json(all_data_file, []) # writes empty json data +def is_gn_build(build_dir): + # TODO(afinch7) maybe find a better check for this? + return os.path.exists( + os.path.join(build_dir, "cli_test" + executable_suffix)) + + def get_binary_sizes(build_dir): + path_prefix = "gn_out/gen" + if is_gn_build(build_dir): + path_prefix = "gen" + path_dict = { "deno": os.path.join(build_dir, "deno" + executable_suffix), "main.js": - os.path.join(build_dir, "gen/cli/bundle/main.js"), + os.path.join(build_dir, path_prefix + "/cli/bundle/main.js"), "main.js.map": - os.path.join(build_dir, "gen/cli/bundle/main.js.map"), + os.path.join(build_dir, path_prefix + "/cli/bundle/main.js.map"), "compiler.js": - os.path.join(build_dir, "gen/cli/bundle/compiler.js"), + os.path.join(build_dir, path_prefix + "/cli/bundle/compiler.js"), "compiler.js.map": - os.path.join(build_dir, "gen/cli/bundle/compiler.js.map"), + os.path.join(build_dir, path_prefix + "/cli/bundle/compiler.js.map"), "snapshot_deno.bin": - os.path.join(build_dir, "gen/cli/snapshot_deno.bin"), + os.path.join(build_dir, path_prefix + "/cli/snapshot_deno.bin"), "snapshot_compiler.bin": - os.path.join(build_dir, "gen/cli/snapshot_compiler.bin") + os.path.join(build_dir, path_prefix + "/cli/snapshot_compiler.bin") } sizes = {} for name, path in path_dict.items(): + print path assert os.path.exists(path) sizes[name] = os.path.getsize(path) return sizes diff --git a/tools/build_common.rs b/tools/build_common.rs index 3acfc310e27dfe..57f51ea5f64f8a 100644 --- a/tools/build_common.rs +++ b/tools/build_common.rs @@ -17,7 +17,7 @@ fn binary_downloads() { // This is essentially a re-write of the original tools/setup.py // but in rust. -fn setup() -> (PathBuf, cargo_gn::NinjaEnv) { +fn setup() -> (PathBuf, Option) { let is_debug = cargo_gn::is_debug(); let mut gn_args: cargo_gn::GnArgs = Vec::new(); if is_debug { @@ -55,8 +55,8 @@ fn setup() -> (PathBuf, cargo_gn::NinjaEnv) { .canonicalize() .unwrap(); - let ninja_env: cargo_gn::NinjaEnv = if !cfg!(target_os = "windows") { - Vec::new() + let ninja_env: Option = if !cfg!(target_os = "windows") { + None } else { // Windows needs special configuration. This is similar to the function of // python_env() in //tools/util.py. @@ -84,7 +84,7 @@ fn setup() -> (PathBuf, cargo_gn::NinjaEnv) { env.push(("PYTHONPATH".to_string(), python_path.join(";"))); env.push(("PATH".to_string(), path + &orig_path)); env.push(("DEPOT_TOOLS_WIN_TOOLCHAIN".to_string(), "0".to_string())); - env + Some(env) }; (cargo_gn::maybe_gen("..", gn_args), ninja_env) From 83ccb06e533b189847a740d0487884bdc656b033 Mon Sep 17 00:00:00 2001 From: afinch7 Date: Wed, 31 Jul 2019 15:08:24 -0400 Subject: [PATCH 10/16] revert cargo_gn dep back to master --- Cargo.lock | 8 ++++---- cli/Cargo.toml | 2 +- core/Cargo.toml | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 43865b8e4a2a15..705ba49f4bbba4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -136,7 +136,7 @@ dependencies = [ [[package]] name = "cargo_gn" version = "0.0.13" -source = "git+https://github.com/afinch7/cargo_gn?branch=ninja_env#7639477242cbe35d2cb37a317b0ce8e2f063f246" +source = "git+https://github.com/denoland/cargo_gn#da37d12445fab1429d6d066bd407aeedc1427b9a" [[package]] name = "cc" @@ -260,7 +260,7 @@ dependencies = [ name = "deno" version = "0.16.0" dependencies = [ - "cargo_gn 0.0.13 (git+https://github.com/afinch7/cargo_gn?branch=ninja_env)", + "cargo_gn 0.0.13 (git+https://github.com/denoland/cargo_gn)", "futures 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", @@ -277,7 +277,7 @@ version = "0.16.0" dependencies = [ "ansi_term 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", - "cargo_gn 0.0.13 (git+https://github.com/afinch7/cargo_gn?branch=ninja_env)", + "cargo_gn 0.0.13 (git+https://github.com/denoland/cargo_gn)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "deno 0.16.0", "dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1933,7 +1933,7 @@ dependencies = [ "checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" "checksum bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c" "checksum c2-chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7d64d04786e0f528460fc884753cf8dddcc466be308f6026f8e355c41a0e4101" -"checksum cargo_gn 0.0.13 (git+https://github.com/afinch7/cargo_gn?branch=ninja_env)" = "" +"checksum cargo_gn 0.0.13 (git+https://github.com/denoland/cargo_gn)" = "" "checksum cc 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)" = "b548a4ee81fccb95919d4e22cfea83c7693ebfd78f0495493178db20b3139da7" "checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33" "checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index d3ee60c4c5d571..cce4346d8a45e3 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -61,7 +61,7 @@ fwdansi = "1.0.1" nix = "0.14.1" [build-dependencies] -cargo_gn = { git = "https://github.com/afinch7/cargo_gn", branch = "ninja_env" } +cargo_gn = { git = "https://github.com/denoland/cargo_gn" } # To avoid building V8 twice, we make sure that the core crate is built before # cli starts building. deno = { path = "../core" } diff --git a/core/Cargo.toml b/core/Cargo.toml index b3ae5a4084bb8a..3a2239edd9b6a2 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -36,5 +36,5 @@ path = "examples/http_bench.rs" tokio = "0.1.18" [build-dependencies] -cargo_gn = { git = "https://github.com/afinch7/cargo_gn", branch = "ninja_env" } +cargo_gn = { git = "https://github.com/denoland/cargo_gn" } which = "2.0.1" From d8c87f42578d6ae2f2a7068ad84b4f6547f52458 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Thu, 29 Aug 2019 18:05:23 -0700 Subject: [PATCH 11/16] Format --- tools/build_common.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/build_common.rs b/tools/build_common.rs index 57f51ea5f64f8a..3b27fb5feffd52 100644 --- a/tools/build_common.rs +++ b/tools/build_common.rs @@ -66,14 +66,16 @@ fn setup() -> (PathBuf, Option) { "third_party/python_packages/win32", "third_party/python_packages/win32/lib", "third_party/python_packages/Pythonwin", - ].into_iter() + ] + .into_iter() .map(|p| { workspace_dir .join(p) .into_os_string() .into_string() .unwrap() - }).collect(); + }) + .collect(); let orig_path = String::from(";") + &env::var_os("PATH").unwrap().into_string().unwrap(); let path = workspace_dir From 6b767d0e84e5295ffb67fcb36ce4758da2666d19 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Thu, 29 Aug 2019 18:06:17 -0700 Subject: [PATCH 12/16] Don't use canonicalize This function is useless on windows and should never be used. --- tools/build_common.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tools/build_common.rs b/tools/build_common.rs index 3b27fb5feffd52..c1eea5548c5178 100644 --- a/tools/build_common.rs +++ b/tools/build_common.rs @@ -49,11 +49,8 @@ fn setup() -> (PathBuf, Option) { Err(_) => {} }; - let workspace_dir = env::current_dir() - .unwrap() - .join("../") - .canonicalize() - .unwrap(); + let cwd = env::current_dir().unwrap(); + let workspace_dir = cwd.parent().unwrap(); let ninja_env: Option = if !cfg!(target_os = "windows") { None From b4786a77acf88129327ed5fbfcb5ac77f2e99449 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Thu, 29 Aug 2019 18:19:54 -0700 Subject: [PATCH 13/16] Can never build debug on windows --- tools/build_common.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tools/build_common.rs b/tools/build_common.rs index c1eea5548c5178..e9728cb23dafa6 100644 --- a/tools/build_common.rs +++ b/tools/build_common.rs @@ -18,10 +18,17 @@ fn binary_downloads() { // This is essentially a re-write of the original tools/setup.py // but in rust. fn setup() -> (PathBuf, Option) { + let is_win = cfg!(target_os = "windows"); let is_debug = cargo_gn::is_debug(); + let mut gn_args: cargo_gn::GnArgs = Vec::new(); - if is_debug { + if is_debug && !is_win { gn_args.push("is_debug=true".to_string()); + } else if is_debug && is_win { + // Rust always links with the release flavor of the CRT. Chromium //build + // uses the debug version of the CRT when 'is_debug` is set, and there's no + // override. Therefore, we cannot build a debug V8 and use Rust to link it. + gn_args.push("is_debug=false".to_string()); } else { gn_args.push("is_official_build=true".to_string()); gn_args.push("symbol_level=0".to_string()); @@ -52,7 +59,7 @@ fn setup() -> (PathBuf, Option) { let cwd = env::current_dir().unwrap(); let workspace_dir = cwd.parent().unwrap(); - let ninja_env: Option = if !cfg!(target_os = "windows") { + let ninja_env: Option = if !is_win { None } else { // Windows needs special configuration. This is similar to the function of From 65352b3702e7f5c5621275fff4badb4d1e628fca Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Thu, 29 Aug 2019 21:03:47 -0700 Subject: [PATCH 14/16] Fix RLS builds --- cli/build.rs | 7 ++++--- core/build.rs | 17 ++++++++++++----- tools/build_common.rs | 15 +++++++++++++++ 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/cli/build.rs b/cli/build.rs index 5c9fb07f562f26..b2d9facc2f1da8 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -3,7 +3,8 @@ include!("../tools/build_common.rs"); fn main() { - // TODO(ry) When running "cargo check" only build "msg_rs" - let (_, ninja_env) = setup(); - cargo_gn::build("cli:deno_deps", ninja_env); + if !is_rls_build() { + let (_, ninja_env) = setup(); + cargo_gn::build("cli:deno_deps", ninja_env); + } } diff --git a/core/build.rs b/core/build.rs index 5945e4f1997459..43f47690911bb0 100644 --- a/core/build.rs +++ b/core/build.rs @@ -2,9 +2,16 @@ // Run "cargo build -vv" if you want to see gn output. include!("../tools/build_common.rs"); fn main() { - let (gn_out_path, ninja_env) = setup(); - cargo_gn::build("core:deno_core_deps", ninja_env); - - let d = gn_out_path.join("obj/core/libdeno/"); - println!("cargo:rustc-link-search=native={}", d.display()); + if !is_rls_build() { + let (gn_out_path, ninja_env) = setup(); + cargo_gn::build("core:deno_core_deps", ninja_env); + println!( + "cargo:rustc-link-search=native={}", + gn_out_path.join("obj/core/libdeno/").to_str().unwrap() + ); + } else { + // Enable the 'check-only' feature, which enables some workarounds in the + // rust source code to compile successfully without a bundle and snapshot. + println!("cargo:rustc-cfg=feature=\"check-only\""); + } } diff --git a/tools/build_common.rs b/tools/build_common.rs index e9728cb23dafa6..469c9959fa80e2 100644 --- a/tools/build_common.rs +++ b/tools/build_common.rs @@ -95,3 +95,18 @@ fn setup() -> (PathBuf, Option) { (cargo_gn::maybe_gen("..", gn_args), ninja_env) } + +/// Detect if we're being invoked by the rust language server (RLS). +/// When RLS is running "cargo check" to analyze the source code, we're not +/// trying to build a working executable, rather we're just compiling all +/// rust code. +/// Unfortunately we can't detect whether we're being run by `cargo check`. +fn is_rls_build() -> bool { + env::var_os("CARGO") + .map(PathBuf::from) + .as_ref() + .and_then(|p| p.file_stem()) + .and_then(|f| f.to_str()) + .map(|s| s.starts_with("rls")) + .unwrap_or(false) +} From bd903a262b5939df3a2af19b3c260388194d5ec1 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Fri, 30 Aug 2019 15:47:52 -0700 Subject: [PATCH 15/16] Add link to rust debug CRT issue --- tools/build_common.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/build_common.rs b/tools/build_common.rs index 469c9959fa80e2..b66b6297c07bce 100644 --- a/tools/build_common.rs +++ b/tools/build_common.rs @@ -28,6 +28,7 @@ fn setup() -> (PathBuf, Option) { // Rust always links with the release flavor of the CRT. Chromium //build // uses the debug version of the CRT when 'is_debug` is set, and there's no // override. Therefore, we cannot build a debug V8 and use Rust to link it. + // Rust issue: https://github.com/rust-lang/rust/issues/39016 gn_args.push("is_debug=false".to_string()); } else { gn_args.push("is_official_build=true".to_string()); From 6a580597b87357ff24543c86c1f7765b5578dadf Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Thu, 5 Sep 2019 13:25:19 -0400 Subject: [PATCH 16/16] update Cargo.lock --- Cargo.lock | 1 - 1 file changed, 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 060174046e1f0a..45916ebdab2c82 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -277,7 +277,6 @@ version = "0.17.0" dependencies = [ "ansi_term 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", - "cargo_gn 0.0.13 (git+https://github.com/denoland/cargo_gn)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "deno 0.17.0", "deno_cli_snapshots 0.17.0",