Skip to content

Commit

Permalink
fix: doctest searches native libs in build script outputs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
weihanglo committed Feb 26, 2024
1 parent 0e8a67f commit 34215b1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/cargo/core/compiler/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,18 @@ impl<'gctx> Compilation<'gctx> {
) -> CargoResult<ProcessBuilder> {
let mut search_path = Vec::new();
if tool_kind.is_rustc_tool() {
if matches!(tool_kind, ToolKind::Rustdoc) {
// 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.
// TODO: handle doctest-xcompile
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());
} else {
search_path.extend(super::filter_dynamic_search_path(
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2801,8 +2801,8 @@ fn doctest_with_library_paths() {
pub fn assert_search_path() {{
let search_path = std::env::var_os("{}").unwrap();
let paths = std::env::split_paths(&search_path).collect::<Vec<_>>();
assert!(!paths.contains(&r#"{}"#.into()));
assert!(!paths.contains(&r#"{}"#.into()));
assert!(paths.contains(&r#"{}"#.into()));
assert!(paths.contains(&r#"{}"#.into()));
}}
"##,
dylib_path_envvar(),
Expand Down

0 comments on commit 34215b1

Please sign in to comment.