about summary refs log tree commit diff
path: root/compiler/rustc_metadata/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-09-20 07:10:18 +0000
committerbors <bors@rust-lang.org>2022-09-20 07:10:18 +0000
commit8fd6d03e22fba2930ad377b87299de6a37076074 (patch)
treec5fa9caa1ae1f3572549c588e78ba3fc400d90c5 /compiler/rustc_metadata/src
parentacb8934fd57b3c2740c4abac0a5728c2c9b1423b (diff)
parenta38a082afb5522a0943e60b556588eb78a4dda80 (diff)
downloadrust-8fd6d03e22fba2930ad377b87299de6a37076074.tar.gz
rust-8fd6d03e22fba2930ad377b87299de6a37076074.zip
Auto merge of #101806 - BelovDV:issue-fix-fn-find_library, r=petrochenkov
fix verbatim with upstream dependencies

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

r? `@petrochenkov`
Diffstat (limited to 'compiler/rustc_metadata/src')
-rw-r--r--compiler/rustc_metadata/src/native_libs.rs23
1 files changed, 10 insertions, 13 deletions
diff --git a/compiler/rustc_metadata/src/native_libs.rs b/compiler/rustc_metadata/src/native_libs.rs
index 257741c13f5..2a986c41d72 100644
--- a/compiler/rustc_metadata/src/native_libs.rs
+++ b/compiler/rustc_metadata/src/native_libs.rs
@@ -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 });
 }