1
Fork 0

fix verbatim with upstream dependencies

https://github.com/rust-lang/rust/issues/99425#issuecomment-1207224161

r? `@petrochenkov`
This commit is contained in:
bors 2022-09-20 07:10:17 +00:00
parent a5b58addae
commit a38a082afb
8 changed files with 75 additions and 19 deletions

View file

@ -439,7 +439,10 @@ impl<'a> Linker for GccLinker<'a> {
}
}
self.hint_dynamic();
self.cmd.arg(format!("-l{}{}", if verbatim { ":" } else { "" }, lib));
self.cmd.arg(format!(
"-l{}{lib}",
if verbatim && self.sess.target.linker_is_gnu { ":" } else { "" },
));
if !as_needed {
if self.sess.target.is_like_osx {
// See above FIXME comment
@ -450,7 +453,10 @@ impl<'a> Linker for GccLinker<'a> {
}
fn link_staticlib(&mut self, lib: &str, verbatim: bool) {
self.hint_static();
self.cmd.arg(format!("-l{}{}", if verbatim { ":" } else { "" }, lib));
self.cmd.arg(format!(
"-l{}{lib}",
if verbatim && self.sess.target.linker_is_gnu { ":" } else { "" },
));
}
fn link_rlib(&mut self, lib: &Path) {
self.hint_static();
@ -504,10 +510,10 @@ impl<'a> Linker for GccLinker<'a> {
self.hint_static();
let target = &self.sess.target;
if !target.is_like_osx {
self.linker_arg("--whole-archive").cmd.arg(format!(
"-l{}{}",
if verbatim { ":" } else { "" },
lib
self.linker_arg("--whole-archive");
self.cmd.arg(format!(
"-l{}{lib}",
if verbatim && self.sess.target.linker_is_gnu { ":" } else { "" },
));
self.linker_arg("--no-whole-archive");
} else {

View file

@ -33,28 +33,25 @@ pub fn find_native_static_library(
search_paths: &[PathBuf],
sess: &Session,
) -> PathBuf {
let verbatim = verbatim.unwrap_or(false);
// On Windows, static libraries sometimes show up as libfoo.a and other
// times show up as foo.lib
let oslibname = if verbatim {
name.to_string()
let formats = if verbatim.unwrap_or(false) {
vec![("".into(), "".into())]
} else {
format!("{}{}{}", sess.target.staticlib_prefix, name, sess.target.staticlib_suffix)
let os = (sess.target.staticlib_prefix.clone(), sess.target.staticlib_suffix.clone());
// On Windows, static libraries sometimes show up as libfoo.a and other
// times show up as foo.lib
let unix = ("lib".into(), ".a".into());
if os == unix { vec![os] } else { vec![os, unix] }
};
let unixlibname = format!("lib{}.a", name);
for path in search_paths {
let test = path.join(&oslibname);
if test.exists() {
return test;
}
if oslibname != unixlibname {
let test = path.join(&unixlibname);
for (prefix, suffix) in &formats {
let test = path.join(format!("{}{}{}", prefix, name, suffix));
if test.exists() {
return test;
}
}
}
sess.emit_fatal(MissingNativeLibrary { libname: name });
}