Skip to content

Commit

Permalink
bootstrap: Set the dylib path when building books with rustdoc
Browse files Browse the repository at this point in the history
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

(cherry picked from commit de4c897)
  • Loading branch information
cuviper committed Sep 26, 2024
1 parent 3cb89a0 commit 1ddfc90
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/bootstrap/src/core/build_steps/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ macro_rules! book {
src: builder.src.join($path),
parent: Some(self),
languages: $lang.into(),
rustdoc: None,
rustdoc_compiler: None,
})
}
}
Expand Down Expand Up @@ -113,7 +113,7 @@ impl Step for UnstableBook {
src: builder.md_doc_out(self.target).join("unstable-book"),
parent: Some(self),
languages: vec![],
rustdoc: None,
rustdoc_compiler: None,
})
}
}
Expand All @@ -125,7 +125,7 @@ struct RustbookSrc<P: Step> {
src: PathBuf,
parent: Option<P>,
languages: Vec<&'static str>,
rustdoc: Option<PathBuf>,
rustdoc_compiler: Option<Compiler>,
}

impl<P: Step> Step for RustbookSrc<P> {
Expand Down Expand Up @@ -157,14 +157,17 @@ impl<P: Step> Step for RustbookSrc<P> {
let _ = fs::remove_dir_all(&out);

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();
let old_path = env::var_os("PATH").unwrap_or_default();
let new_path =
env::join_paths(std::iter::once(rustdoc).chain(env::split_paths(&old_path)))
.expect("could not add rustdoc to 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);
Expand Down Expand Up @@ -240,7 +243,7 @@ impl Step for TheBook {
src: absolute_path.clone(),
parent: Some(self),
languages: vec![],
rustdoc: None,
rustdoc_compiler: None,
});

// building older edition redirects
Expand All @@ -253,7 +256,7 @@ impl Step for TheBook {
// treat the other editions as not having a parent.
parent: Option::<Self>::None,
languages: vec![],
rustdoc: None,
rustdoc_compiler: None,
});
}

Expand Down Expand Up @@ -1218,7 +1221,7 @@ impl Step for RustcBook {
src: out_base,
parent: Some(self),
languages: vec![],
rustdoc: None,
rustdoc_compiler: None,
});
}
}
Expand Down Expand Up @@ -1252,16 +1255,15 @@ impl Step for Reference {
// This is needed for generating links to the standard library using
// the mdbook-spec plugin.
builder.ensure(compile::Std::new(self.compiler, builder.config.build));
let rustdoc = builder.rustdoc(self.compiler);

// Run rustbook/mdbook to generate the HTML pages.
builder.ensure(RustbookSrc {
target: self.target,
name: "reference".to_owned(),
src: builder.src.join("src/doc/reference"),
rustdoc_compiler: Some(self.compiler),
parent: Some(self),
languages: vec![],
rustdoc: Some(rustdoc),
});
}
}

0 comments on commit 1ddfc90

Please sign in to comment.