diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2018-11-12 17:17:30 -0800 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-12-03 13:44:21 -0800 |
commit | f727214db0677ebc31e0988287c71c517a858193 (patch) | |
tree | c7fd194db0b0f68d10022eba2ff98f259a36643b /src | |
parent | 7d02971c2c88705afd019442965f228e0165c73b (diff) |
Use include_bytes! instead of incbin.
This is the second attempt at this patch. The first version was reverted
in 2ffd78daf9956a24098d1f959f21882e350e9d37
The problem, I suspect, was that the snapshot was represented as a
source_set, which inserted a node into the dependency tree.
include_bytes does properly insert the snapshot into rustc's depfile but
the use of source_set confused gn. Now the that the deno executable has
the create_deno_snapshot as a direct dependency, changes will be
propagated.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 2 | ||||
-rw-r--r-- | src/snapshot.cc | 18 | ||||
-rw-r--r-- | src/snapshot.rs | 18 |
3 files changed, 17 insertions, 21 deletions
diff --git a/src/main.rs b/src/main.rs index 7c6806d5d..1224d2af2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -97,7 +97,7 @@ fn main() { }); let state = Arc::new(isolate::IsolateState::new(flags, rest_argv)); - let snapshot = unsafe { snapshot::deno_snapshot.clone() }; + let snapshot = snapshot::deno_snapshot(); let mut isolate = isolate::Isolate::new(snapshot, state, ops::dispatch); tokio_util::init(|| { isolate diff --git a/src/snapshot.cc b/src/snapshot.cc deleted file mode 100644 index b0945d319..000000000 --- a/src/snapshot.cc +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2018 the Deno authors. All rights reserved. MIT license. - -#include "deno.h" - -extern "C" { - -extern const char snapshot_start asm("snapshot_start"); -extern const char snapshot_end asm("snapshot_end"); -asm(".data\n" - "snapshot_start: .incbin \"gen/snapshot_deno.bin\"\n" - "snapshot_end:\n" - ".globl snapshot_start;\n" - ".globl snapshot_end;"); -extern const deno_buf deno_snapshot = { - nullptr, 0, reinterpret_cast<uint8_t*>(const_cast<char*>(&snapshot_start)), - static_cast<size_t>(&snapshot_end - &snapshot_start)}; - -} diff --git a/src/snapshot.rs b/src/snapshot.rs index 52c8df47d..4774ba43f 100644 --- a/src/snapshot.rs +++ b/src/snapshot.rs @@ -1,5 +1,19 @@ // Copyright 2018 the Deno authors. All rights reserved. MIT license. use libdeno::deno_buf; -extern "C" { - pub static deno_snapshot: deno_buf; +use std; + +pub fn deno_snapshot() -> deno_buf { + let data = + include_bytes!(concat!(env!("GN_OUT_DIR"), "/gen/snapshot_deno.bin")); + let ptr = data.as_ptr(); + // TODO The cast is not necessary here. deno_buf specifies mutable + // pointers when it doesn't necessarally need mutable. So maybe the deno_buf + // type should be broken into a mutable and non-mutable version? + let ptr_mut = ptr as *mut u8; + deno_buf { + alloc_ptr: std::ptr::null_mut(), + alloc_len: 0, + data_ptr: ptr_mut, + data_len: data.len(), + } } |