Skip to content

Commit de52ccd

Browse files
committed
Auto merge of #3951 - alexcrichton:lift-cdylib, r=alexcrichton
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
2 parents 8cc22d2 + fccaffb commit de52ccd

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
@@ -3049,3 +3049,34 @@ fn rustc_wrapper() {
30493049
"[RUNNING] `/usr/bin/env rustc --crate-name foo [..]")
30503050
.with_status(0));
30513051
}
3052+
3053+
#[test]
3054+
fn cdylib_not_lifted() {
3055+
let p = project("foo")
3056+
.file("Cargo.toml", r#"
3057+
[project]
3058+
name = "foo"
3059+
authors = []
3060+
version = "0.1.0"
3061+
3062+
[lib]
3063+
crate-type = ["cdylib"]
3064+
"#)
3065+
.file("src/lib.rs", "");
3066+
3067+
assert_that(p.cargo_process("build"), execs().with_status(0));
3068+
3069+
let files = if cfg!(windows) {
3070+
vec!["foo.dll.lib", "foo.dll.exp", "foo.dll"]
3071+
} else if cfg!(target_os = "macos") {
3072+
vec!["libfoo.dylib"]
3073+
} else {
3074+
vec!["libfoo.so"]
3075+
};
3076+
3077+
for file in files {
3078+
println!("checking: {}", file);
3079+
assert_that(&p.root().join("target/debug/deps").join(&file),
3080+
existing_file());
3081+
}
3082+
}

0 commit comments

Comments
 (0)