]> git.lizzy.rs Git - rust.git/commitdiff
Handle --extern-private properly on musl
authorAaron Hill <aa1ronham@gmail.com>
Sat, 13 Apr 2019 00:14:51 +0000 (20:14 -0400)
committerAaron Hill <aa1ronham@gmail.com>
Sun, 14 Apr 2019 19:45:18 +0000 (15:45 -0400)
On musl (and some other platforms), compiletest ends up creating a static rlib
(instead of a dylib) when building 'aux-build' crates.

This commit changes the '--extern-private' path computed by compiletest
to properly take this into account

src/tools/compiletest/src/main.rs
src/tools/compiletest/src/runtest.rs

index dfc023da9736bab422f44557759163008291af9d..9e3c49119deafd16a44ad66fbdc4242b09bebc94 100644 (file)
@@ -1,5 +1,6 @@
 #![crate_name = "compiletest"]
 #![feature(test)]
+#![feature(vec_remove_item)]
 #![deny(warnings, rust_2018_idioms)]
 
 #[cfg(unix)]
index cec1d83eb0262364251ea4341b87ac6ca715c2e3..e6e937f5db4450c29f4967459e8516a5fbf53e39 100644 (file)
@@ -75,7 +75,15 @@ pub fn dylib_env_var() -> &'static str {
 }
 
 /// The platform-specific library file extension
-pub fn lib_extension() -> &'static str {
+pub fn lib_extension(dylib: bool) -> &'static str {
+    // In some casess (e.g. MUSL), we build a static
+    // library, rather than a dynamic library.
+    // In this case, the only path we can pass
+    // with '--extern-meta' is the '.lib' file
+    if !dylib {
+        return ".rlib"
+    }
+
     if cfg!(windows) {
         ".dll"
     } else if cfg!(target_os = "macos") {
@@ -1596,12 +1604,15 @@ fn compose_and_run_compiler(&self, mut rustc: Command, input: Option<String>) ->
             create_dir_all(&aux_dir).unwrap();
         }
 
-        for priv_dep in &self.props.extern_private {
-            let lib_name = format!("lib{}{}", priv_dep, lib_extension());
+        // Use a Vec instead of a HashMap to preserve original order
+        let mut extern_priv = self.props.extern_private.clone();
+
+        let mut add_extern_priv = |priv_dep: &str, dylib: bool| {
+            let lib_name = format!("lib{}{}", priv_dep, lib_extension(dylib));
             rustc
                 .arg("--extern-private")
                 .arg(format!("{}={}", priv_dep, aux_dir.join(lib_name).to_str().unwrap()));
-        }
+        };
 
         for rel_ab in &self.props.aux_builds {
             let aux_testpaths = self.compute_aux_test_paths(rel_ab);
@@ -1619,8 +1630,8 @@ fn compose_and_run_compiler(&self, mut rustc: Command, input: Option<String>) ->
             create_dir_all(aux_cx.output_base_dir()).unwrap();
             let mut aux_rustc = aux_cx.make_compile_args(&aux_testpaths.file, aux_output);
 
-            let crate_type = if aux_props.no_prefer_dynamic {
-                None
+            let (dylib, crate_type) = if aux_props.no_prefer_dynamic {
+                (true, None)
             } else if self.config.target.contains("cloudabi")
                 || self.config.target.contains("emscripten")
                 || (self.config.target.contains("musl") && !aux_props.force_host)
@@ -1636,11 +1647,20 @@ fn compose_and_run_compiler(&self, mut rustc: Command, input: Option<String>) ->
                 // dynamic libraries so we just go back to building a normal library. Note,
                 // however, that for MUSL if the library is built with `force_host` then
                 // it's ok to be a dylib as the host should always support dylibs.
-                Some("lib")
+                (false, Some("lib"))
             } else {
-                Some("dylib")
+                (true, Some("dylib"))
             };
 
+            let trimmed = rel_ab.trim_end_matches(".rs").to_string();
+
+            // Normally, every 'extern-private' has a correspodning 'aux-build'
+            // entry. If so, we remove it from our list of private crates,
+            // and add an '--extern-private' flag to rustc
+            if extern_priv.remove_item(&trimmed).is_some() {
+                add_extern_priv(&trimmed, dylib);
+            }
+
             if let Some(crate_type) = crate_type {
                 aux_rustc.args(&["--crate-type", crate_type]);
             }
@@ -1664,6 +1684,12 @@ fn compose_and_run_compiler(&self, mut rustc: Command, input: Option<String>) ->
             }
         }
 
+        // Add any '--extenr-private' entries without a matching
+        // 'aux-build'
+        for private_lib in extern_priv {
+            add_extern_priv(&private_lib, true);
+        }
+
         rustc.envs(self.props.rustc_env.clone());
         self.compose_and_run(
             rustc,