mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
fix(runtime): only discard extension sources if a snapshot is provided (#22023)
Fixes #21928. We have a code path which empties the extension sources because they're expected to be pre-executed in the snapshot. Instead of using conditional compilation for that, we now just check if a snapshot was provided. Removes the `dont_use_runtime_snapshot` feature. We didn't allow not providing a snapshot unless this feature was provided, now we always do. Adds the `only_snapshotted_js_sources` feature for us to use in CLI. This asserts that a snapshot is provided and gates the runtime transpilation code so it isn't included in the executable.
This commit is contained in:
parent
8f76762793
commit
bc92f87298
4 changed files with 26 additions and 41 deletions
|
@ -39,7 +39,7 @@ __runtime_js_sources = ["deno_runtime/__runtime_js_sources"]
|
||||||
__vendored_zlib_ng = ["flate2/zlib-ng-compat", "libz-sys/zlib-ng"]
|
__vendored_zlib_ng = ["flate2/zlib-ng-compat", "libz-sys/zlib-ng"]
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
deno_runtime = { workspace = true, features = ["include_js_files_for_snapshotting"] }
|
deno_runtime = { workspace = true, features = ["include_js_files_for_snapshotting", "only_snapshotted_js_sources"] }
|
||||||
deno_core = { workspace = true, features = ["include_js_files_for_snapshotting"] }
|
deno_core = { workspace = true, features = ["include_js_files_for_snapshotting"] }
|
||||||
lazy-regex.workspace = true
|
lazy-regex.workspace = true
|
||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
|
|
|
@ -12,8 +12,6 @@ description = "Provides the deno runtime library"
|
||||||
[features]
|
[features]
|
||||||
# "fake" feature that allows to generate docs on docs.rs
|
# "fake" feature that allows to generate docs on docs.rs
|
||||||
docsrs = []
|
docsrs = []
|
||||||
# A feature that disables the requirement for startup snapshot to be provided.
|
|
||||||
dont_use_runtime_snapshot = []
|
|
||||||
# A feature that allows excluding `./js/99_main.js` from the exported extension.
|
# A feature that allows excluding `./js/99_main.js` from the exported extension.
|
||||||
exclude_runtime_main_js = []
|
exclude_runtime_main_js = []
|
||||||
# A feature that disables embedding of the JavaScript source files in the binary.
|
# A feature that disables embedding of the JavaScript source files in the binary.
|
||||||
|
@ -24,7 +22,11 @@ include_js_files_for_snapshotting = [
|
||||||
]
|
]
|
||||||
# A dev feature to disable creations and loading of snapshots in favor of
|
# A dev feature to disable creations and loading of snapshots in favor of
|
||||||
# loading JS sources at runtime.
|
# loading JS sources at runtime.
|
||||||
__runtime_js_sources = []
|
__runtime_js_sources = ["include_js_files_for_snapshotting"]
|
||||||
|
# Signal that only snapshotted JS sources should be used. This will
|
||||||
|
# conditionally exclude the runtime source transpilation logic, and add an
|
||||||
|
# assertion that a snapshot is provided.
|
||||||
|
only_snapshotted_js_sources = ["include_js_files_for_snapshotting"]
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "deno_runtime"
|
name = "deno_runtime"
|
||||||
|
|
|
@ -490,14 +490,16 @@ impl WebWorker {
|
||||||
ops::web_worker::deno_web_worker::init_ops_and_esm(),
|
ops::web_worker::deno_web_worker::init_ops_and_esm(),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
#[cfg(__runtime_js_sources)]
|
||||||
|
assert!(cfg!(not(feature = "only_snapshotted_js_sources")), "'__runtime_js_sources' is incompatible with 'only_snapshotted_js_sources'.");
|
||||||
|
|
||||||
for extension in &mut extensions {
|
for extension in &mut extensions {
|
||||||
#[cfg(not(feature = "__runtime_js_sources"))]
|
if options.startup_snapshot.is_some() {
|
||||||
{
|
|
||||||
extension.js_files = std::borrow::Cow::Borrowed(&[]);
|
extension.js_files = std::borrow::Cow::Borrowed(&[]);
|
||||||
extension.esm_files = std::borrow::Cow::Borrowed(&[]);
|
extension.esm_files = std::borrow::Cow::Borrowed(&[]);
|
||||||
extension.esm_entry_point = None;
|
extension.esm_entry_point = None;
|
||||||
}
|
}
|
||||||
#[cfg(feature = "__runtime_js_sources")]
|
#[cfg(not(feature = "only_snapshotted_js_sources"))]
|
||||||
{
|
{
|
||||||
use crate::shared::maybe_transpile_source;
|
use crate::shared::maybe_transpile_source;
|
||||||
for source in extension.esm_files.to_mut() {
|
for source in extension.esm_files.to_mut() {
|
||||||
|
@ -511,17 +513,8 @@ impl WebWorker {
|
||||||
|
|
||||||
extensions.extend(std::mem::take(&mut options.extensions));
|
extensions.extend(std::mem::take(&mut options.extensions));
|
||||||
|
|
||||||
#[cfg(all(
|
#[cfg(feature = "only_snapshotted_js_sources")]
|
||||||
feature = "include_js_files_for_snapshotting",
|
options.startup_snapshot.as_ref().expect("A user snapshot was not provided, even though 'only_snapshotted_js_sources' is used.");
|
||||||
not(feature = "__runtime_js_sources")
|
|
||||||
))]
|
|
||||||
options
|
|
||||||
.startup_snapshot
|
|
||||||
.as_ref()
|
|
||||||
.expect("Sources are not embedded and a user snapshot was not provided.");
|
|
||||||
|
|
||||||
#[cfg(not(feature = "dont_use_runtime_snapshot"))]
|
|
||||||
options.startup_snapshot.as_ref().expect("A user snapshot was not provided, if you want to create a runtime without a snapshot use 'dont_use_runtime_snapshot' Cargo feature.");
|
|
||||||
|
|
||||||
// Hook up the summary metrics if the user or subcommand requested them
|
// Hook up the summary metrics if the user or subcommand requested them
|
||||||
let (op_summary_metrics, op_metrics_factory_fn) =
|
let (op_summary_metrics, op_metrics_factory_fn) =
|
||||||
|
|
|
@ -418,16 +418,13 @@ impl MainWorker {
|
||||||
ops::signal::deno_signal::init_ops_and_esm(),
|
ops::signal::deno_signal::init_ops_and_esm(),
|
||||||
ops::tty::deno_tty::init_ops_and_esm(),
|
ops::tty::deno_tty::init_ops_and_esm(),
|
||||||
ops::http::deno_http_runtime::init_ops_and_esm(),
|
ops::http::deno_http_runtime::init_ops_and_esm(),
|
||||||
ops::bootstrap::deno_bootstrap::init_ops_and_esm({
|
ops::bootstrap::deno_bootstrap::init_ops_and_esm(
|
||||||
#[cfg(feature = "__runtime_js_sources")]
|
if options.startup_snapshot.is_some() {
|
||||||
{
|
|
||||||
Some(Default::default())
|
|
||||||
}
|
|
||||||
#[cfg(not(feature = "__runtime_js_sources"))]
|
|
||||||
{
|
|
||||||
None
|
None
|
||||||
}
|
} else {
|
||||||
}),
|
Some(Default::default())
|
||||||
|
},
|
||||||
|
),
|
||||||
deno_permissions_worker::init_ops_and_esm(
|
deno_permissions_worker::init_ops_and_esm(
|
||||||
permissions,
|
permissions,
|
||||||
enable_testing_features,
|
enable_testing_features,
|
||||||
|
@ -435,14 +432,16 @@ impl MainWorker {
|
||||||
runtime::init_ops_and_esm(),
|
runtime::init_ops_and_esm(),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
#[cfg(__runtime_js_sources)]
|
||||||
|
assert!(cfg!(not(feature = "only_snapshotted_js_sources")), "'__runtime_js_sources' is incompatible with 'only_snapshotted_js_sources'.");
|
||||||
|
|
||||||
for extension in &mut extensions {
|
for extension in &mut extensions {
|
||||||
#[cfg(not(feature = "__runtime_js_sources"))]
|
if options.startup_snapshot.is_some() {
|
||||||
{
|
|
||||||
extension.js_files = std::borrow::Cow::Borrowed(&[]);
|
extension.js_files = std::borrow::Cow::Borrowed(&[]);
|
||||||
extension.esm_files = std::borrow::Cow::Borrowed(&[]);
|
extension.esm_files = std::borrow::Cow::Borrowed(&[]);
|
||||||
extension.esm_entry_point = None;
|
extension.esm_entry_point = None;
|
||||||
}
|
}
|
||||||
#[cfg(feature = "__runtime_js_sources")]
|
#[cfg(not(feature = "only_snapshotted_js_sources"))]
|
||||||
{
|
{
|
||||||
use crate::shared::maybe_transpile_source;
|
use crate::shared::maybe_transpile_source;
|
||||||
for source in extension.esm_files.to_mut() {
|
for source in extension.esm_files.to_mut() {
|
||||||
|
@ -456,17 +455,8 @@ impl MainWorker {
|
||||||
|
|
||||||
extensions.extend(std::mem::take(&mut options.extensions));
|
extensions.extend(std::mem::take(&mut options.extensions));
|
||||||
|
|
||||||
#[cfg(all(
|
#[cfg(feature = "only_snapshotted_js_sources")]
|
||||||
feature = "include_js_files_for_snapshotting",
|
options.startup_snapshot.as_ref().expect("A user snapshot was not provided, even though 'only_snapshotted_js_sources' is used.");
|
||||||
not(feature = "__runtime_js_sources")
|
|
||||||
))]
|
|
||||||
options
|
|
||||||
.startup_snapshot
|
|
||||||
.as_ref()
|
|
||||||
.expect("Sources are not embedded and a user snapshot was not provided.");
|
|
||||||
|
|
||||||
#[cfg(not(feature = "dont_use_runtime_snapshot"))]
|
|
||||||
options.startup_snapshot.as_ref().expect("A user snapshot was not provided, if you want to create a runtime without a snapshot use 'dont_use_runtime_snapshot' Cargo feature.");
|
|
||||||
|
|
||||||
let has_notified_of_inspector_disconnect = AtomicBool::new(false);
|
let has_notified_of_inspector_disconnect = AtomicBool::new(false);
|
||||||
let wait_for_inspector_disconnect_callback = Box::new(move || {
|
let wait_for_inspector_disconnect_callback = Box::new(move || {
|
||||||
|
|
Loading…
Add table
Reference in a new issue