Skip to content

Commit

Permalink
Remove handlers crate target.
Browse files Browse the repository at this point in the history
- Add build scripts for Rust flatbuffers.
- Rewrites some reply.cc methods in Rust.
- Changes some struct elements to table in msg.fbs (rust flatbuffers
  lacks support currently)
- Renames handlers_test to test_rs.
- This reorg is needed to make progress on the code cache handler.
  • Loading branch information
ry committed Jul 24, 2018
1 parent b79ce93 commit 0213053
Show file tree
Hide file tree
Showing 13 changed files with 377 additions and 181 deletions.
93 changes: 48 additions & 45 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import("//third_party/v8/gni/v8.gni")
import("//third_party/v8/snapshot_toolchain.gni")
import("//build_extra/flatbuffers/flatbuffer.gni")
import("//build_extra/flatbuffers/rust/rust_flatbuffer.gni")
import("//build_extra/deno.gni")
import("//build_extra/rust/rust.gni")

Expand All @@ -10,8 +11,8 @@ group("all") {
deps = [
":deno",
":deno_ns",
":handlers_test",
":test_cc",
":test_rs",
]
}

Expand All @@ -33,12 +34,29 @@ config("deno_config") {
}
}

main_extern = [
"$rust_build:libc",
"$rust_build:log",
"$rust_build:url",
"//build_extra/flatbuffers/rust:flatbuffers",
":msg_rs",

# Indirect rust depdendencies also need to be listed here:
# * Linking to `:handlers` or `:libdeno` isn't possible, because they
# already contain some symbols exported by `handlers.rs`. These duplicate
# symbols trip up the linker.
# * The `rust_test` and `rust_executable` templates only produce an object
# file, and then invoke an external linker. Transitive rust depencenies
# are not resolved in either step.
"$rust_build:idna",
"$rust_build:percent_encoding",
"$rust_build:unicode_bidi",
"$rust_build:unicode_normalization",
]

rust_executable("deno") {
source_root = "src/main.rs"
extern = [
"$rust_build:libc",
"$rust_build:log",
]
extern = main_extern
deps = [
":libdeno",
]
Expand All @@ -50,43 +68,15 @@ rust_executable("deno") {
# ns = no snapshot
rust_executable("deno_ns") {
source_root = "src/main.rs"
extern = [
"$rust_build:libc",
"$rust_build:log",
]
extern = main_extern
deps = [
":libdeno_nosnapshot",
]
}

rust_staticlib("handlers") {
source_root = "src/handlers.rs"
extern = [
"$rust_build:libc",
"$rust_build:url",
"$rust_build:log",
]
}

rust_test("handlers_test") {
source_root = "src/handlers.rs"
extern = [
"$rust_build:libc",
"$rust_build:url",
"$rust_build:log",

# Indirect rust depdendencies also need to be listed here:
# * Linking to `:handlers` or `:libdeno` isn't possible, because they
# already contain some symbols exported by `handlers.rs`. These duplicate
# symbols trip up the linker.
# * The `rust_test` and `rust_executable` templates only produce an object
# file, and then invoke an external linker. Transitive rust depencenies
# are not resolved in either step.
"$rust_build:idna",
"$rust_build:percent_encoding",
"$rust_build:unicode_bidi",
"$rust_build:unicode_normalization",
]
rust_test("test_rs") {
source_root = "src/main.rs"
extern = main_extern
deps = [
":deno_bindings",
]
Expand All @@ -100,8 +90,7 @@ executable("test_cc") {
]
deps = [
":deno_base_test",
":deno_bindings",
":handlers",
":deno_flatbuffer_builder",
"//testing/gtest:gtest",
]
configs += [ ":deno_config" ]
Expand All @@ -115,7 +104,6 @@ static_library("libdeno") {
deps = [
":create_snapshot_deno",
":deno_bindings",
":handlers",
]
configs += [ ":deno_config" ]
}
Expand Down Expand Up @@ -154,23 +142,33 @@ v8_source_set("deno_base_test") {
configs = [ ":deno_config" ]
}

v8_source_set("deno_bindings") {
v8_source_set("deno_flatbuffer_builder") {
sources = [
"src/flatbuffer_builder.cc",
"src/flatbuffer_builder.h",
"src/reply.cc",
"src/reply.h",
]
deps = [
":deno_base",
":msg_cpp",
]
public_deps = [
"build_extra/flatbuffers:flatbuffers",
]
configs = [ ":deno_config" ]
}

v8_source_set("deno_bindings") {
sources = [
"src/reply.cc",
"src/reply.h",
]
deps = [
":deno_base",
":deno_flatbuffer_builder",
":msg_cpp",
]
configs = [ ":deno_config" ]
}

executable("snapshot_creator") {
sources = [
"src/snapshot_creator.cc",
Expand Down Expand Up @@ -232,7 +230,6 @@ source_set("libdeno_nosnapshot") {
deps = [
":bundle",
":deno_bindings",
":handlers",
]
configs += [ ":deno_config" ]
bundle_outputs = get_target_outputs(":bundle")
Expand Down Expand Up @@ -274,6 +271,12 @@ ts_flatbuffer("msg_ts") {
]
}

rust_flatbuffer("msg_rs") {
sources = [
"src/msg.fbs",
]
}

# Generates $target_gen_dir/snapshot_deno.cc
create_snapshot("deno") {
js = "$target_gen_dir/bundle/main.js"
Expand Down
5 changes: 5 additions & 0 deletions build_extra/flatbuffers/rust/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import("//build_extra/rust/rust.gni")

rust_component("flatbuffers") {
source_root = "//third_party/flatbuffers/rust/flatbuffers/src/lib.rs"
}
44 changes: 44 additions & 0 deletions build_extra/flatbuffers/rust/rust_flatbuffer.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import("//build_extra/rust/rust.gni")

# TODO(ry) "flatbuffer.gni" should be "flatbuffers.gni" we should be consistant
# in our pluralization.
import("//build_extra/flatbuffers/flatbuffer.gni")

template("rust_flatbuffer") {
action_name = "${target_name}_gen"
source_set_name = target_name
compiled_action_foreach(action_name) {
tool = "$flatbuffers_build_location:flatc"

sources = invoker.sources
deps = []
out_dir = target_gen_dir

outputs = [
"$out_dir/{{source_name_part}}_generated.rs",
]

args = [
"--rust",
"-o",
rebase_path(out_dir, root_build_dir),
"-I",
rebase_path("//", root_build_dir),
]
args += [ "{{source}}" ]

# The deps may have steps that have to run before running flatc.
if (defined(invoker.deps)) {
deps += invoker.deps
}
}

rust_component(source_set_name) {
sources = get_target_outputs(":$action_name")
source_root = sources[0]
deps = [
":$action_name",
]
extern = [ "//build_extra/flatbuffers/rust:flatbuffers" ]
}
}
1 change: 1 addition & 0 deletions build_extra/rust/rust.gni
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ template("rust_component") {
"is_test",
"testonly",
"args",
"deps",
])
if (!defined(invoker.crate_type)) {
crate_type = "rlib"
Expand Down
5 changes: 3 additions & 2 deletions js/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ function assignCmdId(): number {

function startMsg(cmdId: number): Uint8Array {
const builder = new flatbuffers.Builder();
const msg = fbs.Start.createStart(builder, 0);
fbs.Start.startStart(builder);
const startOffset = fbs.Start.endStart(builder);
fbs.Base.startBase(builder);
fbs.Base.addCmdId(builder, cmdId);
fbs.Base.addMsg(builder, msg);
fbs.Base.addMsg(builder, startOffset);
fbs.Base.addMsgType(builder, fbs.Any.Start);
builder.finish(fbs.Base.endBase(builder));
return builder.asUint8Array();
Expand Down
Loading

0 comments on commit 0213053

Please sign in to comment.