Skip to content

Commit 8a2cf55

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 de870dc commit 8a2cf55

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
@@ -2533,10 +2533,29 @@ impl Build {
25332533
default_ar
25342534
}
25352535
} else if target.contains("msvc") {
2536-
match windows_registry::find(&target, "lib.exe") {
2537-
Some(t) => return Ok((t, "lib.exe".to_string())),
2538-
None => "lib.exe".to_string(),
2536+
let compiler = self.get_base_compiler()?;
2537+
let mut lib = String::new();
2538+
if compiler.family == (ToolFamily::Msvc { clang_cl: true }) {
2539+
// See if there is 'llvm-lib' next to 'clang-cl'
2540+
// Another possibility could be to see if there is 'clang'
2541+
// next to 'clang-cl' and use 'search_programs()' to locate
2542+
// 'llvm-lib'. This is because 'clang-cl' doesn't support
2543+
// the -print-search-dirs option.
2544+
if let Some(mut cmd) = which(&compiler.path, None) {
2545+
cmd.pop();
2546+
cmd.push("llvm-lib.exe");
2547+
if let Some(llvm_lib) = which(&cmd, None) {
2548+
lib = llvm_lib.to_str().unwrap().to_owned();
2549+
}
2550+
}
2551+
}
2552+
if lib.is_empty() {
2553+
lib = match windows_registry::find(&target, "lib.exe") {
2554+
Some(t) => return Ok((t, "lib.exe".to_string())),
2555+
None => "lib.exe".to_string(),
2556+
}
25392557
}
2558+
lib
25402559
} else if target.contains("illumos") {
25412560
// The default 'ar' on illumos uses a non-standard flags,
25422561
// but the OS comes bundled with a GNU-compatible variant.

0 commit comments

Comments
 (0)