#![deny(warnings)]
use std::env;use std::path::{self, Path, PathBuf};use std::process::Command;
fn main() { let gn_mode = if cfg!(target_os = "windows") { String::from("release") } else { env::var("PROFILE").unwrap() };
let cwd = env::current_dir().unwrap(); let gn_out_path = cwd.join(format!("target/{}", gn_mode)); let gn_out_dir = normalize_path(&gn_out_path);
println!("cargo:rerun-if-env-changed=DENO_BUILD_PATH"); println!("cargo:rerun-if-env-changed=APPVEYOR_REPO_COMMIT");
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);
println!("cargo:rustc-env=GN_OUT_DIR={}", gn_out_dir);
let gn_target;
if check_only { gn_target = "msg_rs";
println!("cargo:rustc-cfg=feature=\"check-only\""); } else { gn_target = "deno_deps";
println!("cargo:rustc-link-search=native={}/obj/libdeno", gn_out_dir); if cfg!(target_os = "windows") { println!("cargo:rustc-link-lib=static=libdeno"); } else { println!("cargo:rustc-link-lib=static=deno"); }
if cfg!(any(target_os = "macos", target_os = "freebsd")) { println!("cargo:rustc-link-lib=dylib=c++"); } else if cfg!(target_os = "windows") { for lib in vec!["dbghelp", "shlwapi", "winmm", "ws2_32"] { println!("cargo:rustc-link-lib={}", lib); } } }
if !gn_out_path.join("build.ninja").exists() { let status = Command::new("python") .env("DENO_BUILD_PATH", &gn_out_dir) .env("DENO_BUILD_MODE", &gn_mode) .arg("./tools/setup.py") .status() .expect("setup.py failed"); assert!(status.success()); }
let status = Command::new("python") .env("DENO_BUILD_PATH", &gn_out_dir) .env("DENO_BUILD_MODE", &gn_mode) .arg("./tools/build.py") .arg(gn_target) .arg("-v") .status() .expect("build.py failed"); assert!(status.success());}
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()}