Skip to content

Commit e13b8b6

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 150680c commit e13b8b6

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
@@ -2662,10 +2662,29 @@ impl Build {
26622662
default_ar
26632663
}
26642664
} else if target.contains("msvc") {
2665-
match windows_registry::find(&target, "lib.exe") {
2666-
Some(t) => return Ok((t, "lib.exe".to_string())),
2667-
None => "lib.exe".to_string(),
2665+
let compiler = self.get_base_compiler()?;
2666+
let mut lib = String::new();
2667+
if compiler.family == (ToolFamily::Msvc { clang_cl: true }) {
2668+
// See if there is 'llvm-lib' next to 'clang-cl'
2669+
// Another possibility could be to see if there is 'clang'
2670+
// next to 'clang-cl' and use 'search_programs()' to locate
2671+
// 'llvm-lib'. This is because 'clang-cl' doesn't support
2672+
// the -print-search-dirs option.
2673+
if let Some(mut cmd) = which(&compiler.path, None) {
2674+
cmd.pop();
2675+
cmd.push("llvm-lib.exe");
2676+
if let Some(llvm_lib) = which(&cmd, None) {
2677+
lib = llvm_lib.to_str().unwrap().to_owned();
2678+
}
2679+
}
2680+
}
2681+
if lib.is_empty() {
2682+
lib = match windows_registry::find(&target, "lib.exe") {
2683+
Some(t) => return Ok((t, "lib.exe".to_string())),
2684+
None => "lib.exe".to_string(),
2685+
}
26682686
}
2687+
lib
26692688
} else if target.contains("illumos") {
26702689
// The default 'ar' on illumos uses a non-standard flags,
26712690
// but the OS comes bundled with a GNU-compatible variant.

0 commit comments

Comments
 (0)