Skip to content

Commit

Permalink
Add nosnapshot executables for faster incremental builds (denoland#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
f-a-a authored and ry committed Jul 12, 2018
1 parent 7913571 commit 7e5f0a7
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 8 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ install:
- gn args $BUILD_PATH --list
- ccache -s
# Travis hangs without -j2 argument to ninja.
- ninja -j2 -C $BUILD_PATH mock_runtime_test handlers_test deno_cc deno
- ninja -j2 -C $BUILD_PATH mock_runtime_test handlers_test deno_cc deno_cc_nosnapshot deno deno_nosnapshot
script:
- ./tools/lint.py
- $BUILD_PATH/mock_runtime_test
- $BUILD_PATH/handlers_test
- $BUILD_PATH/deno_cc foo bar
- $BUILD_PATH/deno_cc_nosnapshot foo bar
- $BUILD_PATH/deno meow
- $BUILD_PATH/deno_nosnapshot meow
51 changes: 44 additions & 7 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ config("deno_config") {
rust_executable("deno") {
source_root = "src/main.rs"
extern = [ "$rust_build:libc" ]
deps = [
":libdeno",
]
deps = [ ":libdeno" ]
}

# This target is for fast incremental development.
# When modifying the javascript runtime, this target will not go through the
# extra process of building a snapshot and instead load the bundle from disk.
rust_executable("deno_nosnapshot") {
source_root = "src/main.rs"
extern = [ "$rust_build:libc" ]
deps = [ ":libdeno_nosnapshot" ]
}

rust_staticlib("handlers") {
Expand Down Expand Up @@ -49,6 +56,22 @@ executable("deno_cc") {
configs += [ ":deno_config" ]
}

# This target is for fast incremental development.
# When modifying the javascript runtime, this target will not go through the
# extra process of building a snapshot and instead load the bundle from disk.
executable("deno_cc_nosnapshot") {
sources = [
"src/main.cc",
]
deps = [
":flatbufferjs",
":handlers",
":libdeno_nosnapshot",
":msg_cpp",
]
configs += [ ":deno_config" ]
}

executable("mock_runtime_test") {
testonly = true
sources = [
Expand All @@ -58,7 +81,7 @@ executable("mock_runtime_test") {
]
deps = [
":create_snapshot_mock_runtime",
":deno_nosnapshot",
":deno_bindings",
"//testing/gtest:gtest",
]
defines = [ "DENO_MOCK_RUNTIME" ]
Expand All @@ -72,12 +95,12 @@ static_library("libdeno") {
]
deps = [
":create_snapshot_deno",
":deno_nosnapshot",
":deno_bindings",
]
configs += [ ":deno_config" ]
}

v8_source_set("deno_nosnapshot") {
v8_source_set("deno_bindings") {
sources = [
"src/binding.cc",
"src/deno.h",
Expand All @@ -96,7 +119,7 @@ executable("snapshot_creator") {
"src/snapshot_creator.cc",
]
deps = [
":deno_nosnapshot",
":deno_bindings",
]
configs += [ ":deno_config" ]
}
Expand Down Expand Up @@ -139,6 +162,20 @@ run_node("bundle") {
]
}

source_set("libdeno_nosnapshot") {
sources = [
"src/from_filesystem.cc",
]
deps = [
":bundle",
":deno_bindings",
]
configs += [ ":deno_config" ]
bundle_outputs = get_target_outputs(":bundle")
bundle_location = rebase_path(bundle_outputs[0])
defines = [ "BUNDLE_LOCATION=\"$bundle_location\"" ]
}

# Due to bugs in Parcel we must run TSC independently in order to catch errors.
# https://github.com/parcel-bundler/parcel/issues/954
run_node("run_tsc") {
Expand Down
51 changes: 51 additions & 0 deletions src/from_filesystem.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2018 Ryan Dahl <[email protected]>
// All rights reserved. MIT License.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>

#include "third_party/v8/include/v8.h"
#include "third_party/v8/src/base/logging.h"

#include "deno.h"
#include "file_util.h"
#include "internal.h"

namespace deno {

Deno* NewFromFileSystem(void* data, deno_recv_cb cb) {
printf("Reading javascript runtime bundle from " BUNDLE_LOCATION "\n");

std::string js_source;
CHECK(deno::ReadFileToString(BUNDLE_LOCATION, &js_source));

Deno* d = new Deno;
d->currentArgs = nullptr;
d->cb = cb;
d->data = data;
v8::Isolate::CreateParams params;
params.array_buffer_allocator =
v8::ArrayBuffer::Allocator::NewDefaultAllocator();
v8::Isolate* isolate = v8::Isolate::New(params);
AddIsolate(d, isolate);

v8::Locker locker(isolate);
v8::Isolate::Scope isolate_scope(isolate);
{
v8::HandleScope handle_scope(isolate);
auto context = v8::Context::New(isolate);
InitializeContext(isolate, context, BUNDLE_LOCATION, js_source.c_str());
d->context.Reset(d->isolate, context);
}

return d;
}

} // namespace deno

extern "C" {
Deno* deno_new(void* data, deno_recv_cb cb) {
return deno::NewFromFileSystem(data, cb);
}
}

0 comments on commit 7e5f0a7

Please sign in to comment.