diff --git a/src/cargo/ops/cargo_rustc/compilation.rs b/src/cargo/ops/cargo_rustc/compilation.rs index f1227f3dca5..c853290c756 100644 --- a/src/cargo/ops/cargo_rustc/compilation.rs +++ b/src/cargo/ops/cargo_rustc/compilation.rs @@ -28,12 +28,12 @@ pub struct Compilation<'cfg> { /// Root output directory (for the local package's artifacts) pub root_output: PathBuf, - /// Output directory for rust dependencies + /// Output directory for rust dependencies. + /// May be for the host or for a specific target. pub deps_output: PathBuf, - /// Library search path for compiler plugins and build scripts - /// which have dynamic dependencies. - pub plugins_dylib_path: PathBuf, + /// Output directory for the rust host dependencies. + pub host_deps_output: PathBuf, /// The path to rustc's own libstd pub host_dylib_path: Option, @@ -64,7 +64,7 @@ impl<'cfg> Compilation<'cfg> { native_dirs: HashSet::new(), // TODO: deprecated, remove root_output: PathBuf::from("/"), deps_output: PathBuf::from("/"), - plugins_dylib_path: PathBuf::from("/"), + host_deps_output: PathBuf::from("/"), host_dylib_path: None, target_dylib_path: None, tests: Vec::new(), @@ -124,7 +124,7 @@ impl<'cfg> Compilation<'cfg> { -> CargoResult { let mut search_path = if is_host { - let mut search_path = vec![self.plugins_dylib_path.clone()]; + let mut search_path = vec![self.host_deps_output.clone()]; search_path.extend(self.host_dylib_path.clone()); search_path } else { diff --git a/src/cargo/ops/cargo_rustc/context.rs b/src/cargo/ops/cargo_rustc/context.rs index 865f8b42a50..906a5155a93 100755 --- a/src/cargo/ops/cargo_rustc/context.rs +++ b/src/cargo/ops/cargo_rustc/context.rs @@ -175,7 +175,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> { None => {} } - self.compilation.plugins_dylib_path = self.host.deps().to_path_buf(); + self.compilation.host_deps_output = self.host.deps().to_path_buf(); let layout = self.target.as_ref().unwrap_or(&self.host); self.compilation.root_output = layout.dest().to_path_buf(); diff --git a/src/cargo/ops/cargo_test.rs b/src/cargo/ops/cargo_test.rs index 86e43173302..32c92e73156 100644 --- a/src/cargo/ops/cargo_test.rs +++ b/src/cargo/ops/cargo_test.rs @@ -149,10 +149,17 @@ fn run_doc_tests(options: &TestOptions, arg.push(rust_dep); p.arg("-L").arg(arg); } + for native_dep in compilation.native_dirs.iter() { p.arg("-L").arg(native_dep); } + for &host_rust_dep in &[&compilation.host_deps_output] { + let mut arg = OsString::from("dependency="); + arg.push(host_rust_dep); + p.arg("-L").arg(arg); + } + for arg in test_args { p.arg("--test-args").arg(arg); } diff --git a/tests/test.rs b/tests/test.rs index 017a39d8093..f9d69e1f275 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -6,7 +6,7 @@ use std::fs::File; use std::io::prelude::*; use std::str; -use cargotest::{sleep_ms, is_nightly}; +use cargotest::{sleep_ms, is_nightly, rustc_host}; use cargotest::support::{project, execs, basic_bin_manifest, basic_lib_manifest, cargo_exe}; use cargotest::support::paths::CargoPathExt; use cargotest::support::registry::Package; @@ -2782,3 +2782,58 @@ fn publish_a_crate_without_tests() { assert_that(p.cargo("test").arg("--package").arg("testless"), execs().with_status(0)); } + +#[test] +fn find_dependency_of_proc_macro_dependency_with_target() { + let workspace = project("workspace") + .file("Cargo.toml", r#" + [workspace] + members = ["root", "proc_macro_dep"] + "#) + .file("root/Cargo.toml", r#" + [project] + name = "root" + version = "0.1.0" + authors = [] + + [dependencies] + proc_macro_dep = { path = "../proc_macro_dep" } + "#) + .file("root/src/lib.rs", r#" + #[macro_use] + extern crate proc_macro_dep; + + #[derive(Noop)] + pub struct X; + "#) + .file("proc_macro_dep/Cargo.toml", r#" + [project] + name = "proc_macro_dep" + version = "0.1.0" + authors = [] + + [lib] + proc-macro = true + + [dependencies] + bar = "^0.1" + "#) + .file("proc_macro_dep/src/lib.rs", r#" + extern crate bar; + extern crate proc_macro; + use proc_macro::TokenStream; + + #[proc_macro_derive(Noop)] + pub fn noop(_input: TokenStream) -> TokenStream { + "".parse().unwrap() + } + "#); + Package::new("foo", "0.1.0").publish(); + Package::new("bar", "0.1.0") + .dep("foo", "0.1") + .file("src/lib.rs", "extern crate foo;") + .publish(); + workspace.build(); + assert_that(workspace.cargo("test").arg("--all").arg("--target").arg(rustc_host()), + execs().with_status(0)); +}