diff options
Diffstat (limited to 'runtime/build.rs')
-rw-r--r-- | runtime/build.rs | 160 |
1 files changed, 75 insertions, 85 deletions
diff --git a/runtime/build.rs b/runtime/build.rs index 63bc3439e..c1837de82 100644 --- a/runtime/build.rs +++ b/runtime/build.rs @@ -8,18 +8,18 @@ use std::path::PathBuf; not(feature = "dont_create_runtime_snapshot") ))] mod startup_snapshot { - use std::path::Path; - use super::*; use deno_ast::MediaType; use deno_ast::ParseParams; use deno_ast::SourceTextInfo; use deno_cache::SqliteBackedCache; use deno_core::error::AnyError; - use deno_core::include_js_files; use deno_core::snapshot_util::*; use deno_core::Extension; use deno_core::ExtensionFileSource; + use std::cell::RefCell; + use std::path::Path; + use std::rc::Rc; fn transpile_ts_for_snapshotting( file_source: &ExtensionFileSource, @@ -58,6 +58,7 @@ mod startup_snapshot { Ok(transpiled_source.text) } + #[derive(Clone)] struct Permissions; impl deno_fetch::FetchPermissions for Permissions { @@ -200,36 +201,30 @@ mod startup_snapshot { } } - fn create_runtime_snapshot( - snapshot_path: PathBuf, - maybe_additional_extension: Option<Extension>, - ) { - let runtime_extension = Extension::builder_with_deps( - "runtime", - &[ - "deno_webidl", - "deno_console", - "deno_url", - "deno_tls", - "deno_web", - "deno_fetch", - "deno_cache", - "deno_websocket", - "deno_webstorage", - "deno_crypto", - "deno_broadcast_channel", - // FIXME(bartlomieju): this should be reenabled - // "deno_node", - "deno_ffi", - "deno_net", - "deno_napi", - "deno_http", - "deno_flash", - "deno_io", - "deno_fs", - ], - ) - .esm(include_js_files!( + deno_core::extension!(runtime, + deps = [ + deno_webidl, + deno_console, + deno_url, + deno_tls, + deno_web, + deno_fetch, + deno_cache, + deno_websocket, + deno_webstorage, + deno_crypto, + deno_broadcast_channel, + // FIXME(bartlomieju): this should be reenabled + // "deno_node", + deno_ffi, + deno_net, + deno_napi, + deno_http, + deno_flash, + deno_io, + deno_fs + ], + esm = [ dir "js", "01_errors.js", "01_version.ts", @@ -245,55 +240,72 @@ mod startup_snapshot { "40_tty.js", "41_prompt.js", "90_deno_ns.js", - "98_global_scope.js", - )) - .build(); + "98_global_scope.js" + ], + ); + + #[cfg(not(feature = "snapshot_from_snapshot"))] + deno_core::extension!( + runtime_main, + deps = [runtime], + customizer = |ext: &mut deno_core::ExtensionBuilder| { + ext.esm(vec![ExtensionFileSource { + specifier: "js/99_main.js".to_string(), + code: deno_core::ExtensionFileSourceCode::IncludedInBinary( + include_str!("js/99_main.js"), + ), + }]); + } + ); + pub fn create_runtime_snapshot(snapshot_path: PathBuf) { // NOTE(bartlomieju): ordering is important here, keep it in sync with // `runtime/worker.rs`, `runtime/web_worker.rs` and `cli/build.rs`! - let mut extensions: Vec<Extension> = vec![ - deno_webidl::init_esm(), - deno_console::init_esm(), - deno_url::init_ops_and_esm(), - deno_web::init_ops_and_esm::<Permissions>( + let extensions: Vec<Extension> = vec![ + deno_webidl::deno_webidl::init_ops_and_esm(), + deno_console::deno_console::init_ops_and_esm(), + deno_url::deno_url::init_ops_and_esm(), + deno_web::deno_web::init_ops_and_esm::<Permissions>( deno_web::BlobStore::default(), Default::default(), ), - deno_fetch::init_ops_and_esm::<Permissions>(Default::default()), - deno_cache::init_ops_and_esm::<SqliteBackedCache>(None), - deno_websocket::init_ops_and_esm::<Permissions>( + deno_fetch::deno_fetch::init_ops_and_esm::<Permissions>( + Default::default(), + ), + deno_cache::deno_cache::init_ops_and_esm::<SqliteBackedCache>(None), + deno_websocket::deno_websocket::init_ops_and_esm::<Permissions>( "".to_owned(), None, None, ), - deno_webstorage::init_ops_and_esm(None), - deno_crypto::init_ops_and_esm(None), - deno_broadcast_channel::init_ops_and_esm( + deno_webstorage::deno_webstorage::init_ops_and_esm(None), + deno_crypto::deno_crypto::init_ops_and_esm(None), + deno_broadcast_channel::deno_broadcast_channel::init_ops_and_esm( deno_broadcast_channel::InMemoryBroadcastChannel::default(), false, // No --unstable. ), - deno_ffi::init_ops_and_esm::<Permissions>(false), - deno_net::init_ops_and_esm::<Permissions>( + deno_ffi::deno_ffi::init_ops_and_esm::<Permissions>(false), + deno_net::deno_net::init_ops_and_esm::<Permissions>( None, false, // No --unstable. None, ), - deno_tls::init_ops(), - deno_napi::init_ops::<Permissions>(), - deno_http::init_ops_and_esm(), - deno_io::init_ops_and_esm(Default::default()), - deno_fs::init_ops_and_esm::<Permissions>(false), - deno_flash::init_ops_and_esm::<Permissions>(false), // No --unstable - runtime_extension, + deno_tls::deno_tls::init_ops_and_esm(), + deno_napi::deno_napi::init_ops_and_esm::<Permissions>(), + deno_http::deno_http::init_ops_and_esm(), + deno_io::deno_io::init_ops_and_esm(Rc::new(RefCell::new(Some( + Default::default(), + )))), + deno_fs::deno_fs::init_ops_and_esm::<Permissions>(false), + deno_flash::deno_flash::init_ops_and_esm::<Permissions>(false), // No --unstable + runtime::init_ops_and_esm(), // FIXME(bartlomieju): these extensions are specified last, because they // depend on `runtime`, even though it should be other way around - deno_node::init_ops_and_esm::<Permissions>(None), - deno_node::init_polyfill_ops_and_esm(), + deno_node::deno_node_loading::init_ops_and_esm::<Permissions>(None), + deno_node::deno_node::init_ops_and_esm(), + #[cfg(not(feature = "snapshot_from_snapshot"))] + runtime_main::init_ops_and_esm(), ]; - if let Some(additional_extension) = maybe_additional_extension { - extensions.push(additional_extension); - } - create_snapshot(CreateSnapshotOptions { cargo_manifest_dir: env!("CARGO_MANIFEST_DIR"), snapshot_path, @@ -303,28 +315,6 @@ mod startup_snapshot { snapshot_module_load_cb: Some(Box::new(transpile_ts_for_snapshotting)), }); } - - pub fn build_snapshot(runtime_snapshot_path: PathBuf) { - #[allow(unused_mut, unused_assignments)] - let mut maybe_additional_extension = None; - - #[cfg(not(feature = "snapshot_from_snapshot"))] - { - use deno_core::ExtensionFileSourceCode; - maybe_additional_extension = Some( - Extension::builder_with_deps("runtime_main", &["runtime"]) - .esm(vec![ExtensionFileSource { - specifier: "js/99_main.js".to_string(), - code: ExtensionFileSourceCode::IncludedInBinary(include_str!( - "js/99_main.js" - )), - }]) - .build(), - ); - } - - create_runtime_snapshot(runtime_snapshot_path, maybe_additional_extension); - } } fn main() { @@ -351,5 +341,5 @@ fn main() { not(feature = "docsrs"), not(feature = "dont_create_runtime_snapshot") ))] - startup_snapshot::build_snapshot(runtime_snapshot_path) + startup_snapshot::create_runtime_snapshot(runtime_snapshot_path) } |