1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-26 16:09:27 -05:00
denoland-deno/cli/startup_data.rs

58 lines
2 KiB
Rust
Raw Normal View History

// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
use deno_core::deno_buf;
use deno_core::{StartupData, StartupScript};
pub fn deno_isolate_init() -> StartupData {
if cfg!(feature = "no-snapshot-init") {
debug!("Deno isolate init without snapshots.");
#[cfg(not(feature = "check-only"))]
let source_bytes =
include_bytes!(concat!(env!("GN_OUT_DIR"), "/gen/bundle/main.js"));
#[cfg(feature = "check-only")]
let source_bytes = vec![];
StartupData::Script(StartupScript {
filename: "gen/bundle/main.js".to_string(),
source: std::str::from_utf8(source_bytes).unwrap().to_string(),
})
} else {
debug!("Deno isolate init with snapshots.");
2019-03-08 13:11:05 -05:00
#[cfg(not(any(feature = "check-only", feature = "no-snapshot-init")))]
let data =
include_bytes!(concat!(env!("GN_OUT_DIR"), "/gen/snapshot_deno.bin"));
2019-03-08 13:11:05 -05:00
#[cfg(any(feature = "check-only", feature = "no-snapshot-init"))]
let data = vec![];
unsafe {
StartupData::Snapshot(deno_buf::from_raw_parts(data.as_ptr(), data.len()))
}
}
}
pub fn compiler_isolate_init() -> StartupData {
if cfg!(feature = "no-snapshot-init") {
debug!("Deno isolate init without snapshots.");
#[cfg(not(feature = "check-only"))]
let source_bytes =
include_bytes!(concat!(env!("GN_OUT_DIR"), "/gen/bundle/compiler.js"));
#[cfg(feature = "check-only")]
let source_bytes = vec![];
StartupData::Script(StartupScript {
filename: "gen/bundle/compiler.js".to_string(),
source: std::str::from_utf8(source_bytes).unwrap().to_string(),
})
} else {
debug!("Deno isolate init with snapshots.");
2019-03-08 13:11:05 -05:00
#[cfg(not(any(feature = "check-only", feature = "no-snapshot-init")))]
let data =
include_bytes!(concat!(env!("GN_OUT_DIR"), "/gen/snapshot_compiler.bin"));
2019-03-08 13:11:05 -05:00
#[cfg(any(feature = "check-only", feature = "no-snapshot-init"))]
let data = vec![];
unsafe {
StartupData::Snapshot(deno_buf::from_raw_parts(data.as_ptr(), data.len()))
}
}
}