Skip to content

Commit ce059fc

Browse files
committed
Introduce infrastructure for generating target docs
1 parent 7aa1de7 commit ce059fc

22 files changed

+1081
-24
lines changed

Diff for: Cargo.lock

+36
Original file line numberDiff line numberDiff line change
@@ -1579,6 +1579,12 @@ version = "0.3.1"
15791579
source = "registry+https://github.com/rust-lang/crates.io-index"
15801580
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
15811581

1582+
[[package]]
1583+
name = "glob-match"
1584+
version = "0.2.1"
1585+
source = "registry+https://github.com/rust-lang/crates.io-index"
1586+
checksum = "9985c9503b412198aa4197559e9a318524ebc4519c229bfa05a535828c950b9d"
1587+
15821588
[[package]]
15831589
name = "globset"
15841590
version = "0.4.13"
@@ -5017,6 +5023,19 @@ dependencies = [
50175023
"serde",
50185024
]
50195025

5026+
[[package]]
5027+
name = "serde_yaml"
5028+
version = "0.9.31"
5029+
source = "registry+https://github.com/rust-lang/crates.io-index"
5030+
checksum = "adf8a49373e98a4c5f0ceb5d05aa7c648d75f63774981ed95b7c7443bbd50c6e"
5031+
dependencies = [
5032+
"indexmap",
5033+
"itoa",
5034+
"ryu",
5035+
"serde",
5036+
"unsafe-libyaml",
5037+
]
5038+
50205039
[[package]]
50215040
name = "sha1"
50225041
version = "0.10.6"
@@ -5379,6 +5398,17 @@ dependencies = [
53795398
"xattr",
53805399
]
53815400

5401+
[[package]]
5402+
name = "target-docs"
5403+
version = "0.1.0"
5404+
dependencies = [
5405+
"eyre",
5406+
"glob-match",
5407+
"serde",
5408+
"serde_json",
5409+
"serde_yaml",
5410+
]
5411+
53825412
[[package]]
53835413
name = "tempfile"
53845414
version = "3.10.1"
@@ -6026,6 +6056,12 @@ dependencies = [
60266056
"diff",
60276057
]
60286058

6059+
[[package]]
6060+
name = "unsafe-libyaml"
6061+
version = "0.2.10"
6062+
source = "registry+https://github.com/rust-lang/crates.io-index"
6063+
checksum = "ab4c90930b95a82d00dc9e9ac071b4991924390d46cbd0dfe566148667605e4b"
6064+
60296065
[[package]]
60306066
name = "unstable-book-gen"
60316067
version = "0.1.0"

Diff for: Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ members = [
4646
"src/tools/rustdoc-gui-test",
4747
"src/tools/opt-dist",
4848
"src/tools/coverage-dump",
49+
"src/tools/target-docs",
4950
]
5051

5152
exclude = [

Diff for: compiler/rustc_target/src/spec/targets/aarch64_apple_tvos.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ pub fn target() -> Target {
66
Target {
77
llvm_target: tvos_llvm_target(arch).into(),
88
metadata: crate::spec::TargetMetadata {
9-
description: None,
10-
tier: None,
11-
host_tools: None,
9+
description: Some("ARM64 tvOS".into()),
10+
tier: Some(2),
11+
host_tools: Some(false),
1212
std: None,
1313
},
1414
pointer_width: 64,

Diff for: compiler/rustc_target/src/spec/targets/i686_pc_windows_gnu.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ pub fn target() -> Target {
1818
Target {
1919
llvm_target: "i686-pc-windows-gnu".into(),
2020
metadata: crate::spec::TargetMetadata {
21-
description: None,
22-
tier: None,
23-
host_tools: None,
24-
std: None,
21+
description: Some("32-bit MinGW (Windows 7+)".into()),
22+
tier: Some(1),
23+
host_tools: Some(true),
24+
std: Some(true),
2525
},
2626
pointer_width: 32,
2727
data_layout: "e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:64-\

Diff for: compiler/rustc_target/src/spec/targets/loongarch64_unknown_linux_gnu.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ pub fn target() -> Target {
44
Target {
55
llvm_target: "loongarch64-unknown-linux-gnu".into(),
66
metadata: crate::spec::TargetMetadata {
7-
description: None,
8-
tier: None,
9-
host_tools: None,
10-
std: None,
7+
description: Some("LoongArch64 Linux, LP64D ABI (kernel 5.19, glibc 2.36)".into()),
8+
tier: Some(2),
9+
host_tools: Some(true),
10+
std: Some(true),
1111
},
1212
pointer_width: 64,
1313
data_layout: "e-m:e-p:64:64-i64:64-i128:128-n64-S128".into(),

Diff for: compiler/rustc_target/src/spec/targets/powerpc64_ibm_aix.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ pub fn target() -> Target {
1111
Target {
1212
llvm_target: "powerpc64-ibm-aix".into(),
1313
metadata: crate::spec::TargetMetadata {
14-
description: None,
15-
tier: None,
16-
host_tools: None,
17-
std: None,
14+
description: Some("64-bit AIX (7.2 and newer)".into()),
15+
tier: Some(3),
16+
host_tools: Some(true),
17+
std: Some(true),
1818
},
1919
pointer_width: 64,
2020
data_layout: "E-m:a-Fi64-i64:64-n32:64-S128-v256:256:256-v512:512:512".into(),

Diff for: src/bootstrap/src/core/build_steps/doc.rs

+26-4
Original file line numberDiff line numberDiff line change
@@ -1144,14 +1144,16 @@ impl Step for RustcBook {
11441144

11451145
/// Builds the rustc book.
11461146
///
1147-
/// The lints are auto-generated by a tool, and then merged into the book
1147+
/// The lints and target docs are auto-generated by a tool, and then merged into the book
11481148
/// in the "md-doc" directory in the build output directory. Then
11491149
/// "rustbook" is used to convert it to HTML.
11501150
fn run(self, builder: &Builder<'_>) {
11511151
let out_base = builder.md_doc_out(self.target).join("rustc");
11521152
t!(fs::create_dir_all(&out_base));
1153-
let out_listing = out_base.join("src/lints");
1154-
builder.cp_r(&builder.src.join("src/doc/rustc"), &out_base);
1153+
let out_lints_listing = out_base.join("src/lints");
1154+
let out_src_listing = out_base.join("src");
1155+
1156+
builder.cp_r_but_like_really_copy(&builder.src.join("src/doc/rustc"), &out_base);
11551157
builder.info(&format!("Generating lint docs ({})", self.target));
11561158

11571159
let rustc = builder.rustc(self.compiler);
@@ -1162,7 +1164,7 @@ impl Step for RustcBook {
11621164
cmd.arg("--src");
11631165
cmd.arg(builder.src.join("compiler"));
11641166
cmd.arg("--out");
1165-
cmd.arg(&out_listing);
1167+
cmd.arg(&out_lints_listing);
11661168
cmd.arg("--rustc");
11671169
cmd.arg(&rustc);
11681170
cmd.arg("--rustc-target").arg(self.target.rustc_target_arg());
@@ -1191,6 +1193,26 @@ impl Step for RustcBook {
11911193
builder.run(&mut cmd);
11921194
drop(doc_generator_guard);
11931195

1196+
// Run target-docs generator
1197+
let mut cmd = builder.tool_cmd(Tool::TargetDocs);
1198+
cmd.arg(builder.src.join("src/doc/rustc/target_infos"));
1199+
cmd.arg(&out_src_listing);
1200+
cmd.env("RUSTC", &rustc);
1201+
// For now, we just check that the files are correct but do not generate output.
1202+
// Let the user override it to TARGET_CHECK_ONLY=0 for testing, but use 1 by default.
1203+
// See #120745 for more info.
1204+
cmd.env("TARGET_CHECK_ONLY", std::env::var("TARGET_CHECK_ONLY").unwrap_or("1".to_owned()));
1205+
1206+
let doc_generator_guard = builder.msg(
1207+
Kind::Run,
1208+
self.compiler.stage,
1209+
"target-docs",
1210+
self.compiler.host,
1211+
self.target,
1212+
);
1213+
builder.run(&mut cmd);
1214+
drop(doc_generator_guard);
1215+
11941216
// Run rustbook/mdbook to generate the HTML pages.
11951217
builder.ensure(RustbookSrc {
11961218
target: self.target,

Diff for: src/bootstrap/src/core/build_steps/tool.rs

+1
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ bootstrap_tool!(
301301
RustdocTheme, "src/tools/rustdoc-themes", "rustdoc-themes";
302302
ExpandYamlAnchors, "src/tools/expand-yaml-anchors", "expand-yaml-anchors";
303303
LintDocs, "src/tools/lint-docs", "lint-docs";
304+
TargetDocs, "src/tools/target-docs", "target-docs";
304305
JsonDocCk, "src/tools/jsondocck", "jsondocck";
305306
JsonDocLint, "src/tools/jsondoclint", "jsondoclint";
306307
HtmlChecker, "src/tools/html-checker", "html-checker";

Diff for: src/bootstrap/src/lib.rs

+35-4
Original file line numberDiff line numberDiff line change
@@ -1646,12 +1646,24 @@ impl Build {
16461646
paths
16471647
}
16481648

1649+
/// Copies a file from `src` to `dst`
1650+
// TODO: Rename to cp_r or something like that after #122590 has been merged.
1651+
pub fn copy_but_like_really_copy(&self, src: &Path, dst: &Path) {
1652+
self.copy_internal(src, dst, false, false);
1653+
}
1654+
16491655
/// Copies a file from `src` to `dst`
16501656
pub fn copy(&self, src: &Path, dst: &Path) {
1651-
self.copy_internal(src, dst, false);
1657+
self.copy_internal(src, dst, false, true);
16521658
}
16531659

1654-
fn copy_internal(&self, src: &Path, dst: &Path, dereference_symlinks: bool) {
1660+
fn copy_internal(
1661+
&self,
1662+
src: &Path,
1663+
dst: &Path,
1664+
dereference_symlinks: bool,
1665+
link_if_possible: bool,
1666+
) {
16551667
if self.config.dry_run() {
16561668
return;
16571669
}
@@ -1671,7 +1683,7 @@ impl Build {
16711683
return;
16721684
}
16731685
}
1674-
if let Ok(()) = fs::hard_link(&src, dst) {
1686+
if link_if_possible && fs::hard_link(&src, dst).is_ok() {
16751687
// Attempt to "easy copy" by creating a hard link
16761688
// (symlinks don't work on windows), but if that fails
16771689
// just fall back to a slow `copy` operation.
@@ -1706,6 +1718,25 @@ impl Build {
17061718
}
17071719
}
17081720

1721+
// TODO: Rename to cp_r or something like that after #122590 has been merged.
1722+
pub fn cp_r_but_like_really_copy(&self, src: &Path, dst: &Path) {
1723+
if self.config.dry_run() {
1724+
return;
1725+
}
1726+
for f in self.read_dir(src) {
1727+
let path = f.path();
1728+
let name = path.file_name().unwrap();
1729+
let dst = dst.join(name);
1730+
if t!(f.file_type()).is_dir() {
1731+
t!(fs::create_dir_all(&dst));
1732+
self.cp_r_but_like_really_copy(&path, &dst);
1733+
} else {
1734+
let _ = fs::remove_file(&dst);
1735+
self.copy_but_like_really_copy(&path, &dst);
1736+
}
1737+
}
1738+
}
1739+
17091740
/// Copies the `src` directory recursively to `dst`. Both are assumed to exist
17101741
/// when this function is called. Unwanted files or directories can be skipped
17111742
/// by returning `false` from the filter function.
@@ -1751,7 +1782,7 @@ impl Build {
17511782
if !src.exists() {
17521783
panic!("ERROR: File \"{}\" not found!", src.display());
17531784
}
1754-
self.copy_internal(src, &dst, true);
1785+
self.copy_internal(src, &dst, true, true);
17551786
chmod(&dst, perms);
17561787
}
17571788

Diff for: src/doc/rustc/src/SUMMARY.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@
6969
- [x86_64-fortanix-unknown-sgx](platform-support/x86_64-fortanix-unknown-sgx.md)
7070
- [x86_64-unknown-none](platform-support/x86_64-unknown-none.md)
7171
- [x86_64h-apple-darwin](platform-support/x86_64h-apple-darwin.md)
72+
- [List of Targets](platform-support/targets.md)
73+
<!-- TARGET_LIST SECTION START -->
74+
<!-- TARGET_LIST SECTION END -->
7275
- [Targets](targets/index.md)
7376
- [Built-in Targets](targets/built-in.md)
7477
- [Custom Targets](targets/custom.md)
@@ -79,4 +82,4 @@
7982
- [Exploit Mitigations](exploit-mitigations.md)
8083
- [Symbol Mangling](symbol-mangling/index.md)
8184
- [v0 Symbol Format](symbol-mangling/v0.md)
82-
- [Contributing to `rustc`](contributing.md)
85+
- [Contributing to `rustc`](contributing.md)

Diff for: src/doc/rustc/src/platform-support.md

+9
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ All tier 1 targets with host tools support the full standard library.
3232

3333
target | notes
3434
-------|-------
35+
<!-- TIER1HOST SECTION START -->
36+
<!-- See `src/tools/target-docs` -->
37+
<!-- TIER1HOST SECTION END -->
3538
`aarch64-unknown-linux-gnu` | ARM64 Linux (kernel 4.1, glibc 2.17+)
3639
`i686-pc-windows-gnu` | 32-bit MinGW (Windows 10+) [^windows-support] [^x86_32-floats-return-ABI]
3740
`i686-pc-windows-msvc` | 32-bit MSVC (Windows 10+) [^windows-support] [^x86_32-floats-return-ABI]
@@ -88,6 +91,8 @@ so Rustup may install the documentation for a similar tier 1 target instead.
8891

8992
target | notes
9093
-------|-------
94+
<!-- TIER2HOST SECTION START -->
95+
<!-- TIER2HOST SECTION END -->
9196
`aarch64-apple-darwin` | ARM64 macOS (11.0+, Big Sur+)
9297
`aarch64-pc-windows-msvc` | ARM64 Windows MSVC
9398
`aarch64-unknown-linux-musl` | ARM64 Linux with musl 1.2.3
@@ -134,6 +139,8 @@ so Rustup may install the documentation for a similar tier 1 target instead.
134139

135140
target | std | notes
136141
-------|:---:|-------
142+
<!-- TIER2 SECTION START -->
143+
<!-- TIER2 SECTION END -->
137144
`aarch64-apple-ios` | ✓ | ARM64 iOS
138145
[`aarch64-apple-ios-sim`](platform-support/aarch64-apple-ios-sim.md) | ✓ | Apple iOS Simulator on ARM64
139146
`aarch64-fuchsia` | ✓ | Alias for `aarch64-unknown-fuchsia`
@@ -235,6 +242,8 @@ host tools.
235242

236243
target | std | host | notes
237244
-------|:---:|:----:|-------
245+
<!-- TIER3 SECTION START -->
246+
<!-- TIER3 SECTION END -->
238247
[`arm64e-apple-ios`](platform-support/arm64e-apple-ios.md) | ✓ | | ARM64e Apple iOS
239248
[`arm64e-apple-darwin`](platform-support/arm64e-apple-darwin.md) | ✓ | ✓ | ARM64e Apple Darwin
240249
[`arm64ec-pc-windows-msvc`](platform-support/arm64ec-pc-windows-msvc.md) | ? | | Arm64EC Windows MSVC

Diff for: src/doc/rustc/src/platform-support/targets.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# List of all targets
2+
3+
An alphabetical list of all targets.
4+
5+
<!-- TARGET SECTION START -->
6+
<!-- See `src/tools/target-docs` -->
7+
<!-- TARGET SECTION END -->

0 commit comments

Comments
 (0)