diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2023-12-03 00:40:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-02 23:40:27 +0000 |
commit | f6b889b43219e3c9be770c8b2758bff3048ddcbd (patch) | |
tree | d379a0a92e301b548ba91697804650fb13eba046 /cli/build.rs | |
parent | 0f990d9d927a0b25bc0eac32f2e7eee7c0460693 (diff) |
refactor: snapshotting of runtime/ and cli/ (#21430)
This commit removes some of the technical debt related
to snapshotting JS code:
- "cli/ops/mod.rs" and "cli/build.rs" no longer define "cli" extension
which was not required anymore
- Cargo features for "deno_runtime" crate have been unified in
"cli/Cargo.toml"
- "cli/build.rs" uses "deno_runtime::snapshot::create_runtime_snapshot"
API
instead of copy-pasting the code
- "cli/js/99_main.js" was completely removed as it's not necessary
anymore
Towards https://github.com/denoland/deno/issues/21137
Diffstat (limited to 'cli/build.rs')
-rw-r--r-- | cli/build.rs | 115 |
1 files changed, 12 insertions, 103 deletions
diff --git a/cli/build.rs b/cli/build.rs index 53ee914c2..edb2e4fdd 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -4,8 +4,6 @@ use std::env; use std::path::PathBuf; use deno_core::snapshot_util::*; -use deno_core::ExtensionFileSource; -use deno_core::ExtensionFileSourceCode; use deno_runtime::*; mod ts { @@ -318,36 +316,9 @@ mod ts { } } -// Duplicated in `ops/mod.rs`. Keep in sync! -deno_core::extension!( - cli, - deps = [runtime], - esm_entry_point = "ext:cli/99_main.js", - esm = [ - dir "js", - "99_main.js" - ], - customizer = |ext: &mut deno_core::Extension| { - ext.esm_files.to_mut().push(ExtensionFileSource { - specifier: "ext:cli/runtime/js/99_main.js", - code: ExtensionFileSourceCode::LoadedFromFsDuringSnapshot( - deno_runtime::js::PATH_FOR_99_MAIN_JS, - ), - }); - } -); - #[cfg(not(feature = "__runtime_js_sources"))] -#[must_use = "The files listed by create_cli_snapshot should be printed as 'cargo:rerun-if-changed' lines"] -fn create_cli_snapshot(snapshot_path: PathBuf) -> CreateSnapshotOutput { - use deno_core::Extension; - use deno_runtime::deno_cache::SqliteBackedCache; - use deno_runtime::deno_cron::local::LocalCronHandler; - use deno_runtime::deno_http::DefaultHttpPropertyExtractor; - use deno_runtime::deno_kv::sqlite::SqliteDbHandler; +fn create_cli_snapshot(snapshot_path: PathBuf) { use deno_runtime::ops::bootstrap::SnapshotOptions; - use deno_runtime::permissions::PermissionsContainer; - use std::sync::Arc; // NOTE(bartlomieju): keep in sync with `cli/version.rs`. // Ideally we could deduplicate that code. @@ -359,76 +330,17 @@ fn create_cli_snapshot(snapshot_path: PathBuf) -> CreateSnapshotOutput { } } - // NOTE(bartlomieju): ordering is important here, keep it in sync with - // `runtime/worker.rs`, `runtime/web_worker.rs` and `runtime/build.rs`! - let fs = Arc::new(deno_fs::RealFs); - let extensions: Vec<Extension> = vec![ - deno_webidl::deno_webidl::init_ops(), - deno_console::deno_console::init_ops(), - deno_url::deno_url::init_ops(), - deno_web::deno_web::init_ops::<PermissionsContainer>( - Default::default(), - Default::default(), - ), - deno_fetch::deno_fetch::init_ops::<PermissionsContainer>(Default::default()), - deno_cache::deno_cache::init_ops::<SqliteBackedCache>(None), - deno_websocket::deno_websocket::init_ops::<PermissionsContainer>( - "".to_owned(), - None, - None, - ), - deno_webstorage::deno_webstorage::init_ops(None), - deno_crypto::deno_crypto::init_ops(None), - deno_broadcast_channel::deno_broadcast_channel::init_ops( - deno_broadcast_channel::InMemoryBroadcastChannel::default(), - ), - deno_ffi::deno_ffi::init_ops::<PermissionsContainer>(), - deno_net::deno_net::init_ops::<PermissionsContainer>(None, None), - deno_tls::deno_tls::init_ops(), - deno_kv::deno_kv::init_ops(SqliteDbHandler::<PermissionsContainer>::new( - None, None, - )), - deno_cron::deno_cron::init_ops(LocalCronHandler::new()), - deno_napi::deno_napi::init_ops::<PermissionsContainer>(), - deno_http::deno_http::init_ops::<DefaultHttpPropertyExtractor>(), - deno_io::deno_io::init_ops(Default::default()), - deno_fs::deno_fs::init_ops::<PermissionsContainer>(fs.clone()), - deno_node::deno_node::init_ops::<PermissionsContainer>(None, fs), - deno_runtime::runtime::init_ops(), - deno_runtime::ops::runtime::deno_runtime::init_ops( - "deno:runtime".parse().unwrap(), - ), - deno_runtime::ops::worker_host::deno_worker_host::init_ops( - Arc::new(|_| unreachable!("not used in snapshot.")), - None, - ), - deno_runtime::ops::fs_events::deno_fs_events::init_ops(), - deno_runtime::ops::os::deno_os::init_ops(Default::default()), - deno_runtime::ops::permissions::deno_permissions::init_ops(), - deno_runtime::ops::process::deno_process::init_ops(), - deno_runtime::ops::signal::deno_signal::init_ops(), - deno_runtime::ops::tty::deno_tty::init_ops(), - deno_runtime::ops::http::deno_http_runtime::init_ops(), - deno_runtime::ops::bootstrap::deno_bootstrap::init_ops(Some( - SnapshotOptions { - deno_version: deno_version(), - ts_version: ts::version(), - v8_version: deno_core::v8_version(), - target: std::env::var("TARGET").unwrap(), - }, - )), - cli::init_ops_and_esm(), // NOTE: This needs to be init_ops_and_esm! - ]; - - create_snapshot(CreateSnapshotOptions { - cargo_manifest_dir: env!("CARGO_MANIFEST_DIR"), + let snapshot_options = SnapshotOptions { + deno_version: deno_version(), + ts_version: ts::version(), + v8_version: deno_core::v8_version(), + target: std::env::var("TARGET").unwrap(), + }; + + deno_runtime::snapshot::create_runtime_snapshot( snapshot_path, - startup_snapshot: deno_runtime::js::deno_isolate_init(), - extensions, - compression_cb: None, - with_runtime_cb: None, - skip_op_registration: false, - }) + snapshot_options, + ); } fn git_commit_hash() -> String { @@ -539,10 +451,7 @@ fn main() { #[cfg(not(feature = "__runtime_js_sources"))] { let cli_snapshot_path = o.join("CLI_SNAPSHOT.bin"); - let output = create_cli_snapshot(cli_snapshot_path); - for path in output.files_loaded_during_snapshot { - println!("cargo:rerun-if-changed={}", path.display()) - } + create_cli_snapshot(cli_snapshot_path); } #[cfg(target_os = "windows")] |