Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc: Doctest merging: Remove superfluous library search path logic #138436

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,18 +672,6 @@ fn run_test(
"--extern=doctest_bundle_{edition}=",
edition = doctest.edition
));
for extern_str in &rustdoc_options.extern_strs {
Copy link
Member Author

@fmease fmease Mar 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also note for additional context: This didn't apply to doctest-only dependencies "anyway"1 as registered via -Zunstable-options --doctest-compilation-args as noted here: #137899 (comment)

Footnotes

  1. Very unlikely to occur in practice due to Cargo's dominance which doesn't support that.

if let Some((_cratename, path)) = extern_str.split_once('=') {
// Direct dependencies of the tests themselves are
// indirect dependencies of the test runner.
// They need to be in the library search path.
let dir = Path::new(path)
.parent()
.filter(|x| x.components().count() > 0)
.unwrap_or(Path::new("."));
runner_compiler.arg("-L").arg(dir);
}
}
let output_bundle_file = doctest
.test_opts
.outdir
Expand Down
1 change: 1 addition & 0 deletions tests/run-make/doctests-merge-with-deps/dep_a.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub const STATUS: bool = dep_a_a::STATUS;
1 change: 1 addition & 0 deletions tests/run-make/doctests-merge-with-deps/dep_b.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub const STATUS: bool = dep_b_b::STATUS;
1 change: 1 addition & 0 deletions tests/run-make/doctests-merge-with-deps/deps/dep_a_a.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub const STATUS: bool = true;
1 change: 1 addition & 0 deletions tests/run-make/doctests-merge-with-deps/deps/dep_b_b.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub const STATUS: bool = true;
7 changes: 7 additions & 0 deletions tests/run-make/doctests-merge-with-deps/doctest.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//! ```
//! assert!(dep_a::STATUS);
//! ```
//!
//! ```
//! assert!(dep_b::STATUS);
//! ```
68 changes: 68 additions & 0 deletions tests/run-make/doctests-merge-with-deps/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//! Since PR <https://github.com/rust-lang/rust/pull/137899>, merged doctests reside in so-called
//! "bundle" crates which are separate from the actual "runner" crates that contain the necessary
//! scaffolding / infrastructure for executing the tests by utilizing the unstable crate `test`
//! and the internal lang feature `rustc_attrs`.
//!
//! In the light of this two-crate setup (per edition), this test ensures that rustdoc can handle
//! mergeable doctests with direct and transitive dependencies (which would become ("first-degree")
//! transitive and "second-degree" transitive dependencies of the runner crates, respectively).
//!
//! While this is about doctest merging which is only available in Rust 2024 and beyond,
//! we also test Rust 2021 here to ensure that in this specific scenario rustdoc doesn't
//! grossly diverge in observable behavior.

use run_make_support::{bare_rustc, rustdoc};

fn main() {
// Re. `bare_rustc` over `rustc` (which would implicitly add `-L.`):
// This test is all about verifying that rustdoc is able to find dependencies
// and properly propagates library search paths etc.
// Anything implicit like that would only obfuscate this test or even
// accidentally break it.

//
// Build crate `a_a` and its dependent `a` which is the direct dependency of
// the doctests inside `doctest.rs` *and* of crate `doctest` itself!
//

bare_rustc().current_dir("deps").input("dep_a_a.rs").crate_type("lib").run();

bare_rustc().input("dep_a.rs").crate_type("lib").args(["--extern=dep_a_a", "-Ldeps"]).run();

//
// Build crate `b_b` and its dependent `b` which is the direct dependency of
// the first doctest in `doctest.rs` *but not* of crate `doctest` itself!
//

bare_rustc().current_dir("deps").input("dep_b_b.rs").crate_type("lib").run();

bare_rustc().input("dep_b.rs").crate_type("lib").args(["--extern=dep_b_b", "-Ldeps"]).run();

//
// Collect and run the doctests inside `doctest.rs`.
//

for edition in ["2021", "2024"] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also explicitly add a "2015" edition, since that IIRC influences extern prelude behavior (in 2015, extern extern_prelude; is still needed even if you specify --extern to rustc IIRC).

// NB: `-Ldependency=<path>` only adds *transitive* dependencies to
// the search path contrary to `-L<path>`.

rustdoc()
.input("doctest.rs")
.crate_type("lib")
.edition(edition)
// Adds crate `a` as a dep of `doctest` *and* its contained doctests.
// Also registers transitive dependencies.
.extern_("dep_a", "libdep_a.rlib")
.arg("-Ldependency=deps")
// Adds crate `b` as a dep of `doctest`'s contained doctests.
// Also registers transitive dependencies.
.args([
"-Zunstable-options",
"--doctest-compilation-args",
"--extern=dep_b=libdep_b.rlib -Ldependency=deps",
])
.arg("--test")
.arg("--test-args=--test-threads=1")
.run();
}
}
Loading