2019-11-01 17:50:12 +00:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2019-10-31 16:03:44 +00:00
|
|
|
use cargo_gn;
|
|
|
|
use std::env;
|
|
|
|
use std::path::Path;
|
2019-11-30 02:58:29 +00:00
|
|
|
use std::path::PathBuf;
|
2019-10-31 16:03:44 +00:00
|
|
|
use std::process::Command;
|
|
|
|
use which::which;
|
2019-10-16 01:31:05 +00:00
|
|
|
|
|
|
|
fn main() {
|
2019-11-30 02:58:29 +00:00
|
|
|
env::set_var("DEPOT_TOOLS_WIN_TOOLCHAIN", "0");
|
2019-11-02 18:51:37 +00:00
|
|
|
|
2019-11-30 02:58:29 +00:00
|
|
|
// cargo publish doesn't like pyc files.
|
|
|
|
env::set_var("PYTHONDONTWRITEBYTECODE", "1");
|
|
|
|
|
|
|
|
// git submodule update --init --recursive
|
|
|
|
let libcxx_src = PathBuf::from("buildtools/third_party/libc++/trunk/src");
|
|
|
|
if !libcxx_src.is_dir() {
|
|
|
|
eprintln!(
|
|
|
|
"missing source code. Run 'git submodule update --init --recursive'"
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't build if "cargo doc" is being run.
|
|
|
|
if env::var_os("RUSTDOCFLAGS").is_some() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if need_gn_ninja_download() {
|
|
|
|
download_gn_ninja_binaries();
|
2019-10-31 16:03:44 +00:00
|
|
|
}
|
|
|
|
|
2019-11-01 21:28:09 +00:00
|
|
|
// On windows, rustc cannot link with a V8 debug build.
|
|
|
|
let mut gn_args = if cargo_gn::is_debug() && !cfg!(target_os = "windows") {
|
2019-10-31 16:03:44 +00:00
|
|
|
vec!["is_debug=true".to_string()]
|
|
|
|
} else {
|
|
|
|
vec!["is_debug=false".to_string()]
|
|
|
|
};
|
|
|
|
|
2019-11-30 02:58:29 +00:00
|
|
|
let clang_base_path = clang_download();
|
|
|
|
gn_args.push(format!("clang_base_path={:?}", clang_base_path));
|
|
|
|
|
2019-10-31 16:03:44 +00:00
|
|
|
if let Some(p) = env::var_os("SCCACHE") {
|
|
|
|
cc_wrapper(&mut gn_args, &Path::new(&p));
|
|
|
|
} else if let Ok(p) = which("sccache") {
|
|
|
|
cc_wrapper(&mut gn_args, &p);
|
|
|
|
} else {
|
|
|
|
println!("cargo:warning=Not using sccache");
|
|
|
|
}
|
2019-10-18 19:36:58 +00:00
|
|
|
|
2019-11-19 22:48:50 +00:00
|
|
|
let gn_root = env::var("CARGO_MANIFEST_DIR").unwrap();
|
2019-11-01 04:10:00 +00:00
|
|
|
|
|
|
|
let gn_out = cargo_gn::maybe_gen(&gn_root, gn_args);
|
2019-10-31 16:03:44 +00:00
|
|
|
assert!(gn_out.exists());
|
|
|
|
assert!(gn_out.join("args.gn").exists());
|
|
|
|
cargo_gn::build("rusty_v8");
|
2019-11-01 17:50:12 +00:00
|
|
|
|
2019-10-31 16:03:44 +00:00
|
|
|
println!("cargo:rustc-link-lib=static=rusty_v8");
|
2019-11-01 17:50:12 +00:00
|
|
|
|
2019-10-18 19:36:58 +00:00
|
|
|
if cfg!(target_os = "windows") {
|
|
|
|
println!("cargo:rustc-link-lib=dylib=winmm");
|
2019-11-16 00:21:34 +00:00
|
|
|
println!("cargo:rustc-link-lib=dylib=dbghelp");
|
2019-10-18 19:36:58 +00:00
|
|
|
}
|
2019-10-16 01:31:05 +00:00
|
|
|
}
|
2019-10-31 16:03:44 +00:00
|
|
|
|
2019-11-30 02:58:29 +00:00
|
|
|
fn platform() -> &'static str {
|
|
|
|
#[cfg(target_os = "windows")]
|
|
|
|
{
|
|
|
|
"win"
|
|
|
|
}
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
{
|
|
|
|
"linux64"
|
|
|
|
}
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
{
|
|
|
|
"mac"
|
2019-11-02 18:51:37 +00:00
|
|
|
}
|
2019-10-31 16:03:44 +00:00
|
|
|
}
|
|
|
|
|
2019-11-30 02:58:29 +00:00
|
|
|
fn download_gn_ninja_binaries() {
|
2019-11-01 04:10:00 +00:00
|
|
|
let root = env::current_dir().unwrap();
|
2019-11-30 02:58:29 +00:00
|
|
|
let out_dir = root.join(env::var_os("OUT_DIR").unwrap());
|
|
|
|
let status = Command::new("python")
|
|
|
|
.arg("./tools/gn_ninja_binaries.py")
|
|
|
|
.arg("--dir")
|
|
|
|
.arg(&out_dir)
|
|
|
|
.status()
|
|
|
|
.expect("gn_ninja_binaries.py download failed");
|
|
|
|
assert!(status.success());
|
2019-11-01 01:01:29 +00:00
|
|
|
|
2019-11-30 02:58:29 +00:00
|
|
|
let d = out_dir.join("gn_ninja_binaries").join(platform());
|
|
|
|
|
|
|
|
let gn = d.join("gn");
|
|
|
|
let ninja = d.join("ninja");
|
2019-11-01 04:10:00 +00:00
|
|
|
|
2019-11-30 02:58:29 +00:00
|
|
|
#[cfg(windows)]
|
|
|
|
let gn = gn.with_extension("exe");
|
|
|
|
#[cfg(windows)]
|
|
|
|
let ninja = ninja.with_extension("exe");
|
2019-10-31 16:03:44 +00:00
|
|
|
|
2019-11-30 02:58:29 +00:00
|
|
|
env::set_var("GN", gn);
|
|
|
|
env::set_var("NINJA", ninja);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn need_gn_ninja_download() -> bool {
|
|
|
|
!((which("ninja").is_ok() || env::var_os("NINJA").is_some())
|
|
|
|
&& env::var_os("GN").is_some())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Download chromium's clang into OUT_DIR because Cargo will not allow us to
|
|
|
|
// modify the source directory.
|
|
|
|
fn clang_download() -> PathBuf {
|
|
|
|
// TODO(ry) We can support clang 10 and above.... if that is installed use
|
|
|
|
// it.
|
|
|
|
/*
|
|
|
|
if let Ok(clang_path) = which("clang") {
|
|
|
|
//
|
|
|
|
let bin_path = clang_path.parent().unwrap();
|
|
|
|
return bin_path.parent().unwrap().to_path_buf();
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
let root = env::current_dir().unwrap();
|
|
|
|
let out_dir = env::var_os("OUT_DIR").unwrap();
|
|
|
|
let clang_base_path = root.join(out_dir).join("clang");
|
|
|
|
println!("clang_base_path {}", clang_base_path.display());
|
|
|
|
let status = Command::new("python")
|
|
|
|
.arg("./tools/clang/scripts/update.py")
|
|
|
|
.arg("--clang-dir")
|
|
|
|
.arg(&clang_base_path)
|
2019-11-01 17:50:12 +00:00
|
|
|
.status()
|
2019-11-30 02:58:29 +00:00
|
|
|
.expect("clang download failed");
|
2019-10-31 16:03:44 +00:00
|
|
|
assert!(status.success());
|
2019-11-30 02:58:29 +00:00
|
|
|
assert!(clang_base_path.exists());
|
|
|
|
clang_base_path
|
2019-10-31 16:03:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn cc_wrapper(gn_args: &mut Vec<String>, sccache_path: &Path) {
|
|
|
|
gn_args.push(format!("cc_wrapper={:?}", sccache_path));
|
|
|
|
// Disable treat_warnings_as_errors until this sccache bug is fixed:
|
|
|
|
// https://github.com/mozilla/sccache/issues/264
|
|
|
|
if cfg!(target_os = "windows") {
|
|
|
|
gn_args.push("treat_warnings_as_errors=false".to_string());
|
|
|
|
}
|
|
|
|
}
|