diff --git a/config.toml.example b/config.toml.example index 107375ac5cc..e7a530ba4c2 100644 --- a/config.toml.example +++ b/config.toml.example @@ -388,6 +388,10 @@ # Note: an absolute path should be used, otherwise LLVM build will break. #ar = "ar" +# Ranlib to be used to assemble static libraries compiled from C/C++ code. +# Note: an absolute path should be used, otherwise LLVM build will break. +#ranlib = "ranlib" + # Linker to be used to link Rust code. Note that the # default value is platform specific, and if not specified it may also depend on # what platform is crossing to what platform. diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 43650332d3b..aef97204a4a 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -163,6 +163,7 @@ pub struct Target { pub cc: Option, pub cxx: Option, pub ar: Option, + pub ranlib: Option, pub linker: Option, pub ndk: Option, pub crt_static: Option, @@ -327,6 +328,7 @@ struct TomlTarget { cc: Option, cxx: Option, ar: Option, + ranlib: Option, linker: Option, android_ndk: Option, crt_static: Option, @@ -581,6 +583,7 @@ impl Config { target.cc = cfg.cc.clone().map(PathBuf::from); target.cxx = cfg.cxx.clone().map(PathBuf::from); target.ar = cfg.ar.clone().map(PathBuf::from); + target.ranlib = cfg.ranlib.clone().map(PathBuf::from); target.linker = cfg.linker.clone().map(PathBuf::from); target.crt_static = cfg.crt_static.clone(); target.musl_root = cfg.musl_root.clone().map(PathBuf::from); diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 5bb475e07ba..97b05059c88 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -281,6 +281,7 @@ pub struct Build { cc: HashMap, cc::Tool>, cxx: HashMap, cc::Tool>, ar: HashMap, PathBuf>, + ranlib: HashMap, PathBuf>, // Misc crates: HashMap, Crate>, is_sudo: bool, @@ -406,6 +407,7 @@ impl Build { cc: HashMap::new(), cxx: HashMap::new(), ar: HashMap::new(), + ranlib: HashMap::new(), crates: HashMap::new(), lldb_version: None, lldb_python_dir: None, @@ -772,6 +774,11 @@ impl Build { self.ar.get(&target).map(|p| &**p) } + /// Returns the path to the `ranlib` utility for the target specified. + fn ranlib(&self, target: Interned) -> Option<&Path> { + self.ranlib.get(&target).map(|p| &**p) + } + /// Returns the path to the C++ compiler for the target specified. fn cxx(&self, target: Interned) -> Result<&Path, String> { match self.cxx.get(&target) { diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index c99347aa94e..0e8605750dc 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -379,6 +379,14 @@ fn configure_cmake(builder: &Builder, } } + if let Some(ranlib) = builder.ranlib(target) { + if ranlib.is_absolute() { + // LLVM build breaks if `CMAKE_RANLIB` is a relative path, for some reason it + // tries to resolve this path in the LLVM build directory. + cfg.define("CMAKE_RANLIB", sanitize_cc(ranlib)); + } + } + if env::var_os("SCCACHE_ERROR_LOG").is_some() { cfg.env("RUST_LOG", "sccache=warn"); }