Skip to content

Commit

Permalink
Default to llvm-lib when using clang-cl in msvc environment.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dot-asm authored and ChrisDenton committed Dec 1, 2022
1 parent c4f414f commit 0e51f6d
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2665,10 +2665,29 @@ impl Build {

"emar".to_string()
} else if target.contains("msvc") {
match windows_registry::find(&target, "lib.exe") {
Some(t) => return Ok((t, "lib.exe".to_string())),
None => "lib.exe".to_string(),
let compiler = self.get_base_compiler()?;
let mut lib = String::new();
if compiler.family == (ToolFamily::Msvc { clang_cl: true }) {
// See if there is 'llvm-lib' next to 'clang-cl'
// Another possibility could be to see if there is 'clang'
// next to 'clang-cl' and use 'search_programs()' to locate
// 'llvm-lib'. This is because 'clang-cl' doesn't support
// the -print-search-dirs option.
if let Some(mut cmd) = which(&compiler.path) {
cmd.pop();
cmd.push("llvm-lib.exe");
if let Some(llvm_lib) = which(&cmd) {
lib = llvm_lib.to_str().unwrap().to_owned();
}
}
}
if lib.is_empty() {
lib = match windows_registry::find(&target, "lib.exe") {
Some(t) => return Ok((t, "lib.exe".to_string())),
None => "lib.exe".to_string(),
}
}
lib
} else if target.contains("illumos") {
// The default 'ar' on illumos uses a non-standard flags,
// but the OS comes bundled with a GNU-compatible variant.
Expand Down

0 comments on commit 0e51f6d

Please sign in to comment.