diff --git a/src/cargo/ops/cargo_rustc/compilation.rs b/src/cargo/ops/cargo_rustc/compilation.rs index f1227f3dc..2f5c48553 100644 --- a/src/cargo/ops/cargo_rustc/compilation.rs +++ b/src/cargo/ops/cargo_rustc/compilation.rs @@ -28,9 +28,13 @@ 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, + /// Output directory for the rust host dependencies. + pub host_deps_output: PathBuf, + /// Library search path for compiler plugins and build scripts /// which have dynamic dependencies. pub plugins_dylib_path: PathBuf, @@ -64,6 +68,7 @@ impl<'cfg> Compilation<'cfg> { native_dirs: HashSet::new(), // TODO: deprecated, remove root_output: PathBuf::from("/"), deps_output: PathBuf::from("/"), + host_deps_output: PathBuf::from("/"), plugins_dylib_path: PathBuf::from("/"), host_dylib_path: None, target_dylib_path: None, diff --git a/src/cargo/ops/cargo_rustc/context.rs b/src/cargo/ops/cargo_rustc/context.rs index 865f8b42a..0d34df739 100755 --- a/src/cargo/ops/cargo_rustc/context.rs +++ b/src/cargo/ops/cargo_rustc/context.rs @@ -176,6 +176,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> { } 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 d6c1717f8..32c92e731 100644 --- a/src/cargo/ops/cargo_test.rs +++ b/src/cargo/ops/cargo_test.rs @@ -126,7 +126,6 @@ fn run_doc_tests(options: &TestOptions, -> CargoResult<(Test, Vec)> { let mut errors = Vec::new(); let config = options.compile_opts.config; - let host_deps = find_host_deps(options, compilation); // We don't build/rust doctests if target != host if config.rustc()?.host != compilation.target { @@ -145,17 +144,22 @@ fn run_doc_tests(options: &TestOptions, p.arg("--test").arg(lib) .arg("--crate-name").arg(&crate_name); - p.arg("-L").arg(&host_deps); - for &rust_dep in &[&compilation.deps_output] { let mut arg = OsString::from("dependency="); 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); } @@ -201,24 +205,3 @@ fn run_doc_tests(options: &TestOptions, } Ok((Test::Doc, errors)) } - -fn find_host_deps(options: &TestOptions, compilation: &Compilation) -> OsString { - let build_type = if options.compile_opts.release { "release" } else { "debug" }; - let mut dir = compilation.root_output.clone(); - - // first pop off the build_type - dir.pop(); - // if we see the target next, pop it off - let target: &OsStr = compilation.target.as_ref(); - if dir.file_name().unwrap() == target { - dir.pop(); - } - // push the build_type back on - dir.push(build_type); - // and we are looking for the deps directory - dir.push("deps"); - - let mut host_deps = OsString::from("dependency="); - host_deps.push(dir); - host_deps -} diff --git a/tests/test.rs b/tests/test.rs index adb89f919..40642db91 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -2816,10 +2816,10 @@ fn find_dependency_of_proc_macro_dependency_with_target() { proc-macro = true [dependencies] - base64 = "^0.6" + dep_of_proc_macro_dep = "^0.1" "#) .file("proc_macro_dep/src/lib.rs", r#" - extern crate base64; + extern crate dep_of_proc_macro_dep; extern crate proc_macro; use proc_macro::TokenStream; @@ -2828,6 +2828,7 @@ fn find_dependency_of_proc_macro_dependency_with_target() { "".parse().unwrap() } "#); + Package::new("dep_of_proc_macro_dep", "0.1.0").publish(); workspace.build(); assert_that(workspace.cargo("test").arg("--all").arg("--target").arg(rustc_host()), execs().with_status(0));