From 225f0773c444ef4157a5941ae9d2b052c25cfdaf Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Wed, 31 Oct 2018 03:55:16 -0400 Subject: [PATCH] Support cargo check on mac/linux. - Based on code from @qti3e and @piscisaureus in #724 and #1125 respectively. - TODO The DENO_BUILD_PATH env var must be supplied and must be an absolute path, this restriction should be removed in future work. --- .gitignore | 1 + .travis.yml | 4 ++- BUILD.gn | 102 ++++++++++++++++++++++++++++++---------------------- Cargo.toml | 8 ++++- build.rs | 41 +++++++++++++++++++++ 5 files changed, 111 insertions(+), 45 deletions(-) create mode 100644 build.rs diff --git a/.gitignore b/.gitignore index 98b064c7e6e9be..ec7b9640839be1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # build /out/ +/target/ *.pyc gclient_config.py_entries Cargo.lock diff --git a/.travis.yml b/.travis.yml index ff4e0c211d699a..5d494adcb343c8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,7 @@ env: - HOMEBREW_PATH=$HOME/homebrew/ - DENO_BUILD_ARGS="use_custom_libcxx=false use_sysroot=false" - DENO_BUILD_PATH=$HOME/out/Default + - CARGO_TARGET_DIR=$DENO_BUILD_PATH - DENO_BUILD_MODE=release - PATH=$TRAVIS_BUILD_DIR/third_party/llvm-build/Release+Asserts/bin:$CARGO_HOME/bin:$PATH - CCACHE_CPP2=yes @@ -88,8 +89,9 @@ before_script: script: - ./tools/lint.py - ./tools/test_format.py -- bash -c "sleep 2100; pkill ninja" & +- bash -c "sleep 2100; pkill ninja; pkill cargo" & - ./tools/build.py -j2 +- RUSTC_WRAPPER=sccache cargo check -j2 --release - ./tools/test.py $DENO_BUILD_PATH after_script: - ccache --show-stats diff --git a/BUILD.gn b/BUILD.gn index 37e89626eb5b4d..553188b0b4aa49 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -124,49 +124,10 @@ rust_executable("deno") { source_root = "src/main.rs" extern = main_extern deps = [ - ":libdeno", - ":msg_rs", - ":snapshot", + ":deno_deps", ] } -source_set("snapshot") { - sources = [ - "src/snapshot.cc", - ] - configs += [ ":deno_config" ] - inputs = [ - "$target_gen_dir/snapshot_deno.bin", - ] - deps = [ - ":create_snapshot_deno", - ] - - # snapshot.cc doesn't need to depend on libdeno, it just needs deno_buf. - include_dirs = [ "libdeno/" ] - - # src/snapshot.cc uses an assembly '.incbin' directive to embed the snapshot. - # This causes trouble when using sccache: since the snapshot file is not - # inlined by the c preprocessor, sccache doesn't take its contents into - # consideration, leading to false-positive cache hits. - # Maybe other caching tools have this issue too, but ccache is unaffected. - # Therefore, if a cc_wrapper is used that isn't ccache, include a generated - # header file that contains the the sha256 hash of the snapshot. - if (cc_wrapper != "" && cc_wrapper != "ccache") { - hash_h = "$target_gen_dir/bundle/hash.h" - inputs += [ hash_h ] - deps += [ ":bundle_hash_h" ] - if (is_win) { - cflags = [ "/FI" + rebase_path(hash_h, target_out_dir) ] - } else { - cflags = [ - "-include", - rebase_path(hash_h, target_out_dir), - ] - } - } -} - rust_executable("hyper_hello") { source_root = "tools/hyper_hello.rs" extern = [ @@ -208,8 +169,7 @@ v8_executable("test_cc") { # In particular no flatbuffers, no assets, no rust, no msg handlers. # Because snapshots are slow, it's important that snapshot_creator's # dependencies are minimal. -static_library("libdeno") { - complete_static_lib = true +source_set("libdeno") { sources = [ "libdeno/api.cc", "libdeno/binding.cc", @@ -219,11 +179,67 @@ static_library("libdeno") { "libdeno/internal.h", ] public_deps = [ - "third_party/v8:v8_monolith", + "third_party/v8:v8", + "third_party/v8:v8_libbase", + "third_party/v8:v8_libplatform", + "third_party/v8:v8_libsampler", + "//build/win:default_exe_manifest", ] configs += [ ":deno_config" ] } +static_library("deno_deps") { + complete_static_lib = true + public_deps = [ + ":libdeno", + ":msg_rs", + ":snapshot", + "third_party/v8:v8", + "third_party/v8:v8_libbase", + "third_party/v8:v8_libplatform", + "third_party/v8:v8_libsampler", + "//build/win:default_exe_manifest", + ] + configs += [ ":deno_config" ] +} + +static_library("snapshot") { + sources = [ + "src/snapshot.cc", + ] + configs += [ ":deno_config" ] + inputs = [ + "$target_gen_dir/snapshot_deno.bin", + ] + deps = [ + ":create_snapshot_deno", + ] + + # snapshot.cc doesn't need to depend on libdeno, it just needs deno_buf. + include_dirs = [ "libdeno/" ] + + # src/snapshot.cc uses an assembly '.incbin' directive to embed the snapshot. + # This causes trouble when using sccache: since the snapshot file is not + # inlined by the c preprocessor, sccache doesn't take its contents into + # consideration, leading to false-positive cache hits. + # Maybe other caching tools have this issue too, but ccache is unaffected. + # Therefore, if a cc_wrapper is used that isn't ccache, include a generated + # header file that contains the the sha256 hash of the snapshot. + if (cc_wrapper != "" && cc_wrapper != "ccache") { + hash_h = "$target_gen_dir/bundle/hash.h" + inputs += [ hash_h ] + deps += [ ":bundle_hash_h" ] + if (is_win) { + cflags = [ "/FI" + rebase_path(hash_h, target_out_dir) ] + } else { + cflags = [ + "-include", + rebase_path(hash_h, target_out_dir), + ] + } + } +} + executable("snapshot_creator") { sources = [ "libdeno/snapshot_creator.cc", diff --git a/Cargo.toml b/Cargo.toml index 96499adbd70b33..a06dd54779507c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,15 +13,21 @@ atty = "0.2.11" dirs = "1.0.4" flatbuffers = { path = "third_party/flatbuffers/rust/flatbuffers/" } futures = "0.1.25" +getopts = "0.2.18" hyper = "0.12.12" # The current version of hyper-rustls, 0.14.0, depends on tokio-core, which is # deprecated. hyper-rustls = { git = "https://github.com/ctz/hyper-rustls.git" } +lazy_static = "1.1.0" libc = "0.2.43" log = "0.4.5" rand = "0.4.3" +remove_dir_all = "0.5.1" ring = "0.13.2" tempfile = "3" tokio = "0.1.11" +tokio-executor = "0.1.5" +tokio-fs = "0.1.3" +tokio-io = "0.1.8" +tokio-threadpool = "0.1.6" url = "1.7.1" -getopts = "0.2.18" diff --git a/build.rs b/build.rs new file mode 100644 index 00000000000000..ab3d8e3292569b --- /dev/null +++ b/build.rs @@ -0,0 +1,41 @@ +// Copyright 2018 the Deno authors. All rights reserved. MIT license. + +// Run "cargo build -vv" if you want to see gn output. +// TODO For the time being you must set an env var DENO_BUILD_PATH +// which might be `pwd`/out/debug or `pwd`/out/release. +// TODO Currently DENO_BUILD_PATH must be absolute. +// TODO Combine DENO_BUILD_PATH and OUT_DIR. + +use std::env; +use std::process::Command; +use std::process::Stdio; + fn main() { + let mode = env::var("PROFILE").unwrap(); + let deno_build_path = env::var("DENO_BUILD_PATH").unwrap(); + + let status = Command::new("./tools/setup.py") + .env("DENO_BUILD_PATH", &deno_build_path) + .env("DENO_BUILD_MODE", &mode) + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) + .status() + .expect("setup.py failed"); + assert!(status.success()); + + // These configurations must be outputed after tools/setup.py is run. + println!("cargo:rustc-env=OUT_DIR={}", deno_build_path); + println!("cargo:rustc-link-search=native={}/obj", deno_build_path); + println!("cargo:rustc-link-lib=static=deno_deps"); + + let status = Command::new("python") + .env("DENO_BUILD_PATH", &deno_build_path) + .env("DENO_BUILD_MODE", &mode) + .arg("./tools/build.py") + .arg("deno_deps") + .arg("-v") + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) + .status() + .expect("build.py failed"); + assert!(status.success()); +}