Skip to content
Draft
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
30 changes: 30 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5394,6 +5394,19 @@ dependencies = [
"serde_core",
]

[[package]]
name = "serde_yaml"
version = "0.9.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adf8a49373e98a4c5f0ceb5d05aa7c648d75f63774981ed95b7c7443bbd50c6e"
dependencies = [
"indexmap",
"itoa",
"ryu",
"serde",
"unsafe-libyaml",
]

[[package]]
name = "sha1"
version = "0.10.6"
Expand Down Expand Up @@ -5634,6 +5647,17 @@ dependencies = [
"xattr",
]

[[package]]
name = "target-docs"
version = "0.1.0"
dependencies = [
"eyre",
"glob",
"serde",
"serde_json",
"serde_yaml",
]

[[package]]
name = "tempfile"
version = "3.23.0"
Expand Down Expand Up @@ -6250,6 +6274,12 @@ version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81e544489bf3d8ef66c953931f56617f423cd4b5494be343d9b9d3dda037b9a3"

[[package]]
name = "unsafe-libyaml"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab4c90930b95a82d00dc9e9ac071b4991924390d46cbd0dfe566148667605e4b"

[[package]]
name = "unstable-book-gen"
version = "0.1.0"
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ members = [
"src/tools/rustdoc-gui-test",
"src/tools/rustdoc-themes",
"src/tools/rustfmt",
"src/tools/target-docs",
"src/tools/test-float-parse",
"src/tools/tidy",
"src/tools/tier-check",
Expand Down Expand Up @@ -86,4 +87,3 @@ codegen-units = 1
# If you want to use a crate with local modifications, you can set a path or git dependency here.
# For git dependencies, also add your source to ALLOWED_SOURCES in src/tools/tidy/src/extdeps.rs.
#[patch.crates-io]

41 changes: 35 additions & 6 deletions src/bootstrap/src/core/build_steps/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::core::builder::{
use crate::core::compiler::Compiler;
use crate::core::config::TargetSelection;
use crate::core::session::{FileType, Mode};
use crate::utils::helpers::{exit_process, submodule_path_of, symlink_dir, t, up_to_date};
use crate::utils::helpers::{exit_process, fail, submodule_path_of, symlink_dir, t, up_to_date};

macro_rules! book {
($($name:ident, $path:expr, $book_name:expr, $lang:expr ;)+) => {
Expand Down Expand Up @@ -1664,17 +1664,28 @@ impl CommandLineStep for RustcBook {

/// Builds the rustc book.
///
/// The lints are auto-generated by a tool, and then merged into the book
/// The lints and target docs are auto-generated by a tool, and then merged into the book
/// in the "md-doc" directory in the build output directory. Then
/// "rustbook" is used to convert it to HTML.
fn run(self, builder: &Builder<'_>) {
// The rustc book invokes rustc in its build process and relies on it being the in-tree rustc.
// (by requiring that the targets match and also that nightly flags can be used)
// Using the bootstrap compiler for this doesn't work.
if builder.top_stage < 1 {
fail("building the rustc book with stage 0 is not supported, use --stage 1");
}

let out_base = builder.out.join(self.target).join("md-doc").join("rustc");
t!(fs::create_dir_all(&out_base));
let out_listing = out_base.join("src/lints");
builder.cp_link_r(&builder.src.join("src/doc/rustc"), &out_base);
let out_lints_listing = out_base.join("src/lints");
let out_src_listing = out_base.join("src");
let rustc = builder.rustc(self.build_compiler);

// target-docs will be modifying the files in-place, so we need an actual copy.
builder.cp_r(&builder.src.join("src/doc/rustc"), &out_base);

builder.info(&format!("Generating lint docs ({})", self.target));

let rustc = builder.rustc(self.build_compiler);
// The tool runs `rustc` for extracting output examples, so it needs a
// functional sysroot.
builder.std(self.build_compiler, self.target);
Expand All @@ -1684,7 +1695,7 @@ impl CommandLineStep for RustcBook {
cmd.arg("--src");
cmd.arg(builder.src.join("compiler"));
cmd.arg("--out");
cmd.arg(&out_listing);
cmd.arg(&out_lints_listing);
cmd.arg("--rustc");
cmd.arg(&rustc);
cmd.arg("--rustc-target").arg(self.target.rustc_target_arg());
Expand All @@ -1711,6 +1722,24 @@ impl CommandLineStep for RustcBook {
cmd.run(builder);
drop(doc_generator_guard);

builder.info(&format!("Generating target docs ({})", self.target));

let mut cmd = builder.tool_cmd(Tool::TargetDocs);
cmd.arg(builder.src.join("src/doc/rustc/target_infos"));
cmd.arg(&out_src_listing);
cmd.env("RUSTC", &rustc);
// For now, we just check that the files are correct but do not generate output.
// Let the user override it to TARGET_CHECK_ONLY=0 for testing, but use 1 by default.
// See https://github.com/rust-lang/rust/issues/120745 for more info.
cmd.env("TARGET_CHECK_ONLY", std::env::var("TARGET_CHECK_ONLY").as_deref().unwrap_or("1"));
// target-docs uses -Zunstable-options --print all-target-specs-json
cmd.env("RUSTC_BOOTSTRAP", "1");

let doc_generator_guard =
builder.msg(Kind::Run, "target-docs", None, self.build_compiler, self.target);
cmd.run(builder);
drop(doc_generator_guard);

// Run rustbook/mdbook to generate the HTML pages.
builder.ensure(RustbookSrc {
target: self.target,
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ bootstrap_tool!(
RustInstaller, "src/tools/rust-installer", "rust-installer";
RustdocTheme, "src/tools/rustdoc-themes", "rustdoc-themes";
LintDocs, "src/tools/lint-docs", "lint-docs";
TargetDocs, "src/tools/target-docs", "target-docs";
JsonDocCk, "src/tools/jsondocck", "jsondocck";
JsonDocLint, "src/tools/jsondoclint", "jsondoclint";
HtmlChecker, "src/tools/html-checker", "html-checker";
Expand Down
12 changes: 12 additions & 0 deletions src/bootstrap/src/core/builder/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,7 @@ mod snapshot {
[doc] rustdoc (book) <host>
[doc] rust-by-example (book) <host>
[build] rustc 0 <host> -> LintDocs 1 <host>
[build] rustc 0 <host> -> TargetDocs 1 <host>
[doc] rustc (book) <host>
[doc] cargo (book) <host>
[doc] clippy (book) <host>
Expand Down Expand Up @@ -1030,6 +1031,7 @@ mod snapshot {
[doc] rustdoc (book) <host>
[doc] rust-by-example (book) <host>
[build] rustc 0 <host> -> LintDocs 1 <host>
[build] rustc 0 <host> -> TargetDocs 1 <host>
[doc] rustc (book) <host>
[doc] cargo (book) <host>
[doc] clippy (book) <host>
Expand Down Expand Up @@ -1112,6 +1114,7 @@ mod snapshot {
[doc] rust-by-example (book) <host>
[doc] rust-by-example (book) <target1>
[build] rustc 0 <host> -> LintDocs 1 <host>
[build] rustc 0 <host> -> TargetDocs 1 <host>
[doc] rustc (book) <host>
[doc] cargo (book) <host>
[doc] cargo (book) <target1>
Expand Down Expand Up @@ -1181,6 +1184,7 @@ mod snapshot {
[doc] rustdoc (book) <host>
[doc] rust-by-example (book) <host>
[build] rustc 0 <host> -> LintDocs 1 <host>
[build] rustc 0 <host> -> TargetDocs 1 <host>
[doc] rustc (book) <host>
[doc] rustc (book) <target1>
[doc] cargo (book) <host>
Expand Down Expand Up @@ -1255,6 +1259,7 @@ mod snapshot {
[doc] rust-by-example (book) <host>
[doc] rust-by-example (book) <target1>
[build] rustc 0 <host> -> LintDocs 1 <host>
[build] rustc 0 <host> -> TargetDocs 1 <host>
[doc] rustc (book) <host>
[doc] rustc (book) <target1>
[doc] cargo (book) <host>
Expand Down Expand Up @@ -1371,6 +1376,7 @@ mod snapshot {
[doc] rustdoc (book) <target1>
[doc] rust-by-example (book) <target1>
[build] rustc 0 <host> -> LintDocs 1 <host>
[build] rustc 0 <host> -> TargetDocs 1 <host>
[doc] rustc (book) <target1>
[doc] cargo (book) <target1>
[doc] clippy (book) <target1>
Expand Down Expand Up @@ -1513,6 +1519,7 @@ mod snapshot {
[doc] rustdoc (book) <host>
[doc] rust-by-example (book) <host>
[build] rustc 0 <host> -> LintDocs 1 <host>
[build] rustc 0 <host> -> TargetDocs 1 <host>
[doc] rustc (book) <host>
[doc] cargo (book) <host>
[doc] clippy (book) <host>
Expand Down Expand Up @@ -1913,6 +1920,7 @@ mod snapshot {
[doc] rustdoc (book) <host>
[doc] rust-by-example (book) <host>
[build] rustc 0 <host> -> LintDocs 1 <host>
[build] rustc 0 <host> -> TargetDocs 1 <host>
[doc] rustc (book) <host>
[doc] cargo (book) <host>
[doc] clippy (book) <host>
Expand Down Expand Up @@ -2096,6 +2104,7 @@ mod snapshot {
[doc] rustdoc (book) <host>
[doc] rust-by-example (book) <host>
[build] rustc 0 <host> -> LintDocs 1 <host>
[build] rustc 0 <host> -> TargetDocs 1 <host>
[doc] rustc (book) <host>
[doc] cargo (book) <host>
[doc] clippy (book) <host>
Expand Down Expand Up @@ -2355,6 +2364,7 @@ mod snapshot {
[doc] rustdoc (book) <host>
[doc] rust-by-example (book) <host>
[build] rustc 0 <host> -> LintDocs 1 <host>
[build] rustc 0 <host> -> TargetDocs 1 <host>
[doc] rustc (book) <host>
[doc] cargo (book) <host>
[doc] clippy (book) <host>
Expand Down Expand Up @@ -2741,6 +2751,7 @@ mod snapshot {
[doc] rustdoc (book) <x86_64-unknown-linux-gnu>
[doc] rust-by-example (book) <x86_64-unknown-linux-gnu>
[build] rustc 0 <x86_64-unknown-linux-gnu> -> LintDocs 1 <x86_64-unknown-linux-gnu>
[build] rustc 0 <x86_64-unknown-linux-gnu> -> TargetDocs 1 <x86_64-unknown-linux-gnu>
[doc] rustc (book) <x86_64-unknown-linux-gnu>
[doc] cargo (book) <x86_64-unknown-linux-gnu>
[doc] clippy (book) <x86_64-unknown-linux-gnu>
Expand Down Expand Up @@ -2857,6 +2868,7 @@ mod snapshot {
[doc] rustdoc (book) <x86_64-unknown-linux-gnu>
[doc] rust-by-example (book) <x86_64-unknown-linux-gnu>
[build] rustc 0 <x86_64-unknown-linux-gnu> -> LintDocs 1 <x86_64-unknown-linux-gnu>
[build] rustc 0 <x86_64-unknown-linux-gnu> -> TargetDocs 1 <x86_64-unknown-linux-gnu>
[doc] rustc (book) <x86_64-unknown-linux-gnu>
[doc] cargo (book) <x86_64-unknown-linux-gnu>
[doc] clippy (book) <x86_64-unknown-linux-gnu>
Expand Down
62 changes: 56 additions & 6 deletions src/bootstrap/src/core/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,7 @@ impl Session {
/// and copied to `dst` instead of the symlink itself.
#[track_caller]
pub(crate) fn resolve_symlink_and_copy(&self, src: &Path, dst: &Path) {
self.copy_link_internal(src, dst, true);
self.copy_internal(src, dst, true, true);
}

/// Links a file from `src` to `dst`.
Expand All @@ -1504,21 +1504,47 @@ impl Session {
/// so do not write to dst.
#[track_caller]
pub(crate) fn copy_link(&self, src: &Path, dst: &Path, file_type: FileType) {
self.copy_link_internal(src, dst, false);
self.copy_internal(src, dst, false, true);

if file_type.could_have_split_debuginfo()
&& let Some(dbg_file) = split_debuginfo(src)
{
self.copy_link_internal(
self.copy_internal(
&dbg_file,
&dst.with_extension(dbg_file.extension().unwrap()),
false,
true,
);
}
}

/// Links a file from `src` to `dst`.
/// Unlike, [`Build::copy_link`], this makes an actual copy, which is usually not required,
/// so `copy_link` should be used instead if possible.
#[track_caller]
pub fn copy(&self, src: &Path, dst: &Path, file_type: FileType) {
self.copy_internal(src, dst, false, false);

if file_type.could_have_split_debuginfo()
&& let Some(dbg_file) = split_debuginfo(src)
{
self.copy_internal(
&dbg_file,
&dst.with_extension(dbg_file.extension().unwrap()),
false,
true,
);
}
}

#[track_caller]
fn copy_link_internal(&self, src: &Path, dst: &Path, dereference_symlinks: bool) {
fn copy_internal(
&self,
src: &Path,
dst: &Path,
dereference_symlinks: bool,
link_if_possible: bool,
) {
if self.config.dry_run() {
return;
}
Expand Down Expand Up @@ -1554,7 +1580,8 @@ impl Session {
return;
}
}
if let Ok(()) = fs::hard_link(&src, dst) {

if link_if_possible && fs::hard_link(&src, dst).is_ok() {
// Attempt to "easy copy" by creating a hard link (symlinks are privileged on windows),
// but if that fails just fall back to a slow `copy` operation.
} else {
Expand Down Expand Up @@ -1593,6 +1620,29 @@ impl Session {
}
}

/// Copies the `src` directory recursively to `dst`. Both are assumed to exist
/// when this function is called.
/// Unlike, [`Build::cp_link_r`], this makes an actual copy, which is usually not required,
/// so `cp_link_r` should be used instead if possible.
#[track_caller]
pub fn cp_r(&self, src: &Path, dst: &Path) {
if self.config.dry_run() {
return;
}
for f in self.read_dir(src) {
let path = f.path();
let name = path.file_name().unwrap();
let dst = dst.join(name);
if t!(f.file_type()).is_dir() {
t!(fs::create_dir_all(&dst));
self.cp_r(&path, &dst);
} else {
let _ = fs::remove_file(&dst);
self.copy(&path, &dst, FileType::Regular);
}
}
}

/// Copies the `src` directory recursively to `dst`. Both are assumed to exist
/// when this function is called.
/// Will attempt to use hard links if possible and fall back to copying.
Expand Down Expand Up @@ -1651,7 +1701,7 @@ impl Session {
panic!("ERROR: File \"{}\" not found!", src.display());
}

self.copy_link_internal(src, &dst, true);
self.copy_internal(src, &dst, true, true);
chmod(&dst, file_type.perms());

// If this file can have debuginfo, look for split debuginfo and install it too.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ RUN sh /scripts/sccache.sh
ENV NO_DOWNLOAD_CI_LLVM="1"
ENV EXTERNAL_LLVM="1"

# Ubuntu LLVM 22 does not have support for experimental targets like csky.
ENV TARGET_DOCS_SKIP_TARGETS="csky-unknown-linux-gnuabiv2,csky-unknown-linux-gnuabiv2hf"

# Override the default debugger `discover` behavior
ENV LLDB_PATH="lldb-22"

Expand Down
3 changes: 3 additions & 0 deletions src/ci/docker/host-x86_64/test-x86_64-gnu-llvm-22/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ RUN sh /scripts/sccache.sh
ENV NO_DOWNLOAD_CI_LLVM="1"
ENV EXTERNAL_LLVM="1"

# Ubuntu LLVM 22 does not have support for experimental targets like csky.
ENV TARGET_DOCS_SKIP_TARGETS="csky-unknown-linux-gnuabiv2,csky-unknown-linux-gnuabiv2hf"

# Using llvm-link-shared due to libffi issues -- see #34486
ENV RUST_CONFIGURE_ARGS="--build=x86_64-unknown-linux-gnu \
--llvm-root=/usr/lib/llvm-22 \
Expand Down
4 changes: 4 additions & 0 deletions src/doc/rustc/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
- [Platform Support](platform-support.md)
- [Target Tier Policy](target-tier-policy.md)
- [Template for Target-specific Documentation](platform-support/TEMPLATE.md)
<!-- - [List of Targets](platform-support/targets.md) (see #120745) -->
<!-- - [Currently Unmaintained Targets](platform-support/unmaintained-targets.md) (see #120745) -->
<!-- TARGET_LIST SECTION START -->
- [arm64ec-pc-windows-msvc](platform-support/arm64ec-pc-windows-msvc.md)
- [\*-apple-darwin](platform-support/apple-darwin.md)
- [i686-apple-darwin](platform-support/i686-apple-darwin.md)
Expand Down Expand Up @@ -166,3 +169,4 @@
- [x86_64-unknown-linux-gnutsan](platform-support/x86_64-unknown-linux-gnutsan.md)
- [xtensa-\*-none-elf](platform-support/xtensa.md)
- [\*-nuttx-\*](platform-support/nuttx.md)
<!-- TARGET_LIST SECTION END -->
Loading
Loading