Skip to content

Commit f631293

Browse files
authored
Rollup merge of #76717 - ehuss:fix-rustc-book-libdir, r=Mark-Simulacrum
Fix generating rustc docs with non-default lib directory. If `libdir` is set in `config.toml`, then the tool to generate the rustc docs was unable to run `rustc` because it could not find the shared libraries. The solution is to set the dylib search path to include the libdir. I changed the API of `add_rustc_lib_path` to take `Command` instead of `Cargo` to try to share the code in several places. This is how it worked before #64316, and I think this still retains the spirit of that change. Fixes #76702
2 parents b25261f + 9dad908 commit f631293

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

src/bootstrap/builder.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -683,15 +683,15 @@ impl<'a> Builder<'a> {
683683

684684
/// Adds the compiler's directory of dynamic libraries to `cmd`'s dynamic
685685
/// library lookup path.
686-
pub fn add_rustc_lib_path(&self, compiler: Compiler, cmd: &mut Cargo) {
686+
pub fn add_rustc_lib_path(&self, compiler: Compiler, cmd: &mut Command) {
687687
// Windows doesn't need dylib path munging because the dlls for the
688688
// compiler live next to the compiler and the system will find them
689689
// automatically.
690690
if cfg!(windows) {
691691
return;
692692
}
693693

694-
add_dylib_path(vec![self.rustc_libdir(compiler)], &mut cmd.command);
694+
add_dylib_path(vec![self.rustc_libdir(compiler)], cmd);
695695
}
696696

697697
/// Gets a path to the compiler specified.
@@ -1488,6 +1488,10 @@ impl Cargo {
14881488
self.command.env(key.as_ref(), value.as_ref());
14891489
self
14901490
}
1491+
1492+
pub fn add_rustc_lib_path(&mut self, builder: &Builder<'_>, compiler: Compiler) {
1493+
builder.add_rustc_lib_path(compiler, &mut self.command);
1494+
}
14911495
}
14921496

14931497
impl From<Cargo> for Command {

src/bootstrap/doc.rs

+4
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,10 @@ impl Step for RustcBook {
766766
if builder.config.verbose() {
767767
cmd.arg("--verbose");
768768
}
769+
// If the lib directories are in an unusual location (changed in
770+
// config.toml), then this needs to explicitly update the dylib search
771+
// path.
772+
builder.add_rustc_lib_path(self.compiler, &mut cmd);
769773
builder.run(&mut cmd);
770774
// Run rustbook/mdbook to generate the HTML pages.
771775
builder.ensure(RustbookSrc {

src/bootstrap/test.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ impl Step for Rls {
270270
&[],
271271
);
272272

273-
builder.add_rustc_lib_path(compiler, &mut cargo);
273+
cargo.add_rustc_lib_path(builder, compiler);
274274
cargo.arg("--").args(builder.config.cmd.test_args());
275275

276276
if try_run(builder, &mut cargo.into()) {
@@ -328,7 +328,7 @@ impl Step for Rustfmt {
328328
t!(fs::create_dir_all(&dir));
329329
cargo.env("RUSTFMT_TEST_DIR", dir);
330330

331-
builder.add_rustc_lib_path(compiler, &mut cargo);
331+
cargo.add_rustc_lib_path(builder, compiler);
332332

333333
if try_run(builder, &mut cargo.into()) {
334334
builder.save_toolstate("rustfmt", ToolState::TestPass);
@@ -449,7 +449,7 @@ impl Step for Miri {
449449

450450
cargo.arg("--").args(builder.config.cmd.test_args());
451451

452-
builder.add_rustc_lib_path(compiler, &mut cargo);
452+
cargo.add_rustc_lib_path(builder, compiler);
453453

454454
if !try_run(builder, &mut cargo.into()) {
455455
return;
@@ -554,7 +554,7 @@ impl Step for Clippy {
554554

555555
cargo.arg("--").args(builder.config.cmd.test_args());
556556

557-
builder.add_rustc_lib_path(compiler, &mut cargo);
557+
cargo.add_rustc_lib_path(builder, compiler);
558558

559559
builder.run(&mut cargo.into());
560560
}

src/tools/lint-docs/src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,12 @@ fn generate_lint_output(
402402
None => {
403403
let rendered: Vec<&str> =
404404
msgs.iter().filter_map(|msg| msg["rendered"].as_str()).collect();
405+
let non_json: Vec<&str> =
406+
stderr.lines().filter(|line| !line.starts_with('{')).collect();
405407
Err(format!(
406-
"did not find lint `{}` in output of example, got:\n{}",
408+
"did not find lint `{}` in output of example, got:\n{}\n{}",
407409
name,
410+
non_json.join("\n"),
408411
rendered.join("\n")
409412
)
410413
.into())

0 commit comments

Comments
 (0)