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
This commit is contained in:
parent
4dfce34912
commit
3c7c2c6ca7
@ -1,5 +1,6 @@
|
|||||||
#![crate_name = "compiletest"]
|
#![crate_name = "compiletest"]
|
||||||
#![feature(test)]
|
#![feature(test)]
|
||||||
|
#![feature(vec_remove_item)]
|
||||||
#![deny(warnings, rust_2018_idioms)]
|
#![deny(warnings, rust_2018_idioms)]
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
|
@ -75,7 +75,15 @@ pub fn dylib_env_var() -> &'static str {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The platform-specific library file extension
|
/// 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) {
|
if cfg!(windows) {
|
||||||
".dll"
|
".dll"
|
||||||
} else if cfg!(target_os = "macos") {
|
} else if cfg!(target_os = "macos") {
|
||||||
@ -1596,12 +1604,15 @@ impl<'test> TestCx<'test> {
|
|||||||
create_dir_all(&aux_dir).unwrap();
|
create_dir_all(&aux_dir).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
for priv_dep in &self.props.extern_private {
|
// Use a Vec instead of a HashMap to preserve original order
|
||||||
let lib_name = format!("lib{}{}", priv_dep, lib_extension());
|
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
|
rustc
|
||||||
.arg("--extern-private")
|
.arg("--extern-private")
|
||||||
.arg(format!("{}={}", priv_dep, aux_dir.join(lib_name).to_str().unwrap()));
|
.arg(format!("{}={}", priv_dep, aux_dir.join(lib_name).to_str().unwrap()));
|
||||||
}
|
};
|
||||||
|
|
||||||
for rel_ab in &self.props.aux_builds {
|
for rel_ab in &self.props.aux_builds {
|
||||||
let aux_testpaths = self.compute_aux_test_paths(rel_ab);
|
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();
|
create_dir_all(aux_cx.output_base_dir()).unwrap();
|
||||||
let mut aux_rustc = aux_cx.make_compile_args(&aux_testpaths.file, aux_output);
|
let mut aux_rustc = aux_cx.make_compile_args(&aux_testpaths.file, aux_output);
|
||||||
|
|
||||||
let crate_type = if aux_props.no_prefer_dynamic {
|
let (dylib, crate_type) = if aux_props.no_prefer_dynamic {
|
||||||
None
|
(true, None)
|
||||||
} else if self.config.target.contains("cloudabi")
|
} else if self.config.target.contains("cloudabi")
|
||||||
|| self.config.target.contains("emscripten")
|
|| self.config.target.contains("emscripten")
|
||||||
|| (self.config.target.contains("musl") && !aux_props.force_host)
|
|| (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,
|
// 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
|
// 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.
|
// it's ok to be a dylib as the host should always support dylibs.
|
||||||
Some("lib")
|
(false, Some("lib"))
|
||||||
} else {
|
} 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 {
|
if let Some(crate_type) = crate_type {
|
||||||
aux_rustc.args(&["--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());
|
rustc.envs(self.props.rustc_env.clone());
|
||||||
self.compose_and_run(
|
self.compose_and_run(
|
||||||
rustc,
|
rustc,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user