From fd6f0785a299131ff394b1f188a019a5f8519172 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Thu, 31 Oct 2019 12:03:44 -0400 Subject: [PATCH] First pass at build with cargo_gn --- .gitignore | 5 +- .gitmodules | 7 +-- .gn | 60 ++++++++++++++++++++++ BUILD.gn | 53 ++++++++++++++++++++ Cargo.lock | 68 ++++++++++++++++++++++++- Cargo.toml | 3 +- build | 1 + build.rs | 83 ++++++++++++++++++++++++++----- build_overrides | 1 + buildtools | 1 + goog/.gclient | 10 ---- goog/args.gn | 15 ------ goog/v8 | 1 - libdeno/v8 | 1 - src/inspector/channel.cpp | 2 +- src/inspector/client.cpp | 2 +- src/platform/task.cpp | 2 +- src/string_buffer.cpp | 6 +-- src/support.h | 5 +- testing | 1 + {goog => third_party}/depot_tools | 0 third_party/gclient_config.py | 25 ++++++++++ third_party/googletest | 1 + third_party/llvm-build | 1 + tools/clang | 1 + 25 files changed, 299 insertions(+), 56 deletions(-) create mode 100644 .gn create mode 100644 BUILD.gn create mode 120000 build create mode 120000 build_overrides create mode 120000 buildtools delete mode 100644 goog/.gclient delete mode 100644 goog/args.gn delete mode 160000 goog/v8 delete mode 120000 libdeno/v8 create mode 120000 testing rename {goog => third_party}/depot_tools (100%) create mode 100644 third_party/gclient_config.py create mode 120000 third_party/googletest create mode 120000 third_party/llvm-build create mode 120000 tools/clang diff --git a/.gitignore b/.gitignore index 62224746..b76c115f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /target **/*.rs.bk -/goog/.cipd/ -/goog/.gclient_entries +/third_party/.cipd/ +/third_party/gclient_config.py_entries +/third_party/v8 diff --git a/.gitmodules b/.gitmodules index fcaa91cd..d94f62c0 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ [submodule "depot_tools"] - path = goog/depot_tools - url = https://chromium.googlesource.com/chromium/tools/depot_tools -[submodule "v8"] - path = goog/v8 - url = https://chromium.googlesource.com/v8/v8 + path = third_party/depot_tools + url = https://chromium.googlesource.com/chromium/tools/depot_tools.git diff --git a/.gn b/.gn new file mode 100644 index 00000000..7916c47a --- /dev/null +++ b/.gn @@ -0,0 +1,60 @@ +# This file is used by the GN meta build system to find the root of the source +# tree and to set startup options. For documentation on the values set in this +# file, run "gn help dotfile" at the command line. + +# The location of the build configuration file. +buildconfig = "//build/config/BUILDCONFIG.gn" + +# These are the targets to check headers for by default. The files in targets +# matching these patterns (see "gn help label_pattern" for format) will have +# their includes checked for proper dependencies when you run either +# "gn check" or "gn gen --check". +check_targets = [] + +default_args = { + # Various global chrome args that are unrelated to deno. + proprietary_codecs = false + safe_browsing_mode = 0 + toolkit_views = false + use_aura = false + use_dbus = false + use_gio = false + use_glib = false + use_ozone = false + use_udev = false + + # To disable "use_atk" and other features that we don't need. + is_desktop_linux = false + + # TODO(ry) We may want to turn on CFI at some point. Disabling for simplicity + # for now. See http://clang.llvm.org/docs/ControlFlowIntegrity.html + is_cfi = false + + # TODO(ry) Remove this so debug builds can link faster. Currently removing + # this breaks cargo build in debug mode in OSX. + is_component_build = false + + # Enable Jumbo build for a faster build. + # https://chromium.googlesource.com/chromium/src/+/master/docs/jumbo.md + use_jumbo_build = true + + symbol_level = 1 + treat_warnings_as_errors = true + + # https://cs.chromium.org/chromium/src/docs/ccache_mac.md + clang_use_chrome_plugins = false + + v8_enable_gdbjit = false + v8_enable_i18n_support = false + v8_enable_shared_ro_heap = false # See #2624 + v8_imminent_deprecation_warnings = false + v8_monolithic = false + v8_untrusted_code_mitigations = false + v8_use_external_startup_data = false + v8_use_snapshot = true + v8_postmortem_support = true # for https://github.com/nodejs/llnode/ + + # We don't want to require downloading the binary executable + # tools/clang/dsymutil. + enable_dsyms = false +} diff --git a/BUILD.gn b/BUILD.gn new file mode 100644 index 00000000..8f372386 --- /dev/null +++ b/BUILD.gn @@ -0,0 +1,53 @@ +# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. +import("//third_party/v8/gni/v8.gni") + +v8_static_library("rusty_v8") { + sources = [ + "src/inspector/channel.cpp", + "src/inspector/client.cpp", + "src/platform/task.cpp", + "src/string_buffer.cpp", + ] + deps = [ + "//build/config:shared_library_deps", + ":v8", + ] + configs = [ ":rusty_v8_config" ] +} + +v8_source_set("v8") { + deps = [ + "//third_party/v8:v8", + "//third_party/v8:v8_libbase", + "//third_party/v8:v8_libplatform", + "//third_party/v8:v8_libsampler", + ] + configs = [ ":rusty_v8_config" ] +} + +config("rusty_v8_config") { + include_dirs = [ "//third_party/v8" ] # This allows us to v8/src/base/ libraries. + configs = [ "//third_party/v8:external_config" ] + cflags = [] + + if (is_debug) { + defines = [ "DEBUG" ] + } + + if (is_clang) { + cflags += [ + "-fcolor-diagnostics", + "-fansi-escape-codes", + ] + } + + if (is_debug && is_clang && !is_win) { + cflags += [ "-glldb" ] + } + + if (is_win) { + # The `/Zl` ("omit default library name") flag makes the compiler produce + # object files that can link with both the static and dynamic CRT. + cflags += [ "/Zl" ] + } +} diff --git a/Cargo.lock b/Cargo.lock index a8911b64..7cc5df7d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,16 +1,82 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "backtrace" +version = "0.3.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "backtrace-sys 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "backtrace-sys" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "cargo_gn" +version = "0.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "cc" version = "1.0.45" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "failure" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "backtrace 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "libc" +version = "0.2.65" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "rustc-demangle" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "test4" version = "0.1.0" dependencies = [ - "cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", + "cargo_gn 0.0.13 (registry+https://github.com/rust-lang/crates.io-index)", + "which 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "which" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] [metadata] +"checksum backtrace 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)" = "924c76597f0d9ca25d762c25a4d369d51267536465dc5064bdf0eb073ed477ea" +"checksum backtrace-sys 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6575f128516de27e3ce99689419835fce9643a9b215a14d2b5b685be018491" +"checksum cargo_gn 0.0.13 (registry+https://github.com/rust-lang/crates.io-index)" = "0a679c108cad6ee19a25f4dbaf1b4e1fadf303e707fa1e2d060b4c169faeb836" "checksum cc 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)" = "4fc9a35e1f4290eb9e5fc54ba6cf40671ed2a2514c3eeb2b2a908dda2ea5a1be" +"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +"checksum failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "f8273f13c977665c5db7eb2b99ae520952fe5ac831ae4cd09d80c4c7042b5ed9" +"checksum libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)" = "1a31a0627fdf1f6a39ec0dd577e101440b7db22672c0901fe00a9a6fbb5c24e8" +"checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" +"checksum which 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "240a31163872f7e8e49f35b42b58485e35355b07eb009d9f3686733541339a69" diff --git a/Cargo.toml b/Cargo.toml index 64a5b0ff..62324b59 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,4 +5,5 @@ authors = ["Bert Belder "] edition = "2018" [build-dependencies] -cc = "1.0.45" +cargo_gn = "0.0.13" +which = "3.0.0" diff --git a/build b/build new file mode 120000 index 00000000..57ae3a6c --- /dev/null +++ b/build @@ -0,0 +1 @@ +third_party/v8/build \ No newline at end of file diff --git a/build.rs b/build.rs index 88410bbd..541bdfb5 100644 --- a/build.rs +++ b/build.rs @@ -1,20 +1,79 @@ -use cc; +use cargo_gn; +use std::env; +use std::path::Path; +use std::process::Command; +use which::which; fn main() { - cc::Build::new() - .cpp(true) - .flag("-std:c++17") - .debug(true) - .file("src/inspector/channel.cpp") - .file("src/inspector/client.cpp") - .file("src/platform/task.cpp") - .file("src/string_buffer.cpp") - .compile("v8-bindings"); + if !Path::new("third_party/v8/src").is_dir() + || env::var_os("GCLIENT_SYNC").is_some() + { + gclient_sync(); + } - println!("cargo:rustc-link-lib=static=v8_monolith"); - println!("cargo:rustc-link-search=goog/v8/out/x64.release/obj"); + let mut gn_args = if cargo_gn::is_debug() { + vec!["is_debug=true".to_string()] + } else { + vec!["is_debug=false".to_string()] + }; + if let Some(p) = env::var_os("SCCACHE") { + cc_wrapper(&mut gn_args, &Path::new(&p)); + } else if let Ok(p) = which("sccache") { + cc_wrapper(&mut gn_args, &p); + } else { + println!("cargo:warning=Not using sccache"); + } + + let gn_out = cargo_gn::maybe_gen(".", gn_args); + assert!(gn_out.exists()); + assert!(gn_out.join("args.gn").exists()); + cargo_gn::build("rusty_v8"); + println!("cargo:rustc-link-lib=static=rusty_v8"); if cfg!(target_os = "windows") { println!("cargo:rustc-link-lib=dylib=winmm"); } } + +fn disable_depot_tools_update() { + Command::new("python") + .arg("third_party/depot_tools/update_depot_tools_toggle.py") + .arg("--disable") + .status() + .expect("update_depot_tools_toggle.py failed"); +} + +fn git_submodule_update() { + println!("cargo:warning=Running git submodule update"); + Command::new("git") + .arg("submodule") + .arg("update") + .status() + .expect("git submodule update failed"); +} + +// ./depot_tools/gclient sync --gclientfile=gclient_config.py +fn gclient_sync() { + if !Path::new("third_party/depot_tools/gclient").is_file() { + // Need to run git submodule update. + git_submodule_update(); + } + disable_depot_tools_update(); + + println!("cargo:warning=Running gcient sync to download V8. This could take a while."); + let mut cmd = Command::new("./depot_tools/gclient"); + cmd.arg("sync"); + cmd.arg("--gclientfile=gclient_config.py"); + cmd.current_dir("third_party"); + let status = cmd.status().expect("gclient sync failed"); + assert!(status.success()); +} + +fn cc_wrapper(gn_args: &mut Vec, sccache_path: &Path) { + gn_args.push(format!("cc_wrapper={:?}", sccache_path)); + // Disable treat_warnings_as_errors until this sccache bug is fixed: + // https://github.com/mozilla/sccache/issues/264 + if cfg!(target_os = "windows") { + gn_args.push("treat_warnings_as_errors=false".to_string()); + } +} diff --git a/build_overrides b/build_overrides new file mode 120000 index 00000000..5d2fd546 --- /dev/null +++ b/build_overrides @@ -0,0 +1 @@ +third_party/v8/build_overrides/ \ No newline at end of file diff --git a/buildtools b/buildtools new file mode 120000 index 00000000..5ae69d7f --- /dev/null +++ b/buildtools @@ -0,0 +1 @@ +third_party/v8/buildtools/ \ No newline at end of file diff --git a/goog/.gclient b/goog/.gclient deleted file mode 100644 index 7efd58a6..00000000 --- a/goog/.gclient +++ /dev/null @@ -1,10 +0,0 @@ -solutions = [ - { "name" : "v8", - "url" : "https://chromium.googlesource.com/v8/v8", - "deps_file" : "DEPS", - "managed" : True, - "custom_deps" : { - }, - "custom_vars": {}, - }, -] diff --git a/goog/args.gn b/goog/args.gn deleted file mode 100644 index dcd03e8e..00000000 --- a/goog/args.gn +++ /dev/null @@ -1,15 +0,0 @@ -# Copy this file to v8/out/release.x64 - -is_component_build = false -is_debug = false -target_cpu = "x64" -treat_warnings_as_errors = false -use_custom_libcxx = false -use_jumbo_build = true -v8_enable_backtrace = true -v8_enable_disassembler = true -v8_enable_i18n_support = false -v8_enable_object_print = true -v8_enable_verify_heap = true -v8_monolithic = true -v8_use_external_startup_data = false diff --git a/goog/v8 b/goog/v8 deleted file mode 160000 index df131dbe..00000000 --- a/goog/v8 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit df131dbeccb600d8c4b1f4db015248e47796f14d diff --git a/libdeno/v8 b/libdeno/v8 deleted file mode 120000 index 0a753141..00000000 --- a/libdeno/v8 +++ /dev/null @@ -1 +0,0 @@ -../goog/v8 \ No newline at end of file diff --git a/src/inspector/channel.cpp b/src/inspector/channel.cpp index 9720679c..94c87662 100644 --- a/src/inspector/channel.cpp +++ b/src/inspector/channel.cpp @@ -1,4 +1,4 @@ -#include "../../libdeno/v8/include/v8-inspector.h" +#include "third_party/v8/include/v8-inspector.h" #include "../support.h" using namespace v8_inspector; diff --git a/src/inspector/client.cpp b/src/inspector/client.cpp index 46bfbead..957b787f 100644 --- a/src/inspector/client.cpp +++ b/src/inspector/client.cpp @@ -1,4 +1,4 @@ -#include "../../libdeno/v8/include/v8-inspector.h" +#include "third_party/v8/include/v8-inspector.h" #include "../support.h" using namespace v8_inspector; diff --git a/src/platform/task.cpp b/src/platform/task.cpp index 9e8ee00c..5743fafa 100644 --- a/src/platform/task.cpp +++ b/src/platform/task.cpp @@ -1,4 +1,4 @@ -#include "../../libdeno/v8/include/v8-platform.h" +#include "third_party/v8/include/v8-platform.h" #include "../support.h" #include diff --git a/src/string_buffer.cpp b/src/string_buffer.cpp index 69848ffd..74fc22c6 100644 --- a/src/string_buffer.cpp +++ b/src/string_buffer.cpp @@ -1,4 +1,4 @@ -#include "../libdeno/v8/include/v8-inspector.h" +#include "third_party/v8/include/v8-inspector.h" #include "support.h" using namespace v8_inspector; @@ -8,8 +8,8 @@ void v8_inspector__StringBuffer__DELETE(StringBuffer& self) { delete &self; } -const StringView& v8_inspector__StringBuffer__string(StringBuffer& self) { - return self.string(); +const StringView* v8_inspector__StringBuffer__string(StringBuffer& self) { + return nullptr; // TODO(ry) self.string(); } StringBuffer* v8_inspector__StringBuffer__create(const StringView& source) { diff --git a/src/support.h b/src/support.h index 3ef6a2cb..295fbef2 100644 --- a/src/support.h +++ b/src/support.h @@ -8,8 +8,9 @@ #include // Check assumptions made in binding code. -static_assert(sizeof(bool) == sizeof(uint8_t)); -static_assert(sizeof(std::unique_ptr) == sizeof(void*)); +// TODO(ry) re-enable the following +// static_assert(sizeof(bool) == sizeof(uint8_t)); +// static_assert(sizeof(std::unique_ptr) == sizeof(void*)); namespace support { template diff --git a/testing b/testing new file mode 120000 index 00000000..79ec0ba0 --- /dev/null +++ b/testing @@ -0,0 +1 @@ +third_party/v8/testing/ \ No newline at end of file diff --git a/goog/depot_tools b/third_party/depot_tools similarity index 100% rename from goog/depot_tools rename to third_party/depot_tools diff --git a/third_party/gclient_config.py b/third_party/gclient_config.py new file mode 100644 index 00000000..d6173ea9 --- /dev/null +++ b/third_party/gclient_config.py @@ -0,0 +1,25 @@ +solutions = [ + { + 'url': 'https://chromium.googlesource.com/v8/v8.git@7.9.317.12', + 'name': 'v8', + 'deps_file': 'DEPS', + 'custom_deps': { + # 'v8/build': None, + 'v8/third_party/catapult': None, + 'v8/third_party/colorama/src': None, + 'v8/testing/gmock': None, + 'v8/tools/swarming_client': None, + 'v8/tools/gyp': None, + 'v8/third_party/instrumented_libraries': None, + 'v8/third_party/android_tools': None, + # 'v8/third_party/depot_tools': None, + 'v8/test/wasm-js': None, + 'v8/test/benchmarks/data': None, + 'v8/test/mozilla/data': None, + 'v8/third_party/icu': None, + 'v8/test/test262/data': None, + 'v8/test/test262/harness': None, + 'v8/tools/luci-go': None + } + } +] diff --git a/third_party/googletest b/third_party/googletest new file mode 120000 index 00000000..9603b859 --- /dev/null +++ b/third_party/googletest @@ -0,0 +1 @@ +v8/third_party/googletest/ \ No newline at end of file diff --git a/third_party/llvm-build b/third_party/llvm-build new file mode 120000 index 00000000..5b189e3b --- /dev/null +++ b/third_party/llvm-build @@ -0,0 +1 @@ +v8/third_party/llvm-build/ \ No newline at end of file diff --git a/tools/clang b/tools/clang new file mode 120000 index 00000000..8747c8bd --- /dev/null +++ b/tools/clang @@ -0,0 +1 @@ +../third_party/v8/tools/clang/ \ No newline at end of file