}
/// 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") {
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);
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)
// 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]);
}
}
}
+ // 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,