use std::fs::File;
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
+use std::thread;
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:
///
Err(e) => panic!("{} failed with {}", stringify!($e), e),
}
};
+ // it can show extra info in the second parameter
+ ($e:expr, $extra:expr) => {
+ match $e {
+ Ok(e) => e,
+ Err(e) => panic!("{} failed with {} ({:?})", stringify!($e), e, $extra),
+ }
+ };
}
// Because Cargo adds the compiler's dylib path to our library search path, llvm-config may
pub fn try_run(cmd: &mut Command) -> bool {
let status = match cmd.status() {
Ok(status) => status,
- Err(e) => fail(&format!(
- "failed to execute command: {:?}\nerror: {}",
- cmd, e
- )),
+ Err(e) => fail(&format!("failed to execute command: {:?}\nerror: {}", cmd, e)),
};
if !status.success() {
println!(
pub fn try_run_suppressed(cmd: &mut Command) -> bool {
let output = match cmd.output() {
Ok(status) => status,
- Err(e) => fail(&format!(
- "failed to execute command: {:?}\nerror: {}",
- cmd, e
- )),
+ Err(e) => fail(&format!("failed to execute command: {:?}\nerror: {}", cmd, e)),
};
if !output.status.success() {
println!(
}
pub fn make(host: &str) -> PathBuf {
- if host.contains("dragonfly") || host.contains("freebsd")
- || host.contains("netbsd") || host.contains("openbsd")
+ if host.contains("dragonfly")
+ || host.contains("freebsd")
+ || host.contains("netbsd")
+ || host.contains("openbsd")
{
PathBuf::from("gmake")
} else {
pub fn output(cmd: &mut Command) -> String {
let output = match cmd.stderr(Stdio::inherit()).output() {
Ok(status) => status,
- Err(e) => fail(&format!(
- "failed to execute command: {:?}\nerror: {}",
- cmd, e
- )),
+ Err(e) => fail(&format!("failed to execute command: {:?}\nerror: {}", cmd, e)),
};
if !output.status.success() {
panic!(
}
pub fn rerun_if_changed_anything_in_dir(dir: &Path) {
- let mut stack = dir.read_dir()
+ let mut stack = dir
+ .read_dir()
.unwrap()
.map(|e| e.unwrap())
.filter(|e| &*e.file_name() != ".git")
/// Returns the last-modified time for `path`, or zero if it doesn't exist.
pub fn mtime(path: &Path) -> SystemTime {
- fs::metadata(path)
- .and_then(|f| f.modified())
- .unwrap_or(UNIX_EPOCH)
+ fs::metadata(path).and_then(|f| f.modified()).unwrap_or(UNIX_EPOCH)
}
/// Returns `true` if `dst` is up to date given that the file or files in `src`
/// ensure it's linked against correctly.
pub fn fixup_sanitizer_lib_name(&self, sanitizer_name: &str) {
if env::var("TARGET").unwrap() != "x86_64-apple-darwin" {
- return
+ return;
}
let dir = self.out_dir.join("build/lib/darwin");
) -> Result<NativeLibBoilerplate, ()> {
rerun_if_changed_anything_in_dir(src_dir);
- let out_dir = env::var_os("RUSTBUILD_NATIVE_DIR").unwrap_or_else(||
- env::var_os("OUT_DIR").unwrap());
+ let out_dir =
+ env::var_os("RUSTBUILD_NATIVE_DIR").unwrap_or_else(|| env::var_os("OUT_DIR").unwrap());
let out_dir = PathBuf::from(out_dir).join(out_name);
t!(fs::create_dir_all(&out_dir));
if link_name.contains('=') {
} else {
println!("cargo:rustc-link-lib=static={}", link_name);
}
- println!(
- "cargo:rustc-link-search=native={}",
- out_dir.join(search_subdir).display()
- );
+ println!("cargo:rustc-link-search=native={}", out_dir.join(search_subdir).display());
let timestamp = out_dir.join("rustbuild.timestamp");
if !up_to_date(Path::new("build.rs"), ×tamp) || !up_to_date(src_dir, ×tamp) {
- Ok(NativeLibBoilerplate {
- src_dir: src_dir.to_path_buf(),
- out_dir,
- })
+ Ok(NativeLibBoilerplate { src_dir: src_dir.to_path_buf(), out_dir })
} else {
Err(())
}
}
-pub fn sanitizer_lib_boilerplate(sanitizer_name: &str)
- -> Result<(NativeLibBoilerplate, String), ()>
-{
+pub fn sanitizer_lib_boilerplate(
+ sanitizer_name: &str,
+) -> Result<(NativeLibBoilerplate, String), ()> {
let (link_name, search_path, apple) = 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!("clang_rt.{}_osx_dynamic", sanitizer_name),
- "build/lib/darwin",
- true,
- ),
+ "x86_64-unknown-linux-gnu" => {
+ (format!("clang_rt.{}-x86_64", sanitizer_name), "build/lib/linux", false)
+ }
+ "x86_64-apple-darwin" => {
+ (format!("clang_rt.{}_osx_dynamic", sanitizer_name), "build/lib/darwin", true)
+ }
_ => return Err(()),
};
let to_link = if apple {
// This env var is provided by rustbuild to tell us where `compiler-rt`
// lives.
let dir = env::var_os("RUST_COMPILER_RT_ROOT").unwrap();
- let lib = native_lib_boilerplate(
- dir.as_ref(),
- sanitizer_name,
- &to_link,
- search_path,
- )?;
+ let lib = native_lib_boilerplate(dir.as_ref(), sanitizer_name, &to_link, search_path)?;
Ok((lib, link_name))
}