Skip to content

Commit

Permalink
Don't build twice the sanitizers on Linux
Browse files Browse the repository at this point in the history
This commit is an attempted fix at rust-lang#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 rust-lang#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.
  • Loading branch information
alexcrichton committed Jul 18, 2018
1 parent 29ee654 commit 2e5d925
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 15 deletions.
27 changes: 20 additions & 7 deletions src/build_helper/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
///
Expand Down Expand Up @@ -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")));
}
}
}

Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_asan/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_lsan/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_msan/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_tsan/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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");
Expand Down

0 comments on commit 2e5d925

Please sign in to comment.