Skip to content

Commit fc85328

Browse files
committed
Add new tool for dumping feature status based on tidy
format files features-status-dump: pass key paths via cli flags + misc changes bootstrap: register `features-status-dump` as runnable tool
1 parent 1e9b017 commit fc85328

File tree

10 files changed

+115
-0
lines changed

10 files changed

+115
-0
lines changed

Cargo.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,17 @@ version = "2.3.0"
11951195
source = "registry+https://github.com/rust-lang/crates.io-index"
11961196
checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
11971197

1198+
[[package]]
1199+
name = "features-status-dump"
1200+
version = "0.1.0"
1201+
dependencies = [
1202+
"anyhow",
1203+
"clap",
1204+
"serde",
1205+
"serde_json",
1206+
"tidy",
1207+
]
1208+
11981209
[[package]]
11991210
name = "field-offset"
12001211
version = "0.3.6"
@@ -5372,6 +5383,7 @@ dependencies = [
53725383
"regex",
53735384
"rustc-hash 2.1.0",
53745385
"semver",
5386+
"serde",
53755387
"similar",
53765388
"termcolor",
53775389
"walkdir",

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ members = [
4747
"src/tools/coverage-dump",
4848
"src/tools/rustc-perf-wrapper",
4949
"src/tools/wasm-component-ld",
50+
"src/tools/features-status-dump",
5051
]
5152

5253
exclude = [

src/bootstrap/src/core/build_steps/run.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,3 +311,34 @@ impl Step for UnicodeTableGenerator {
311311
cmd.run(builder);
312312
}
313313
}
314+
315+
#[derive(Debug, PartialOrd, Ord, Clone, Hash, PartialEq, Eq)]
316+
pub struct FeaturesStatusDump;
317+
318+
impl Step for FeaturesStatusDump {
319+
type Output = ();
320+
const ONLY_HOSTS: bool = true;
321+
322+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
323+
run.path("src/tools/features-status-dump")
324+
}
325+
326+
fn make_run(run: RunConfig<'_>) {
327+
run.builder.ensure(FeaturesStatusDump);
328+
}
329+
330+
fn run(self, builder: &Builder<'_>) {
331+
let mut cmd = builder.tool_cmd(Tool::FeaturesStatusDump);
332+
333+
cmd.arg("--library-path");
334+
cmd.arg(builder.src.join("library"));
335+
336+
cmd.arg("--compiler-path");
337+
cmd.arg(builder.src.join("compiler"));
338+
339+
cmd.arg("--output-path");
340+
cmd.arg(builder.out.join("features-status-dump.json"));
341+
342+
cmd.run(builder);
343+
}
344+
}

src/bootstrap/src/core/build_steps/tool.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ bootstrap_tool!(
363363
RustcPerfWrapper, "src/tools/rustc-perf-wrapper", "rustc-perf-wrapper";
364364
WasmComponentLd, "src/tools/wasm-component-ld", "wasm-component-ld", is_unstable_tool = true, allow_features = "min_specialization";
365365
UnicodeTableGenerator, "src/tools/unicode-table-generator", "unicode-table-generator";
366+
FeaturesStatusDump, "src/tools/features-status-dump", "features-status-dump";
366367
);
367368

368369
/// These are the submodules that are required for rustbook to work due to

src/bootstrap/src/core/builder/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,7 @@ impl<'a> Builder<'a> {
10891089
run::GenerateWindowsSys,
10901090
run::GenerateCompletions,
10911091
run::UnicodeTableGenerator,
1092+
run::FeaturesStatusDump,
10921093
),
10931094
Kind::Setup => {
10941095
describe!(setup::Profile, setup::Hook, setup::Link, setup::Editor)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "features-status-dump"
3+
version = "0.1.0"
4+
license = "MIT OR Apache-2.0"
5+
edition = "2021"
6+
7+
[dependencies]
8+
anyhow = { version = "1", features = ["backtrace"] }
9+
clap = { version = "4", features = ["derive"] }
10+
serde = { version = "1.0.125", features = [ "derive" ] }
11+
serde_json = "1.0.59"
12+
tidy = { path = "../tidy" }
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
use std::collections::HashMap;
2+
use std::fs::File;
3+
use std::io::BufWriter;
4+
use std::path::PathBuf;
5+
6+
use anyhow::{Context, Result};
7+
use clap::Parser;
8+
use tidy::features::{Feature, collect_lang_features, collect_lib_features};
9+
10+
#[derive(Debug, Parser)]
11+
struct Cli {
12+
/// Path to `library/` directory.
13+
#[arg(long)]
14+
library_path: PathBuf,
15+
/// Path to `compiler/` directory.
16+
#[arg(long)]
17+
compiler_path: PathBuf,
18+
/// Path to `output/` directory.
19+
#[arg(long)]
20+
output_path: PathBuf,
21+
}
22+
23+
#[derive(Debug, serde::Serialize)]
24+
struct FeaturesStatus {
25+
lang_features_status: HashMap<String, Feature>,
26+
lib_features_status: HashMap<String, Feature>,
27+
}
28+
29+
fn main() -> Result<()> {
30+
let Cli { compiler_path, library_path, output_path } = Cli::parse();
31+
32+
let lang_features_status = collect_lang_features(&compiler_path, &mut false);
33+
let lib_features_status = collect_lib_features(&library_path)
34+
.into_iter()
35+
.filter(|&(ref name, _)| !lang_features_status.contains_key(name))
36+
.collect();
37+
let features_status = FeaturesStatus { lang_features_status, lib_features_status };
38+
39+
let output_dir = output_path.parent().with_context(|| {
40+
format!("failed to get parent dir of output path `{}`", output_path.display())
41+
})?;
42+
std::fs::create_dir_all(output_dir).with_context(|| {
43+
format!("failed to create output directory at `{}`", output_dir.display())
44+
})?;
45+
46+
let output_file = File::create(&output_path).with_context(|| {
47+
format!("failed to create file at given output path `{}`", output_path.display())
48+
})?;
49+
let writer = BufWriter::new(output_file);
50+
serde_json::to_writer_pretty(writer, &features_status)
51+
.context("failed to write json output")?;
52+
Ok(())
53+
}

src/tools/tidy/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ miropt-test-tools = { path = "../miropt-test-tools" }
1212
walkdir = "2"
1313
ignore = "0.4.18"
1414
semver = "1.0"
15+
serde = { version = "1.0.125", features = [ "derive" ] }
1516
termcolor = "1.1.3"
1617
rustc-hash = "2.0.0"
1718
fluent-syntax = "0.11.1"

src/tools/tidy/src/features.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const FEATURE_GROUP_START_PREFIX: &str = "// feature-group-start";
2727
const FEATURE_GROUP_END_PREFIX: &str = "// feature-group-end";
2828

2929
#[derive(Debug, PartialEq, Clone)]
30+
#[derive(serde::Serialize)]
3031
pub enum Status {
3132
Accepted,
3233
Removed,
@@ -45,6 +46,7 @@ impl fmt::Display for Status {
4546
}
4647

4748
#[derive(Debug, Clone)]
49+
#[derive(serde::Serialize)]
4850
pub struct Feature {
4951
pub level: Status,
5052
pub since: Option<Version>,

src/tools/tidy/src/features/version.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ mod tests;
88
pub const VERSION_PLACEHOLDER: &str = "CURRENT_RUSTC_VERSION";
99

1010
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
11+
#[derive(serde::Serialize)]
1112
pub enum Version {
1213
Explicit { parts: [u32; 3] },
1314
CurrentPlaceholder,

0 commit comments

Comments
 (0)