2024-01-01 19:58:21 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2020-09-06 00:34:02 +00:00
|
|
|
|
2019-09-02 21:07:11 +00:00
|
|
|
use std::env;
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
2024-02-17 22:22:46 +00:00
|
|
|
use deno_core::snapshot::*;
|
2022-11-21 13:36:26 +00:00
|
|
|
use deno_runtime::*;
|
2024-08-15 21:47:16 +00:00
|
|
|
mod shared;
|
2022-11-21 13:36:26 +00:00
|
|
|
|
|
|
|
mod ts {
|
|
|
|
use super::*;
|
|
|
|
use deno_core::error::custom_error;
|
|
|
|
use deno_core::error::AnyError;
|
2023-09-12 11:14:45 +00:00
|
|
|
use deno_core::op2;
|
2022-11-21 13:36:26 +00:00
|
|
|
use deno_core::OpState;
|
2023-09-12 00:55:57 +00:00
|
|
|
use serde::Serialize;
|
2022-11-21 13:36:26 +00:00
|
|
|
use std::collections::HashMap;
|
2024-02-27 15:05:57 +00:00
|
|
|
use std::io::Write;
|
2022-11-21 13:36:26 +00:00
|
|
|
use std::path::Path;
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
2023-09-12 00:55:57 +00:00
|
|
|
#[derive(Debug, Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
struct BuildInfoResponse {
|
|
|
|
build_specifier: String,
|
|
|
|
libs: Vec<String>,
|
|
|
|
}
|
2023-03-17 18:22:15 +00:00
|
|
|
|
2023-09-12 11:14:45 +00:00
|
|
|
#[op2]
|
|
|
|
#[serde]
|
|
|
|
fn op_build_info(state: &mut OpState) -> BuildInfoResponse {
|
2023-09-12 00:55:57 +00:00
|
|
|
let build_specifier = "asset:///bootstrap.ts".to_string();
|
|
|
|
let build_libs = state
|
|
|
|
.borrow::<Vec<&str>>()
|
|
|
|
.iter()
|
|
|
|
.map(|s| s.to_string())
|
|
|
|
.collect();
|
|
|
|
BuildInfoResponse {
|
|
|
|
build_specifier,
|
|
|
|
libs: build_libs,
|
|
|
|
}
|
2023-03-17 18:22:15 +00:00
|
|
|
}
|
|
|
|
|
2023-09-12 11:14:45 +00:00
|
|
|
#[op2(fast)]
|
2023-03-17 18:22:15 +00:00
|
|
|
fn op_is_node_file() -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
2023-09-12 11:14:45 +00:00
|
|
|
#[op2]
|
|
|
|
#[string]
|
2023-03-17 18:22:15 +00:00
|
|
|
fn op_script_version(
|
|
|
|
_state: &mut OpState,
|
2023-12-01 21:57:52 +00:00
|
|
|
#[string] _arg: &str,
|
2023-03-17 18:22:15 +00:00
|
|
|
) -> Result<Option<String>, AnyError> {
|
|
|
|
Ok(Some("1".to_string()))
|
|
|
|
}
|
|
|
|
|
2023-09-12 00:55:57 +00:00
|
|
|
#[derive(Debug, Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
struct LoadResponse {
|
|
|
|
data: String,
|
|
|
|
version: String,
|
|
|
|
script_kind: i32,
|
|
|
|
}
|
|
|
|
|
2023-09-12 11:14:45 +00:00
|
|
|
#[op2]
|
|
|
|
#[serde]
|
2023-03-17 18:22:15 +00:00
|
|
|
// using the same op that is used in `tsc.rs` for loading modules and reading
|
|
|
|
// files, but a slightly different implementation at build time.
|
2023-09-12 00:55:57 +00:00
|
|
|
fn op_load(
|
|
|
|
state: &mut OpState,
|
2023-12-03 02:07:04 +00:00
|
|
|
#[string] load_specifier: &str,
|
2023-09-12 00:55:57 +00:00
|
|
|
) -> Result<LoadResponse, AnyError> {
|
2023-03-17 18:22:15 +00:00
|
|
|
let op_crate_libs = state.borrow::<HashMap<&str, PathBuf>>();
|
|
|
|
let path_dts = state.borrow::<PathBuf>();
|
2023-04-13 01:08:01 +00:00
|
|
|
let re_asset = lazy_regex::regex!(r"asset:/{3}lib\.(\S+)\.d\.ts");
|
2023-03-17 18:22:15 +00:00
|
|
|
let build_specifier = "asset:///bootstrap.ts";
|
|
|
|
|
|
|
|
// we need a basic file to send to tsc to warm it up.
|
2023-12-03 02:07:04 +00:00
|
|
|
if load_specifier == build_specifier {
|
2023-09-12 00:55:57 +00:00
|
|
|
Ok(LoadResponse {
|
|
|
|
data: r#"Deno.writeTextFile("hello.txt", "hello deno!");"#.to_string(),
|
|
|
|
version: "1".to_string(),
|
2023-03-17 18:22:15 +00:00
|
|
|
// this corresponds to `ts.ScriptKind.TypeScript`
|
2023-09-12 00:55:57 +00:00
|
|
|
script_kind: 3,
|
|
|
|
})
|
2023-03-17 18:22:15 +00:00
|
|
|
// specifiers come across as `asset:///lib.{lib_name}.d.ts` and we need to
|
|
|
|
// parse out just the name so we can lookup the asset.
|
2023-12-03 02:07:04 +00:00
|
|
|
} else if let Some(caps) = re_asset.captures(load_specifier) {
|
2023-03-17 18:22:15 +00:00
|
|
|
if let Some(lib) = caps.get(1).map(|m| m.as_str()) {
|
|
|
|
// if it comes from an op crate, we were supplied with the path to the
|
|
|
|
// file.
|
|
|
|
let path = if let Some(op_crate_lib) = op_crate_libs.get(lib) {
|
|
|
|
PathBuf::from(op_crate_lib).canonicalize()?
|
|
|
|
// otherwise we will generate the path ourself
|
|
|
|
} else {
|
|
|
|
path_dts.join(format!("lib.{lib}.d.ts"))
|
|
|
|
};
|
|
|
|
let data = std::fs::read_to_string(path)?;
|
2023-09-12 00:55:57 +00:00
|
|
|
Ok(LoadResponse {
|
|
|
|
data,
|
|
|
|
version: "1".to_string(),
|
2023-03-17 18:22:15 +00:00
|
|
|
// this corresponds to `ts.ScriptKind.TypeScript`
|
2023-09-12 00:55:57 +00:00
|
|
|
script_kind: 3,
|
|
|
|
})
|
2023-03-17 18:22:15 +00:00
|
|
|
} else {
|
|
|
|
Err(custom_error(
|
|
|
|
"InvalidSpecifier",
|
2023-12-03 02:07:04 +00:00
|
|
|
format!("An invalid specifier was requested: {}", load_specifier),
|
2023-03-17 18:22:15 +00:00
|
|
|
))
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Err(custom_error(
|
|
|
|
"InvalidSpecifier",
|
2023-12-03 02:07:04 +00:00
|
|
|
format!("An invalid specifier was requested: {}", load_specifier),
|
2023-03-17 18:22:15 +00:00
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
deno_core::extension!(deno_tsc,
|
|
|
|
ops = [op_build_info, op_is_node_file, op_load, op_script_version],
|
|
|
|
js = [
|
|
|
|
dir "tsc",
|
|
|
|
"00_typescript.js",
|
|
|
|
"99_main_compiler.js",
|
|
|
|
],
|
2023-03-17 22:15:27 +00:00
|
|
|
options = {
|
2023-03-17 18:22:15 +00:00
|
|
|
op_crate_libs: HashMap<&'static str, PathBuf>,
|
|
|
|
build_libs: Vec<&'static str>,
|
|
|
|
path_dts: PathBuf,
|
|
|
|
},
|
2023-03-17 22:15:27 +00:00
|
|
|
state = |state, options| {
|
|
|
|
state.put(options.op_crate_libs);
|
|
|
|
state.put(options.build_libs);
|
|
|
|
state.put(options.path_dts);
|
2023-03-17 18:22:15 +00:00
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2023-02-08 21:40:18 +00:00
|
|
|
pub fn create_compiler_snapshot(snapshot_path: PathBuf, cwd: &Path) {
|
2022-11-21 13:36:26 +00:00
|
|
|
// libs that are being provided by op crates.
|
|
|
|
let mut op_crate_libs = HashMap::new();
|
|
|
|
op_crate_libs.insert("deno.cache", deno_cache::get_declaration());
|
|
|
|
op_crate_libs.insert("deno.console", deno_console::get_declaration());
|
|
|
|
op_crate_libs.insert("deno.url", deno_url::get_declaration());
|
|
|
|
op_crate_libs.insert("deno.web", deno_web::get_declaration());
|
|
|
|
op_crate_libs.insert("deno.fetch", deno_fetch::get_declaration());
|
2023-12-09 00:19:16 +00:00
|
|
|
op_crate_libs.insert("deno.webgpu", deno_webgpu_get_declaration());
|
2022-11-21 13:36:26 +00:00
|
|
|
op_crate_libs.insert("deno.websocket", deno_websocket::get_declaration());
|
|
|
|
op_crate_libs.insert("deno.webstorage", deno_webstorage::get_declaration());
|
2024-01-22 11:08:01 +00:00
|
|
|
op_crate_libs.insert("deno.canvas", deno_canvas::get_declaration());
|
2022-11-21 13:36:26 +00:00
|
|
|
op_crate_libs.insert("deno.crypto", deno_crypto::get_declaration());
|
|
|
|
op_crate_libs.insert(
|
|
|
|
"deno.broadcast_channel",
|
|
|
|
deno_broadcast_channel::get_declaration(),
|
2022-07-04 22:12:41 +00:00
|
|
|
);
|
2022-11-21 13:36:26 +00:00
|
|
|
op_crate_libs.insert("deno.net", deno_net::get_declaration());
|
2022-07-04 22:12:41 +00:00
|
|
|
|
2022-11-21 13:36:26 +00:00
|
|
|
// ensure we invalidate the build properly.
|
|
|
|
for (_, path) in op_crate_libs.iter() {
|
|
|
|
println!("cargo:rerun-if-changed={}", path.display());
|
|
|
|
}
|
2022-07-04 22:12:41 +00:00
|
|
|
|
2022-11-21 13:36:26 +00:00
|
|
|
// libs that should be loaded into the isolate before snapshotting.
|
|
|
|
let libs = vec![
|
|
|
|
// Deno custom type libraries
|
|
|
|
"deno.window",
|
|
|
|
"deno.worker",
|
|
|
|
"deno.shared_globals",
|
|
|
|
"deno.ns",
|
|
|
|
"deno.unstable",
|
|
|
|
// Deno built-in type libraries
|
2023-03-21 15:46:40 +00:00
|
|
|
"decorators",
|
|
|
|
"decorators.legacy",
|
2022-11-21 13:36:26 +00:00
|
|
|
"es5",
|
|
|
|
"es2015.collection",
|
|
|
|
"es2015.core",
|
|
|
|
"es2015",
|
|
|
|
"es2015.generator",
|
|
|
|
"es2015.iterable",
|
|
|
|
"es2015.promise",
|
|
|
|
"es2015.proxy",
|
|
|
|
"es2015.reflect",
|
|
|
|
"es2015.symbol",
|
|
|
|
"es2015.symbol.wellknown",
|
|
|
|
"es2016.array.include",
|
2024-03-26 22:52:57 +00:00
|
|
|
"es2016.intl",
|
2022-11-21 13:36:26 +00:00
|
|
|
"es2016",
|
|
|
|
"es2017",
|
2023-09-09 19:03:21 +00:00
|
|
|
"es2017.date",
|
2022-11-21 13:36:26 +00:00
|
|
|
"es2017.intl",
|
|
|
|
"es2017.object",
|
|
|
|
"es2017.sharedmemory",
|
|
|
|
"es2017.string",
|
|
|
|
"es2017.typedarrays",
|
|
|
|
"es2018.asyncgenerator",
|
|
|
|
"es2018.asynciterable",
|
|
|
|
"es2018",
|
|
|
|
"es2018.intl",
|
|
|
|
"es2018.promise",
|
|
|
|
"es2018.regexp",
|
|
|
|
"es2019.array",
|
|
|
|
"es2019",
|
2023-01-14 14:36:19 +00:00
|
|
|
"es2019.intl",
|
2022-11-21 13:36:26 +00:00
|
|
|
"es2019.object",
|
|
|
|
"es2019.string",
|
|
|
|
"es2019.symbol",
|
|
|
|
"es2020.bigint",
|
|
|
|
"es2020",
|
|
|
|
"es2020.date",
|
|
|
|
"es2020.intl",
|
|
|
|
"es2020.number",
|
|
|
|
"es2020.promise",
|
|
|
|
"es2020.sharedmemory",
|
|
|
|
"es2020.string",
|
|
|
|
"es2020.symbol.wellknown",
|
|
|
|
"es2021",
|
|
|
|
"es2021.intl",
|
|
|
|
"es2021.promise",
|
|
|
|
"es2021.string",
|
|
|
|
"es2021.weakref",
|
|
|
|
"es2022",
|
|
|
|
"es2022.array",
|
|
|
|
"es2022.error",
|
|
|
|
"es2022.intl",
|
|
|
|
"es2022.object",
|
2023-03-21 15:46:40 +00:00
|
|
|
"es2022.regexp",
|
2023-01-14 14:36:19 +00:00
|
|
|
"es2022.sharedmemory",
|
2022-11-21 13:36:26 +00:00
|
|
|
"es2022.string",
|
2023-03-21 15:46:40 +00:00
|
|
|
"es2023",
|
|
|
|
"es2023.array",
|
2023-09-09 19:03:21 +00:00
|
|
|
"es2023.collection",
|
2024-07-03 14:09:54 +00:00
|
|
|
"es2023.intl",
|
2022-11-21 13:36:26 +00:00
|
|
|
"esnext",
|
|
|
|
"esnext.array",
|
2024-03-26 22:52:57 +00:00
|
|
|
"esnext.collection",
|
2023-09-09 19:03:21 +00:00
|
|
|
"esnext.decorators",
|
|
|
|
"esnext.disposable",
|
2022-11-21 13:36:26 +00:00
|
|
|
"esnext.intl",
|
2024-09-14 10:58:47 +00:00
|
|
|
"esnext.iterator",
|
2023-11-01 23:18:41 +00:00
|
|
|
"esnext.object",
|
2024-03-26 22:52:57 +00:00
|
|
|
"esnext.promise",
|
2024-07-03 14:09:54 +00:00
|
|
|
"esnext.regexp",
|
|
|
|
"esnext.string",
|
2022-11-21 13:36:26 +00:00
|
|
|
];
|
|
|
|
|
2022-11-25 23:29:48 +00:00
|
|
|
let path_dts = cwd.join("tsc/dts");
|
2022-11-21 13:36:26 +00:00
|
|
|
// ensure we invalidate the build properly.
|
|
|
|
for name in libs.iter() {
|
|
|
|
println!(
|
|
|
|
"cargo:rerun-if-changed={}",
|
2023-01-27 15:43:16 +00:00
|
|
|
path_dts.join(format!("lib.{name}.d.ts")).display()
|
2022-11-21 13:36:26 +00:00
|
|
|
);
|
|
|
|
}
|
2022-07-04 22:12:41 +00:00
|
|
|
|
2022-11-21 13:36:26 +00:00
|
|
|
// create a copy of the vector that includes any op crate libs to be passed
|
|
|
|
// to the JavaScript compiler to build into the snapshot
|
|
|
|
let mut build_libs = libs.clone();
|
|
|
|
for (op_lib, _) in op_crate_libs.iter() {
|
|
|
|
build_libs.push(op_lib.to_owned());
|
|
|
|
}
|
2022-07-04 22:12:41 +00:00
|
|
|
|
2023-01-14 14:36:19 +00:00
|
|
|
// used in the tests to verify that after snapshotting it has the same number
|
|
|
|
// of lib files loaded and hasn't included any ones lazily loaded from Rust
|
|
|
|
std::fs::write(
|
|
|
|
PathBuf::from(env::var_os("OUT_DIR").unwrap())
|
|
|
|
.join("lib_file_names.json"),
|
|
|
|
serde_json::to_string(&build_libs).unwrap(),
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
2024-02-14 02:44:37 +00:00
|
|
|
let output = create_snapshot(
|
|
|
|
CreateSnapshotOptions {
|
|
|
|
cargo_manifest_dir: env!("CARGO_MANIFEST_DIR"),
|
|
|
|
startup_snapshot: None,
|
|
|
|
extensions: vec![deno_tsc::init_ops_and_esm(
|
|
|
|
op_crate_libs,
|
|
|
|
build_libs,
|
|
|
|
path_dts,
|
|
|
|
)],
|
2024-03-05 01:17:39 +00:00
|
|
|
extension_transpiler: None,
|
2024-02-14 02:44:37 +00:00
|
|
|
with_runtime_cb: None,
|
|
|
|
skip_op_registration: false,
|
|
|
|
},
|
|
|
|
None,
|
2024-02-17 22:22:46 +00:00
|
|
|
)
|
|
|
|
.unwrap();
|
2024-02-27 15:05:57 +00:00
|
|
|
|
|
|
|
// NOTE(bartlomieju): Compressing the TSC snapshot in debug build took
|
|
|
|
// ~45s on M1 MacBook Pro; without compression it took ~1s.
|
2024-04-12 14:33:43 +00:00
|
|
|
// Thus we're not using compressed snapshot, trading off
|
2024-02-27 15:05:57 +00:00
|
|
|
// a lot of build time for some startup time in debug build.
|
|
|
|
let mut file = std::fs::File::create(snapshot_path).unwrap();
|
|
|
|
if cfg!(debug_assertions) {
|
|
|
|
file.write_all(&output.output).unwrap();
|
|
|
|
} else {
|
|
|
|
let mut vec = Vec::with_capacity(output.output.len());
|
|
|
|
vec.extend((output.output.len() as u32).to_le_bytes());
|
|
|
|
vec.extend_from_slice(
|
|
|
|
&zstd::bulk::compress(&output.output, 22)
|
|
|
|
.expect("snapshot compression failed"),
|
|
|
|
);
|
|
|
|
file.write_all(&vec).unwrap();
|
|
|
|
}
|
|
|
|
|
2023-06-13 22:36:16 +00:00
|
|
|
for path in output.files_loaded_during_snapshot {
|
|
|
|
println!("cargo:rerun-if-changed={}", path.display());
|
|
|
|
}
|
2022-07-04 22:12:41 +00:00
|
|
|
}
|
|
|
|
|
2022-11-21 13:36:26 +00:00
|
|
|
pub(crate) fn version() -> String {
|
2022-12-07 17:59:59 +00:00
|
|
|
let file_text = std::fs::read_to_string("tsc/00_typescript.js").unwrap();
|
2024-07-03 14:09:54 +00:00
|
|
|
let version_text = " version = \"";
|
2022-12-07 17:59:59 +00:00
|
|
|
for line in file_text.lines() {
|
2023-03-21 15:46:40 +00:00
|
|
|
if let Some(index) = line.find(version_text) {
|
2022-12-07 17:59:59 +00:00
|
|
|
let remaining_line = &line[index + version_text.len()..];
|
2023-03-21 15:46:40 +00:00
|
|
|
return remaining_line[..remaining_line.find('"').unwrap()].to_string();
|
2022-12-07 17:59:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
panic!("Could not find ts version.")
|
2022-11-21 13:36:26 +00:00
|
|
|
}
|
2022-07-04 22:12:41 +00:00
|
|
|
}
|
|
|
|
|
2024-07-05 12:17:53 +00:00
|
|
|
#[cfg(not(feature = "hmr"))]
|
2023-12-02 23:40:27 +00:00
|
|
|
fn create_cli_snapshot(snapshot_path: PathBuf) {
|
2023-11-15 12:25:55 +00:00
|
|
|
use deno_runtime::ops::bootstrap::SnapshotOptions;
|
2023-08-05 23:47:15 +00:00
|
|
|
|
2023-12-02 23:40:27 +00:00
|
|
|
let snapshot_options = SnapshotOptions {
|
|
|
|
ts_version: ts::version(),
|
2024-08-19 14:51:16 +00:00
|
|
|
v8_version: deno_core::v8::VERSION_STRING,
|
2023-12-02 23:40:27 +00:00
|
|
|
target: std::env::var("TARGET").unwrap(),
|
|
|
|
};
|
|
|
|
|
|
|
|
deno_runtime::snapshot::create_runtime_snapshot(
|
2022-11-21 13:36:26 +00:00
|
|
|
snapshot_path,
|
2023-12-02 23:40:27 +00:00
|
|
|
snapshot_options,
|
2024-05-01 22:00:32 +00:00
|
|
|
vec![],
|
2023-12-02 23:40:27 +00:00
|
|
|
);
|
2022-07-04 22:12:41 +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()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2024-10-24 07:13:54 +00:00
|
|
|
deno_napi::print_linker_flags("deno");
|
|
|
|
deno_napi::print_linker_flags("denort");
|
|
|
|
|
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();
|
2023-09-17 16:06:51 +00:00
|
|
|
let skip_cross_check =
|
|
|
|
env::var("DENO_SKIP_CROSS_BUILD_CHECK").map_or(false, |v| v == "1");
|
|
|
|
if !skip_cross_check && target != host {
|
2022-03-16 13:47:15 +00:00
|
|
|
panic!("Cross compiling with snapshot is not supported.");
|
|
|
|
}
|
2022-10-05 14:06:44 +00:00
|
|
|
|
2022-07-04 22:12:41 +00:00
|
|
|
// To debug snapshot issues uncomment:
|
|
|
|
// op_fetch_asset::trace_serializer();
|
2020-07-19 17:49:44 +00:00
|
|
|
|
2021-07-20 17:52:09 +00:00
|
|
|
if let Ok(c) = env::var("DENO_CANARY") {
|
2023-01-27 15:43:16 +00:00
|
|
|
println!("cargo:rustc-env=DENO_CANARY={c}");
|
2021-07-20 17:52:09 +00:00
|
|
|
}
|
|
|
|
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");
|
2023-03-23 22:27:58 +00:00
|
|
|
println!(
|
|
|
|
"cargo:rustc-env=GIT_COMMIT_HASH_SHORT={}",
|
|
|
|
&git_commit_hash()[..7]
|
|
|
|
);
|
2021-07-20 17:52:09 +00:00
|
|
|
|
2023-03-21 15:46:40 +00:00
|
|
|
let ts_version = ts::version();
|
2024-09-14 10:58:47 +00:00
|
|
|
debug_assert_eq!(ts_version, "5.6.2"); // bump this assertion when it changes
|
2023-03-21 15:46:40 +00:00
|
|
|
println!("cargo:rustc-env=TS_VERSION={}", ts_version);
|
2021-07-20 17:52:09 +00:00
|
|
|
println!("cargo:rerun-if-env-changed=TS_VERSION");
|
|
|
|
|
2022-07-04 22:12:41 +00:00
|
|
|
println!("cargo:rustc-env=TARGET={}", env::var("TARGET").unwrap());
|
|
|
|
println!("cargo:rustc-env=PROFILE={}", env::var("PROFILE").unwrap());
|
|
|
|
|
2024-11-18 20:44:17 +00:00
|
|
|
if cfg!(windows) {
|
|
|
|
// these dls load slowly, so delay loading them
|
|
|
|
let dlls = [
|
|
|
|
// webgpu
|
|
|
|
"d3dcompiler_47",
|
|
|
|
"OPENGL32",
|
|
|
|
// network related functions
|
|
|
|
"iphlpapi",
|
|
|
|
];
|
|
|
|
for dll in dlls {
|
|
|
|
println!("cargo:rustc-link-arg-bin=deno=/delayload:{dll}.dll");
|
|
|
|
println!("cargo:rustc-link-arg-bin=denort=/delayload:{dll}.dll");
|
|
|
|
}
|
|
|
|
// enable delay loading
|
|
|
|
println!("cargo:rustc-link-arg-bin=deno=delayimp.lib");
|
|
|
|
println!("cargo:rustc-link-arg-bin=denort=delayimp.lib");
|
|
|
|
}
|
|
|
|
|
2022-07-04 22:12:41 +00:00
|
|
|
let c = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
|
|
|
|
let o = PathBuf::from(env::var_os("OUT_DIR").unwrap());
|
|
|
|
|
|
|
|
let compiler_snapshot_path = o.join("COMPILER_SNAPSHOT.bin");
|
2023-02-08 21:40:18 +00:00
|
|
|
ts::create_compiler_snapshot(compiler_snapshot_path, &c);
|
2022-07-04 22:12:41 +00:00
|
|
|
|
2024-07-05 12:17:53 +00:00
|
|
|
#[cfg(not(feature = "hmr"))]
|
2023-08-05 23:47:15 +00:00
|
|
|
{
|
|
|
|
let cli_snapshot_path = o.join("CLI_SNAPSHOT.bin");
|
2023-12-02 23:40:27 +00:00
|
|
|
create_cli_snapshot(cli_snapshot_path);
|
2023-06-13 22:36:16 +00:00
|
|
|
}
|
2022-07-04 22:12:41 +00:00
|
|
|
|
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
|
|
|
}
|
2023-12-09 00:19:16 +00:00
|
|
|
|
|
|
|
fn deno_webgpu_get_declaration() -> PathBuf {
|
|
|
|
let manifest_dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR"));
|
|
|
|
manifest_dir
|
|
|
|
.join("tsc")
|
|
|
|
.join("dts")
|
|
|
|
.join("lib.deno_webgpu.d.ts")
|
|
|
|
}
|