Skip to content

Commit 4003e74

Browse files
committed
MsvcLinker: allow linking statically to Meson and MinGW-style named libraries
See #122455
1 parent 4fd4797 commit 4003e74

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -830,11 +830,17 @@ impl<'a> Linker for MsvcLinker<'a> {
830830
name: &str,
831831
verbatim: bool,
832832
whole_archive: bool,
833-
_search_paths: &SearchPaths,
833+
search_paths: &SearchPaths,
834834
) {
835+
// Static libraries built by MSVC are usually called foo.lib.
836+
// However, under MinGW and build systems such as Meson, they are
837+
// called libfoo.a
835838
let prefix = if whole_archive { "/WHOLEARCHIVE:" } else { "" };
836-
let suffix = if verbatim { "" } else { ".lib" };
837-
self.cmd.arg(format!("{prefix}{name}{suffix}"));
839+
let search_paths = search_paths.get(self.sess);
840+
let path = find_native_static_library(name, verbatim, search_paths, self.sess);
841+
let mut arg = OsString::from(prefix);
842+
arg.push(path);
843+
self.cmd.arg(arg);
838844
}
839845

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

0 commit comments

Comments
 (0)