2019-03-04 23:09:35 +00:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2019-03-14 23:17:52 +00:00
|
|
|
use deno_core::deno_buf;
|
2019-03-04 23:09:35 +00:00
|
|
|
|
|
|
|
pub struct IsolateInitScript {
|
|
|
|
pub source: String,
|
|
|
|
pub filename: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct IsolateInit {
|
|
|
|
pub snapshot: Option<deno_buf>,
|
|
|
|
pub init_script: Option<IsolateInitScript>,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn deno_isolate_init() -> IsolateInit {
|
2019-03-05 22:26:59 +00:00
|
|
|
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![];
|
2019-03-04 23:09:35 +00:00
|
|
|
|
2019-03-05 22:26:59 +00:00
|
|
|
IsolateInit {
|
|
|
|
snapshot: None,
|
|
|
|
init_script: Some(IsolateInitScript {
|
|
|
|
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 18:11:05 +00:00
|
|
|
#[cfg(not(any(feature = "check-only", feature = "no-snapshot-init")))]
|
2019-03-05 22:26:59 +00:00
|
|
|
let data =
|
|
|
|
include_bytes!(concat!(env!("GN_OUT_DIR"), "/gen/snapshot_deno.bin"));
|
2019-03-08 18:11:05 +00:00
|
|
|
#[cfg(any(feature = "check-only", feature = "no-snapshot-init"))]
|
2019-03-05 22:26:59 +00:00
|
|
|
let data = vec![];
|
2019-03-04 23:09:35 +00:00
|
|
|
|
2019-03-05 22:26:59 +00:00
|
|
|
unsafe {
|
2019-03-04 23:09:35 +00:00
|
|
|
IsolateInit {
|
2019-03-05 22:26:59 +00:00
|
|
|
snapshot: Some(deno_buf::from_raw_parts(data.as_ptr(), data.len())),
|
|
|
|
init_script: None,
|
2019-03-04 23:09:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn compiler_isolate_init() -> IsolateInit {
|
2019-03-05 22:26:59 +00:00
|
|
|
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![];
|
2019-03-04 23:09:35 +00:00
|
|
|
|
2019-03-05 22:26:59 +00:00
|
|
|
IsolateInit {
|
|
|
|
snapshot: None,
|
|
|
|
init_script: Some(IsolateInitScript {
|
|
|
|
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 18:11:05 +00:00
|
|
|
#[cfg(not(any(feature = "check-only", feature = "no-snapshot-init")))]
|
2019-03-05 22:26:59 +00:00
|
|
|
let data =
|
|
|
|
include_bytes!(concat!(env!("GN_OUT_DIR"), "/gen/snapshot_compiler.bin"));
|
2019-03-08 18:11:05 +00:00
|
|
|
#[cfg(any(feature = "check-only", feature = "no-snapshot-init"))]
|
2019-03-05 22:26:59 +00:00
|
|
|
let data = vec![];
|
2019-03-04 23:09:35 +00:00
|
|
|
|
2019-03-05 22:26:59 +00:00
|
|
|
unsafe {
|
2019-03-04 23:09:35 +00:00
|
|
|
IsolateInit {
|
2019-03-05 22:26:59 +00:00
|
|
|
snapshot: Some(deno_buf::from_raw_parts(data.as_ptr(), data.len())),
|
|
|
|
init_script: None,
|
2019-03-04 23:09:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|