2022-01-07 22:09:52 -05:00
|
|
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
2020-09-05 20:34:02 -04:00
|
|
|
|
2022-06-24 09:04:45 -04:00
|
|
|
use deno_runtime::deno_broadcast_channel;
|
|
|
|
use deno_runtime::deno_console;
|
|
|
|
use deno_runtime::deno_crypto;
|
|
|
|
use deno_runtime::deno_fetch;
|
|
|
|
use deno_runtime::deno_net;
|
|
|
|
use deno_runtime::deno_url;
|
|
|
|
use deno_runtime::deno_web;
|
|
|
|
use deno_runtime::deno_websocket;
|
|
|
|
use deno_runtime::deno_webstorage;
|
|
|
|
|
2019-09-02 17:07:11 -04:00
|
|
|
use std::env;
|
2020-07-19 13:49:44 -04:00
|
|
|
use std::path::Path;
|
2019-09-02 17:07:11 -04:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
2020-07-19 13:49:44 -04:00
|
|
|
fn main() {
|
2020-12-14 09:15:16 -05:00
|
|
|
// Skip building from docs.rs.
|
|
|
|
if env::var_os("DOCS_RS").is_some() {
|
2020-07-19 13:49:44 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-16 09:47:15 -04:00
|
|
|
// Host snapshots won't work when cross compiling.
|
|
|
|
let target = env::var("TARGET").unwrap();
|
|
|
|
let host = env::var("HOST").unwrap();
|
|
|
|
if target != host {
|
|
|
|
panic!("Cross compiling with snapshot is not supported.");
|
|
|
|
}
|
2022-06-24 09:04:45 -04:00
|
|
|
|
|
|
|
println!("cargo:rustc-env=TARGET={}", env::var("TARGET").unwrap());
|
|
|
|
println!("cargo:rustc-env=PROFILE={}", env::var("PROFILE").unwrap());
|
2020-07-19 13:49:44 -04:00
|
|
|
|
2021-07-20 13:52:09 -04:00
|
|
|
if let Ok(c) = env::var("DENO_CANARY") {
|
|
|
|
println!("cargo:rustc-env=DENO_CANARY={}", c);
|
|
|
|
}
|
|
|
|
println!("cargo:rerun-if-env-changed=DENO_CANARY");
|
2022-03-16 20:25:44 -04:00
|
|
|
|
2020-11-02 12:40:33 -05:00
|
|
|
println!("cargo:rustc-env=GIT_COMMIT_HASH={}", git_commit_hash());
|
2021-07-20 13:52:09 -04:00
|
|
|
println!("cargo:rerun-if-env-changed=GIT_COMMIT_HASH");
|
|
|
|
|
|
|
|
println!("cargo:rustc-env=TS_VERSION={}", ts_version());
|
|
|
|
println!("cargo:rerun-if-env-changed=TS_VERSION");
|
|
|
|
|
2022-03-16 20:25:44 -04:00
|
|
|
println!(
|
|
|
|
"cargo:rustc-env=DENO_CONSOLE_LIB_PATH={}",
|
|
|
|
deno_console::get_declaration().display()
|
|
|
|
);
|
|
|
|
println!(
|
|
|
|
"cargo:rustc-env=DENO_URL_LIB_PATH={}",
|
|
|
|
deno_url::get_declaration().display()
|
|
|
|
);
|
|
|
|
println!(
|
|
|
|
"cargo:rustc-env=DENO_WEB_LIB_PATH={}",
|
|
|
|
deno_web::get_declaration().display()
|
|
|
|
);
|
|
|
|
println!(
|
|
|
|
"cargo:rustc-env=DENO_FETCH_LIB_PATH={}",
|
|
|
|
deno_fetch::get_declaration().display()
|
|
|
|
);
|
|
|
|
println!(
|
|
|
|
"cargo:rustc-env=DENO_WEBGPU_LIB_PATH={}",
|
|
|
|
deno_webgpu_get_declaration().display()
|
|
|
|
);
|
|
|
|
println!(
|
|
|
|
"cargo:rustc-env=DENO_WEBSOCKET_LIB_PATH={}",
|
|
|
|
deno_websocket::get_declaration().display()
|
|
|
|
);
|
|
|
|
println!(
|
|
|
|
"cargo:rustc-env=DENO_WEBSTORAGE_LIB_PATH={}",
|
|
|
|
deno_webstorage::get_declaration().display()
|
|
|
|
);
|
|
|
|
println!(
|
|
|
|
"cargo:rustc-env=DENO_CRYPTO_LIB_PATH={}",
|
|
|
|
deno_crypto::get_declaration().display()
|
|
|
|
);
|
|
|
|
println!(
|
|
|
|
"cargo:rustc-env=DENO_BROADCAST_CHANNEL_LIB_PATH={}",
|
|
|
|
deno_broadcast_channel::get_declaration().display()
|
|
|
|
);
|
|
|
|
println!(
|
|
|
|
"cargo:rustc-env=DENO_NET_LIB_PATH={}",
|
|
|
|
deno_net::get_declaration().display()
|
|
|
|
);
|
|
|
|
|
2020-07-22 13:19:37 -04:00
|
|
|
#[cfg(target_os = "windows")]
|
|
|
|
{
|
|
|
|
let mut res = winres::WindowsResource::new();
|
|
|
|
res.set_icon("deno.ico");
|
|
|
|
res.set_language(winapi::um::winnt::MAKELANGID(
|
|
|
|
winapi::um::winnt::LANG_ENGLISH,
|
|
|
|
winapi::um::winnt::SUBLANG_ENGLISH_US,
|
|
|
|
));
|
|
|
|
res.compile().unwrap();
|
|
|
|
}
|
2020-07-22 12:03:46 -04:00
|
|
|
}
|
2020-12-14 12:42:40 -05:00
|
|
|
|
2022-03-16 20:25:44 -04:00
|
|
|
fn deno_webgpu_get_declaration() -> PathBuf {
|
|
|
|
let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
|
|
|
|
manifest_dir.join("dts").join("lib.deno_webgpu.d.ts")
|
|
|
|
}
|
|
|
|
|
2022-06-24 09:04:45 -04:00
|
|
|
fn git_commit_hash() -> String {
|
|
|
|
if let Ok(output) = std::process::Command::new("git")
|
|
|
|
.arg("rev-list")
|
|
|
|
.arg("-1")
|
|
|
|
.arg("HEAD")
|
|
|
|
.output()
|
|
|
|
{
|
|
|
|
if output.status.success() {
|
|
|
|
std::str::from_utf8(&output.stdout[..40])
|
|
|
|
.unwrap()
|
|
|
|
.to_string()
|
|
|
|
} else {
|
|
|
|
// When not in git repository
|
|
|
|
// (e.g. when the user install by `cargo install deno`)
|
|
|
|
"UNKNOWN".to_string()
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// When there is no git command for some reason
|
|
|
|
"UNKNOWN".to_string()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn ts_version() -> String {
|
|
|
|
std::fs::read_to_string("tsc/00_typescript.js")
|
2020-12-14 12:42:40 -05:00
|
|
|
.unwrap()
|
2022-06-24 09:04:45 -04:00
|
|
|
.lines()
|
|
|
|
.find(|l| l.contains("ts.version = "))
|
|
|
|
.expect(
|
|
|
|
"Failed to find the pattern `ts.version = ` in typescript source code",
|
|
|
|
)
|
|
|
|
.chars()
|
|
|
|
.skip_while(|c| !char::is_numeric(*c))
|
|
|
|
.take_while(|c| *c != '"')
|
|
|
|
.collect::<String>()
|
2020-12-14 12:42:40 -05:00
|
|
|
}
|