1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-22 15:10:44 -05:00
denoland-deno/BUILD.gn

389 lines
8.8 KiB
Text
Raw Normal View History

# Copyright 2018 the Deno authors. All rights reserved. MIT license.
import("//build/toolchain/cc_wrapper.gni")
2018-07-03 17:15:32 +09:00
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")
import("//build_extra/toolchain/validate.gni")
2018-08-17 18:23:14 -04:00
group("default") {
2018-07-12 18:37:06 -04:00
testonly = true
deps = [
":deno",
":hyper_hello",
2018-07-12 18:37:06 -04:00
":test_cc",
":test_rs",
2018-07-12 18:37:06 -04:00
]
}
# Set of targets that need to be built for `cargo check` to succeed.
group("cargo_check_deps") {
deps = [
":msg_rs",
]
}
2018-06-19 12:54:24 +02:00
config("deno_config") {
2018-07-03 17:15:32 +09:00
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" ]
}
if (is_clang) {
cflags = [
"-fcolor-diagnostics",
"-fansi-escape-codes",
]
}
2018-06-19 12:54:24 +02:00
}
main_extern = [
"$rust_build:atty",
"$rust_build:dirs",
"$rust_build:futures",
"$rust_build:getopts",
"$rust_build:http",
2018-08-06 00:50:15 +02:00
"$rust_build:hyper",
"$rust_build:hyper_rustls",
"$rust_build:lazy_static",
"$rust_build:libc",
"$rust_build:log",
"$rust_build:rand",
"$rust_build:remove_dir_all",
"$rust_build:ring",
"$rust_build:rustyline",
2018-07-24 01:45:23 -04:00
"$rust_build:tempfile",
"$rust_build:tokio",
"$rust_build:tokio_executor",
"$rust_build:tokio_fs",
"$rust_build:tokio_io",
"$rust_build:tokio_process",
2018-09-22 04:42:07 -04:00
"$rust_build:tokio_threadpool",
"$rust_build:url",
"//build_extra/flatbuffers/rust:flatbuffers",
]
2018-09-12 10:33:30 -04:00
ts_sources = [
"js/assets.ts",
2018-09-14 17:15:50 +04:30
"js/blob.ts",
"js/buffer.ts",
"js/chmod.ts",
2018-09-12 10:33:30 -04:00
"js/compiler.ts",
"js/console.ts",
"js/copy_file.ts",
2018-09-12 10:33:30 -04:00
"js/deno.ts",
2018-10-14 01:33:27 +05:30
"js/dir.ts",
2018-09-12 10:33:30 -04:00
"js/dispatch.ts",
2018-09-16 16:46:12 +10:00
"js/dom_types.ts",
2018-09-12 10:33:30 -04:00
"js/errors.ts",
"js/fetch.ts",
"js/file.ts",
2018-10-03 21:41:59 -04:00
"js/file_info.ts",
"js/files.ts",
"js/flatbuffers.ts",
"js/form_data.ts",
2018-10-03 21:41:59 -04:00
"js/global_eval.ts",
2018-09-12 10:33:30 -04:00
"js/globals.ts",
"js/headers.ts",
"js/io.ts",
2018-09-12 10:33:30 -04:00
"js/libdeno.ts",
"js/main.ts",
2018-09-13 11:04:45 +09:00
"js/make_temp_dir.ts",
2018-10-05 19:21:15 +02:00
"js/metrics.ts",
"js/mkdir.ts",
2018-09-12 10:33:30 -04:00
"js/mock_builtin.js",
"js/net.ts",
2018-09-12 10:33:30 -04:00
"js/os.ts",
2018-09-19 23:13:59 -07:00
"js/platform.ts",
2018-09-12 10:33:30 -04:00
"js/plugins.d.ts",
"js/process.ts",
2018-10-12 11:22:52 -07:00
"js/promise_util.ts",
2018-10-04 06:56:56 +09:00
"js/read_dir.ts",
"js/read_file.ts",
"js/read_link.ts",
2018-09-12 10:33:30 -04:00
"js/remove.ts",
"js/rename.ts",
"js/repl.ts",
"js/resources.ts",
2018-11-20 10:51:35 +11:00
"js/runner.ts",
2018-09-12 10:33:30 -04:00
"js/stat.ts",
2018-09-18 21:38:24 -07:00
"js/symlink.ts",
2018-09-12 10:33:30 -04:00
"js/text_encoding.ts",
"js/timers.ts",
2018-10-01 03:06:20 +08:00
"js/truncate.ts",
2018-09-12 10:33:30 -04:00
"js/types.ts",
2018-10-21 17:07:29 +02:00
"js/url_search_params.ts",
2018-09-12 10:33:30 -04:00
"js/util.ts",
"js/v8_source_maps.ts",
"js/write_file.ts",
"tsconfig.json",
# Listing package.json and yarn.lock as sources ensures the bundle is rebuilt
# when npm packages are added/removed or their contents changes.
"package.json",
"third_party/yarn.lock",
2018-09-12 10:33:30 -04:00
]
2018-06-23 09:42:06 +02:00
rust_executable("deno") {
source_root = "src/main.rs"
extern = main_extern
2018-07-12 18:38:00 -04:00
deps = [
":deno_deps",
2018-07-12 18:38:00 -04:00
]
}
source_set("snapshot") {
sources = [
"src/snapshot.cc",
]
configs += [ ":deno_config" ]
inputs = [
"$target_gen_dir/snapshot_deno.bin",
]
2018-06-10 14:24:39 +02:00
deps = [
2018-06-11 17:01:35 +02:00
":create_snapshot_deno",
2018-06-10 14:24:39 +02:00
]
# 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),
]
}
}
2018-06-10 14:24:39 +02:00
}
rust_executable("hyper_hello") {
source_root = "tools/hyper_hello.rs"
extern = [
"$rust_build:hyper",
"$rust_build:ring",
]
}
rust_test("test_rs") {
source_root = "src/main.rs"
extern = main_extern
deps = [
2018-11-01 18:27:13 -04:00
":deno_deps",
]
}
v8_executable("test_cc") {
testonly = true
sources = [
"libdeno/file_util_test.cc",
"libdeno/libdeno_test.cc",
2018-10-23 19:16:27 -04:00
"libdeno/test.cc",
]
deps = [
":create_snapshot_libdeno_test",
":libdeno",
"//testing/gtest:gtest",
]
2018-10-23 19:16:27 -04:00
data = [
"$target_gen_dir/snapshot_libdeno_test.bin",
]
2018-11-01 13:05:21 +01:00
snapshot_path = rebase_path(data[0], root_build_dir)
defines = [ "SNAPSHOT_PATH=\"$snapshot_path\"" ]
configs = [ ":deno_config" ]
}
2018-11-27 17:21:05 -05:00
v8_static_library("v8") {
public_deps = [
"third_party/v8:v8",
"third_party/v8:v8_libbase",
"third_party/v8:v8_libplatform",
"third_party/v8:v8_libsampler",
"//build/win:default_exe_manifest",
]
configs = [ ":deno_config" ]
}
# Only functionality needed for libdeno_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.
2018-11-27 17:21:05 -05:00
v8_static_library("libdeno") {
configs = [ ":deno_config" ]
sources = [
"libdeno/api.cc",
"libdeno/binding.cc",
"libdeno/deno.h",
"libdeno/file_util.cc",
"libdeno/file_util.h",
"libdeno/internal.h",
]
2018-11-27 17:21:05 -05:00
if (!use_prebuilt_v8) {
public_deps = [
":v8",
]
} else {
# TODO(ry) It would be nice to have a standalone target for the prebuilt
# library that could simply be added to the deps here, but it wasn't
# obvious how to accomplish that in gn.
if (is_mac) {
libs = [ "//prebuilt/mac/libv8.a" ]
} else if (is_linux) {
libs = [ "//prebuilt/linux64/libv8.a" ]
} else if (is_win) {
libs = [ "//prebuilt/win/v8.lib" ]
} else {
assert(false, "We don't have prebuilt binaries for this platform yet.")
}
}
}
2018-11-27 17:21:05 -05:00
v8_static_library("deno_deps") {
complete_static_lib = true
public_deps = [
":libdeno",
":msg_rs",
":snapshot",
]
2018-11-27 17:21:05 -05:00
configs = [ ":deno_config" ]
}
2018-11-27 17:21:05 -05:00
v8_executable("snapshot_creator") {
2018-06-10 14:24:39 +02:00
sources = [
"libdeno/snapshot_creator.cc",
2018-06-10 14:24:39 +02:00
]
deps = [
":libdeno",
2018-06-10 14:24:39 +02:00
]
2018-11-27 17:21:05 -05:00
configs = [ ":deno_config" ]
2018-06-10 14:24:39 +02:00
}
# Generates the core TypeScript type library for deno that will be
# included in the runtime bundle
run_node("deno_runtime_declaration") {
2018-08-07 13:27:31 -07:00
out_dir = target_gen_dir
2018-09-12 10:33:30 -04:00
sources = ts_sources
2018-08-07 13:27:31 -07:00
outputs = [
"$out_dir/lib/lib.deno_runtime.d.ts",
2018-08-07 13:27:31 -07:00
]
deps = [
":msg_ts",
]
args = [
rebase_path("node_modules/ts-node/dist/bin.js", root_build_dir),
"--project",
rebase_path("tools/ts_library_builder/tsconfig.json"),
rebase_path("tools/ts_library_builder/main.ts", root_build_dir),
"--basePath",
rebase_path(".", root_build_dir),
"--buildPath",
rebase_path(root_build_dir, root_build_dir),
"--outFile",
rebase_path("$out_dir/lib/lib.deno_runtime.d.ts", root_build_dir),
"--silent",
2018-08-07 13:27:31 -07:00
]
if (is_debug) {
args += [ "--debug" ]
}
2018-08-07 13:27:31 -07:00
}
2018-06-12 03:54:55 +02:00
run_node("bundle") {
out_dir = "$target_gen_dir/bundle/"
outputs = [
out_dir + "main.js",
2018-07-22 03:14:52 +02:00
out_dir + "main.js.map",
2018-06-12 03:54:55 +02:00
]
depfile = out_dir + "main.d"
2018-06-12 03:54:55 +02:00
deps = [
":deno_runtime_declaration",
2018-07-26 13:07:50 +10:00
":msg_ts",
]
2018-06-12 03:54:55 +02:00
args = [
rebase_path("third_party/node_modules/rollup/bin/rollup", root_build_dir),
2018-07-22 03:14:52 +02:00
"-c",
rebase_path("rollup.config.js", root_build_dir),
"-i",
rebase_path("js/main.ts", root_build_dir),
2018-07-22 03:14:52 +02:00
"-o",
rebase_path(out_dir + "main.js", root_build_dir),
"--sourcemapFile",
rebase_path("."),
2018-07-22 03:14:52 +02:00
"--silent",
2018-06-12 03:54:55 +02:00
]
}
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),
]
}
}
2018-07-04 14:50:28 -04:00
ts_flatbuffer("msg_ts") {
sources = [
"src/msg.fbs",
]
}
rust_flatbuffer("msg_rs") {
sources = [
"src/msg.fbs",
]
}
# Generates $target_gen_dir/snapshot_deno.bin
create_snapshot("deno") {
2018-06-12 03:54:55 +02:00
js = "$target_gen_dir/bundle/main.js"
source_map = "$target_gen_dir/bundle/main.js.map"
deps = [
2018-06-12 03:54:55 +02:00
":bundle",
]
}
2018-06-11 17:01:35 +02:00
# Generates $target_gen_dir/snapshot_libdeno_test.bin
create_snapshot("libdeno_test") {
2018-06-11 17:01:35 +02:00
testonly = true
js = "libdeno/libdeno_test.js"
2018-06-11 17:01:35 +02:00
}