Skip to content

Commit bbd2aff

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 dd2909c commit bbd2aff

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
@@ -2581,10 +2581,29 @@ impl Build {
25812581
default_ar
25822582
}
25832583
} else if target.contains("msvc") {
2584-
match windows_registry::find(&target, "lib.exe") {
2585-
Some(t) => return Ok((t, "lib.exe".to_string())),
2586-
None => "lib.exe".to_string(),
2584+
let compiler = self.get_base_compiler()?;
2585+
let mut lib = String::new();
2586+
if compiler.family == (ToolFamily::Msvc { clang_cl: true }) {
2587+
// See if there is 'llvm-lib' next to 'clang-cl'
2588+
// Another possibility could be to see if there is 'clang'
2589+
// next to 'clang-cl' and use 'search_programs()' to locate
2590+
// 'llvm-lib'. This is because 'clang-cl' doesn't support
2591+
// the -print-search-dirs option.
2592+
if let Some(mut cmd) = which(&compiler.path, None) {
2593+
cmd.pop();
2594+
cmd.push("llvm-lib.exe");
2595+
if let Some(llvm_lib) = which(&cmd, None) {
2596+
lib = llvm_lib.to_str().unwrap().to_owned();
2597+
}
2598+
}
2599+
}
2600+
if lib.is_empty() {
2601+
lib = match windows_registry::find(&target, "lib.exe") {
2602+
Some(t) => return Ok((t, "lib.exe".to_string())),
2603+
None => "lib.exe".to_string(),
2604+
}
25872605
}
2606+
lib
25882607
} else if target.contains("illumos") {
25892608
// The default 'ar' on illumos uses a non-standard flags,
25902609
// but the OS comes bundled with a GNU-compatible variant.

0 commit comments

Comments
 (0)