Skip to content

Commit 1e5a8c6

Browse files
committed
Rollup merge of rust-lang#52487 - alexcrichton:build-less-sanitizers, r=kennytm
Don't build twice the sanitizers on Linux 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.
2 parents 091c9d2 + 2e5d925 commit 1e5a8c6

File tree

5 files changed

+28
-15
lines changed

5 files changed

+28
-15
lines changed

src/build_helper/lib.rs

+20-7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use std::path::{Path, PathBuf};
1515
use std::process::{Command, Stdio};
1616
use std::time::{SystemTime, UNIX_EPOCH};
1717
use std::{env, fs};
18+
use std::thread;
1819

1920
/// A helper macro to `unwrap` a result except also print out details like:
2021
///
@@ -181,7 +182,9 @@ pub struct NativeLibBoilerplate {
181182

182183
impl Drop for NativeLibBoilerplate {
183184
fn drop(&mut self) {
184-
t!(File::create(self.out_dir.join("rustbuild.timestamp")));
185+
if !thread::panicking() {
186+
t!(File::create(self.out_dir.join("rustbuild.timestamp")));
187+
}
185188
}
186189
}
187190

@@ -225,24 +228,34 @@ pub fn native_lib_boilerplate(
225228
}
226229
}
227230

228-
pub fn sanitizer_lib_boilerplate(sanitizer_name: &str) -> Result<NativeLibBoilerplate, ()> {
229-
let (link_name, search_path) = match &*env::var("TARGET").unwrap() {
231+
pub fn sanitizer_lib_boilerplate(sanitizer_name: &str)
232+
-> Result<(NativeLibBoilerplate, String), ()>
233+
{
234+
let (link_name, search_path, dynamic) = match &*env::var("TARGET").unwrap() {
230235
"x86_64-unknown-linux-gnu" => (
231236
format!("clang_rt.{}-x86_64", sanitizer_name),
232237
"build/lib/linux",
238+
false,
233239
),
234240
"x86_64-apple-darwin" => (
235-
format!("dylib=clang_rt.{}_osx_dynamic", sanitizer_name),
241+
format!("clang_rt.{}_osx_dynamic", sanitizer_name),
236242
"build/lib/darwin",
243+
true,
237244
),
238245
_ => return Err(()),
239246
};
240-
native_lib_boilerplate(
247+
let to_link = if dynamic {
248+
format!("dylib={}", link_name)
249+
} else {
250+
format!("static={}", link_name)
251+
};
252+
let lib = native_lib_boilerplate(
241253
"libcompiler_builtins/compiler-rt",
242254
sanitizer_name,
243-
&link_name,
255+
&to_link,
244256
search_path,
245-
)
257+
)?;
258+
Ok((lib, link_name))
246259
}
247260

248261
fn dir_up_to_date(src: &Path, threshold: SystemTime) -> bool {

src/librustc_asan/build.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use cmake::Config;
1818

1919
fn main() {
2020
if let Some(llvm_config) = env::var_os("LLVM_CONFIG") {
21-
let native = match sanitizer_lib_boilerplate("asan") {
21+
let (native, target) = match sanitizer_lib_boilerplate("asan") {
2222
Ok(native) => native,
2323
_ => return,
2424
};
@@ -29,7 +29,7 @@ fn main() {
2929
.define("COMPILER_RT_BUILD_XRAY", "OFF")
3030
.define("LLVM_CONFIG_PATH", llvm_config)
3131
.out_dir(&native.out_dir)
32-
.build_target("asan")
32+
.build_target(&target)
3333
.build();
3434
}
3535
println!("cargo:rerun-if-env-changed=LLVM_CONFIG");

src/librustc_lsan/build.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use cmake::Config;
1818

1919
fn main() {
2020
if let Some(llvm_config) = env::var_os("LLVM_CONFIG") {
21-
let native = match sanitizer_lib_boilerplate("lsan") {
21+
let (native, target) = match sanitizer_lib_boilerplate("lsan") {
2222
Ok(native) => native,
2323
_ => return,
2424
};
@@ -29,7 +29,7 @@ fn main() {
2929
.define("COMPILER_RT_BUILD_XRAY", "OFF")
3030
.define("LLVM_CONFIG_PATH", llvm_config)
3131
.out_dir(&native.out_dir)
32-
.build_target("lsan")
32+
.build_target(&target)
3333
.build();
3434
}
3535
println!("cargo:rerun-if-env-changed=LLVM_CONFIG");

src/librustc_msan/build.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use cmake::Config;
1818

1919
fn main() {
2020
if let Some(llvm_config) = env::var_os("LLVM_CONFIG") {
21-
let native = match sanitizer_lib_boilerplate("msan") {
21+
let (native, target) = match sanitizer_lib_boilerplate("msan") {
2222
Ok(native) => native,
2323
_ => return,
2424
};
@@ -29,7 +29,7 @@ fn main() {
2929
.define("COMPILER_RT_BUILD_XRAY", "OFF")
3030
.define("LLVM_CONFIG_PATH", llvm_config)
3131
.out_dir(&native.out_dir)
32-
.build_target("msan")
32+
.build_target(&target)
3333
.build();
3434
}
3535
println!("cargo:rerun-if-env-changed=LLVM_CONFIG");

src/librustc_tsan/build.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use cmake::Config;
1818

1919
fn main() {
2020
if let Some(llvm_config) = env::var_os("LLVM_CONFIG") {
21-
let native = match sanitizer_lib_boilerplate("tsan") {
21+
let (native, target) = match sanitizer_lib_boilerplate("tsan") {
2222
Ok(native) => native,
2323
_ => return,
2424
};
@@ -29,7 +29,7 @@ fn main() {
2929
.define("COMPILER_RT_BUILD_XRAY", "OFF")
3030
.define("LLVM_CONFIG_PATH", llvm_config)
3131
.out_dir(&native.out_dir)
32-
.build_target("tsan")
32+
.build_target(&target)
3333
.build();
3434
}
3535
println!("cargo:rerun-if-env-changed=LLVM_CONFIG");

0 commit comments

Comments
 (0)