diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2018-11-12 15:05:13 -0500 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-11-30 16:34:10 -0800 |
commit | 5d161f366fbc8df635f3b6082ed928ed305e2107 (patch) | |
tree | 6f12e7d43dd6122330599d73300f8ea6fcf186b1 | |
parent | b5c6bfa0c8a3df9598211bc68db5408f5eec147d (diff) |
Cargo and GN should build into same directory.
Currently gn builds into "target/debug"
however cargo tells gn to build into
"target/debug/build/deno-26d2b5325de0f0cf/out"
This patch changes it so that they both build into "target/debug".
-rw-r--r-- | build.rs | 30 |
1 files changed, 20 insertions, 10 deletions
@@ -13,22 +13,34 @@ fn main() { // matches the build modes we support. let mode = env::var("PROFILE").unwrap(); + let out_dir = env::var_os("OUT_DIR").unwrap(); + let out_dir = env::current_dir().unwrap().join(out_dir); + // Normally we configure GN+Ninja to build into Cargo's OUT_DIR. // However, when DENO_BUILD_PATH is set, perform the ninja build in that dir // instead. This is used by CI to avoid building V8 etc twice. - let out_dir = env::var_os("OUT_DIR").unwrap(); let gn_out_dir = match env::var_os("DENO_BUILD_PATH") { - None => abs_path(out_dir), - Some(deno_build_path) => abs_path(deno_build_path), + None => { + // out_dir looks like: "target/debug/build/deno-26d2b5325de0f0cf/out" + // The gn build is "target/debug" + // So we go up two directories. Blame cargo for these hacks. + let d = out_dir.parent().unwrap(); + let d = d.parent().unwrap(); + let d = d.parent().unwrap(); + PathBuf::from(d) + } + Some(deno_build_path) => PathBuf::from(deno_build_path), }; // Give cargo some instructions. We do this first so the `rerun-if-*-changed` // directives can take effect even if something the build itself fails. - println!("cargo:rustc-env=GN_OUT_DIR={}", gn_out_dir); - println!("cargo:rustc-link-search=native={}/obj", gn_out_dir); + println!("cargo:rustc-env=GN_OUT_DIR={}", normalize_path(&gn_out_dir)); + println!( + "cargo:rustc-link-search=native={}/obj", + normalize_path(&gn_out_dir) + ); println!("cargo:rustc-link-lib=static=deno_deps"); - println!("cargo:rerun-if-changed={}", abs_path("src/msg.fbs")); 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"); @@ -72,10 +84,8 @@ fn main() { // Utility function to make a path absolute, normalizing it to use forward // slashes only. The returned value is an owned String, otherwise panics. -fn abs_path<P: AsRef<Path>>(path: P) -> String { - env::current_dir() - .unwrap() - .join(path) +fn normalize_path(path: &Path) -> String { + path .to_str() .unwrap() .to_owned() |