From 84a1b4d7935c69c3d12aa74b90c7dfb7931b825a Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Sun, 25 Nov 2018 13:56:04 -0800 Subject: Move libdeno build config to libdeno/BUILD.gn --- BUILD.gn | 120 +++------------------------------------------------ build_extra/deno.gni | 52 ---------------------- libdeno/BUILD.gn | 98 +++++++++++++++++++++++++++++++++++++++++ libdeno/deno.gni | 52 ++++++++++++++++++++++ tools/format.py | 3 +- 5 files changed, 159 insertions(+), 166 deletions(-) delete mode 100644 build_extra/deno.gni create mode 100644 libdeno/BUILD.gn create mode 100644 libdeno/deno.gni diff --git a/BUILD.gn b/BUILD.gn index 060b024a1..c6b29306e 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1,20 +1,20 @@ # Copyright 2018 the Deno authors. All rights reserved. MIT license. import("//build/toolchain/cc_wrapper.gni") -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") +import("//third_party/v8/gni/v8.gni") +import("//third_party/v8/snapshot_toolchain.gni") +import("libdeno/deno.gni") group("default") { testonly = true deps = [ ":deno", ":hyper_hello", - ":test_cc", ":test_rs", + "libdeno:test_cc", ] } @@ -25,31 +25,6 @@ group("cargo_check_deps") { ] } -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" ] - } - - if (is_clang) { - cflags = [ - "-fcolor-diagnostics", - "-fansi-escape-codes", - ] - } -} - main_extern = [ "$rust_build:atty", "$rust_build:dirs", @@ -149,7 +124,7 @@ source_set("snapshot") { sources = [ "src/snapshot.cc", ] - configs += [ ":deno_config" ] + configs += [ "libdeno:deno_config" ] inputs = [ "$target_gen_dir/snapshot_deno.bin", ] @@ -198,89 +173,14 @@ rust_test("test_rs") { ] } -v8_executable("test_cc") { - testonly = true - sources = [ - "libdeno/file_util_test.cc", - "libdeno/libdeno_test.cc", - "libdeno/test.cc", - ] - deps = [ - ":create_snapshot_libdeno_test", - ":libdeno", - "//testing/gtest:gtest", - ] - data = [ - "$target_gen_dir/snapshot_libdeno_test.bin", - ] - snapshot_path = rebase_path(data[0], root_build_dir) - defines = [ "SNAPSHOT_PATH=\"$snapshot_path\"" ] - configs = [ ":deno_config" ] -} - -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. -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", - ] - 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.") - } - } -} - v8_static_library("deno_deps") { complete_static_lib = true public_deps = [ - ":libdeno", ":msg_rs", ":snapshot", + "libdeno:libdeno", ] - configs = [ ":deno_config" ] -} - -v8_executable("snapshot_creator") { - sources = [ - "libdeno/snapshot_creator.cc", - ] - deps = [ - ":libdeno", - ] - configs = [ ":deno_config" ] + configs = [ "libdeno:deno_config" ] } # Generates the core TypeScript type library for deno that will be @@ -380,9 +280,3 @@ create_snapshot("deno") { ":bundle", ] } - -# Generates $target_gen_dir/snapshot_libdeno_test.bin -create_snapshot("libdeno_test") { - testonly = true - js = "libdeno/libdeno_test.js" -} diff --git a/build_extra/deno.gni b/build_extra/deno.gni deleted file mode 100644 index 9e0d43cab..000000000 --- a/build_extra/deno.gni +++ /dev/null @@ -1,52 +0,0 @@ -# Copyright 2018 the Deno authors. All rights reserved. MIT license. -import("//build/compiled_action.gni") - -declare_args() { - # Use prebuilt V8 libraries from //prebuilt/ - use_prebuilt_v8 = true -} - -template("run_node") { - action(target_name) { - forward_variables_from(invoker, "*") - script = "//tools/run_node.py" - } -} - -# Template to generate different V8 snapshots based on different runtime flags. -# Can be invoked with run_mksnapshot(). The target will resolve to -# run_mksnapshot_. If is "default", no file suffixes will be used. -# Otherwise files are suffixed, e.g. embedded_.cc and -# snapshot_blob_.bin. -# -# The template exposes the variables: -# args: additional flags for mksnapshots -# embedded_suffix: a camel case suffix for method names in the embedded -# snapshot. -template("create_snapshot") { - name = target_name - compiled_action("create_snapshot_" + name) { - forward_variables_from(invoker, - [ - "testonly", - "deps", - ]) - tool = ":snapshot_creator" - visibility = [ ":*" ] # Only targets in this file can depend on this. - snapshot_out_bin = "$target_gen_dir/snapshot_$name.bin" - inputs = [ - invoker.js, - ] - if (defined(invoker.source_map)) { - inputs += [ invoker.source_map ] - } - outputs = [ - snapshot_out_bin, - ] - args = rebase_path(outputs, root_build_dir) + - rebase_path(inputs, root_build_dir) - - # To debug snapshotting problems: - # args += ["--trace-serializer"] - } -} diff --git a/libdeno/BUILD.gn b/libdeno/BUILD.gn new file mode 100644 index 000000000..5cd774eaa --- /dev/null +++ b/libdeno/BUILD.gn @@ -0,0 +1,98 @@ +# Copyright 2018 the Deno authors. All rights reserved. MIT license. +import("./deno.gni") +import("//third_party/v8/gni/v8.gni") + +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" ] + } + if (is_clang) { + cflags = [ + "-fcolor-diagnostics", + "-fansi-escape-codes", + ] + } +} + +v8_static_library("v8") { + public_deps = [ + "//build/win:default_exe_manifest", + "//third_party/v8:v8", + "//third_party/v8:v8_libbase", + "//third_party/v8:v8_libplatform", + "//third_party/v8:v8_libsampler", + ] + 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. +v8_static_library("libdeno") { + configs = [ ":deno_config" ] + sources = [ + "api.cc", + "binding.cc", + "deno.h", + "file_util.cc", + "file_util.h", + "internal.h", + ] + 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.") + } + } +} + +v8_executable("snapshot_creator") { + sources = [ + "snapshot_creator.cc", + ] + deps = [ + ":libdeno", + ] + configs = [ ":deno_config" ] +} + +v8_executable("test_cc") { + testonly = true + sources = [ + "file_util_test.cc", + "libdeno_test.cc", + "test.cc", + ] + deps = [ + ":create_snapshot_libdeno_test", + ":libdeno", + "//testing/gtest:gtest", + ] + data = [ + "$target_gen_dir/snapshot_libdeno_test.bin", + ] + snapshot_path = rebase_path(data[0], root_build_dir) + defines = [ "SNAPSHOT_PATH=\"$snapshot_path\"" ] + configs = [ ":deno_config" ] +} + +# Generates $target_gen_dir/snapshot_libdeno_test.bin +create_snapshot("libdeno_test") { + testonly = true + js = "libdeno_test.js" +} diff --git a/libdeno/deno.gni b/libdeno/deno.gni new file mode 100644 index 000000000..55662145f --- /dev/null +++ b/libdeno/deno.gni @@ -0,0 +1,52 @@ +# Copyright 2018 the Deno authors. All rights reserved. MIT license. +import("//build/compiled_action.gni") + +declare_args() { + # Use prebuilt V8 libraries from //prebuilt/ + use_prebuilt_v8 = true +} + +template("run_node") { + action(target_name) { + forward_variables_from(invoker, "*") + script = "//tools/run_node.py" + } +} + +# Template to generate different V8 snapshots based on different runtime flags. +# Can be invoked with run_mksnapshot(). The target will resolve to +# run_mksnapshot_. If is "default", no file suffixes will be used. +# Otherwise files are suffixed, e.g. embedded_.cc and +# snapshot_blob_.bin. +# +# The template exposes the variables: +# args: additional flags for mksnapshots +# embedded_suffix: a camel case suffix for method names in the embedded +# snapshot. +template("create_snapshot") { + name = target_name + compiled_action("create_snapshot_" + name) { + forward_variables_from(invoker, + [ + "testonly", + "deps", + ]) + tool = "//libdeno:snapshot_creator" + visibility = [ ":*" ] # Only targets in this file can depend on this. + snapshot_out_bin = "$target_gen_dir/snapshot_$name.bin" + inputs = [ + invoker.js, + ] + if (defined(invoker.source_map)) { + inputs += [ invoker.source_map ] + } + outputs = [ + snapshot_out_bin, + ] + args = rebase_path(outputs, root_build_dir) + + rebase_path(inputs, root_build_dir) + + # To debug snapshotting problems: + # args += ["--trace-serializer"] + } +} diff --git a/tools/format.py b/tools/format.py index d1e8753d8..d0f2dbab4 100755 --- a/tools/format.py +++ b/tools/format.py @@ -26,7 +26,8 @@ qrun([clang_format_path, "-i", "-style", "Google"] + find_exts(["libdeno"], [".cc", ".h"])) print "gn format" -for fn in ["BUILD.gn", ".gn"] + find_exts(["build_extra"], [".gn", ".gni"]): +for fn in ["BUILD.gn", ".gn"] + find_exts(["build_extra", "libdeno"], + [".gn", ".gni"]): qrun(["third_party/depot_tools/gn", "format", fn], env=google_env()) print "yapf" -- cgit v1.2.3