Rollup merge of #52487 - alexcrichton:build-less-sanitizers, r=kennytm
Don't build twice the sanitizers on Linux This commit is an attempted fix at #50887. It was noticed that on that issue we're building both x86_64 and i386 versions of libraries, but we only actually need the x86_64 versions! This hopes that the build race condition exhibited in #50887 is connected to building both architectures and/or building a lot of libraries, so this should help us build precisely what we need and no more.
This commit is contained in:
commit
1e5a8c65c1
|
@ -15,6 +15,7 @@ use std::path::{Path, PathBuf};
|
|||
use std::process::{Command, Stdio};
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
use std::{env, fs};
|
||||
use std::thread;
|
||||
|
||||
/// A helper macro to `unwrap` a result except also print out details like:
|
||||
///
|
||||
|
@ -181,7 +182,9 @@ pub struct NativeLibBoilerplate {
|
|||
|
||||
impl Drop for NativeLibBoilerplate {
|
||||
fn drop(&mut self) {
|
||||
t!(File::create(self.out_dir.join("rustbuild.timestamp")));
|
||||
if !thread::panicking() {
|
||||
t!(File::create(self.out_dir.join("rustbuild.timestamp")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -225,24 +228,34 @@ pub fn native_lib_boilerplate(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn sanitizer_lib_boilerplate(sanitizer_name: &str) -> Result<NativeLibBoilerplate, ()> {
|
||||
let (link_name, search_path) = match &*env::var("TARGET").unwrap() {
|
||||
pub fn sanitizer_lib_boilerplate(sanitizer_name: &str)
|
||||
-> Result<(NativeLibBoilerplate, String), ()>
|
||||
{
|
||||
let (link_name, search_path, dynamic) = match &*env::var("TARGET").unwrap() {
|
||||
"x86_64-unknown-linux-gnu" => (
|
||||
format!("clang_rt.{}-x86_64", sanitizer_name),
|
||||
"build/lib/linux",
|
||||
false,
|
||||
),
|
||||
"x86_64-apple-darwin" => (
|
||||
format!("dylib=clang_rt.{}_osx_dynamic", sanitizer_name),
|
||||
format!("clang_rt.{}_osx_dynamic", sanitizer_name),
|
||||
"build/lib/darwin",
|
||||
true,
|
||||
),
|
||||
_ => return Err(()),
|
||||
};
|
||||
native_lib_boilerplate(
|
||||
let to_link = if dynamic {
|
||||
format!("dylib={}", link_name)
|
||||
} else {
|
||||
format!("static={}", link_name)
|
||||
};
|
||||
let lib = native_lib_boilerplate(
|
||||
"libcompiler_builtins/compiler-rt",
|
||||
sanitizer_name,
|
||||
&link_name,
|
||||
&to_link,
|
||||
search_path,
|
||||
)
|
||||
)?;
|
||||
Ok((lib, link_name))
|
||||
}
|
||||
|
||||
fn dir_up_to_date(src: &Path, threshold: SystemTime) -> bool {
|
||||
|
|
|
@ -18,7 +18,7 @@ use cmake::Config;
|
|||
|
||||
fn main() {
|
||||
if let Some(llvm_config) = env::var_os("LLVM_CONFIG") {
|
||||
let native = match sanitizer_lib_boilerplate("asan") {
|
||||
let (native, target) = match sanitizer_lib_boilerplate("asan") {
|
||||
Ok(native) => native,
|
||||
_ => return,
|
||||
};
|
||||
|
@ -29,7 +29,7 @@ fn main() {
|
|||
.define("COMPILER_RT_BUILD_XRAY", "OFF")
|
||||
.define("LLVM_CONFIG_PATH", llvm_config)
|
||||
.out_dir(&native.out_dir)
|
||||
.build_target("asan")
|
||||
.build_target(&target)
|
||||
.build();
|
||||
}
|
||||
println!("cargo:rerun-if-env-changed=LLVM_CONFIG");
|
||||
|
|
|
@ -18,7 +18,7 @@ use cmake::Config;
|
|||
|
||||
fn main() {
|
||||
if let Some(llvm_config) = env::var_os("LLVM_CONFIG") {
|
||||
let native = match sanitizer_lib_boilerplate("lsan") {
|
||||
let (native, target) = match sanitizer_lib_boilerplate("lsan") {
|
||||
Ok(native) => native,
|
||||
_ => return,
|
||||
};
|
||||
|
@ -29,7 +29,7 @@ fn main() {
|
|||
.define("COMPILER_RT_BUILD_XRAY", "OFF")
|
||||
.define("LLVM_CONFIG_PATH", llvm_config)
|
||||
.out_dir(&native.out_dir)
|
||||
.build_target("lsan")
|
||||
.build_target(&target)
|
||||
.build();
|
||||
}
|
||||
println!("cargo:rerun-if-env-changed=LLVM_CONFIG");
|
||||
|
|
|
@ -18,7 +18,7 @@ use cmake::Config;
|
|||
|
||||
fn main() {
|
||||
if let Some(llvm_config) = env::var_os("LLVM_CONFIG") {
|
||||
let native = match sanitizer_lib_boilerplate("msan") {
|
||||
let (native, target) = match sanitizer_lib_boilerplate("msan") {
|
||||
Ok(native) => native,
|
||||
_ => return,
|
||||
};
|
||||
|
@ -29,7 +29,7 @@ fn main() {
|
|||
.define("COMPILER_RT_BUILD_XRAY", "OFF")
|
||||
.define("LLVM_CONFIG_PATH", llvm_config)
|
||||
.out_dir(&native.out_dir)
|
||||
.build_target("msan")
|
||||
.build_target(&target)
|
||||
.build();
|
||||
}
|
||||
println!("cargo:rerun-if-env-changed=LLVM_CONFIG");
|
||||
|
|
|
@ -18,7 +18,7 @@ use cmake::Config;
|
|||
|
||||
fn main() {
|
||||
if let Some(llvm_config) = env::var_os("LLVM_CONFIG") {
|
||||
let native = match sanitizer_lib_boilerplate("tsan") {
|
||||
let (native, target) = match sanitizer_lib_boilerplate("tsan") {
|
||||
Ok(native) => native,
|
||||
_ => return,
|
||||
};
|
||||
|
@ -29,7 +29,7 @@ fn main() {
|
|||
.define("COMPILER_RT_BUILD_XRAY", "OFF")
|
||||
.define("LLVM_CONFIG_PATH", llvm_config)
|
||||
.out_dir(&native.out_dir)
|
||||
.build_target("tsan")
|
||||
.build_target(&target)
|
||||
.build();
|
||||
}
|
||||
println!("cargo:rerun-if-env-changed=LLVM_CONFIG");
|
||||
|
|
Loading…
Reference in New Issue