Rollup merge of #130536 - cuviper:rustbook-dylib-path, r=Mark-Simulacrum

bootstrap: Set the dylib path when building books with rustdoc

The library path is needed when the toolchain has been configured with
`[rust] rpath = false`. Otherwise, building the reference book will get
an error when it tries to run rustdoc, like:

    rustdoc: error while loading shared libraries: librustc_driver-2ec457c3b8826b72.so
This commit is contained in:
Jubilee 2024-09-23 07:54:43 -07:00 committed by GitHub
commit c58e3cb1e2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -63,7 +63,7 @@ fn run(self, builder: &Builder<'_>) {
src: builder.src.join($path), src: builder.src.join($path),
parent: Some(self), parent: Some(self),
languages: $lang.into(), languages: $lang.into(),
rustdoc: None, rustdoc_compiler: None,
}) })
} }
} }
@ -113,7 +113,7 @@ fn run(self, builder: &Builder<'_>) {
src: builder.md_doc_out(self.target).join("unstable-book"), src: builder.md_doc_out(self.target).join("unstable-book"),
parent: Some(self), parent: Some(self),
languages: vec![], languages: vec![],
rustdoc: None, rustdoc_compiler: None,
}) })
} }
} }
@ -125,7 +125,7 @@ struct RustbookSrc<P: Step> {
src: PathBuf, src: PathBuf,
parent: Option<P>, parent: Option<P>,
languages: Vec<&'static str>, languages: Vec<&'static str>,
rustdoc: Option<PathBuf>, rustdoc_compiler: Option<Compiler>,
} }
impl<P: Step> Step for RustbookSrc<P> { impl<P: Step> Step for RustbookSrc<P> {
@ -157,7 +157,9 @@ fn run(self, builder: &Builder<'_>) {
let _ = fs::remove_dir_all(&out); let _ = fs::remove_dir_all(&out);
let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook); let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
if let Some(mut rustdoc) = self.rustdoc {
if let Some(compiler) = self.rustdoc_compiler {
let mut rustdoc = builder.rustdoc(compiler);
rustdoc.pop(); rustdoc.pop();
let old_path = env::var_os("PATH").unwrap_or_default(); let old_path = env::var_os("PATH").unwrap_or_default();
let new_path = let new_path =
@ -165,6 +167,7 @@ fn run(self, builder: &Builder<'_>) {
.expect("could not add rustdoc to PATH"); .expect("could not add rustdoc to PATH");
rustbook_cmd.env("PATH", new_path); rustbook_cmd.env("PATH", new_path);
builder.add_rustc_lib_path(compiler, &mut rustbook_cmd);
} }
rustbook_cmd.arg("build").arg(&src).arg("-d").arg(&out).run(builder); rustbook_cmd.arg("build").arg(&src).arg("-d").arg(&out).run(builder);
@ -240,7 +243,7 @@ fn run(self, builder: &Builder<'_>) {
src: absolute_path.clone(), src: absolute_path.clone(),
parent: Some(self), parent: Some(self),
languages: vec![], languages: vec![],
rustdoc: None, rustdoc_compiler: None,
}); });
// building older edition redirects // building older edition redirects
@ -253,7 +256,7 @@ fn run(self, builder: &Builder<'_>) {
// treat the other editions as not having a parent. // treat the other editions as not having a parent.
parent: Option::<Self>::None, parent: Option::<Self>::None,
languages: vec![], languages: vec![],
rustdoc: None, rustdoc_compiler: None,
}); });
} }
@ -1236,7 +1239,7 @@ fn run(self, builder: &Builder<'_>) {
src: out_base, src: out_base,
parent: Some(self), parent: Some(self),
languages: vec![], languages: vec![],
rustdoc: None, rustdoc_compiler: None,
}); });
} }
} }
@ -1270,16 +1273,15 @@ fn run(self, builder: &Builder<'_>) {
// This is needed for generating links to the standard library using // This is needed for generating links to the standard library using
// the mdbook-spec plugin. // the mdbook-spec plugin.
builder.ensure(compile::Std::new(self.compiler, builder.config.build)); builder.ensure(compile::Std::new(self.compiler, builder.config.build));
let rustdoc = builder.rustdoc(self.compiler);
// Run rustbook/mdbook to generate the HTML pages. // Run rustbook/mdbook to generate the HTML pages.
builder.ensure(RustbookSrc { builder.ensure(RustbookSrc {
target: self.target, target: self.target,
name: "reference".to_owned(), name: "reference".to_owned(),
src: builder.src.join("src/doc/reference"), src: builder.src.join("src/doc/reference"),
rustdoc_compiler: Some(self.compiler),
parent: Some(self), parent: Some(self),
languages: vec![], languages: vec![],
rustdoc: Some(rustdoc),
}); });
} }
} }