From 5d161f366fbc8df635f3b6082ed928ed305e2107 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Mon, 12 Nov 2018 15:05:13 -0500 Subject: 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". --- build.rs | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/build.rs b/build.rs index 74c80ed55..64794934f 100644 --- a/build.rs +++ b/build.rs @@ -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>(path: P) -> String { - env::current_dir() - .unwrap() - .join(path) +fn normalize_path(path: &Path) -> String { + path .to_str() .unwrap() .to_owned() -- cgit v1.2.3