summaryrefslogtreecommitdiff
path: root/runtime/js.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-02-20 21:45:34 +0100
committerGitHub <noreply@github.com>2023-02-20 21:45:34 +0100
commit914b08fc19e5c7268e7b04a216337e765d6a06e8 (patch)
tree39f73f4e046346f358d74ff10f62cb2d5f7078a8 /runtime/js.rs
parent4d1a14ca7fa9496f36470a7771448a9b006b0204 (diff)
build: add "include_js_files_for_snapshotting" Cargo feature (#17826)
This allows to not include source code into the binary (because it will already be included in the V8 snapshot). Nothing changes for the embedders - everything should still build the same. This commit brings the binary size from 87Mb to 82Mb on M1. Alternative to https://github.com/denoland/deno/pull/17820 and https://github.com/denoland/deno/pull/17653 --------- Co-authored-by: Leo Kettmeir <crowlkats@toaxl.com>
Diffstat (limited to 'runtime/js.rs')
-rw-r--r--runtime/js.rs18
1 files changed, 14 insertions, 4 deletions
diff --git a/runtime/js.rs b/runtime/js.rs
index 82e58a09c..57b1e7be4 100644
--- a/runtime/js.rs
+++ b/runtime/js.rs
@@ -1,16 +1,21 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+#[cfg(not(feature = "dont_create_runtime_snapshot"))]
use deno_core::Snapshot;
+#[cfg(not(feature = "dont_create_runtime_snapshot"))]
use log::debug;
+#[cfg(not(feature = "dont_create_runtime_snapshot"))]
use once_cell::sync::Lazy;
+#[cfg(not(feature = "dont_create_runtime_snapshot"))]
+static COMPRESSED_RUNTIME_SNAPSHOT: &[u8] =
+ include_bytes!(concat!(env!("OUT_DIR"), "/RUNTIME_SNAPSHOT.bin"));
+
+#[cfg(not(feature = "dont_create_runtime_snapshot"))]
pub static RUNTIME_SNAPSHOT: Lazy<Box<[u8]>> = Lazy::new(
#[allow(clippy::uninit_vec)]
#[cold]
#[inline(never)]
|| {
- static COMPRESSED_RUNTIME_SNAPSHOT: &[u8] =
- include_bytes!(concat!(env!("OUT_DIR"), "/RUNTIME_SNAPSHOT.bin"));
-
let size =
u32::from_le_bytes(COMPRESSED_RUNTIME_SNAPSHOT[0..4].try_into().unwrap())
as usize;
@@ -29,10 +34,15 @@ pub static RUNTIME_SNAPSHOT: Lazy<Box<[u8]>> = Lazy::new(
},
);
+#[cfg(not(feature = "dont_create_runtime_snapshot"))]
pub fn deno_isolate_init() -> Snapshot {
debug!("Deno isolate init with snapshots.");
Snapshot::Static(&RUNTIME_SNAPSHOT)
}
-#[cfg(feature = "snapshot_from_snapshot")]
+#[cfg(not(feature = "include_js_files_for_snapshotting"))]
pub static SOURCE_CODE_FOR_99_MAIN_JS: &str = include_str!("js/99_main.js");
+
+#[cfg(feature = "include_js_files_for_snapshotting")]
+pub static PATH_FOR_99_MAIN_JS: &str =
+ concat!(env!("CARGO_MANIFEST_DIR"), "/js/99_main.js");