From 2ffd78daf9956a24098d1f959f21882e350e9d37 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Fri, 23 Nov 2018 09:19:14 -0800 Subject: [PATCH] Revert "Use include_bytes! instead of incbin. (#1182)" Reverting because this is causing Appveyor to be red. However I hope we can reintroduce include_bytes! soon in a way that works on windows. Fixes #1208. This reverts commits 96c3641fffe8509af9351cec4580861e76d89cc9 and 92e404706b0b1a26cdaf6f8cf81aac148292557f. --- BUILD.gn | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ src/isolate.rs | 12 ++++++++---- src/main.rs | 2 +- src/snapshot.cc | 18 +++++++++++++++++ src/snapshot.rs | 18 ++--------------- 5 files changed, 80 insertions(+), 21 deletions(-) create mode 100644 src/snapshot.cc diff --git a/BUILD.gn b/BUILD.gn index d35ded31..064f8d14 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -146,12 +146,40 @@ rust_executable("deno") { } source_set("snapshot") { + sources = [ + "src/snapshot.cc", + ] + configs += [ ":deno_config" ] inputs = [ "$target_gen_dir/snapshot_deno.bin", ] deps = [ ":create_snapshot_deno", ] + + # snapshot.cc doesn't need to depend on libdeno, it just needs deno_buf. + include_dirs = [ "libdeno/" ] + + # src/snapshot.cc uses an assembly '.incbin' directive to embed the snapshot. + # This causes trouble when using sccache: since the snapshot file is not + # inlined by the c preprocessor, sccache doesn't take its contents into + # consideration, leading to false-positive cache hits. + # Maybe other caching tools have this issue too, but ccache is unaffected. + # Therefore, if a cc_wrapper is used that isn't ccache, include a generated + # header file that contains the the sha256 hash of the snapshot. + if (cc_wrapper != "" && cc_wrapper != "ccache") { + hash_h = "$target_gen_dir/bundle/hash.h" + inputs += [ hash_h ] + deps += [ ":bundle_hash_h" ] + if (is_win) { + cflags = [ "/FI" + rebase_path(hash_h, target_out_dir) ] + } else { + cflags = [ + "-include", + rebase_path(hash_h, target_out_dir), + ] + } + } } rust_executable("hyper_hello") { @@ -283,6 +311,29 @@ run_node("bundle") { ] } +action("bundle_hash_h") { + script = "//tools/sha256sum.py" + inputs = get_target_outputs(":bundle") + outputs = [ + "$target_gen_dir/bundle/hash.h", + ] + deps = [ + ":bundle", + ] + args = [ + "--format", + "__attribute__((__unused__)) static const int dummy_%s = 0;", + "--outfile", + rebase_path(outputs[0], root_build_dir), + ] + foreach(input, inputs) { + args += [ + "--infile", + rebase_path(input, root_build_dir), + ] + } +} + ts_flatbuffer("msg_ts") { sources = [ "src/msg.fbs", diff --git a/src/isolate.rs b/src/isolate.rs index c02f4d6c..abc5ded4 100644 --- a/src/isolate.rs +++ b/src/isolate.rs @@ -400,8 +400,12 @@ mod tests { let argv = vec![String::from("./deno"), String::from("hello.js")]; let (flags, rest_argv, _) = flags::set_flags(argv).unwrap(); // TODO Don't use deno_snapshot for these tests. - let mut isolate = - Isolate::new(snapshot::deno_snapshot(), flags, rest_argv, dispatch_sync); + let mut isolate = Isolate::new( + unsafe { snapshot::deno_snapshot.clone() }, + flags, + rest_argv, + dispatch_sync, + ); tokio_util::init(|| { isolate .execute( @@ -443,7 +447,7 @@ mod tests { let (flags, rest_argv, _) = flags::set_flags(argv).unwrap(); // TODO Don't use deno_snapshot for these tests. let mut isolate = Isolate::new( - snapshot::deno_snapshot(), + unsafe { snapshot::deno_snapshot.clone() }, flags, rest_argv, metrics_dispatch_sync, @@ -484,7 +488,7 @@ mod tests { let (flags, rest_argv, _) = flags::set_flags(argv).unwrap(); // TODO Don't use deno_snapshot for these tests. let mut isolate = Isolate::new( - snapshot::deno_snapshot(), + unsafe { snapshot::deno_snapshot.clone() }, flags, rest_argv, metrics_dispatch_async, diff --git a/src/main.rs b/src/main.rs index b05a4164..4595f716 100644 --- a/src/main.rs +++ b/src/main.rs @@ -96,7 +96,7 @@ fn main() { }); let mut isolate = isolate::Isolate::new( - snapshot::deno_snapshot(), + unsafe { snapshot::deno_snapshot.clone() }, flags, rest_argv, ops::dispatch, diff --git a/src/snapshot.cc b/src/snapshot.cc new file mode 100644 index 00000000..b0945d31 --- /dev/null +++ b/src/snapshot.cc @@ -0,0 +1,18 @@ +// 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(const_cast(&snapshot_start)), + static_cast(&snapshot_end - &snapshot_start)}; + +} diff --git a/src/snapshot.rs b/src/snapshot.rs index fcb41f6c..52c8df47 100644 --- a/src/snapshot.rs +++ b/src/snapshot.rs @@ -1,19 +1,5 @@ // Copyright 2018 the Deno authors. All rights reserved. MIT license. use libdeno::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 transmute 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 = unsafe { std::mem::transmute::<*const u8, *mut u8>(ptr) }; - deno_buf { - alloc_ptr: std::ptr::null_mut(), - alloc_len: 0, - data_ptr: ptr_mut, - data_len: data.len(), - } +extern "C" { + pub static deno_snapshot: deno_buf; } -- GitLab