Skip to content

Commit 82dcb68

Browse files
committed
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 58bb2fc commit 82dcb68

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
@@ -2518,10 +2518,29 @@ impl Build {
25182518

25192519
"emar".to_string()
25202520
} else if target.contains("msvc") {
2521-
match windows_registry::find(&target, "lib.exe") {
2522-
Some(t) => return Ok((t, "lib.exe".to_string())),
2523-
None => "lib.exe".to_string(),
2521+
let compiler = self.get_base_compiler()?;
2522+
let mut lib = String::new();
2523+
if compiler.family == (ToolFamily::Msvc { clang_cl: true }) {
2524+
// See if there is 'llvm-lib' next to 'clang-cl'
2525+
// Another possibility could be to see if there is 'clang'
2526+
// next to 'clang-cl' and use 'search_programs()' to locate
2527+
// 'llvm-lib'. This is because 'clang-cl' doesn't support
2528+
// the -print-search-dirs option.
2529+
if let Some(mut cmd) = which(&compiler.path, None) {
2530+
cmd.pop();
2531+
cmd.push("llvm-lib.exe");
2532+
if let Some(llvm_lib) = which(&cmd, None) {
2533+
lib = llvm_lib.to_str().unwrap().to_owned();
2534+
}
2535+
}
2536+
}
2537+
if lib.is_empty() {
2538+
lib = match windows_registry::find(&target, "lib.exe") {
2539+
Some(t) => return Ok((t, "lib.exe".to_string())),
2540+
None => "lib.exe".to_string(),
2541+
}
25242542
}
2543+
lib
25252544
} else if target.contains("illumos") {
25262545
// The default 'ar' on illumos uses a non-standard flags,
25272546
// but the OS comes bundled with a GNU-compatible variant.

0 commit comments

Comments
 (0)