Skip to content

Commit ce71747

Browse files
committed
Add a script to verify the Platform Support page is up-to-date.
1 parent 392116e commit ce71747

File tree

7 files changed

+119
-8
lines changed

7 files changed

+119
-8
lines changed

Cargo.lock

+4
Original file line numberDiff line numberDiff line change
@@ -4623,6 +4623,10 @@ dependencies = [
46234623
"walkdir",
46244624
]
46254625

4626+
[[package]]
4627+
name = "tier-check"
4628+
version = "0.1.0"
4629+
46264630
[[package]]
46274631
name = "time"
46284632
version = "0.1.42"

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ members = [
1313
"src/tools/rustbook",
1414
"src/tools/unstable-book-gen",
1515
"src/tools/tidy",
16+
"src/tools/tier-check",
1617
"src/tools/build-manifest",
1718
"src/tools/remote-test-client",
1819
"src/tools/remote-test-server",

src/bootstrap/builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ impl<'a> Builder<'a> {
404404
test::CrateLibrustc,
405405
test::CrateRustdoc,
406406
test::Linkcheck,
407+
test::TierCheck,
407408
test::Cargotest,
408409
test::Cargo,
409410
test::Rls,

src/bootstrap/test.rs

+44
Original file line numberDiff line numberDiff line change
@@ -2043,3 +2043,47 @@ impl Step for Bootstrap {
20432043
run.builder.ensure(Bootstrap);
20442044
}
20452045
}
2046+
2047+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2048+
pub struct TierCheck {
2049+
pub compiler: Compiler,
2050+
target: TargetSelection,
2051+
}
2052+
2053+
impl Step for TierCheck {
2054+
type Output = ();
2055+
const DEFAULT: bool = true;
2056+
const ONLY_HOSTS: bool = true;
2057+
2058+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2059+
run.path("src/tools/tier-check")
2060+
}
2061+
2062+
fn make_run(run: RunConfig<'_>) {
2063+
let compiler = run.builder.compiler_for(run.builder.top_stage, run.host, run.host);
2064+
run.builder.ensure(TierCheck { compiler, target: run.host });
2065+
}
2066+
2067+
/// Tests the Platform Support page in the rustc book.
2068+
fn run(self, builder: &Builder<'_>) {
2069+
builder.ensure(compile::Std { compiler: self.compiler, target: self.target });
2070+
let mut cargo = tool::prepare_tool_cargo(
2071+
builder,
2072+
self.compiler,
2073+
Mode::ToolRustc,
2074+
self.target,
2075+
"run",
2076+
"src/tools/tier-check",
2077+
SourceType::InTree,
2078+
&[],
2079+
);
2080+
cargo.arg(builder.src.join("src/doc/rustc/src/platform-support.md"));
2081+
cargo.arg(&builder.rustc(self.compiler));
2082+
if builder.is_verbose() {
2083+
cargo.arg("--verbose");
2084+
}
2085+
2086+
builder.info("platform support check");
2087+
try_run(builder, &mut cargo.into());
2088+
}
2089+
}

src/doc/rustc/src/platform-support.md

+9-8
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Specifically, these platforms are required to have each of the following:
5757

5858
target | std | host | notes
5959
-------|-----|------|-------
60-
`aarch64-apple-ios` | ✓ | | ARM64 iOS
60+
`aarch64-apple-ios` | ✓[^apple] | | ARM64 iOS
6161
`aarch64-fuchsia` | ✓ | | ARM64 Fuchsia
6262
`aarch64-linux-android` | ✓ | | ARM64 Android
6363
`aarch64-pc-windows-msvc` | ✓ | | ARM64 Windows MSVC
@@ -122,7 +122,7 @@ target | std | host | notes
122122
`wasm32-unknown-emscripten` | ✓ | | WebAssembly via Emscripten
123123
`wasm32-unknown-unknown` | ✓ | | WebAssembly
124124
`wasm32-wasi` | ✓ | | WebAssembly with WASI
125-
`x86_64-apple-ios` | ✓ | | 64-bit x86 iOS
125+
`x86_64-apple-ios` | ✓[^apple] | | 64-bit x86 iOS
126126
`x86_64-fortanix-unknown-sgx` | ✓ | | [Fortanix ABI] for 64-bit Intel SGX
127127
`x86_64-fuchsia` | ✓ | | 64-bit Fuchsia
128128
`x86_64-linux-android` | ✓ | | 64-bit x86 Android
@@ -147,7 +147,7 @@ not available.
147147
target | std | host | notes
148148
-------|-----|------|-------
149149
`aarch64-apple-darwin` | ? | | ARM64 macOS
150-
`aarch64-apple-tvos` | * | | ARM64 tvOS
150+
`aarch64-apple-tvos` | *[^apple] | | ARM64 tvOS
151151
`aarch64-unknown-cloudabi` | ✓ | | ARM64 CloudABI
152152
`aarch64-unknown-freebsd` | ✓ | ✓ | ARM64 FreeBSD
153153
`aarch64-unknown-hermit` | ? | |
@@ -159,16 +159,16 @@ target | std | host | notes
159159
`armv4t-unknown-linux-gnueabi` | ? | |
160160
`armv6-unknown-freebsd` | ✓ | ✓ | ARMv6 FreeBSD
161161
`armv6-unknown-netbsd-eabihf` | ? | |
162-
`armv7-apple-ios` | ✓ | | RMv7 iOS, Cortex-
162+
`armv7-apple-ios` | ✓[^apple] | | ARMv7 iOS, Cortex-a8
163163
`armv7-unknown-cloudabi-eabihf` | ✓ | | ARMv7 CloudABI, hardfloat
164164
`armv7-unknown-freebsd` | ✓ | ✓ | ARMv7 FreeBSD
165165
`armv7-unknown-netbsd-eabihf` | ? | |
166166
`armv7-wrs-vxworks-eabihf` | ? | |
167167
`armv7a-none-eabihf` | * | | ARM Cortex-A, hardfloat
168-
`armv7s-apple-ios` | ✓ | |
168+
`armv7s-apple-ios` | ✓[^apple] | |
169169
`avr-unknown-unknown` | ? | | AVR
170170
`hexagon-unknown-linux-musl` | ? | |
171-
`i386-apple-ios` | ✓ | | 32-bit x86 iOS
171+
`i386-apple-ios` | ✓[^apple] | | 32-bit x86 iOS
172172
`i686-apple-darwin` | ✓ | ✓ | 32-bit OSX (10.7+, Lion+)
173173
`i686-pc-windows-msvc` | ✓ | | 32-bit Windows XP support
174174
`i686-unknown-cloudabi` | ✓ | | 32-bit CloudABI
@@ -203,8 +203,8 @@ target | std | host | notes
203203
`thumbv7a-uwp-windows-msvc` | ✓ | |
204204
`thumbv7neon-unknown-linux-musleabihf` | ? | | Thumb2-mode ARMv7a Linux with NEON, MUSL
205205
`thumbv4t-none-eabi` | * | | ARMv4T T32
206-
`x86_64-apple-ios-macabi` | ✓ | | Apple Catalyst
207-
`x86_64-apple-tvos` | * | | x86 64-bit tvOS
206+
`x86_64-apple-ios-macabi` | ✓[^apple] | | Apple Catalyst
207+
`x86_64-apple-tvos` | *[^apple] | | x86 64-bit tvOS
208208
`x86_64-linux-kernel` | ? | | Linux kernel modules
209209
`x86_64-pc-solaris` | ? | |
210210
`x86_64-pc-windows-msvc` | ✓ | | 64-bit Windows XP support
@@ -220,3 +220,4 @@ target | std | host | notes
220220
`x86_64-wrs-vxworks` | ? | |
221221

222222
[runs on NVIDIA GPUs]: https://github.com/japaric-archived/nvptx#targets
223+
[^apple]: These targets are only available on macOS.

src/tools/tier-check/Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "tier-check"
3+
version = "0.1.0"
4+
authors = ["Eric Huss"]
5+
edition = "2018"
6+
license = "MIT OR Apache-2.0"
7+
8+
[dependencies]

src/tools/tier-check/src/main.rs

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//! This is a script for validating the platform support page in the rustc book.
2+
//!
3+
//! The script takes two arguments, the path to the Platform Support source
4+
//! page, and the second argument is the path to `rustc`.
5+
6+
use std::collections::HashSet;
7+
8+
fn main() {
9+
let mut args = std::env::args().skip(1);
10+
let src = args.next().expect("expected source file as first argument");
11+
let filename = std::path::Path::new(&src).file_name().unwrap().to_str().unwrap();
12+
let rustc = args.next().expect("expected rustc as second argument");
13+
let output = std::process::Command::new(rustc)
14+
.arg("--print=target-list")
15+
.output()
16+
.expect("rustc should run");
17+
if !output.status.success() {
18+
eprintln!("rustc failed to run");
19+
std::process::exit(0);
20+
}
21+
let stdout = std::str::from_utf8(&output.stdout).expect("utf8");
22+
let target_list: HashSet<_> = stdout.lines().collect();
23+
24+
let doc_targets_md = std::fs::read_to_string(&src).expect("failed to read input source");
25+
let doc_targets: HashSet<_> = doc_targets_md
26+
.lines()
27+
.filter(|line| line.starts_with('`') && line.contains('|'))
28+
// These platforms only exist on macos.
29+
.filter(|line| !line.contains("[^apple]") || cfg!(target_os = "macos"))
30+
.map(|line| line.split('`').skip(1).next().expect("expected target code span"))
31+
.collect();
32+
33+
let missing: Vec<_> = target_list.difference(&doc_targets).collect();
34+
let extra: Vec<_> = doc_targets.difference(&target_list).collect();
35+
for target in &missing {
36+
eprintln!(
37+
"error: target `{}` is missing from {}\n\
38+
If this is a new target, please add it to {}.",
39+
target, filename, src
40+
);
41+
}
42+
for target in &extra {
43+
eprintln!(
44+
"error: target `{}` is in {}, but does not appear in the rustc target list\n\
45+
If the target has been removed, please edit {} and remove the target.",
46+
target, filename, src
47+
);
48+
}
49+
if !missing.is_empty() || !extra.is_empty() {
50+
std::process::exit(1);
51+
}
52+
}

0 commit comments

Comments
 (0)