Skip to content

Commit fccaffb

Browse files
committed
Don't use -C metadata cdylibs like we do with dylibs
Dylibs don't get any metadata/extra filename info applied to them as "final targets" because it can mess with system-specific information (e.g. on OSX) so this just applies the same logic to cdylibs which need similar treatment on more platforms (like Windows). Closes #3934
1 parent 03efb7f commit fccaffb

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

src/cargo/core/manifest.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,19 @@ impl Target {
435435
}
436436
}
437437

438+
pub fn is_cdylib(&self) -> bool {
439+
let libs = match self.kind {
440+
TargetKind::Lib(ref libs) => libs,
441+
_ => return false
442+
};
443+
libs.iter().any(|l| {
444+
match *l {
445+
LibKind::Other(ref s) => s == "cdylib",
446+
_ => false,
447+
}
448+
})
449+
}
450+
438451
pub fn linkable(&self) -> bool {
439452
match self.kind {
440453
TargetKind::Lib(ref kinds) => {

src/cargo/ops/cargo_rustc/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
388388
// just here for rustbuild. We need a more principled method
389389
// doing this eventually.
390390
if !unit.profile.test &&
391-
unit.target.is_dylib() &&
391+
(unit.target.is_dylib() || unit.target.is_cdylib()) &&
392392
unit.pkg.package_id().source_id().is_path() &&
393393
!env::var("__CARGO_DEFAULT_LIB_METADATA").is_ok() {
394394
return None;
@@ -940,7 +940,7 @@ fn env_args(config: &Config,
940940
let mut rustflags = Vec::new();
941941

942942
let name = name.chars().flat_map(|c| c.to_lowercase()).collect::<String>();
943-
// Then the target.*.rustflags value...
943+
// Then the target.*.rustflags value...
944944
let target = build_config.requested_target.as_ref().unwrap_or(&build_config.host_triple);
945945
let key = format!("target.{}.{}", target, name);
946946
if let Some(args) = config.get_list_or_split_string(&key)? {

tests/build.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2909,3 +2909,34 @@ fn rustc_wrapper() {
29092909
"[RUNNING] `/usr/bin/env rustc --crate-name foo [..]")
29102910
.with_status(0));
29112911
}
2912+
2913+
#[test]
2914+
fn cdylib_not_lifted() {
2915+
let p = project("foo")
2916+
.file("Cargo.toml", r#"
2917+
[project]
2918+
name = "foo"
2919+
authors = []
2920+
version = "0.1.0"
2921+
2922+
[lib]
2923+
crate-type = ["cdylib"]
2924+
"#)
2925+
.file("src/lib.rs", "");
2926+
2927+
assert_that(p.cargo_process("build"), execs().with_status(0));
2928+
2929+
let files = if cfg!(windows) {
2930+
vec!["foo.dll.lib", "foo.dll.exp", "foo.dll"]
2931+
} else if cfg!(target_os = "macos") {
2932+
vec!["libfoo.dylib"]
2933+
} else {
2934+
vec!["libfoo.so"]
2935+
};
2936+
2937+
for file in files {
2938+
println!("checking: {}", file);
2939+
assert_that(&p.root().join("target/debug/deps").join(&file),
2940+
existing_file());
2941+
}
2942+
}

0 commit comments

Comments
 (0)