Build compiler-rt and sanitizers only once
This commit is contained in:
parent
a7c8afd28d
commit
aeadc81ddc
@ -12,7 +12,7 @@
|
||||
|
||||
extern crate filetime;
|
||||
|
||||
use std::fs;
|
||||
use std::{fs, env};
|
||||
use std::process::{Command, Stdio};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
@ -166,6 +166,41 @@ pub fn up_to_date(src: &Path, dst: &Path) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct NativeLibBoilerplate {
|
||||
pub skip_build: bool,
|
||||
pub src_dir: PathBuf,
|
||||
pub out_dir: PathBuf,
|
||||
pub timestamp: PathBuf,
|
||||
}
|
||||
|
||||
pub fn native_lib_boilerplate(src_name: &str,
|
||||
out_name: &str,
|
||||
link_name: &str,
|
||||
timestamp_name: &str,
|
||||
search_subdir: &str)
|
||||
-> NativeLibBoilerplate {
|
||||
let current_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
|
||||
let src_dir = current_dir.join("..").join(src_name);
|
||||
rerun_if_changed_anything_in_dir(&src_dir);
|
||||
|
||||
let out_dir = env::var_os("RUSTBUILD_NATIVE_DIR").unwrap_or(env::var_os("OUT_DIR").unwrap());
|
||||
let out_dir = PathBuf::from(out_dir).join(out_name);
|
||||
let _ = fs::create_dir_all(&out_dir);
|
||||
println!("cargo:rustc-link-lib=static={}", link_name);
|
||||
println!("cargo:rustc-link-search=native={}", out_dir.join(search_subdir).display());
|
||||
|
||||
let timestamp = out_dir.join(timestamp_name);
|
||||
let skip_build = up_to_date(Path::new("build.rs"), ×tamp) &&
|
||||
up_to_date(&src_dir, ×tamp);
|
||||
|
||||
NativeLibBoilerplate {
|
||||
skip_build: skip_build,
|
||||
src_dir: src_dir,
|
||||
out_dir: out_dir,
|
||||
timestamp: timestamp,
|
||||
}
|
||||
}
|
||||
|
||||
fn dir_up_to_date(src: &Path, threshold: &FileTime) -> bool {
|
||||
t!(fs::read_dir(src)).map(|e| t!(e)).all(|e| {
|
||||
let meta = t!(e.metadata());
|
||||
|
@ -15,10 +15,10 @@ extern crate build_helper;
|
||||
extern crate gcc;
|
||||
|
||||
use std::env;
|
||||
use std::fs::{self, File};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::fs::File;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
use build_helper::{run, rerun_if_changed_anything_in_dir, up_to_date};
|
||||
use build_helper::{run, native_lib_boilerplate};
|
||||
|
||||
fn main() {
|
||||
// FIXME: This is a hack to support building targets that don't
|
||||
@ -59,20 +59,10 @@ fn main() {
|
||||
return;
|
||||
}
|
||||
|
||||
let build_dir = env::var_os("RUSTBUILD_NATIVE_DIR").unwrap_or(env::var_os("OUT_DIR").unwrap());
|
||||
let build_dir = PathBuf::from(build_dir).join("jemalloc");
|
||||
let _ = fs::create_dir_all(&build_dir);
|
||||
|
||||
if target.contains("windows") {
|
||||
println!("cargo:rustc-link-lib=static=jemalloc");
|
||||
} else {
|
||||
println!("cargo:rustc-link-lib=static=jemalloc_pic");
|
||||
}
|
||||
println!("cargo:rustc-link-search=native={}/lib", build_dir.display());
|
||||
let src_dir = env::current_dir().unwrap().join("../jemalloc");
|
||||
rerun_if_changed_anything_in_dir(&src_dir);
|
||||
let timestamp = build_dir.join("rustbuild.timestamp");
|
||||
if up_to_date(&Path::new("build.rs"), ×tamp) && up_to_date(&src_dir, ×tamp) {
|
||||
let link_name = if target.contains("windows") { "jemalloc" } else { "jemalloc_pic" };
|
||||
let native = native_lib_boilerplate("jemalloc", "jemalloc", link_name,
|
||||
"rustbuild.timestamp", "lib");
|
||||
if native.skip_build {
|
||||
return
|
||||
}
|
||||
|
||||
@ -86,12 +76,12 @@ fn main() {
|
||||
.join(" ");
|
||||
|
||||
let mut cmd = Command::new("sh");
|
||||
cmd.arg(src_dir.join("configure")
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.replace("C:\\", "/c/")
|
||||
.replace("\\", "/"))
|
||||
.current_dir(&build_dir)
|
||||
cmd.arg(native.src_dir.join("configure")
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.replace("C:\\", "/c/")
|
||||
.replace("\\", "/"))
|
||||
.current_dir(&native.out_dir)
|
||||
.env("CC", compiler.path())
|
||||
.env("EXTRA_CFLAGS", cflags.clone())
|
||||
// jemalloc generates Makefile deps using GCC's "-MM" flag. This means
|
||||
@ -164,7 +154,7 @@ fn main() {
|
||||
run(&mut cmd);
|
||||
|
||||
let mut make = Command::new(build_helper::make(&host));
|
||||
make.current_dir(&build_dir)
|
||||
make.current_dir(&native.out_dir)
|
||||
.arg("build_lib_static");
|
||||
|
||||
// mingw make seems... buggy? unclear...
|
||||
@ -186,5 +176,5 @@ fn main() {
|
||||
.compile("libpthread_atfork_dummy.a");
|
||||
}
|
||||
|
||||
t!(File::create(×tamp));
|
||||
t!(File::create(&native.timestamp));
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ extern crate gcc;
|
||||
use std::collections::BTreeMap;
|
||||
use std::env;
|
||||
use std::path::Path;
|
||||
use build_helper::native_lib_boilerplate;
|
||||
|
||||
struct Sources {
|
||||
// SYMBOL -> PATH TO SOURCE
|
||||
@ -80,7 +81,17 @@ fn main() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Can't reuse `sources` list for the freshness check becuse it doesn't contain header files.
|
||||
// Use the produced library itself as a timestamp.
|
||||
let out_name = "libcompiler-rt.a";
|
||||
let native = native_lib_boilerplate("compiler-rt", "compiler-rt", "compiler-rt",
|
||||
out_name, ".");
|
||||
if native.skip_build {
|
||||
return
|
||||
}
|
||||
|
||||
let cfg = &mut gcc::Config::new();
|
||||
cfg.out_dir(native.out_dir);
|
||||
|
||||
if target.contains("msvc") {
|
||||
// Don't pull in extra libraries on MSVC
|
||||
@ -405,8 +416,5 @@ fn main() {
|
||||
cfg.file(Path::new("../compiler-rt/lib/builtins").join(src));
|
||||
}
|
||||
|
||||
// Can't reuse `sources` list becuse it doesn't contain header files.
|
||||
build_helper::rerun_if_changed_anything_in_dir(Path::new("../compiler-rt"));
|
||||
|
||||
cfg.compile("libcompiler-rt.a");
|
||||
cfg.compile(out_name);
|
||||
}
|
||||
|
@ -8,30 +8,33 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#[macro_use]
|
||||
extern crate build_helper;
|
||||
extern crate cmake;
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use build_helper::native_lib_boilerplate;
|
||||
|
||||
use cmake::Config;
|
||||
|
||||
fn main() {
|
||||
if let Some(llvm_config) = env::var_os("LLVM_CONFIG") {
|
||||
let dst = Config::new("../compiler-rt")
|
||||
let native = native_lib_boilerplate("compiler-rt", "asan", "clang_rt.asan-x86_64",
|
||||
"rustbuild.timestamp", "build/lib/linux");
|
||||
if native.skip_build {
|
||||
return
|
||||
}
|
||||
|
||||
Config::new(&native.src_dir)
|
||||
.define("COMPILER_RT_BUILD_SANITIZERS", "ON")
|
||||
.define("COMPILER_RT_BUILD_BUILTINS", "OFF")
|
||||
.define("COMPILER_RT_BUILD_XRAY", "OFF")
|
||||
.define("LLVM_CONFIG_PATH", llvm_config)
|
||||
.out_dir(&native.out_dir)
|
||||
.build_target("asan")
|
||||
.build();
|
||||
|
||||
println!("cargo:rustc-link-search=native={}",
|
||||
dst.join("build/lib/linux").display());
|
||||
println!("cargo:rustc-link-lib=static=clang_rt.asan-x86_64");
|
||||
|
||||
build_helper::rerun_if_changed_anything_in_dir(&PathBuf::from(env::var("CARGO_MANIFEST_DIR")
|
||||
.unwrap())
|
||||
.join("../compiler-rt"));
|
||||
t!(File::create(&native.timestamp));
|
||||
}
|
||||
}
|
||||
|
@ -8,30 +8,33 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#[macro_use]
|
||||
extern crate build_helper;
|
||||
extern crate cmake;
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use build_helper::native_lib_boilerplate;
|
||||
|
||||
use cmake::Config;
|
||||
|
||||
fn main() {
|
||||
if let Some(llvm_config) = env::var_os("LLVM_CONFIG") {
|
||||
let dst = Config::new("../compiler-rt")
|
||||
let native = native_lib_boilerplate("compiler-rt", "lsan", "clang_rt.lsan-x86_64",
|
||||
"rustbuild.timestamp", "build/lib/linux");
|
||||
if native.skip_build {
|
||||
return
|
||||
}
|
||||
|
||||
Config::new(&native.src_dir)
|
||||
.define("COMPILER_RT_BUILD_SANITIZERS", "ON")
|
||||
.define("COMPILER_RT_BUILD_BUILTINS", "OFF")
|
||||
.define("COMPILER_RT_BUILD_XRAY", "OFF")
|
||||
.define("LLVM_CONFIG_PATH", llvm_config)
|
||||
.out_dir(&native.out_dir)
|
||||
.build_target("lsan")
|
||||
.build();
|
||||
|
||||
println!("cargo:rustc-link-search=native={}",
|
||||
dst.join("build/lib/linux").display());
|
||||
println!("cargo:rustc-link-lib=static=clang_rt.lsan-x86_64");
|
||||
|
||||
build_helper::rerun_if_changed_anything_in_dir(&PathBuf::from(env::var("CARGO_MANIFEST_DIR")
|
||||
.unwrap())
|
||||
.join("../compiler-rt"));
|
||||
t!(File::create(&native.timestamp));
|
||||
}
|
||||
}
|
||||
|
@ -8,30 +8,33 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#[macro_use]
|
||||
extern crate build_helper;
|
||||
extern crate cmake;
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use build_helper::native_lib_boilerplate;
|
||||
|
||||
use cmake::Config;
|
||||
|
||||
fn main() {
|
||||
if let Some(llvm_config) = env::var_os("LLVM_CONFIG") {
|
||||
let dst = Config::new("../compiler-rt")
|
||||
let native = native_lib_boilerplate("compiler-rt", "msan", "clang_rt.msan-x86_64",
|
||||
"rustbuild.timestamp", "build/lib/linux");
|
||||
if native.skip_build {
|
||||
return
|
||||
}
|
||||
|
||||
Config::new(&native.src_dir)
|
||||
.define("COMPILER_RT_BUILD_SANITIZERS", "ON")
|
||||
.define("COMPILER_RT_BUILD_BUILTINS", "OFF")
|
||||
.define("COMPILER_RT_BUILD_XRAY", "OFF")
|
||||
.define("LLVM_CONFIG_PATH", llvm_config)
|
||||
.out_dir(&native.out_dir)
|
||||
.build_target("msan")
|
||||
.build();
|
||||
|
||||
println!("cargo:rustc-link-search=native={}",
|
||||
dst.join("build/lib/linux").display());
|
||||
println!("cargo:rustc-link-lib=static=clang_rt.msan-x86_64");
|
||||
|
||||
build_helper::rerun_if_changed_anything_in_dir(&PathBuf::from(env::var("CARGO_MANIFEST_DIR")
|
||||
.unwrap())
|
||||
.join("../compiler-rt"));
|
||||
t!(File::create(&native.timestamp));
|
||||
}
|
||||
}
|
||||
|
@ -8,30 +8,33 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#[macro_use]
|
||||
extern crate build_helper;
|
||||
extern crate cmake;
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use build_helper::native_lib_boilerplate;
|
||||
|
||||
use cmake::Config;
|
||||
|
||||
fn main() {
|
||||
if let Some(llvm_config) = env::var_os("LLVM_CONFIG") {
|
||||
let dst = Config::new("../compiler-rt")
|
||||
let native = native_lib_boilerplate("compiler-rt", "tsan", "clang_rt.tsan-x86_64",
|
||||
"rustbuild.timestamp", "build/lib/linux");
|
||||
if native.skip_build {
|
||||
return
|
||||
}
|
||||
|
||||
Config::new(&native.src_dir)
|
||||
.define("COMPILER_RT_BUILD_SANITIZERS", "ON")
|
||||
.define("COMPILER_RT_BUILD_BUILTINS", "OFF")
|
||||
.define("COMPILER_RT_BUILD_XRAY", "OFF")
|
||||
.define("LLVM_CONFIG_PATH", llvm_config)
|
||||
.out_dir(&native.out_dir)
|
||||
.build_target("tsan")
|
||||
.build();
|
||||
|
||||
println!("cargo:rustc-link-search=native={}",
|
||||
dst.join("build/lib/linux").display());
|
||||
println!("cargo:rustc-link-lib=static=clang_rt.tsan-x86_64");
|
||||
|
||||
build_helper::rerun_if_changed_anything_in_dir(&PathBuf::from(env::var("CARGO_MANIFEST_DIR")
|
||||
.unwrap())
|
||||
.join("../compiler-rt"));
|
||||
t!(File::create(&native.timestamp));
|
||||
}
|
||||
}
|
||||
|
@ -15,10 +15,9 @@ extern crate build_helper;
|
||||
extern crate gcc;
|
||||
|
||||
use std::env;
|
||||
use std::fs::{self, File};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::fs::File;
|
||||
use std::process::Command;
|
||||
use build_helper::{run, rerun_if_changed_anything_in_dir, up_to_date};
|
||||
use build_helper::{run, native_lib_boilerplate};
|
||||
|
||||
fn main() {
|
||||
let target = env::var("TARGET").expect("TARGET was not set");
|
||||
@ -68,16 +67,9 @@ fn main() {
|
||||
}
|
||||
|
||||
fn build_libbacktrace(host: &str, target: &str) {
|
||||
let build_dir = env::var_os("RUSTBUILD_NATIVE_DIR").unwrap_or(env::var_os("OUT_DIR").unwrap());
|
||||
let build_dir = PathBuf::from(build_dir).join("libbacktrace");
|
||||
let _ = fs::create_dir_all(&build_dir);
|
||||
|
||||
println!("cargo:rustc-link-lib=static=backtrace");
|
||||
println!("cargo:rustc-link-search=native={}/.libs", build_dir.display());
|
||||
let src_dir = env::current_dir().unwrap().join("../libbacktrace");
|
||||
rerun_if_changed_anything_in_dir(&src_dir);
|
||||
let timestamp = build_dir.join("rustbuild.timestamp");
|
||||
if up_to_date(&Path::new("build.rs"), ×tamp) && up_to_date(&src_dir, ×tamp) {
|
||||
let native = native_lib_boilerplate("libbacktrace", "libbacktrace", "backtrace",
|
||||
"rustbuild.timestamp", ".libs");
|
||||
if native.skip_build {
|
||||
return
|
||||
}
|
||||
|
||||
@ -88,10 +80,10 @@ fn build_libbacktrace(host: &str, target: &str) {
|
||||
.collect::<Vec<_>>().join(" ");
|
||||
cflags.push_str(" -fvisibility=hidden");
|
||||
run(Command::new("sh")
|
||||
.current_dir(&build_dir)
|
||||
.arg(src_dir.join("configure").to_str().unwrap()
|
||||
.replace("C:\\", "/c/")
|
||||
.replace("\\", "/"))
|
||||
.current_dir(&native.out_dir)
|
||||
.arg(native.src_dir.join("configure").to_str().unwrap()
|
||||
.replace("C:\\", "/c/")
|
||||
.replace("\\", "/"))
|
||||
.arg("--with-pic")
|
||||
.arg("--disable-multilib")
|
||||
.arg("--disable-shared")
|
||||
@ -104,9 +96,9 @@ fn build_libbacktrace(host: &str, target: &str) {
|
||||
.env("CFLAGS", cflags));
|
||||
|
||||
run(Command::new(build_helper::make(host))
|
||||
.current_dir(&build_dir)
|
||||
.arg(format!("INCDIR={}", src_dir.display()))
|
||||
.current_dir(&native.out_dir)
|
||||
.arg(format!("INCDIR={}", native.src_dir.display()))
|
||||
.arg("-j").arg(env::var("NUM_JOBS").expect("NUM_JOBS was not set")));
|
||||
|
||||
t!(File::create(×tamp));
|
||||
t!(File::create(&native.timestamp));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user