diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/BUILD.gn | 79 | ||||
-rw-r--r-- | core/build.rs | 145 | ||||
-rw-r--r-- | core/libdeno/BUILD.gn | 9 |
3 files changed, 150 insertions, 83 deletions
diff --git a/core/BUILD.gn b/core/BUILD.gn deleted file mode 100644 index bf9d910c0..000000000 --- a/core/BUILD.gn +++ /dev/null @@ -1,79 +0,0 @@ -import("//build_extra/rust/rust.gni") - -group("default") { - testonly = true - deps = [ - ":deno", - ":deno_core_http_bench", - ":deno_core_http_bench_test", - ":deno_core_test", - ] -} - -group("deno_core_deps") { - deps = [ - "libdeno:libdeno_static_lib", - "libdeno:v8", - ] -} - -# deno does not depend on flatbuffers nor tokio. -main_extern_rlib = [ - "futures", - "libc", - "serde_json", - "log", - "url", -] - -rust_rlib("deno") { - source_root = "lib.rs" - deps = [ - ":deno_core_deps", - ] - extern_rlib = main_extern_rlib -} - -rust_test("deno_core_test") { - source_root = "lib.rs" - deps = [ - ":deno_core_deps", - ] - extern_rlib = main_extern_rlib -} - -http_bench_extern = [ - { - label = ":deno" - crate_name = "deno" - crate_type = "rlib" - }, -] -http_bench_extern_rlib = [ - "futures", - "lazy_static", - "libc", - "log", - "tokio", -] -if (is_win) { - http_bench_extern_rlib += [ "winapi" ] -} - -rust_executable("deno_core_http_bench") { - source_root = "examples/http_bench.rs" - deps = [ - ":deno_core_deps", - ] - extern = http_bench_extern - extern_rlib = http_bench_extern_rlib -} - -rust_test("deno_core_http_bench_test") { - source_root = "examples/http_bench.rs" - deps = [ - ":deno_core_deps", - ] - extern = http_bench_extern - extern_rlib = http_bench_extern_rlib -} diff --git a/core/build.rs b/core/build.rs index 43e993dc9..83569eeee 100644 --- a/core/build.rs +++ b/core/build.rs @@ -1,8 +1,5 @@ // 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"); -} fn main() { let build = gn::Build::setup(); @@ -12,5 +9,145 @@ fn main() { build.gn_out_dir ); - build.run("core:deno_core_deps"); + build.run("core/libdeno:default"); +} + +mod gn { + use std::env; + use std::path::{self, Path, PathBuf}; + use std::process::Command; + + pub struct Build { + gn_mode: String, + root: PathBuf, + pub gn_out_dir: String, + pub gn_out_path: PathBuf, + pub check_only: bool, + } + + impl Build { + pub fn setup() -> Build { + let gn_mode = if cfg!(target_os = "windows") { + // On Windows, we need to link with a release build of libdeno, because + // rust always uses the release CRT. + // TODO(piscisaureus): make linking with debug libdeno possible. + String::from("release") + } else { + // Cargo sets PROFILE to either "debug" or "release", which conveniently + // matches the build modes we support. + env::var("PROFILE").unwrap() + }; + + // cd into workspace root. + assert!(env::set_current_dir("..").is_ok()); + + let root = env::current_dir().unwrap(); + // If not using host default target the output folder will change + // target/release will become target/$TARGET/release + // Gn should also be using this output directory as well + // most things will work with gn using the default + // output directory but some tests depend on artifacts + // being in a specific directory relative to the main build output + let gn_out_path = root.join(format!("target/{}", gn_mode.clone())); + let gn_out_dir = normalize_path(&gn_out_path); + + // Tell Cargo when to re-run this file. We do this first, so these directives + // can take effect even if something goes wrong later in the build process. + println!("cargo:rerun-if-env-changed=DENO_BUILD_PATH"); + // TODO: this is obviously not appropriate here. + println!("cargo:rerun-if-env-changed=APPVEYOR_REPO_COMMIT"); + + // This helps Rust source files locate the snapshot, source map etc. + println!("cargo:rustc-env=GN_OUT_DIR={}", gn_out_dir); + + // Detect if we're being invoked by the rust language server (RLS). + // Unfortunately we can't detect whether we're being run by `cargo check`. + let check_only = 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); + + if check_only { + // 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\""); + } + + Build { + gn_out_dir, + gn_out_path, + check_only, + gn_mode, + root, + } + } + + pub fn run(&self, gn_target: &str) { + if !self.gn_out_path.join("build.ninja").exists() { + let mut cmd = Command::new("python"); + cmd.env("DENO_BUILD_PATH", &self.gn_out_dir); + cmd.env("DENO_BUILD_MODE", &self.gn_mode); + cmd.env("DEPOT_TOOLS_WIN_TOOLCHAIN", "0"); + cmd.arg("./tools/setup.py"); + if env::var_os("DENO_NO_BINARY_DOWNLOAD").is_some() { + cmd.arg("--no-binary-download"); + } + let status = cmd.status().expect("setup.py failed"); + assert!(status.success()); + } + + let mut ninja = Command::new("third_party/depot_tools/ninja"); + let ninja = if !cfg!(target_os = "windows") { + &mut ninja + } else { + // Windows needs special configuration. This is similar to the function of + // python_env() in //tools/util.py. + let python_path: Vec<String> = 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| self.root.join(p).into_os_string().into_string().unwrap()) + .collect(); + let orig_path = String::from(";") + + &env::var_os("PATH").unwrap().into_string().unwrap(); + let path = self + .root + .join("third_party/python_packages/pywin32_system32") + .into_os_string() + .into_string() + .unwrap(); + ninja + .env("PYTHONPATH", python_path.join(";")) + .env("PATH", path + &orig_path) + .env("DEPOT_TOOLS_WIN_TOOLCHAIN", "0") + }; + + let status = ninja + .arg(gn_target) + .arg("-C") + .arg(&self.gn_out_dir) + .status() + .expect("ninja failed"); + assert!(status.success()); + } + } + + // Utility function to make a path absolute, normalizing it to use forward + // slashes only. The returned value is an owned String, otherwise panics. + fn normalize_path<T: AsRef<Path>>(path: T) -> String { + path + .as_ref() + .to_str() + .unwrap() + .to_owned() + .chars() + .map(|c| if path::is_separator(c) { '/' } else { c }) + .collect() + } } diff --git a/core/libdeno/BUILD.gn b/core/libdeno/BUILD.gn index 2623fef2d..6bbda98c5 100644 --- a/core/libdeno/BUILD.gn +++ b/core/libdeno/BUILD.gn @@ -1,6 +1,15 @@ # Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. import("//third_party/v8/gni/v8.gni") +group("default") { + testonly = true + deps = [ + ":libdeno_static_lib", + ":libdeno_test", + ":v8", + ] +} + config("deno_config") { include_dirs = [ "//third_party/v8" ] # This allows us to v8/src/base/ libraries. configs = [ "//third_party/v8:external_config" ] |