diff --git a/src/cargo/core/compiler/compilation.rs b/src/cargo/core/compiler/compilation.rs index e03a08d3947..59f583c348a 100644 --- a/src/cargo/core/compiler/compilation.rs +++ b/src/cargo/core/compiler/compilation.rs @@ -274,7 +274,12 @@ impl<'cfg> Compilation<'cfg> { is_rustc_tool: bool, ) -> CargoResult { let mut search_path = Vec::new(); + // this divides rustc/rustdoc invocations and other executions of build artifacts if is_rustc_tool { + search_path.extend(super::filter_dynamic_search_path( + self.native_dirs.iter(), + &self.root_output[&CompileKind::Host], + )); search_path.push(self.deps_output[&CompileKind::Host].clone()); search_path.push(self.sysroot_host_libdir.clone()); } else { diff --git a/tests/testsuite/run.rs b/tests/testsuite/run.rs index 64cf4e16c6b..307b6eb5d95 100644 --- a/tests/testsuite/run.rs +++ b/tests/testsuite/run.rs @@ -1175,9 +1175,27 @@ fn run_with_library_paths() { ) .file( "src/main.rs", + r##" + extern crate foo; + + fn main() { + foo::assert_search_path(); + } + "##, + ) + .file( + "src/lib.rs", &format!( r##" - fn main() {{ + #[test] + fn test_search_path() {{ + assert_search_path(); + }} + + /// ``` + /// foo::assert_search_path(); + /// ``` + pub fn assert_search_path() {{ let search_path = std::env::var_os("{}").unwrap(); let paths = std::env::split_paths(&search_path).collect::>(); println!("{{:#?}}", paths); @@ -1193,6 +1211,7 @@ fn run_with_library_paths() { .build(); p.cargo("run").run(); + p.cargo("test").run(); } #[cargo_test]