1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-29 16:30:56 -05:00
denoland-deno/BUILD.gn
2018-07-24 10:38:11 -04:00

290 lines
6.5 KiB
Text

# Copyright 2018 the Deno authors. All rights reserved. MIT license.
import("//third_party/v8/gni/v8.gni")
import("//third_party/v8/snapshot_toolchain.gni")
import("//build_extra/flatbuffers/flatbuffer.gni")
import("//build_extra/deno.gni")
import("//build_extra/rust/rust.gni")
group("all") {
testonly = true
deps = [
":deno",
":deno_ns",
":handlers_test",
":test_cc",
]
}
config("deno_config") {
include_dirs = [ "third_party/v8" ] # This allows us to v8/src/base/ libraries.
configs = [ "third_party/v8:external_config" ]
if (is_debug) {
defines = [ "DEBUG" ]
}
# Targets built with the `rust_executable()` template automatically pick up
# these dependencies, but those built with `executable()` need them when they
# have Rust inputs. Currently, there's only one such target, `test_cc`.
if (is_mac) {
libs = [ "resolv" ]
}
if (is_win) {
libs = [ "userenv.lib" ]
}
}
rust_executable("deno") {
source_root = "src/main.rs"
extern = [
"$rust_build:libc",
"$rust_build:log",
]
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.
# ns = no snapshot
rust_executable("deno_ns") {
source_root = "src/main.rs"
extern = [
"$rust_build:libc",
"$rust_build:log",
]
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",
]
deps = [
":deno_bindings",
]
}
executable("test_cc") {
testonly = true
sources = [
"src/flatbuffer_builder_test.cc",
"src/test.cc",
]
deps = [
":deno_base_test",
":deno_bindings",
":handlers",
"//testing/gtest:gtest",
]
configs += [ ":deno_config" ]
}
static_library("libdeno") {
complete_static_lib = true
sources = [
"src/from_snapshot.cc",
]
deps = [
":create_snapshot_deno",
":deno_bindings",
":handlers",
]
configs += [ ":deno_config" ]
}
# Only functionality needed for mock_runtime_test and snapshot_creator
# In particular no flatbuffers, no assets, no rust, no msg handlers.
# Because snapshots are slow, it's important that snapshot_creator's
# dependencies are minimal.
v8_source_set("deno_base") {
sources = [
"src/binding.cc",
"src/deno.h",
"src/file_util.cc",
"src/file_util.h",
"src/internal.h",
]
public_deps = [
"third_party/v8:v8_monolith",
]
configs = [ ":deno_config" ]
}
v8_source_set("deno_base_test") {
testonly = true
sources = [
"src/file_util_test.cc",
"src/from_snapshot.cc",
"src/mock_runtime_test.cc",
]
deps = [
":create_snapshot_mock_runtime",
":deno_base",
"//testing/gtest:gtest",
]
defines = [ "DENO_MOCK_RUNTIME" ]
configs = [ ":deno_config" ]
}
v8_source_set("deno_bindings") {
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" ]
}
executable("snapshot_creator") {
sources = [
"src/snapshot_creator.cc",
]
deps = [
":deno_base",
]
configs += [ ":deno_config" ]
}
flatbuffer("msg_cpp") {
sources = [
"src/msg.fbs",
]
}
run_node("bundle") {
out_dir = "$target_gen_dir/bundle/"
sources = [
"js/assets.ts",
"js/console.ts",
"js/deno.d.ts",
"js/dispatch.ts",
"js/globals.ts",
"js/main.ts",
"js/msg_generated.ts",
"js/os.ts",
"js/runtime.ts",
"js/types.ts",
"js/util.ts",
"rollup.config.js",
"tsconfig.json",
]
outputs = [
out_dir + "main.js",
out_dir + "main.js.map",
]
deps = [
":flatbufferjs",
]
args = [
"./node_modules/rollup/bin/rollup",
"-c",
rebase_path("rollup.config.js", root_build_dir),
"-i",
rebase_path("js/main.ts", root_build_dir),
"-o",
rebase_path(out_dir + "main.js", root_build_dir),
"--silent",
"--environment",
"BASEPATH:" + rebase_path(".", root_build_dir),
]
}
source_set("libdeno_nosnapshot") {
sources = [
"src/from_filesystem.cc",
]
deps = [
":bundle",
":deno_bindings",
":handlers",
]
configs += [ ":deno_config" ]
bundle_outputs = get_target_outputs(":bundle")
bundle_location = rebase_path(bundle_outputs[0])
defines = [ "BUNDLE_LOCATION=\"$bundle_location\"" ]
}
# Generates flatbuffer TypeScript code.
# TODO(ry) Ideally flatc output files should be written into
# target_gen_dir, but its difficult to get this working in a way that the
# bundler can resolve their location. (The bundler does not support NODE_PATH?)
# Therefore this hack: write the msg_generated.ts output
# into the js/ folder, and we check it into the repo. Hopefully this hack can
# be removed at some point. If msg.fps is changed, commit changes to the
# generated JS files. The stamp file is just to make gn work.
action("flatbufferjs") {
script = "//tools/flatbufferjs_hack.py"
sources = [
"src/msg.fbs",
]
outputs = [
"$target_gen_dir/flatbufferjs_hack.stamp",
]
args = [
rebase_path("$target_gen_dir/msg_generated.ts", root_build_dir),
rebase_path("js/msg_generated.ts", root_build_dir),
rebase_path(outputs[0], root_build_dir),
]
deps = [
":msg_ts",
]
}
ts_flatbuffer("msg_ts") {
sources = [
"src/msg.fbs",
]
}
# Generates $target_gen_dir/snapshot_deno.cc
create_snapshot("deno") {
js = "$target_gen_dir/bundle/main.js"
deps = [
":bundle",
]
}
# Generates $target_gen_dir/snapshot_mock_runtime.cc
create_snapshot("mock_runtime") {
testonly = true
js = "js/mock_runtime.js"
deps = []
}