Skip to content

Commit 34215b1

Browse files
committed
fix: doctest searches native libs in build script outputs
HACK: `rustdoc --test` not only compiles but executes doctests. Ideally only execution phase should have search paths appended, so the executions can find native libs just like other tests. However, there is no way to separate these two phase, so this hack is added for both phases.
1 parent 0e8a67f commit 34215b1

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/cargo/core/compiler/compilation.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,18 @@ impl<'gctx> Compilation<'gctx> {
293293
) -> CargoResult<ProcessBuilder> {
294294
let mut search_path = Vec::new();
295295
if tool_kind.is_rustc_tool() {
296+
if matches!(tool_kind, ToolKind::Rustdoc) {
297+
// HACK: `rustdoc --test` not only compiles but executes doctests.
298+
// Ideally only execution phase should have search paths appended,
299+
// so the executions can find native libs just like other tests.
300+
// However, there is no way to separate these two phase, so this
301+
// hack is added for both phases.
302+
// TODO: handle doctest-xcompile
303+
search_path.extend(super::filter_dynamic_search_path(
304+
self.native_dirs.iter(),
305+
&self.root_output[&CompileKind::Host],
306+
));
307+
}
296308
search_path.push(self.deps_output[&CompileKind::Host].clone());
297309
} else {
298310
search_path.extend(super::filter_dynamic_search_path(

tests/testsuite/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2801,8 +2801,8 @@ fn doctest_with_library_paths() {
28012801
pub fn assert_search_path() {{
28022802
let search_path = std::env::var_os("{}").unwrap();
28032803
let paths = std::env::split_paths(&search_path).collect::<Vec<_>>();
2804-
assert!(!paths.contains(&r#"{}"#.into()));
2805-
assert!(!paths.contains(&r#"{}"#.into()));
2804+
assert!(paths.contains(&r#"{}"#.into()));
2805+
assert!(paths.contains(&r#"{}"#.into()));
28062806
}}
28072807
"##,
28082808
dylib_path_envvar(),

0 commit comments

Comments
 (0)