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.
This commit is contained in:
Weihang Lo 2024-02-22 10:31:48 -05:00
parent 0e8a67fde3
commit 34215b1b4a
No known key found for this signature in database
GPG Key ID: D7DBF189825E82E7
2 changed files with 14 additions and 2 deletions

View File

@ -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(

View File

@ -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(),