about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAaron Hill <aa1ronham@gmail.com>2019-04-12 20:14:51 -0400
committerAaron Hill <aa1ronham@gmail.com>2019-04-14 15:45:18 -0400
commit3c7c2c6ca7de0317b5852c0e77aa39a2493f2dee (patch)
treed5fd564bdb9f51ddf5f0519e94cec93c5c608ca8 /src
parent4dfce34912f866d6fef52907f1e5c56117becf27 (diff)
downloadrust-3c7c2c6ca7de0317b5852c0e77aa39a2493f2dee.tar.gz
rust-3c7c2c6ca7de0317b5852c0e77aa39a2493f2dee.zip
Handle --extern-private properly on musl
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
Diffstat (limited to 'src')
-rw-r--r--src/tools/compiletest/src/main.rs1
-rw-r--r--src/tools/compiletest/src/runtest.rs42
2 files changed, 35 insertions, 8 deletions
diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs
index dfc023da973..9e3c49119de 100644
--- a/src/tools/compiletest/src/main.rs
+++ b/src/tools/compiletest/src/main.rs
@@ -1,5 +1,6 @@
 #![crate_name = "compiletest"]
 #![feature(test)]
+#![feature(vec_remove_item)]
 #![deny(warnings, rust_2018_idioms)]
 
 #[cfg(unix)]
diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs
index cec1d83eb02..e6e937f5db4 100644
--- a/src/tools/compiletest/src/runtest.rs
+++ b/src/tools/compiletest/src/runtest.rs
@@ -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 @@ impl<'test> TestCx<'test> {
             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 @@ impl<'test> TestCx<'test> {
             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 @@ impl<'test> TestCx<'test> {
                 // 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 @@ impl<'test> TestCx<'test> {
             }
         }
 
+        // 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,