Skip to content

Commit 0e51f6d

Browse files
dot-asmChrisDenton
authored andcommitted
Default to llvm-lib when using clang-cl in msvc environment.
The problem is that the vendor librarian can't handle object modules compiled with clang-cl -flto. llvm-lib on the other hand can handle any object modules, which makes it a preferred option.
1 parent c4f414f commit 0e51f6d

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/lib.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2665,10 +2665,29 @@ impl Build {
26652665

26662666
"emar".to_string()
26672667
} else if target.contains("msvc") {
2668-
match windows_registry::find(&target, "lib.exe") {
2669-
Some(t) => return Ok((t, "lib.exe".to_string())),
2670-
None => "lib.exe".to_string(),
2668+
let compiler = self.get_base_compiler()?;
2669+
let mut lib = String::new();
2670+
if compiler.family == (ToolFamily::Msvc { clang_cl: true }) {
2671+
// See if there is 'llvm-lib' next to 'clang-cl'
2672+
// Another possibility could be to see if there is 'clang'
2673+
// next to 'clang-cl' and use 'search_programs()' to locate
2674+
// 'llvm-lib'. This is because 'clang-cl' doesn't support
2675+
// the -print-search-dirs option.
2676+
if let Some(mut cmd) = which(&compiler.path) {
2677+
cmd.pop();
2678+
cmd.push("llvm-lib.exe");
2679+
if let Some(llvm_lib) = which(&cmd) {
2680+
lib = llvm_lib.to_str().unwrap().to_owned();
2681+
}
2682+
}
2683+
}
2684+
if lib.is_empty() {
2685+
lib = match windows_registry::find(&target, "lib.exe") {
2686+
Some(t) => return Ok((t, "lib.exe".to_string())),
2687+
None => "lib.exe".to_string(),
2688+
}
26712689
}
2690+
lib
26722691
} else if target.contains("illumos") {
26732692
// The default 'ar' on illumos uses a non-standard flags,
26742693
// but the OS comes bundled with a GNU-compatible variant.

0 commit comments

Comments
 (0)