2022-01-08 03:09:52 +00:00
|
|
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
2020-09-06 00:34:02 +00:00
|
|
|
|
2022-06-24 13:04:45 +00: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 21:07:11 +00:00
|
|
|
use std::env;
|
2020-07-19 17:49:44 +00:00
|
|
|
use std::path::Path;
|
2019-09-02 21:07:11 +00:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
2020-07-19 17:49:44 +00:00
|
|
|
fn main() {
|
2020-12-14 14:15:16 +00:00
|
|
|
// Skip building from docs.rs.
|
|
|
|
if env::var_os("DOCS_RS").is_some() {
|
2020-07-19 17:49:44 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-16 13:47:15 +00: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 13:04:45 +00:00
|
|
|
|
|
|
|
println!("cargo:rustc-env=TARGET={}", env::var("TARGET").unwrap());
|
|
|
|
println!("cargo:rustc-env=PROFILE={}", env::var("PROFILE").unwrap());
|
2020-07-19 17:49:44 +00:00
|
|
|
|
2021-07-20 17:52:09 +00: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-17 00:25:44 +00:00
|
|
|
|
2020-11-02 17:40:33 +00:00
|
|
|
println!("cargo:rustc-env=GIT_COMMIT_HASH={}", git_commit_hash());
|
2021-07-20 17:52:09 +00: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-17 00:25:44 +00: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 17:19:37 +00: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 16:03:46 +00:00
|
|
|
}
|
2020-12-14 17:42:40 +00:00
|
|
|
|
2022-03-17 00:25:44 +00: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 13:04:45 +00: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 17:42:40 +00:00
|
|
|
.unwrap()
|
2022-06-24 13:04:45 +00: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 17:42:40 +00:00
|
|
|
}
|