Skip to content

Commit dfbc4a4

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 7011c79 commit dfbc4a4

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
@@ -2624,10 +2624,29 @@ impl Build {
26242624
default_ar
26252625
}
26262626
} else if target.contains("msvc") {
2627-
match windows_registry::find(&target, "lib.exe") {
2628-
Some(t) => return Ok((t, "lib.exe".to_string())),
2629-
None => "lib.exe".to_string(),
2627+
let compiler = self.get_base_compiler()?;
2628+
let mut lib = String::new();
2629+
if compiler.family == (ToolFamily::Msvc { clang_cl: true }) {
2630+
// See if there is 'llvm-lib' next to 'clang-cl'
2631+
// Another possibility could be to see if there is 'clang'
2632+
// next to 'clang-cl' and use 'search_programs()' to locate
2633+
// 'llvm-lib'. This is because 'clang-cl' doesn't support
2634+
// the -print-search-dirs option.
2635+
if let Some(mut cmd) = which(&compiler.path, None) {
2636+
cmd.pop();
2637+
cmd.push("llvm-lib.exe");
2638+
if let Some(llvm_lib) = which(&cmd, None) {
2639+
lib = llvm_lib.to_str().unwrap().to_owned();
2640+
}
2641+
}
2642+
}
2643+
if lib.is_empty() {
2644+
lib = match windows_registry::find(&target, "lib.exe") {
2645+
Some(t) => return Ok((t, "lib.exe".to_string())),
2646+
None => "lib.exe".to_string(),
2647+
}
26302648
}
2649+
lib
26312650
} else if target.contains("illumos") {
26322651
// The default 'ar' on illumos uses a non-standard flags,
26332652
// but the OS comes bundled with a GNU-compatible variant.

0 commit comments

Comments
 (0)