Skip to content

Commit fd68f85

Browse files
committed
libdeno: deno_new should take a snapshot parameter.
1 parent 3438dbe commit fd68f85

13 files changed

+193
-160
lines changed

.appveyor.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,11 @@ after_test:
390390
Select-String $trap -Path $files -SimpleMatch | where {
391391
# V8 took the liberty to produce an absolute path in their ninja
392392
# output. We can't do much about that, so we just ignore it.
393-
$_.Line -notmatch "v8/builtins-generated/bytecodes-builtins-list.h"
393+
$_.Line -notmatch "v8/builtins-generated/bytecodes-builtins-list.h" -and
394+
# The absolute path to snapshot_libdeno_test.bin is passed to test_cc
395+
# via pre-processor variable. It's absolute because we want to be able
396+
# to execute test_cc from both the project root and the build root.
397+
$_.Line -notmatch "snapshot_libdeno_test.bin"
394398
} | tee -Variable line_matches
395399
if ($line_matches) {
396400
$ctx = $line_matches.Line |

BUILD.gn

Lines changed: 47 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -124,52 +124,26 @@ rust_executable("deno") {
124124
extern = main_extern
125125
deps = [
126126
":libdeno",
127+
":snapshot",
127128
]
128129
}
129130

130-
rust_executable("hyper_hello") {
131-
source_root = "tools/hyper_hello.rs"
132-
extern = [
133-
"$rust_build:hyper",
134-
"$rust_build:ring",
135-
]
136-
}
137-
138-
rust_test("test_rs") {
139-
source_root = "src/main.rs"
140-
extern = main_extern
141-
deps = [
142-
":libdeno",
143-
]
144-
}
145-
146-
v8_executable("test_cc") {
147-
testonly = true
148-
sources = [
149-
"libdeno/test.cc",
150-
]
151-
deps = [
152-
":deno_base_test",
153-
"//testing/gtest:gtest",
154-
]
155-
configs = [ ":deno_config" ]
156-
}
157-
158-
static_library("libdeno") {
159-
complete_static_lib = true
131+
source_set("snapshot") {
160132
sources = [
161-
"libdeno/from_snapshot.cc",
133+
"src/snapshot.cc",
162134
]
163-
inputs = [
135+
configs += [ ":deno_config" ]
136+
data = [
164137
"$target_gen_dir/snapshot_deno.bin",
165138
]
166139
deps = [
167140
":create_snapshot_deno",
168-
":deno_bindings",
169141
]
170-
configs += [ ":deno_config" ]
171142

172-
# from_snapshot.cc uses an assembly '.incbin' directive to embed the snapshot.
143+
# snapshot.cc doesn't need to depend on libdeno, it just needs deno_buf.
144+
include_dirs = [ "libdeno/" ]
145+
146+
# src/snapshot.cc uses an assembly '.incbin' directive to embed the snapshot.
173147
# This causes trouble when using sccache: since the snapshot file is not
174148
# inlined by the c preprocessor, sccache doesn't take its contents into
175149
# consideration, leading to false-positive cache hits.
@@ -178,7 +152,9 @@ static_library("libdeno") {
178152
# header file that contains the the sha256 hash of the snapshot.
179153
if (cc_wrapper != "" && cc_wrapper != "ccache") {
180154
hash_h = "$target_gen_dir/bundle/hash.h"
181-
inputs += [ hash_h ]
155+
inputs = [
156+
hash_h,
157+
]
182158
deps += [ ":bundle_hash_h" ]
183159
if (is_win) {
184160
cflags = [ "/FI" + rebase_path(hash_h, target_out_dir) ]
@@ -191,57 +167,69 @@ static_library("libdeno") {
191167
}
192168
}
193169

194-
# Only functionality needed for libdeno_test and snapshot_creator
195-
# In particular no flatbuffers, no assets, no rust, no msg handlers.
196-
# Because snapshots are slow, it's important that snapshot_creator's
197-
# dependencies are minimal.
198-
v8_source_set("deno_base") {
199-
sources = [
200-
"libdeno/binding.cc",
201-
"libdeno/deno.h",
202-
"libdeno/file_util.cc",
203-
"libdeno/file_util.h",
204-
"libdeno/internal.h",
170+
rust_executable("hyper_hello") {
171+
source_root = "tools/hyper_hello.rs"
172+
extern = [
173+
"$rust_build:hyper",
174+
"$rust_build:ring",
205175
]
206-
public_deps = [
207-
"third_party/v8:v8_monolith",
176+
}
177+
178+
rust_test("test_rs") {
179+
source_root = "src/main.rs"
180+
extern = main_extern
181+
deps = [
182+
":libdeno",
183+
":snapshot",
208184
]
209-
configs = [ ":deno_config" ]
210185
}
211186

212-
v8_source_set("deno_base_test") {
187+
v8_executable("test_cc") {
213188
testonly = true
214189
sources = [
215190
"libdeno/file_util_test.cc",
216-
"libdeno/from_snapshot.cc",
217191
"libdeno/libdeno_test.cc",
218192
"libdeno/test.cc",
219193
]
220194
deps = [
221195
":create_snapshot_libdeno_test",
222-
":deno_base",
196+
":libdeno",
223197
"//testing/gtest:gtest",
224198
]
225199
data = [
226200
"$target_gen_dir/snapshot_libdeno_test.bin",
227201
]
228-
defines = [ "LIBDENO_TEST" ]
202+
snapshot_abs_path = rebase_path(data[0])
203+
defines = [ "SNAPSHOT_PATH=\"$snapshot_abs_path\"" ]
229204
configs = [ ":deno_config" ]
230205
}
231206

232-
v8_source_set("deno_bindings") {
233-
deps = [
234-
":deno_base",
207+
# Only functionality needed for libdeno_test and snapshot_creator
208+
# In particular no flatbuffers, no assets, no rust, no msg handlers.
209+
# Because snapshots are slow, it's important that snapshot_creator's
210+
# dependencies are minimal.
211+
static_library("libdeno") {
212+
complete_static_lib = true
213+
sources = [
214+
"libdeno/binding.cc",
215+
"libdeno/deno.h",
216+
"libdeno/file_util.cc",
217+
"libdeno/file_util.h",
218+
"libdeno/internal.h",
219+
"libdeno/new.cc",
235220
]
236-
configs = [ ":deno_config" ]
221+
public_deps = [
222+
"third_party/v8:v8_monolith",
223+
]
224+
configs += [ ":deno_config" ]
237225
}
238226

239227
executable("snapshot_creator") {
240228
sources = [
241229
"libdeno/snapshot_creator.cc",
242230
]
243231
deps = [
244-
":deno_base",
232+
":libdeno",
245233
]
246234
configs += [ ":deno_config" ]
247235
}

libdeno/deno.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void deno_init();
3030
const char* deno_v8_version();
3131
void deno_set_v8_flags(int* argc, char** argv);
3232

33-
Deno* deno_new(deno_recv_cb cb);
33+
Deno* deno_new(deno_buf snapshot, deno_recv_cb cb);
3434
void deno_delete(Deno* d);
3535

3636
// Returns false on error.

libdeno/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct deno_s {
1717
v8::Persistent<v8::Function> global_error_handler;
1818
v8::Persistent<v8::Function> promise_reject_handler;
1919
v8::Persistent<v8::Function> promise_error_examiner;
20-
20+
v8::StartupData snapshot;
2121
v8::Persistent<v8::ArrayBuffer> global_import_buf;
2222
void* global_import_buf_ptr;
2323

0 commit comments

Comments
 (0)