0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-12-23 15:50:11 -05:00

allow building with compatible system clang (#109)

This commit is contained in:
Christian Moritz 2019-12-26 15:43:39 +01:00 committed by Ry Dahl
parent 6cdb55ed62
commit 0303984286
4 changed files with 130 additions and 20 deletions

43
Cargo.lock generated
View file

@ -1,5 +1,13 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "aho-corasick"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "backtrace"
version = "0.3.40"
@ -68,6 +76,11 @@ name = "libc"
version = "0.2.66"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "memchr"
version = "2.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "proc-macro2"
version = "1.0.6"
@ -84,6 +97,22 @@ dependencies = [
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "regex"
version = "1.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)",
"memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"regex-syntax 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)",
"thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "regex-syntax"
version = "0.6.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rustc-demangle"
version = "0.1.16"
@ -97,6 +126,7 @@ dependencies = [
"cargo_gn 0.0.13 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"trybuild 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)",
"which 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -152,6 +182,14 @@ dependencies = [
"wincolor 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "thread_local"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "toml"
version = "0.5.5"
@ -224,6 +262,7 @@ dependencies = [
]
[metadata]
"checksum aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d"
"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 bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
@ -235,8 +274,11 @@ dependencies = [
"checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f"
"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
"checksum libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)" = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558"
"checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e"
"checksum proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9c9e470a8dc4aeae2dee2f335e8f533e2d4b347e1434e5671afc49b054592f27"
"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe"
"checksum regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dc220bd33bdce8f093101afe22a037b8eb0e5af33592e6a9caafff0d4cb81cbd"
"checksum regex-syntax 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "11a7e20d1cce64ef2fed88b66d347f88bd9babb82845b2b858f3edbf59a4f716"
"checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783"
"checksum ryu 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "bfa8506c1de11c9c4e4c38863ccbe02a305c8188e85a05a784c9e11e1c3910c8"
"checksum serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449"
@ -244,6 +286,7 @@ dependencies = [
"checksum serde_json 1.0.44 (registry+https://github.com/rust-lang/crates.io-index)" = "48c575e0cc52bdd09b47f330f646cf59afc586e9c4e3ccd6fc1f625b8ea1dad7"
"checksum syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)" = "dff0acdb207ae2fe6d5976617f887eb1e35a2ba52c13c7234c790960cdad9238"
"checksum termcolor 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "96d6098003bde162e4277c70665bd87c326f5a0c3f3fbfb285787fa482d54e6e"
"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
"checksum toml 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "01d1404644c8b12b16bfcffa4322403a91a451584daaaa7c28d3152e6cbc98cf"
"checksum trybuild 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)" = "b75e31d624df08744532e935f1d4bfedd319a277d5a162c5b15f6ced59307575"
"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"

View file

@ -55,6 +55,7 @@ bitflags = "1.2.1"
[build-dependencies]
cargo_gn = "0.0.13"
which = "3.1.0"
regex = "1.3.1"
[dev-dependencies]
trybuild = "1.0.18"

View file

@ -41,15 +41,17 @@ For linux builds: glib-2.0 development files need to be installed such that
pkg-config can find them. On Ubuntu, run `sudo apt install libglib2.0-dev` to
install them.
There are several binary tools that are automatically downloaded during the
build: clang, gn, and ninja. V8 relies on bleeding edge features of clang that
are not generally available, so we download the clang binary that chromium uses.
gn and ninja are also not generally available so we download them. It should be
possible to opt out of the gn and ninja download by specifying the `$GN` and
`$NINJA` environmental variables. The clang download cannot currently be
skipped, but we welcome any patches to make that possible.
The build depends on several binary tools: `gn`, `ninja` and a recent version
of `clang` (V8 relies on bleeding edge features). Because these are not
generally available they are automatically download during the build by default.
It should be possible to opt out of the gn and ninja download by specifying the
`$GN` and `$NINJA` environmental variables. The clang download can be skipped by
providing a `$CLANG_BASE_PATH` environmental variable pointing to a recent
`llvm`/`clang` installation (currently LLVM v8.0+ or Apple clang v11.0+).
You could also pass in additional arguments to `gn` by setting the `$GN_ARGS`
environmental variable.
Env vars used in build.rs: `SCCACHE`, `GN`, `NINJA`
Env vars used in build.rs: `SCCACHE`, `GN`, `NINJA`, `CLANG_BASE_PATH`, `GN_ARGS`
## FAQ

View file

@ -1,5 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
use cargo_gn;
use regex::Regex;
use std::env;
use std::path::Path;
use std::path::PathBuf;
@ -7,6 +8,10 @@ use std::process::exit;
use std::process::Command;
use which::which;
// Update these whenever a V8 upgrade depends on newer clang features
const MIN_APPLE_CLANG_VER: f32 = 11.0;
const MIN_LLVM_CLANG_VER: f32 = 8.0;
fn main() {
// Detect if trybuild tests are being compiled.
let is_trybuild = env::var_os("DENO_TRYBUILD").is_some();
@ -48,8 +53,17 @@ fn build_v8() {
vec!["is_debug=false".to_string()]
};
let clang_base_path = clang_download();
gn_args.push(format!("clang_base_path={:?}", clang_base_path));
if let Some(clang_base_path) = find_compatible_system_clang() {
println!("clang_base_path {}", clang_base_path.display());
gn_args.push(format!("clang_base_path={:?}", clang_base_path));
// TODO: Dedupe this with the one from cc_wrapper()
gn_args.push("treat_warnings_as_errors=false".to_string());
// we can't use chromiums clang plugins with a system clang
gn_args.push("clang_use_chrome_plugins=false".to_string());
} else {
let clang_base_path = clang_download();
gn_args.push(format!("clang_base_path={:?}", clang_base_path));
}
if let Some(p) = env::var_os("SCCACHE") {
cc_wrapper(&mut gn_args, &Path::new(&p));
@ -59,6 +73,12 @@ fn build_v8() {
println!("cargo:warning=Not using sccache");
}
if let Ok(args) = env::var("GN_ARGS") {
for arg in args.split_whitespace() {
gn_args.push(arg.to_string());
}
}
let gn_root = env::var("CARGO_MANIFEST_DIR").unwrap();
let gn_out = cargo_gn::maybe_gen(&gn_root, gn_args);
@ -122,19 +142,63 @@ fn need_gn_ninja_download() -> bool {
&& env::var_os("GN").is_some())
}
// Chromiums gn arg clang_base_path is currently compatible with:
// * Apples clang and clang from homebrew's llvm@x packages
// * the official binaries from releases.llvm.org
// * unversioned (Linux) packages of clang (if recent enough)
// but unfortunately it doesn't work with version-suffixed packages commonly
// found in Linux packet managers
fn is_compatible_clang_version(clang_path: &Path) -> bool {
let apple_clang_re =
Regex::new(r"(^Apple (?:clang|LLVM) version) ([0-9]+\.[0-9]+)").unwrap();
let llvm_clang_re =
Regex::new(r"(^(?:FreeBSD )?clang version|based on LLVM) ([0-9]+\.[0-9]+)")
.unwrap();
if let Ok(o) = Command::new(clang_path).arg("--version").output() {
let output = String::from_utf8(o.stdout).unwrap();
if let Some(clang_ver) = apple_clang_re.captures(&output) {
let ver: f32 = clang_ver.get(2).unwrap().as_str().parse().unwrap();
if ver >= MIN_APPLE_CLANG_VER {
println!("using Apple clang v{}", ver);
return true;
}
}
if let Some(clang_ver) = llvm_clang_re.captures(&output) {
let ver: f32 = clang_ver.get(2).unwrap().as_str().parse().unwrap();
if ver >= MIN_LLVM_CLANG_VER {
println!("using LLVM clang v{}", ver);
return true;
}
}
}
false
}
fn find_compatible_system_clang() -> Option<PathBuf> {
if let Ok(p) = env::var("CLANG_BASE_PATH") {
let base_path = Path::new(&p);
let clang_path = base_path.join("bin").join("clang");
if is_compatible_clang_version(&clang_path) {
return Some(base_path.to_path_buf());
}
}
if let Ok(clang_path) = which("clang") {
if is_compatible_clang_version(&clang_path) {
return Some(
clang_path.parent().unwrap().parent().unwrap().to_path_buf(),
);
}
}
println!("using Chromiums clang");
None
}
// Download chromium's clang into OUT_DIR because Cargo will not allow us to
// modify the source directory.
fn clang_download() -> PathBuf {
// TODO(ry) We can support clang 10 and above.... if that is installed use
// it.
/*
if let Ok(clang_path) = which("clang") {
//
let bin_path = clang_path.parent().unwrap();
return bin_path.parent().unwrap().to_path_buf();
}
*/
let root = env::current_dir().unwrap();
let out_dir = env::var_os("OUT_DIR").unwrap();
let clang_base_path = root.join(out_dir).join("clang");