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 committed Nov 3, 2022
1 parent 7011c79 commit dfbc4a4
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 @@ -2624,10 +2624,29 @@ impl Build {
default_ar
}
} 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, None) {
cmd.pop();
cmd.push("llvm-lib.exe");
if let Some(llvm_lib) = which(&cmd, None) {
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 dfbc4a4

Please sign in to comment.