Skip to content

Commit 43653c1

Browse files
committed
linker: Fix staticlib naming for UEFI
It uses `libname.a` instead of the standard MSVC naming `name.lib`. Naming for import libraries isn't touched.
1 parent 4510e86 commit 43653c1

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,12 @@ fn print_native_static_libs(
14941494
| NativeLibKind::Unspecified => {
14951495
let verbatim = lib.verbatim;
14961496
if sess.target.is_like_msvc {
1497-
Some(format!("{}{}", name, if verbatim { "" } else { ".lib" }))
1497+
let (prefix, suffix) = if verbatim {
1498+
("", "")
1499+
} else {
1500+
(&*sess.target.staticlib_prefix, &*sess.target.staticlib_suffix)
1501+
};
1502+
Some(format!("{prefix}{name}{suffix}"))
14981503
} else if sess.target.linker_flavor.is_gnu() {
14991504
Some(format!("-l{}{}", if verbatim { ":" } else { "" }, name))
15001505
} else {

compiler/rustc_codegen_ssa/src/back/linker.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -958,9 +958,13 @@ impl<'a> Linker for MsvcLinker<'a> {
958958
if let Some(path) = try_find_native_static_library(self.sess, name, verbatim) {
959959
self.link_staticlib_by_path(&path, whole_archive);
960960
} else {
961-
let prefix = if whole_archive { "/WHOLEARCHIVE:" } else { "" };
962-
let suffix = if verbatim { "" } else { ".lib" };
963-
self.link_arg(format!("{prefix}{name}{suffix}"));
961+
let opts = if whole_archive { "/WHOLEARCHIVE:" } else { "" };
962+
let (prefix, suffix) = if verbatim {
963+
("", "")
964+
} else {
965+
(&*self.sess.target.staticlib_prefix, &*self.sess.target.staticlib_suffix)
966+
};
967+
self.link_arg(format!("{opts}{prefix}{name}{suffix}"));
964968
}
965969
}
966970

0 commit comments

Comments
 (0)