Skip to content

Commit b46c3f2

Browse files
committed
use shared stage0 parser from build_helper
Signed-off-by: onur-ozkan <[email protected]>
1 parent f2d50b6 commit b46c3f2

File tree

7 files changed

+120
-141
lines changed

7 files changed

+120
-141
lines changed

Cargo.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,10 @@ name = "bump-stage0"
380380
version = "0.1.0"
381381
dependencies = [
382382
"anyhow",
383+
"build_helper",
383384
"curl",
384385
"indexmap",
385386
"serde",
386-
"serde_json",
387387
"toml 0.5.11",
388388
]
389389

src/bootstrap/src/core/config/config.rs

+4-34
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ pub struct Config {
181181
pub test_compare_mode: bool,
182182
pub color: Color,
183183
pub patch_binaries_for_nix: Option<bool>,
184-
pub stage0_metadata: Stage0Metadata,
184+
pub stage0_metadata: build_helper::stage0_parser::Stage0,
185185
pub android_ndk: Option<PathBuf>,
186186
/// Whether to use the `c` feature of the `compiler_builtins` crate.
187187
pub optimized_compiler_builtins: bool,
@@ -350,34 +350,6 @@ pub struct Config {
350350
pub paths: Vec<PathBuf>,
351351
}
352352

353-
#[derive(Default, Deserialize, Clone)]
354-
pub struct Stage0Metadata {
355-
pub compiler: CompilerMetadata,
356-
pub config: Stage0Config,
357-
pub checksums_sha256: HashMap<String, String>,
358-
pub rustfmt: Option<RustfmtMetadata>,
359-
}
360-
#[derive(Default, Deserialize, Clone)]
361-
pub struct CompilerMetadata {
362-
pub date: String,
363-
pub version: String,
364-
}
365-
366-
#[derive(Default, Deserialize, Clone)]
367-
pub struct Stage0Config {
368-
pub dist_server: String,
369-
pub artifacts_server: String,
370-
pub artifacts_with_llvm_assertions_server: String,
371-
pub git_merge_commit_email: String,
372-
pub git_repository: String,
373-
pub nightly_branch: String,
374-
}
375-
#[derive(Default, Deserialize, Clone)]
376-
pub struct RustfmtMetadata {
377-
pub date: String,
378-
pub version: String,
379-
}
380-
381353
#[derive(Clone, Debug, Default)]
382354
pub enum RustfmtState {
383355
SystemToolchain(PathBuf),
@@ -1296,13 +1268,13 @@ impl Config {
12961268
Some(p) => PathBuf::from(p),
12971269
None => git_root,
12981270
};
1299-
// If this doesn't have at least `stage0.json`, we guessed wrong. This can happen when,
1271+
// If this doesn't have at least `stage0`, we guessed wrong. This can happen when,
13001272
// for example, the build directory is inside of another unrelated git directory.
13011273
// In that case keep the original `CARGO_MANIFEST_DIR` handling.
13021274
//
13031275
// NOTE: this implies that downloadable bootstrap isn't supported when the build directory is outside
13041276
// the source directory. We could fix that by setting a variable from all three of python, ./x, and x.ps1.
1305-
if git_root.join("src").join("stage0.json").exists() {
1277+
if git_root.join("src").join("stage0").exists() {
13061278
config.src = git_root;
13071279
}
13081280
} else {
@@ -1320,9 +1292,7 @@ impl Config {
13201292
.to_path_buf();
13211293
}
13221294

1323-
let stage0_json = t!(std::fs::read(config.src.join("src").join("stage0.json")));
1324-
1325-
config.stage0_metadata = t!(serde_json::from_slice::<Stage0Metadata>(&stage0_json));
1295+
config.stage0_metadata = build_helper::stage0_parser::parse_stage0_file();
13261296

13271297
// Read from `--config`, then `RUST_BOOTSTRAP_CONFIG`, then `./config.toml`, then `config.toml` in the root directory.
13281298
let toml_path = flags

src/bootstrap/src/core/download.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use std::{
99
};
1010

1111
use build_helper::ci::CiEnv;
12+
use build_helper::stage0_parser::VersionMetadata;
1213
use xz2::bufread::XzDecoder;
1314

14-
use crate::core::config::RustfmtMetadata;
1515
use crate::utils::helpers::{check_run, exe, program_out_of_date};
1616
use crate::{core::build_steps::llvm::detect_llvm_sha, utils::helpers::hex_encode};
1717
use crate::{t, Config};
@@ -408,7 +408,7 @@ impl Config {
408408
/// NOTE: rustfmt is a completely different toolchain than the bootstrap compiler, so it can't
409409
/// reuse target directories or artifacts
410410
pub(crate) fn maybe_download_rustfmt(&self) -> Option<PathBuf> {
411-
let RustfmtMetadata { date, version } = self.stage0_metadata.rustfmt.as_ref()?;
411+
let VersionMetadata { date, version } = self.stage0_metadata.rustfmt.as_ref()?;
412412
let channel = format!("{version}-{date}");
413413

414414
let host = self.build;
@@ -606,7 +606,7 @@ impl Config {
606606
DownloadSource::Dist => {
607607
let dist_server = env::var("RUSTUP_DIST_SERVER")
608608
.unwrap_or(self.stage0_metadata.config.dist_server.to_string());
609-
// NOTE: make `dist` part of the URL because that's how it's stored in src/stage0.json
609+
// NOTE: make `dist` part of the URL because that's how it's stored in src/stage0
610610
(dist_server, format!("dist/{key}/{filename}"), true)
611611
}
612612
};
@@ -616,7 +616,7 @@ impl Config {
616616
// this on each and every nightly ...
617617
let checksum = if should_verify {
618618
let error = format!(
619-
"src/stage0.json doesn't contain a checksum for {url}. \
619+
"src/stage0 doesn't contain a checksum for {url}. \
620620
Pre-built artifacts might not be available for this \
621621
target at this time, see https://doc.rust-lang.org/nightly\
622622
/rustc/platform-support.html for more information."

src/tools/build_helper/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ pub mod ci;
22
pub mod git;
33
pub mod metrics;
44
pub mod util;
5+
pub mod stage0_parser;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
use std::collections::BTreeMap;
2+
3+
#[derive(Default, Clone)]
4+
pub struct Stage0 {
5+
pub compiler: VersionMetadata,
6+
pub rustfmt: Option<VersionMetadata>,
7+
pub config: Stage0Config,
8+
pub checksums_sha256: BTreeMap<String, String>,
9+
}
10+
11+
#[derive(Default, Clone)]
12+
pub struct VersionMetadata {
13+
pub date: String,
14+
pub version: String,
15+
}
16+
17+
#[derive(Default, Clone)]
18+
pub struct Stage0Config {
19+
pub dist_server: String,
20+
pub artifacts_server: String,
21+
pub artifacts_with_llvm_assertions_server: String,
22+
pub git_merge_commit_email: String,
23+
pub git_repository: String,
24+
pub nightly_branch: String,
25+
}
26+
27+
pub fn parse_stage0_file() -> Stage0 {
28+
let stage0_content = include_str!("../../../stage0");
29+
30+
let mut stage0 = Stage0::default();
31+
for line in stage0_content.lines() {
32+
let line = line.trim();
33+
34+
if line.is_empty() {
35+
continue;
36+
}
37+
38+
// Ignore comments
39+
if line.starts_with('#') {
40+
continue;
41+
}
42+
43+
let (key, value) = line.split_once('=').unwrap();
44+
45+
match key {
46+
"dist_server" => stage0.config.dist_server = value.to_owned(),
47+
"artifacts_server" => stage0.config.artifacts_server = value.to_owned(),
48+
"artifacts_with_llvm_assertions_server" => {
49+
stage0.config.artifacts_with_llvm_assertions_server = value.to_owned()
50+
}
51+
"git_merge_commit_email" => stage0.config.git_merge_commit_email = value.to_owned(),
52+
"git_repository" => stage0.config.git_repository = value.to_owned(),
53+
"nightly_branch" => stage0.config.nightly_branch = value.to_owned(),
54+
55+
"compiler_date" => stage0.compiler.date = value.to_owned(),
56+
"compiler_version" => stage0.compiler.version = value.to_owned(),
57+
58+
"rustfmt_date" => {
59+
stage0.rustfmt.get_or_insert(VersionMetadata::default()).date = value.to_owned();
60+
}
61+
"rustfmt_version" => {
62+
stage0.rustfmt.get_or_insert(VersionMetadata::default()).version = value.to_owned();
63+
}
64+
65+
dist if dist.starts_with("dist") => {
66+
stage0.checksums_sha256.insert(key.to_owned(), value.to_owned());
67+
}
68+
69+
unsupported => {
70+
println!("'{unsupported}' field is not supported.");
71+
}
72+
}
73+
}
74+
75+
stage0
76+
}

src/tools/bump-stage0/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ edition = "2021"
77

88
[dependencies]
99
anyhow = "1.0.34"
10+
build_helper = { path = "../build_helper" }
1011
curl = "0.4.38"
1112
indexmap = { version = "2.0.0", features = ["serde"] }
1213
serde = { version = "1.0.125", features = ["derive"] }
13-
serde_json = { version = "1.0.59", features = ["preserve_order"] }
1414
toml = "0.5.7"

0 commit comments

Comments
 (0)