Skip to content

Commit 529c4c7

Browse files
committed
Auto merge of #98216 - JohnTitor:rollup-jlcmu5d, r=JohnTitor
Rollup of 5 pull requests Successful merges: - #97803 (Impl Termination for Infallible and then make the Result impls of Termination more generic) - #97828 (Allow configuring where artifacts are downloaded from) - #98150 (Emscripten target: replace -g4 with -g, and -g3 with --profiling-funcs) - #98195 (Fix rustdoc json primitive handling) - #98205 (Remove a possible unnecessary assignment) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents aaf1005 + f514aa4 commit 529c4c7

File tree

13 files changed

+172
-108
lines changed

13 files changed

+172
-108
lines changed

compiler/rustc_codegen_ssa/src/back/linker.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1134,8 +1134,8 @@ impl<'a> Linker for EmLinker<'a> {
11341134
// Preserve names or generate source maps depending on debug info
11351135
self.cmd.arg(match self.sess.opts.debuginfo {
11361136
DebugInfo::None => "-g0",
1137-
DebugInfo::Limited => "-g3",
1138-
DebugInfo::Full => "-g4",
1137+
DebugInfo::Limited => "--profiling-funcs",
1138+
DebugInfo::Full => "-g",
11391139
});
11401140
}
11411141

compiler/rustc_passes/src/reachable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,6 @@ fn check_item<'tcx>(
316316
item.kind
317317
{
318318
if !access_levels.is_reachable(item.def_id) {
319-
// FIXME(#53488) remove `let`
320-
let tcx = tcx;
321319
worklist.extend(items.iter().map(|ii_ref| ii_ref.id.def_id));
322320

323321
let Res::Def(DefKind::Trait, trait_def_id) = trait_ref.path.res else {

library/std/src/process.rs

+15-22
Original file line numberDiff line numberDiff line change
@@ -2140,16 +2140,6 @@ impl Termination for () {
21402140
}
21412141
}
21422142

2143-
#[stable(feature = "termination_trait_lib", since = "1.61.0")]
2144-
impl<E: fmt::Debug> Termination for Result<(), E> {
2145-
fn report(self) -> ExitCode {
2146-
match self {
2147-
Ok(()) => ().report(),
2148-
Err(err) => Err::<!, _>(err).report(),
2149-
}
2150-
}
2151-
}
2152-
21532143
#[stable(feature = "termination_trait_lib", since = "1.61.0")]
21542144
impl Termination for ! {
21552145
fn report(self) -> ExitCode {
@@ -2158,28 +2148,31 @@ impl Termination for ! {
21582148
}
21592149

21602150
#[stable(feature = "termination_trait_lib", since = "1.61.0")]
2161-
impl<E: fmt::Debug> Termination for Result<!, E> {
2151+
impl Termination for Infallible {
21622152
fn report(self) -> ExitCode {
2163-
let Err(err) = self;
2164-
// Ignore error if the write fails, for example because stderr is
2165-
// already closed. There is not much point panicking at this point.
2166-
let _ = writeln!(io::stderr(), "Error: {err:?}");
2167-
ExitCode::FAILURE
2153+
match self {}
21682154
}
21692155
}
21702156

21712157
#[stable(feature = "termination_trait_lib", since = "1.61.0")]
2172-
impl<E: fmt::Debug> Termination for Result<Infallible, E> {
2158+
impl Termination for ExitCode {
2159+
#[inline]
21732160
fn report(self) -> ExitCode {
2174-
let Err(err) = self;
2175-
Err::<!, _>(err).report()
2161+
self
21762162
}
21772163
}
21782164

21792165
#[stable(feature = "termination_trait_lib", since = "1.61.0")]
2180-
impl Termination for ExitCode {
2181-
#[inline]
2166+
impl<T: Termination, E: fmt::Debug> Termination for Result<T, E> {
21822167
fn report(self) -> ExitCode {
2183-
self
2168+
match self {
2169+
Ok(val) => val.report(),
2170+
Err(err) => {
2171+
// Ignore error if the write fails, for example because stderr is
2172+
// already closed. There is not much point panicking at this point.
2173+
let _ = writeln!(io::stderr(), "Error: {err:?}");
2174+
ExitCode::FAILURE
2175+
}
2176+
}
21842177
}
21852178
}

src/bootstrap/bootstrap.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ def bootstrap(help_triggered):
10431043
build.checksums_sha256 = data["checksums_sha256"]
10441044
build.stage0_compiler = Stage0Toolchain(data["compiler"])
10451045

1046-
build.set_dist_environment(data["dist_server"])
1046+
build.set_dist_environment(data["config"]["dist_server"])
10471047

10481048
build.build = args.build or build.build_triple()
10491049

src/bootstrap/builder.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -870,20 +870,23 @@ impl<'a> Builder<'a> {
870870
self.try_run(patchelf.arg(fname));
871871
}
872872

873-
pub(crate) fn download_component(
874-
&self,
875-
base: &str,
876-
url: &str,
877-
dest_path: &Path,
878-
help_on_error: &str,
879-
) {
873+
pub(crate) fn download_component(&self, url: &str, dest_path: &Path, help_on_error: &str) {
880874
// Use a temporary file in case we crash while downloading, to avoid a corrupt download in cache/.
881875
let tempfile = self.tempdir().join(dest_path.file_name().unwrap());
882-
self.download_with_retries(&tempfile, &format!("{}/{}", base, url), help_on_error);
876+
// While bootstrap itself only supports http and https downloads, downstream forks might
877+
// need to download components from other protocols. The match allows them adding more
878+
// protocols without worrying about merge conficts if we change the HTTP implementation.
879+
match url.split_once("://").map(|(proto, _)| proto) {
880+
Some("http") | Some("https") => {
881+
self.download_http_with_retries(&tempfile, url, help_on_error)
882+
}
883+
Some(other) => panic!("unsupported protocol {other} in {url}"),
884+
None => panic!("no protocol in {url}"),
885+
}
883886
t!(std::fs::rename(&tempfile, dest_path));
884887
}
885888

886-
fn download_with_retries(&self, tempfile: &Path, url: &str, help_on_error: &str) {
889+
fn download_http_with_retries(&self, tempfile: &Path, url: &str, help_on_error: &str) {
887890
println!("downloading {}", url);
888891
// Try curl. If that fails and we are on windows, fallback to PowerShell.
889892
let mut curl = Command::new("curl");

src/bootstrap/config.rs

+47-16
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use crate::channel::GitInfo;
2020
pub use crate::flags::Subcommand;
2121
use crate::flags::{Color, Flags};
2222
use crate::util::{exe, output, program_out_of_date, t};
23-
use crate::RustfmtMetadata;
2423
use once_cell::sync::OnceCell;
2524
use serde::{Deserialize, Deserializer};
2625

@@ -73,6 +72,7 @@ pub struct Config {
7372
pub test_compare_mode: bool,
7473
pub color: Color,
7574
pub patch_binaries_for_nix: bool,
75+
pub stage0_metadata: Stage0Metadata,
7676

7777
pub on_fail: Option<String>,
7878
pub stage: u32,
@@ -212,6 +212,28 @@ pub struct Config {
212212
pub out: PathBuf,
213213
}
214214

215+
#[derive(Default, Deserialize)]
216+
#[cfg_attr(test, derive(Clone))]
217+
pub struct Stage0Metadata {
218+
pub config: Stage0Config,
219+
pub checksums_sha256: HashMap<String, String>,
220+
pub rustfmt: Option<RustfmtMetadata>,
221+
}
222+
#[derive(Default, Deserialize)]
223+
#[cfg_attr(test, derive(Clone))]
224+
pub struct Stage0Config {
225+
pub dist_server: String,
226+
pub artifacts_server: String,
227+
pub artifacts_with_llvm_assertions_server: String,
228+
pub git_merge_commit_email: String,
229+
}
230+
#[derive(Default, Deserialize)]
231+
#[cfg_attr(test, derive(Clone))]
232+
pub struct RustfmtMetadata {
233+
pub date: String,
234+
pub version: String,
235+
}
236+
215237
#[derive(Clone, Debug)]
216238
pub enum RustfmtState {
217239
SystemToolchain(PathBuf),
@@ -776,6 +798,9 @@ impl Config {
776798
config.llvm_profile_use = flags.llvm_profile_use;
777799
config.llvm_profile_generate = flags.llvm_profile_generate;
778800

801+
let stage0_json = t!(std::fs::read(&config.src.join("src").join("stage0.json")));
802+
config.stage0_metadata = t!(serde_json::from_slice::<Stage0Metadata>(&stage0_json));
803+
779804
#[cfg(test)]
780805
let get_toml = |_| TomlConfig::default();
781806
#[cfg(not(test))]
@@ -1103,8 +1128,11 @@ impl Config {
11031128
config.rust_codegen_units_std = rust.codegen_units_std.map(threads_from_config);
11041129
config.rust_profile_use = flags.rust_profile_use.or(rust.profile_use);
11051130
config.rust_profile_generate = flags.rust_profile_generate.or(rust.profile_generate);
1106-
config.download_rustc_commit =
1107-
download_ci_rustc_commit(rust.download_rustc, config.verbose > 0);
1131+
config.download_rustc_commit = download_ci_rustc_commit(
1132+
&config.stage0_metadata,
1133+
rust.download_rustc,
1134+
config.verbose > 0,
1135+
);
11081136
} else {
11091137
config.rust_profile_use = flags.rust_profile_use;
11101138
config.rust_profile_generate = flags.rust_profile_generate;
@@ -1424,7 +1452,11 @@ fn threads_from_config(v: u32) -> u32 {
14241452
}
14251453

14261454
/// Returns the commit to download, or `None` if we shouldn't download CI artifacts.
1427-
fn download_ci_rustc_commit(download_rustc: Option<StringOrBool>, verbose: bool) -> Option<String> {
1455+
fn download_ci_rustc_commit(
1456+
stage0_metadata: &Stage0Metadata,
1457+
download_rustc: Option<StringOrBool>,
1458+
verbose: bool,
1459+
) -> Option<String> {
14281460
// If `download-rustc` is not set, default to rebuilding.
14291461
let if_unchanged = match download_rustc {
14301462
None | Some(StringOrBool::Bool(false)) => return None,
@@ -1443,13 +1475,12 @@ fn download_ci_rustc_commit(download_rustc: Option<StringOrBool>, verbose: bool)
14431475

14441476
// Look for a version to compare to based on the current commit.
14451477
// Only commits merged by bors will have CI artifacts.
1446-
let merge_base = output(Command::new("git").args(&[
1447-
"rev-list",
1448-
1449-
"-n1",
1450-
"--first-parent",
1451-
"HEAD",
1452-
]));
1478+
let merge_base = output(
1479+
Command::new("git")
1480+
.arg("rev-list")
1481+
.arg(format!("--author={}", stage0_metadata.config.git_merge_commit_email))
1482+
.args(&["-n1", "--first-parent", "HEAD"]),
1483+
);
14531484
let commit = merge_base.trim_end();
14541485
if commit.is_empty() {
14551486
println!("error: could not find commit hash for downloading rustc");
@@ -1484,7 +1515,7 @@ fn download_ci_rustc_commit(download_rustc: Option<StringOrBool>, verbose: bool)
14841515
}
14851516

14861517
fn maybe_download_rustfmt(builder: &Builder<'_>) -> Option<PathBuf> {
1487-
let RustfmtMetadata { date, version } = builder.stage0_metadata.rustfmt.as_ref()?;
1518+
let RustfmtMetadata { date, version } = builder.config.stage0_metadata.rustfmt.as_ref()?;
14881519
let channel = format!("{version}-{date}");
14891520

14901521
let host = builder.config.build;
@@ -1568,13 +1599,13 @@ fn download_component(
15681599
let tarball = cache_dir.join(&filename);
15691600
let (base_url, url, should_verify) = match mode {
15701601
DownloadSource::CI => (
1571-
"https://ci-artifacts.rust-lang.org/rustc-builds".to_string(),
1602+
builder.config.stage0_metadata.config.artifacts_server.clone(),
15721603
format!("{key}/{filename}"),
15731604
false,
15741605
),
15751606
DownloadSource::Dist => {
15761607
let dist_server = env::var("RUSTUP_DIST_SERVER")
1577-
.unwrap_or(builder.stage0_metadata.dist_server.to_string());
1608+
.unwrap_or(builder.config.stage0_metadata.config.dist_server.to_string());
15781609
// NOTE: make `dist` part of the URL because that's how it's stored in src/stage0.json
15791610
(dist_server, format!("dist/{key}/{filename}"), true)
15801611
}
@@ -1590,7 +1621,7 @@ fn download_component(
15901621
target at this time, see https://doc.rust-lang.org/nightly\
15911622
/rustc/platform-support.html for more information."
15921623
);
1593-
let sha256 = builder.stage0_metadata.checksums_sha256.get(&url).expect(&error);
1624+
let sha256 = builder.config.stage0_metadata.checksums_sha256.get(&url).expect(&error);
15941625
if tarball.exists() {
15951626
if builder.verify(&tarball, sha256) {
15961627
builder.unpack(&tarball, &bin_root, prefix);
@@ -1610,7 +1641,7 @@ fn download_component(
16101641
None
16111642
};
16121643

1613-
builder.download_component(&base_url, &url, &tarball, "");
1644+
builder.download_component(&format!("{base_url}/{url}"), &tarball, "");
16141645
if let Some(sha256) = checksum {
16151646
if !builder.verify(&tarball, sha256) {
16161647
panic!("failed to verify {}", tarball.display());

src/bootstrap/lib.rs

-19
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ use std::os::windows::fs::symlink_file;
118118

119119
use filetime::FileTime;
120120
use once_cell::sync::OnceCell;
121-
use serde::Deserialize;
122121

123122
use crate::builder::Kind;
124123
use crate::config::{LlvmLibunwind, TargetSelection};
@@ -294,8 +293,6 @@ pub struct Build {
294293
hosts: Vec<TargetSelection>,
295294
targets: Vec<TargetSelection>,
296295

297-
// Stage 0 (downloaded) compiler, lld and cargo or their local rust equivalents
298-
stage0_metadata: Stage0Metadata,
299296
initial_rustc: PathBuf,
300297
initial_cargo: PathBuf,
301298
initial_lld: PathBuf,
@@ -322,18 +319,6 @@ pub struct Build {
322319
metrics: metrics::BuildMetrics,
323320
}
324321

325-
#[derive(Deserialize)]
326-
struct Stage0Metadata {
327-
dist_server: String,
328-
checksums_sha256: HashMap<String, String>,
329-
rustfmt: Option<RustfmtMetadata>,
330-
}
331-
#[derive(Deserialize)]
332-
struct RustfmtMetadata {
333-
date: String,
334-
version: String,
335-
}
336-
337322
#[derive(Debug)]
338323
struct Crate {
339324
name: Interned<String>,
@@ -482,11 +467,7 @@ impl Build {
482467
bootstrap_out
483468
};
484469

485-
let stage0_json = t!(std::fs::read_to_string(&src.join("src").join("stage0.json")));
486-
let stage0_metadata = t!(serde_json::from_str::<Stage0Metadata>(&stage0_json));
487-
488470
let mut build = Build {
489-
stage0_metadata,
490471
initial_rustc: config.initial_rustc.clone(),
491472
initial_cargo: config.initial_cargo.clone(),
492473
initial_lld,

src/bootstrap/native.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pub(crate) fn maybe_download_ci_llvm(builder: &Builder<'_>) {
121121
let mut rev_list = Command::new("git");
122122
rev_list.args(&[
123123
PathBuf::from("rev-list"),
124-
"--author=[email protected]".into(),
124+
format!("--author={}", builder.config.stage0_metadata.config.git_merge_commit_email).into(),
125125
"-n1".into(),
126126
"--first-parent".into(),
127127
"HEAD".into(),
@@ -170,11 +170,10 @@ fn download_ci_llvm(builder: &Builder<'_>, llvm_sha: &str) {
170170
if !rustc_cache.exists() {
171171
t!(fs::create_dir_all(&rustc_cache));
172172
}
173-
let base = "https://ci-artifacts.rust-lang.org";
174-
let url = if llvm_assertions {
175-
format!("rustc-builds-alt/{}", llvm_sha)
173+
let base = if llvm_assertions {
174+
&builder.config.stage0_metadata.config.artifacts_with_llvm_assertions_server
176175
} else {
177-
format!("rustc-builds/{}", llvm_sha)
176+
&builder.config.stage0_metadata.config.artifacts_server
178177
};
179178
let filename = format!("rust-dev-nightly-{}.tar.xz", builder.build.build.triple);
180179
let tarball = rustc_cache.join(&filename);
@@ -187,7 +186,11 @@ help: if trying to compile an old commit of rustc, disable `download-ci-llvm` in
187186
[llvm]
188187
download-ci-llvm = false
189188
";
190-
builder.download_component(base, &format!("{}/{}", url, filename), &tarball, help_on_error);
189+
builder.download_component(
190+
&format!("{base}/{llvm_sha}/{filename}"),
191+
&tarball,
192+
help_on_error,
193+
);
191194
}
192195
let llvm_root = builder.config.ci_llvm_root();
193196
builder.unpack(&tarball, &llvm_root, "rust-dev");

src/librustdoc/json/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
201201

202202
types::ItemEnum::Method(_)
203203
| types::ItemEnum::AssocConst { .. }
204-
| types::ItemEnum::AssocType { .. } => true,
204+
| types::ItemEnum::AssocType { .. }
205+
| types::ItemEnum::PrimitiveType(_) => true,
205206
types::ItemEnum::Module(_)
206207
| types::ItemEnum::ExternCrate { .. }
207208
| types::ItemEnum::Import(_)
@@ -216,8 +217,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
216217
| types::ItemEnum::Static(_)
217218
| types::ItemEnum::ForeignType
218219
| types::ItemEnum::Macro(_)
219-
| types::ItemEnum::ProcMacro(_)
220-
| types::ItemEnum::PrimitiveType(_) => false,
220+
| types::ItemEnum::ProcMacro(_) => false,
221221
};
222222
let removed = self
223223
.index

src/stage0.json

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
{
2-
"__comment": "Generated by `./x.py run src/tools/bump-stage0`. Run that command again to update the bootstrap compiler.",
3-
"dist_server": "https://static.rust-lang.org",
2+
"config": {
3+
"dist_server": "https://static.rust-lang.org",
4+
"artifacts_server": "https://ci-artifacts.rust-lang.org/rustc-builds",
5+
"artifacts_with_llvm_assertions_server": "https://ci-artifacts.rust-lang.org/rustc-builds-alt",
6+
"git_merge_commit_email": "[email protected]"
7+
},
8+
"__comments": [
9+
"The configuration above this comment is editable, and can be changed",
10+
"by forks of the repository if they have alternate values.",
11+
"",
12+
"The section below is generated by `./x.py run src/tools/bump-stage0`,",
13+
"run that command again to update the bootstrap compiler.",
14+
"",
15+
"All changes below this comment will be overridden the next time the",
16+
"tool is executed."
17+
],
418
"compiler": {
519
"date": "2022-05-20",
620
"version": "beta"

0 commit comments

Comments
 (0)