Skip to content

Commit 291a31d

Browse files
committed
MsvcLinker: allow linking statically to Meson and MinGW-style named libraries
See #122455
1 parent f9b1614 commit 291a31d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

compiler/rustc_codegen_ssa/src/back/linker.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -812,9 +812,14 @@ impl<'a> Linker for MsvcLinker<'a> {
812812
}
813813

814814
fn link_staticlib_by_name(&mut self, name: &str, verbatim: bool, whole_archive: bool) {
815+
// Static libraries built by MSVC are usually called foo.lib.
816+
// However, under MinGW and build systems such as Meson, they are
817+
// called libfoo.a
815818
let prefix = if whole_archive { "/WHOLEARCHIVE:" } else { "" };
816-
let suffix = if verbatim { "" } else { ".lib" };
817-
self.cmd.arg(format!("{prefix}{name}{suffix}"));
819+
let path = find_native_static_library(name, verbatim, self.sess);
820+
let mut arg = OsString::from(prefix);
821+
arg.push(path);
822+
self.cmd.arg(arg);
818823
}
819824

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

0 commit comments

Comments
 (0)