Skip to content

Commit 61f9698

Browse files
authored
Fix get_base_archiver_variant for clang-cl: use --print-search-dirs (#1587)
* Fix `get_base_archiver_variant` for clang-cl: use `--print-search-dirs` Fix #1565 (comment) * Fix lib.rs * Simplify `search_programs` * Fix fmt in lib.rs * Updated doc and parameter name of `search_programs` * Fix llvm-lib search_programs fallback in get_base_archiver_variant Remove `.exe` suffix since `which` automatically applies it on windows
1 parent 1ca8b2a commit 61f9698

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

src/lib.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3326,12 +3326,8 @@ impl Build {
33263326
let compiler = self.get_base_compiler().ok()?;
33273327
if compiler.is_like_clang() {
33283328
name = format!("llvm-{tool}").into();
3329-
self.search_programs(
3330-
&mut self.cmd(&compiler.path),
3331-
&name,
3332-
&self.cargo_output,
3333-
)
3334-
.map(|name| self.cmd(name))
3329+
self.search_programs(&compiler.path, &name, &self.cargo_output)
3330+
.map(|name| self.cmd(name))
33353331
} else {
33363332
None
33373333
}
@@ -3361,23 +3357,30 @@ impl Build {
33613357
// here.
33623358

33633359
let compiler = self.get_base_compiler()?;
3364-
let mut lib = String::new();
3365-
if compiler.family == (ToolFamily::Msvc { clang_cl: true }) {
3366-
// See if there is 'llvm-lib' next to 'clang-cl'
3367-
// Another possibility could be to see if there is 'clang'
3368-
// next to 'clang-cl' and use 'search_programs()' to locate
3369-
// 'llvm-lib'. This is because 'clang-cl' doesn't support
3370-
// the -print-search-dirs option.
3371-
if let Some(mut cmd) = self.which(&compiler.path, None) {
3372-
cmd.pop();
3373-
cmd.push("llvm-lib.exe");
3374-
if let Some(llvm_lib) = self.which(&cmd, None) {
3375-
llvm_lib.to_str().unwrap().clone_into(&mut lib);
3360+
let lib = if compiler.family == (ToolFamily::Msvc { clang_cl: true }) {
3361+
self.search_programs(
3362+
&compiler.path,
3363+
Path::new("llvm-lib"),
3364+
&self.cargo_output,
3365+
)
3366+
.or_else(|| {
3367+
// See if there is 'llvm-lib' next to 'clang-cl'
3368+
if let Some(mut cmd) = self.which(&compiler.path, None) {
3369+
cmd.pop();
3370+
cmd.push("llvm-lib");
3371+
self.which(&cmd, None)
3372+
} else {
3373+
None
33763374
}
3377-
}
3378-
}
3375+
})
3376+
} else {
3377+
None
3378+
};
33793379

3380-
if lib.is_empty() {
3380+
if let Some(lib) = lib {
3381+
name = lib;
3382+
self.cmd(&name)
3383+
} else {
33813384
name = PathBuf::from("lib.exe");
33823385
let mut cmd = match self.find_msvc_tools_find(&target, "lib.exe") {
33833386
Some(t) => t,
@@ -3387,9 +3390,6 @@ impl Build {
33873390
cmd.arg("/machine:arm64ec");
33883391
}
33893392
cmd
3390-
} else {
3391-
name = lib.into();
3392-
self.cmd(&name)
33933393
}
33943394
} else if target.os == "illumos" {
33953395
// The default 'ar' on illumos uses a non-standard flags,
@@ -4132,15 +4132,15 @@ impl Build {
41324132
}
41334133
}
41344134

4135-
/// search for |prog| on 'programs' path in '|cc| -print-search-dirs' output
4135+
/// search for |prog| on 'programs' path in '|cc| --print-search-dirs' output
41364136
fn search_programs(
41374137
&self,
4138-
cc: &mut Command,
4138+
cc: &Path,
41394139
prog: &Path,
41404140
cargo_output: &CargoOutput,
41414141
) -> Option<PathBuf> {
41424142
let search_dirs = run_output(
4143-
cc.arg("-print-search-dirs"),
4143+
self.cmd(cc).arg("--print-search-dirs"),
41444144
// this doesn't concern the compilation so we always want to show warnings.
41454145
cargo_output,
41464146
)

0 commit comments

Comments
 (0)