From b29d4d4896d20af39a265832def8a322785d20db Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Thu, 11 Oct 2018 19:42:32 -0700 Subject: [PATCH] Fix dylib reuse with uplift. --- src/cargo/core/compiler/compilation.rs | 2 +- tests/testsuite/features.rs | 61 ++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/src/cargo/core/compiler/compilation.rs b/src/cargo/core/compiler/compilation.rs index 2427941b4d1..29965a21275 100644 --- a/src/cargo/core/compiler/compilation.rs +++ b/src/cargo/core/compiler/compilation.rs @@ -193,8 +193,8 @@ impl<'cfg> Compilation<'cfg> { } else { let mut search_path = super::filter_dynamic_search_path(self.native_dirs.iter(), &self.root_output); - search_path.push(self.root_output.clone()); search_path.push(self.deps_output.clone()); + search_path.push(self.root_output.clone()); search_path.extend(self.target_dylib_path.clone()); search_path }; diff --git a/tests/testsuite/features.rs b/tests/testsuite/features.rs index 4e917c6ceaa..daf68a6053d 100644 --- a/tests/testsuite/features.rs +++ b/tests/testsuite/features.rs @@ -1669,3 +1669,64 @@ fn all_features_all_crates() { p.cargo("build --all-features --all").run(); } + +#[test] +fn feature_off_dylib() { + let p = project() + .file( + "Cargo.toml", + r#" + [workspace] + members = ["bar"] + + [package] + name = "foo" + version = "0.0.1" + + [lib] + crate-type = ["dylib"] + + [features] + f1 = [] + "#, + ) + .file( + "src/lib.rs", + r#" + pub fn hello() -> &'static str { + if cfg!(feature = "f1") { + "f1" + } else { + "no f1" + } + } + "#, + ) + .file( + "bar/Cargo.toml", + r#" + [package] + name = "bar" + version = "0.0.1" + + [dependencies] + foo = { path = ".." } + "#, + ) + .file( + "bar/src/main.rs", + r#" + extern crate foo; + + fn main() { + assert_eq!(foo::hello(), "no f1"); + } + "#, + ) + .build(); + + // Build the dylib with `f1` feature. + p.cargo("build --features f1").run(); + // Check that building without `f1` uses a dylib without `f1`. + p.cargo("run -p bar").run(); +}