Skip to content

Commit 80e27cd

Browse files
bootstrap: Allow to specify ranlib tool used when compiling C++ code.
1 parent 758239c commit 80e27cd

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

config.toml.example

+4
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,10 @@
388388
# Note: an absolute path should be used, otherwise LLVM build will break.
389389
#ar = "ar"
390390

391+
# Ranlib to be used to assemble static libraries compiled from C/C++ code.
392+
# Note: an absolute path should be used, otherwise LLVM build will break.
393+
#ranlib = "ranlib"
394+
391395
# Linker to be used to link Rust code. Note that the
392396
# default value is platform specific, and if not specified it may also depend on
393397
# what platform is crossing to what platform.

src/bootstrap/config.rs

+3
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ pub struct Target {
163163
pub cc: Option<PathBuf>,
164164
pub cxx: Option<PathBuf>,
165165
pub ar: Option<PathBuf>,
166+
pub ranlib: Option<PathBuf>,
166167
pub linker: Option<PathBuf>,
167168
pub ndk: Option<PathBuf>,
168169
pub crt_static: Option<bool>,
@@ -327,6 +328,7 @@ struct TomlTarget {
327328
cc: Option<String>,
328329
cxx: Option<String>,
329330
ar: Option<String>,
331+
ranlib: Option<String>,
330332
linker: Option<String>,
331333
android_ndk: Option<String>,
332334
crt_static: Option<bool>,
@@ -581,6 +583,7 @@ impl Config {
581583
target.cc = cfg.cc.clone().map(PathBuf::from);
582584
target.cxx = cfg.cxx.clone().map(PathBuf::from);
583585
target.ar = cfg.ar.clone().map(PathBuf::from);
586+
target.ranlib = cfg.ranlib.clone().map(PathBuf::from);
584587
target.linker = cfg.linker.clone().map(PathBuf::from);
585588
target.crt_static = cfg.crt_static.clone();
586589
target.musl_root = cfg.musl_root.clone().map(PathBuf::from);

src/bootstrap/lib.rs

+7
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ pub struct Build {
281281
cc: HashMap<Interned<String>, cc::Tool>,
282282
cxx: HashMap<Interned<String>, cc::Tool>,
283283
ar: HashMap<Interned<String>, PathBuf>,
284+
ranlib: HashMap<Interned<String>, PathBuf>,
284285
// Misc
285286
crates: HashMap<Interned<String>, Crate>,
286287
is_sudo: bool,
@@ -406,6 +407,7 @@ impl Build {
406407
cc: HashMap::new(),
407408
cxx: HashMap::new(),
408409
ar: HashMap::new(),
410+
ranlib: HashMap::new(),
409411
crates: HashMap::new(),
410412
lldb_version: None,
411413
lldb_python_dir: None,
@@ -772,6 +774,11 @@ impl Build {
772774
self.ar.get(&target).map(|p| &**p)
773775
}
774776

777+
/// Returns the path to the `ranlib` utility for the target specified.
778+
fn ranlib(&self, target: Interned<String>) -> Option<&Path> {
779+
self.ranlib.get(&target).map(|p| &**p)
780+
}
781+
775782
/// Returns the path to the C++ compiler for the target specified.
776783
fn cxx(&self, target: Interned<String>) -> Result<&Path, String> {
777784
match self.cxx.get(&target) {

src/bootstrap/native.rs

+8
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,14 @@ fn configure_cmake(builder: &Builder,
379379
}
380380
}
381381

382+
if let Some(ranlib) = builder.ranlib(target) {
383+
if ranlib.is_absolute() {
384+
// LLVM build breaks if `CMAKE_RANLIB` is a relative path, for some reason it
385+
// tries to resolve this path in the LLVM build directory.
386+
cfg.define("CMAKE_RANLIB", sanitize_cc(ranlib));
387+
}
388+
}
389+
382390
if env::var_os("SCCACHE_ERROR_LOG").is_some() {
383391
cfg.env("RUST_LOG", "sccache=warn");
384392
}

0 commit comments

Comments
 (0)