summaryrefslogtreecommitdiff
path: root/cli/startup_data.rs
blob: 6e636e5790c61126d525887be746073a46d5d207 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
use deno_core::deno_buf;
use deno_core::{Script, StartupData};

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(Script {
      filename: "gen/bundle/main.js".to_string(),
      source: std::str::from_utf8(&source_bytes[..]).unwrap().to_string(),
    })
  } else {
    debug!("Deno isolate init with snapshots.");
    #[cfg(not(any(feature = "check-only", feature = "no-snapshot-init")))]
    let data =
      include_bytes!(concat!(env!("GN_OUT_DIR"), "/gen/snapshot_deno.bin"));
    #[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(Script {
      filename: "gen/bundle/compiler.js".to_string(),
      source: std::str::from_utf8(&source_bytes[..]).unwrap().to_string(),
    })
  } else {
    debug!("Deno isolate init with snapshots.");
    #[cfg(not(any(feature = "check-only", feature = "no-snapshot-init")))]
    let data =
      include_bytes!(concat!(env!("GN_OUT_DIR"), "/gen/snapshot_compiler.bin"));
    #[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()))
    }
  }
}