diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2023-06-13 16:45:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-13 09:45:06 -0600 |
commit | ceb03cfb037cf7024a5048b17b508ddda59cfa05 (patch) | |
tree | 0c2df444e00f17131f9e2af708f80cdc4b032ce8 /cli/build.rs | |
parent | 5348778666d2d8d7ce138bbdf75ac5aa9f7ed428 (diff) |
refactor(core): cleanup feature flags for js source inclusion (#19463)
Remove `ExtensionFileSourceCode::LoadedFromFsDuringSnapshot` and feature
`include_js_for_snapshotting` since they leak paths that are only
applicable in this repo to embedders. Replace with feature
`exclude_js_sources`. Additionally the feature
`force_include_js_sources` allows negating it, if both features are set.
We need both of these because features are additive and there must be a
way of force including sources for snapshot creation while still having
the `exclude_js_sources` feature. `force_include_js_sources` is only set
for build deps, so sources are still excluded from the final binary.
You can also specify `force_include_js_sources` on any extension to
override the above features for that extension. Towards #19398.
But there was still the snapshot-from-snapshot situation where code
could be executed twice, I addressed that by making `mod_evaluate()` and
scripts like `core/01_core.js` behave idempotently. This allowed
unifying `ext::init_ops()` and `ext::init_ops_and_esm()` into
`ext::init()`.
Diffstat (limited to 'cli/build.rs')
-rw-r--r-- | cli/build.rs | 64 |
1 files changed, 25 insertions, 39 deletions
diff --git a/cli/build.rs b/cli/build.rs index 5ff86fa20..77e0ee1de 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -7,7 +7,6 @@ use std::sync::Arc; use deno_core::snapshot_util::*; use deno_core::Extension; use deno_core::ExtensionFileSource; -use deno_core::ExtensionFileSourceCode; use deno_runtime::deno_cache::SqliteBackedCache; use deno_runtime::deno_http::DefaultHttpPropertyExtractor; use deno_runtime::deno_kv::sqlite::SqliteDbHandler; @@ -262,15 +261,11 @@ mod ts { ) .unwrap(); - let output = create_snapshot(CreateSnapshotOptions { + create_snapshot(CreateSnapshotOptions { cargo_manifest_dir: env!("CARGO_MANIFEST_DIR"), snapshot_path, startup_snapshot: None, - extensions: vec![deno_tsc::init_ops_and_esm( - op_crate_libs, - build_libs, - path_dts, - )], + extensions: vec![deno_tsc::init(op_crate_libs, build_libs, path_dts)], // NOTE(bartlomieju): Compressing the TSC snapshot in debug build took // ~45s on M1 MacBook Pro; without compression it took ~1s. @@ -289,9 +284,6 @@ mod ts { })), snapshot_module_load_cb: None, }); - for path in output.files_loaded_during_snapshot { - println!("cargo:rerun-if-changed={}", path.display()); - } } pub(crate) fn version() -> String { @@ -322,55 +314,52 @@ deno_core::extension!( customizer = |ext: &mut deno_core::ExtensionBuilder| { ext.esm(vec![ExtensionFileSource { specifier: "ext:cli/runtime/js/99_main.js", - code: ExtensionFileSourceCode::LoadedFromFsDuringSnapshot( - std::path::PathBuf::from(deno_runtime::js::PATH_FOR_99_MAIN_JS), - ), + code: include_str!("../runtime/js/99_main.js"), }]); } ); -#[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 { +fn create_cli_snapshot(snapshot_path: PathBuf) { // 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>( + deno_webidl::deno_webidl::init(), + deno_console::deno_console::init(), + deno_url::deno_url::init(), + deno_web::deno_web::init::<PermissionsContainer>( deno_web::BlobStore::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>( + deno_fetch::deno_fetch::init::<PermissionsContainer>(Default::default()), + deno_cache::deno_cache::init::<SqliteBackedCache>(None), + deno_websocket::deno_websocket::init::<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_webstorage::deno_webstorage::init(None), + deno_crypto::deno_crypto::init(None), + deno_broadcast_channel::deno_broadcast_channel::init( deno_broadcast_channel::InMemoryBroadcastChannel::default(), false, // No --unstable. ), - deno_ffi::deno_ffi::init_ops::<PermissionsContainer>(false), - deno_net::deno_net::init_ops::<PermissionsContainer>( + deno_ffi::deno_ffi::init::<PermissionsContainer>(false), + deno_net::deno_net::init::<PermissionsContainer>( None, false, // No --unstable. None, ), - deno_tls::deno_tls::init_ops(), - deno_kv::deno_kv::init_ops( + deno_tls::deno_tls::init(), + deno_kv::deno_kv::init( SqliteDbHandler::<PermissionsContainer>::new(None), false, // No --unstable. ), - 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>(false, fs.clone()), - deno_node::deno_node::init_ops::<PermissionsContainer>(None, fs), - cli::init_ops_and_esm(), // NOTE: This needs to be init_ops_and_esm! + deno_napi::deno_napi::init::<PermissionsContainer>(), + deno_http::deno_http::init::<DefaultHttpPropertyExtractor>(), + deno_io::deno_io::init(Default::default()), + deno_fs::deno_fs::init::<PermissionsContainer>(false, fs.clone()), + deno_node::deno_node::init::<PermissionsContainer>(None, fs), + cli::init(), ]; create_snapshot(CreateSnapshotOptions { @@ -485,10 +474,7 @@ fn main() { ts::create_compiler_snapshot(compiler_snapshot_path, &c); 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")] { |