Skip to content

Commit

Permalink
Auto merge of rust-lang#98216 - JohnTitor:rollup-jlcmu5d, r=JohnTitor
Browse files Browse the repository at this point in the history
Rollup of 5 pull requests

Successful merges:

 - rust-lang#97803 (Impl Termination for Infallible and then make the Result impls of Termination more generic)
 - rust-lang#97828 (Allow configuring where artifacts are downloaded from)
 - rust-lang#98150 (Emscripten target: replace -g4 with -g, and -g3 with --profiling-funcs)
 - rust-lang#98195 (Fix rustdoc json primitive handling)
 - rust-lang#98205 (Remove a possible unnecessary assignment)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Jun 18, 2022
2 parents aaf1005 + f514aa4 commit 529c4c7
Show file tree
Hide file tree
Showing 13 changed files with 172 additions and 108 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1134,8 +1134,8 @@ impl<'a> Linker for EmLinker<'a> {
// Preserve names or generate source maps depending on debug info
self.cmd.arg(match self.sess.opts.debuginfo {
DebugInfo::None => "-g0",
DebugInfo::Limited => "-g3",
DebugInfo::Full => "-g4",
DebugInfo::Limited => "--profiling-funcs",
DebugInfo::Full => "-g",
});
}

Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_passes/src/reachable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,6 @@ fn check_item<'tcx>(
item.kind
{
if !access_levels.is_reachable(item.def_id) {
// FIXME(#53488) remove `let`
let tcx = tcx;
worklist.extend(items.iter().map(|ii_ref| ii_ref.id.def_id));

let Res::Def(DefKind::Trait, trait_def_id) = trait_ref.path.res else {
Expand Down
37 changes: 15 additions & 22 deletions library/std/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2140,16 +2140,6 @@ impl Termination for () {
}
}

#[stable(feature = "termination_trait_lib", since = "1.61.0")]
impl<E: fmt::Debug> Termination for Result<(), E> {
fn report(self) -> ExitCode {
match self {
Ok(()) => ().report(),
Err(err) => Err::<!, _>(err).report(),
}
}
}

#[stable(feature = "termination_trait_lib", since = "1.61.0")]
impl Termination for ! {
fn report(self) -> ExitCode {
Expand All @@ -2158,28 +2148,31 @@ impl Termination for ! {
}

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

#[stable(feature = "termination_trait_lib", since = "1.61.0")]
impl<E: fmt::Debug> Termination for Result<Infallible, E> {
impl Termination for ExitCode {
#[inline]
fn report(self) -> ExitCode {
let Err(err) = self;
Err::<!, _>(err).report()
self
}
}

#[stable(feature = "termination_trait_lib", since = "1.61.0")]
impl Termination for ExitCode {
#[inline]
impl<T: Termination, E: fmt::Debug> Termination for Result<T, E> {
fn report(self) -> ExitCode {
self
match self {
Ok(val) => val.report(),
Err(err) => {
// Ignore error if the write fails, for example because stderr is
// already closed. There is not much point panicking at this point.
let _ = writeln!(io::stderr(), "Error: {err:?}");
ExitCode::FAILURE
}
}
}
}
2 changes: 1 addition & 1 deletion src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ def bootstrap(help_triggered):
build.checksums_sha256 = data["checksums_sha256"]
build.stage0_compiler = Stage0Toolchain(data["compiler"])

build.set_dist_environment(data["dist_server"])
build.set_dist_environment(data["config"]["dist_server"])

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

Expand Down
21 changes: 12 additions & 9 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -870,20 +870,23 @@ impl<'a> Builder<'a> {
self.try_run(patchelf.arg(fname));
}

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

fn download_with_retries(&self, tempfile: &Path, url: &str, help_on_error: &str) {
fn download_http_with_retries(&self, tempfile: &Path, url: &str, help_on_error: &str) {
println!("downloading {}", url);
// Try curl. If that fails and we are on windows, fallback to PowerShell.
let mut curl = Command::new("curl");
Expand Down
63 changes: 47 additions & 16 deletions src/bootstrap/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use crate::channel::GitInfo;
pub use crate::flags::Subcommand;
use crate::flags::{Color, Flags};
use crate::util::{exe, output, program_out_of_date, t};
use crate::RustfmtMetadata;
use once_cell::sync::OnceCell;
use serde::{Deserialize, Deserializer};

Expand Down Expand Up @@ -73,6 +72,7 @@ pub struct Config {
pub test_compare_mode: bool,
pub color: Color,
pub patch_binaries_for_nix: bool,
pub stage0_metadata: Stage0Metadata,

pub on_fail: Option<String>,
pub stage: u32,
Expand Down Expand Up @@ -212,6 +212,28 @@ pub struct Config {
pub out: PathBuf,
}

#[derive(Default, Deserialize)]
#[cfg_attr(test, derive(Clone))]
pub struct Stage0Metadata {
pub config: Stage0Config,
pub checksums_sha256: HashMap<String, String>,
pub rustfmt: Option<RustfmtMetadata>,
}
#[derive(Default, Deserialize)]
#[cfg_attr(test, derive(Clone))]
pub struct Stage0Config {
pub dist_server: String,
pub artifacts_server: String,
pub artifacts_with_llvm_assertions_server: String,
pub git_merge_commit_email: String,
}
#[derive(Default, Deserialize)]
#[cfg_attr(test, derive(Clone))]
pub struct RustfmtMetadata {
pub date: String,
pub version: String,
}

#[derive(Clone, Debug)]
pub enum RustfmtState {
SystemToolchain(PathBuf),
Expand Down Expand Up @@ -776,6 +798,9 @@ impl Config {
config.llvm_profile_use = flags.llvm_profile_use;
config.llvm_profile_generate = flags.llvm_profile_generate;

let stage0_json = t!(std::fs::read(&config.src.join("src").join("stage0.json")));
config.stage0_metadata = t!(serde_json::from_slice::<Stage0Metadata>(&stage0_json));

#[cfg(test)]
let get_toml = |_| TomlConfig::default();
#[cfg(not(test))]
Expand Down Expand Up @@ -1103,8 +1128,11 @@ impl Config {
config.rust_codegen_units_std = rust.codegen_units_std.map(threads_from_config);
config.rust_profile_use = flags.rust_profile_use.or(rust.profile_use);
config.rust_profile_generate = flags.rust_profile_generate.or(rust.profile_generate);
config.download_rustc_commit =
download_ci_rustc_commit(rust.download_rustc, config.verbose > 0);
config.download_rustc_commit = download_ci_rustc_commit(
&config.stage0_metadata,
rust.download_rustc,
config.verbose > 0,
);
} else {
config.rust_profile_use = flags.rust_profile_use;
config.rust_profile_generate = flags.rust_profile_generate;
Expand Down Expand Up @@ -1424,7 +1452,11 @@ fn threads_from_config(v: u32) -> u32 {
}

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

// Look for a version to compare to based on the current commit.
// Only commits merged by bors will have CI artifacts.
let merge_base = output(Command::new("git").args(&[
"rev-list",
"[email protected]",
"-n1",
"--first-parent",
"HEAD",
]));
let merge_base = output(
Command::new("git")
.arg("rev-list")
.arg(format!("--author={}", stage0_metadata.config.git_merge_commit_email))
.args(&["-n1", "--first-parent", "HEAD"]),
);
let commit = merge_base.trim_end();
if commit.is_empty() {
println!("error: could not find commit hash for downloading rustc");
Expand Down Expand Up @@ -1484,7 +1515,7 @@ fn download_ci_rustc_commit(download_rustc: Option<StringOrBool>, verbose: bool)
}

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

let host = builder.config.build;
Expand Down Expand Up @@ -1568,13 +1599,13 @@ fn download_component(
let tarball = cache_dir.join(&filename);
let (base_url, url, should_verify) = match mode {
DownloadSource::CI => (
"https://ci-artifacts.rust-lang.org/rustc-builds".to_string(),
builder.config.stage0_metadata.config.artifacts_server.clone(),
format!("{key}/{filename}"),
false,
),
DownloadSource::Dist => {
let dist_server = env::var("RUSTUP_DIST_SERVER")
.unwrap_or(builder.stage0_metadata.dist_server.to_string());
.unwrap_or(builder.config.stage0_metadata.config.dist_server.to_string());
// NOTE: make `dist` part of the URL because that's how it's stored in src/stage0.json
(dist_server, format!("dist/{key}/{filename}"), true)
}
Expand All @@ -1590,7 +1621,7 @@ fn download_component(
target at this time, see https://doc.rust-lang.org/nightly\
/rustc/platform-support.html for more information."
);
let sha256 = builder.stage0_metadata.checksums_sha256.get(&url).expect(&error);
let sha256 = builder.config.stage0_metadata.checksums_sha256.get(&url).expect(&error);
if tarball.exists() {
if builder.verify(&tarball, sha256) {
builder.unpack(&tarball, &bin_root, prefix);
Expand All @@ -1610,7 +1641,7 @@ fn download_component(
None
};

builder.download_component(&base_url, &url, &tarball, "");
builder.download_component(&format!("{base_url}/{url}"), &tarball, "");
if let Some(sha256) = checksum {
if !builder.verify(&tarball, sha256) {
panic!("failed to verify {}", tarball.display());
Expand Down
19 changes: 0 additions & 19 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ use std::os::windows::fs::symlink_file;

use filetime::FileTime;
use once_cell::sync::OnceCell;
use serde::Deserialize;

use crate::builder::Kind;
use crate::config::{LlvmLibunwind, TargetSelection};
Expand Down Expand Up @@ -294,8 +293,6 @@ pub struct Build {
hosts: Vec<TargetSelection>,
targets: Vec<TargetSelection>,

// Stage 0 (downloaded) compiler, lld and cargo or their local rust equivalents
stage0_metadata: Stage0Metadata,
initial_rustc: PathBuf,
initial_cargo: PathBuf,
initial_lld: PathBuf,
Expand All @@ -322,18 +319,6 @@ pub struct Build {
metrics: metrics::BuildMetrics,
}

#[derive(Deserialize)]
struct Stage0Metadata {
dist_server: String,
checksums_sha256: HashMap<String, String>,
rustfmt: Option<RustfmtMetadata>,
}
#[derive(Deserialize)]
struct RustfmtMetadata {
date: String,
version: String,
}

#[derive(Debug)]
struct Crate {
name: Interned<String>,
Expand Down Expand Up @@ -482,11 +467,7 @@ impl Build {
bootstrap_out
};

let stage0_json = t!(std::fs::read_to_string(&src.join("src").join("stage0.json")));
let stage0_metadata = t!(serde_json::from_str::<Stage0Metadata>(&stage0_json));

let mut build = Build {
stage0_metadata,
initial_rustc: config.initial_rustc.clone(),
initial_cargo: config.initial_cargo.clone(),
initial_lld,
Expand Down
15 changes: 9 additions & 6 deletions src/bootstrap/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ pub(crate) fn maybe_download_ci_llvm(builder: &Builder<'_>) {
let mut rev_list = Command::new("git");
rev_list.args(&[
PathBuf::from("rev-list"),
"--author=[email protected]".into(),
format!("--author={}", builder.config.stage0_metadata.config.git_merge_commit_email).into(),
"-n1".into(),
"--first-parent".into(),
"HEAD".into(),
Expand Down Expand Up @@ -170,11 +170,10 @@ fn download_ci_llvm(builder: &Builder<'_>, llvm_sha: &str) {
if !rustc_cache.exists() {
t!(fs::create_dir_all(&rustc_cache));
}
let base = "https://ci-artifacts.rust-lang.org";
let url = if llvm_assertions {
format!("rustc-builds-alt/{}", llvm_sha)
let base = if llvm_assertions {
&builder.config.stage0_metadata.config.artifacts_with_llvm_assertions_server
} else {
format!("rustc-builds/{}", llvm_sha)
&builder.config.stage0_metadata.config.artifacts_server
};
let filename = format!("rust-dev-nightly-{}.tar.xz", builder.build.build.triple);
let tarball = rustc_cache.join(&filename);
Expand All @@ -187,7 +186,11 @@ help: if trying to compile an old commit of rustc, disable `download-ci-llvm` in
[llvm]
download-ci-llvm = false
";
builder.download_component(base, &format!("{}/{}", url, filename), &tarball, help_on_error);
builder.download_component(
&format!("{base}/{llvm_sha}/{filename}"),
&tarball,
help_on_error,
);
}
let llvm_root = builder.config.ci_llvm_root();
builder.unpack(&tarball, &llvm_root, "rust-dev");
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {

types::ItemEnum::Method(_)
| types::ItemEnum::AssocConst { .. }
| types::ItemEnum::AssocType { .. } => true,
| types::ItemEnum::AssocType { .. }
| types::ItemEnum::PrimitiveType(_) => true,
types::ItemEnum::Module(_)
| types::ItemEnum::ExternCrate { .. }
| types::ItemEnum::Import(_)
Expand All @@ -216,8 +217,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
| types::ItemEnum::Static(_)
| types::ItemEnum::ForeignType
| types::ItemEnum::Macro(_)
| types::ItemEnum::ProcMacro(_)
| types::ItemEnum::PrimitiveType(_) => false,
| types::ItemEnum::ProcMacro(_) => false,
};
let removed = self
.index
Expand Down
18 changes: 16 additions & 2 deletions src/stage0.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
{
"__comment": "Generated by `./x.py run src/tools/bump-stage0`. Run that command again to update the bootstrap compiler.",
"dist_server": "https://static.rust-lang.org",
"config": {
"dist_server": "https://static.rust-lang.org",
"artifacts_server": "https://ci-artifacts.rust-lang.org/rustc-builds",
"artifacts_with_llvm_assertions_server": "https://ci-artifacts.rust-lang.org/rustc-builds-alt",
"git_merge_commit_email": "[email protected]"
},
"__comments": [
"The configuration above this comment is editable, and can be changed",
"by forks of the repository if they have alternate values.",
"",
"The section below is generated by `./x.py run src/tools/bump-stage0`,",
"run that command again to update the bootstrap compiler.",
"",
"All changes below this comment will be overridden the next time the",
"tool is executed."
],
"compiler": {
"date": "2022-05-20",
"version": "beta"
Expand Down
Loading

0 comments on commit 529c4c7

Please sign in to comment.