Skip to content

Commit 093cbd6

Browse files
Add unstable --test-builder to rustdoc
This allows overriding the rustc binary used to build tests; it should not generally be necessary as we fallback to the sysroot.
1 parent 2fc32b9 commit 093cbd6

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/librustdoc/config.rs

+6
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ pub struct Options {
8686
/// contains "foo" as a substring
8787
pub enable_per_target_ignores: bool,
8888

89+
/// The path to a rustc-like binary to build tests with. If not set, we
90+
/// default to loading from $sysroot/bin/rustc.
91+
pub test_builder: Option<PathBuf>,
92+
8993
// Options that affect the documentation process
9094

9195
/// The selected default set of passes to use.
@@ -476,6 +480,7 @@ impl Options {
476480
let generate_search_filter = !matches.opt_present("disable-per-crate-search");
477481
let persist_doctests = matches.opt_str("persist-doctests").map(PathBuf::from);
478482
let generate_redirect_pages = matches.opt_present("generate-redirect-pages");
483+
let test_builder = matches.opt_str("test-builder").map(PathBuf::from);
479484
let codegen_options_strs = matches.opt_strs("C");
480485
let lib_strs = matches.opt_strs("L");
481486
let extern_strs = matches.opt_strs("extern");
@@ -515,6 +520,7 @@ impl Options {
515520
runtool,
516521
runtool_args,
517522
enable_per_target_ignores,
523+
test_builder,
518524
render_options: RenderOptions {
519525
output,
520526
external_html,

src/librustdoc/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,11 @@ fn opts() -> Vec<RustcOptGroup> {
373373
"",
374374
"One (of possibly many) arguments to pass to the runtool")
375375
}),
376+
unstable("test-builder", |o| {
377+
o.optflag("",
378+
"test-builder",
379+
"specified the rustc-like binary to use as the test builder")
380+
}),
376381
]
377382
}
378383

src/librustdoc/test.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,10 @@ fn run_test(
248248
};
249249
let output_file = outdir.path().join("rust_out");
250250

251-
let mut compiler = Command::new(rustc_interface::util::rustc_path().expect("found rustc"));
251+
let rustc_binary = options.test_builder.as_ref().map(|v| &**v).unwrap_or_else(|| {
252+
rustc_interface::util::rustc_path().expect("found rustc")
253+
});
254+
let mut compiler = Command::new(&rustc_binary);
252255
compiler.arg("--crate-type").arg("bin");
253256
for cfg in &options.cfgs {
254257
compiler.arg("--cfg").arg(&cfg);

0 commit comments

Comments
 (0)