Skip to content

Commit

Permalink
MsvcLinker: allow linking statically to Meson and MinGW-style named l…
Browse files Browse the repository at this point in the history
…ibraries

See rust-lang#122455
  • Loading branch information
amyspark committed Apr 18, 2024
1 parent becebb3 commit 266326f
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -811,10 +811,22 @@ impl<'a> Linker for MsvcLinker<'a> {
self.cmd.arg(format!("{}{}", name, if verbatim { "" } else { ".lib" }));
}

fn link_staticlib_by_name(&mut self, name: &str, verbatim: bool, whole_archive: bool) {
fn link_staticlib_by_name(
&mut self,
name: &str,
verbatim: bool,
whole_archive: bool,
search_paths: &SearchPaths,
) {
// Static libraries built by MSVC are usually called foo.lib.
// However, under MinGW and build systems such as Meson, they are
// called libfoo.a
let prefix = if whole_archive { "/WHOLEARCHIVE:" } else { "" };
let suffix = if verbatim { "" } else { ".lib" };
self.cmd.arg(format!("{prefix}{name}{suffix}"));
let search_paths = search_paths.get(self.sess);
let path = find_native_static_library(name, verbatim, search_paths, self.sess);
let mut arg = OsString::from(prefix);
arg.push(path);
self.cmd.arg(arg);
}

fn link_staticlib_by_path(&mut self, path: &Path, whole_archive: bool) {
Expand Down

0 comments on commit 266326f

Please sign in to comment.