Skip to content

Commit 1b2a0e6

Browse files
committed
Auto merge of rust-lang#118836 - matthiaskrgr:rollup-0chcgi1, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#118647 (dump bootstrap shims) - rust-lang#118708 (tests: add sanity-check assembly test for every target) - rust-lang#118818 (llvm-wrapper: adapt for LLVM API change) - rust-lang#118826 (Edit target doc template to remove email) - rust-lang#118827 (Update table for linker-plugin-lto docs) - rust-lang#118835 (Fix again `rustc_codegen_gcc` tests) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5701093 + 11c49c0 commit 1b2a0e6

File tree

22 files changed

+925
-30
lines changed

22 files changed

+925
-30
lines changed

compiler/rustc_codegen_gcc/example/mini_core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
thread_local
55
)]
66
#![no_core]
7-
#![allow(dead_code, internal_features)]
7+
#![allow(dead_code, internal_features, ambiguous_wide_pointer_comparisons)]
88

99
#[no_mangle]
1010
unsafe extern "C" fn _Unwind_Resume() {

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,11 @@ LLVMRustOptimize(
841841
// cargo run tests in multhreading mode by default
842842
// so use atomics for coverage counters
843843
Options.Atomic = true;
844+
#if LLVM_VERSION_GE(18, 0)
845+
MPM.addPass(InstrProfilingLoweringPass(Options, false));
846+
#else
844847
MPM.addPass(InstrProfiling(Options, false));
848+
#endif
845849
}
846850
);
847851
}

src/bootstrap/src/bin/main.rs

+29-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ use std::io::Write;
1010
#[cfg(all(any(unix, windows), not(target_os = "solaris")))]
1111
use std::process;
1212
use std::{
13-
env, fs,
14-
io::{self, IsTerminal},
13+
env,
14+
fs::{self, OpenOptions},
15+
io::{self, BufRead, BufReader, IsTerminal},
1516
};
1617

1718
use bootstrap::{
@@ -79,6 +80,9 @@ fn main() {
7980
}
8081

8182
let pre_commit = config.src.join(".git").join("hooks").join("pre-commit");
83+
let dump_bootstrap_shims = config.dump_bootstrap_shims;
84+
let out_dir = config.out.clone();
85+
8286
Build::new(config).build();
8387

8488
if suggest_setup {
@@ -107,6 +111,29 @@ fn main() {
107111
if suggest_setup || changelog_suggestion.is_some() {
108112
println!("NOTE: this message was printed twice to make it more likely to be seen");
109113
}
114+
115+
if dump_bootstrap_shims {
116+
let dump_dir = out_dir.join("bootstrap-shims-dump");
117+
assert!(dump_dir.exists());
118+
119+
for entry in walkdir::WalkDir::new(&dump_dir) {
120+
let entry = t!(entry);
121+
122+
if !entry.file_type().is_file() {
123+
continue;
124+
}
125+
126+
let file = t!(fs::File::open(&entry.path()));
127+
128+
// To ensure deterministic results we must sort the dump lines.
129+
// This is necessary because the order of rustc invocations different
130+
// almost all the time.
131+
let mut lines: Vec<String> = t!(BufReader::new(&file).lines().collect());
132+
lines.sort_by_key(|t| t.to_lowercase());
133+
let mut file = t!(OpenOptions::new().write(true).truncate(true).open(&entry.path()));
134+
t!(file.write_all(lines.join("\n").as_bytes()));
135+
}
136+
}
110137
}
111138

112139
fn check_version(config: &Config) -> Option<String> {

src/bootstrap/src/bin/rustc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ fn main() {
3232
let args = env::args_os().skip(1).collect::<Vec<_>>();
3333
let arg = |name| args.windows(2).find(|args| args[0] == name).and_then(|args| args[1].to_str());
3434

35-
// We don't use the stage in this shim, but let's parse it to make sure that we're invoked
36-
// by bootstrap, or that we provide a helpful error message if not.
37-
bin_helpers::parse_rustc_stage();
35+
let stage = bin_helpers::parse_rustc_stage();
3836
let verbose = bin_helpers::parse_rustc_verbose();
3937

4038
// Detect whether or not we're a build script depending on whether --target
@@ -214,6 +212,8 @@ fn main() {
214212
}
215213
}
216214

215+
bin_helpers::maybe_dump(format!("stage{stage}-rustc"), &cmd);
216+
217217
let start = Instant::now();
218218
let (child, status) = {
219219
let errmsg = format!("\nFailed to run:\n{cmd:?}\n-------------");

src/bootstrap/src/bin/rustdoc.rs

+2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ fn main() {
6262
cmd.arg("-Zunstable-options");
6363
cmd.arg("--check-cfg=cfg(bootstrap)");
6464

65+
bin_helpers::maybe_dump(format!("stage{stage}-rustdoc"), &cmd);
66+
6567
if verbose > 1 {
6668
eprintln!(
6769
"rustdoc command: {:?}={:?} {:?}",

src/bootstrap/src/core/build_steps/clean.rs

+1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ fn clean_default(build: &Build) {
146146
rm_rf(&build.out.join("tmp"));
147147
rm_rf(&build.out.join("dist"));
148148
rm_rf(&build.out.join("bootstrap").join(".last-warned-change-id"));
149+
rm_rf(&build.out.join("bootstrap-shims-dump"));
149150
rm_rf(&build.out.join("rustfmt.stamp"));
150151

151152
for host in &build.hosts {

src/bootstrap/src/core/builder.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ use crate::core::build_steps::tool::{self, SourceType};
1818
use crate::core::build_steps::{check, clean, compile, dist, doc, install, run, setup, test};
1919
use crate::core::config::flags::{Color, Subcommand};
2020
use crate::core::config::{DryRun, SplitDebuginfo, TargetSelection};
21+
use crate::prepare_behaviour_dump_dir;
2122
use crate::utils::cache::{Cache, Interned, INTERNER};
2223
use crate::utils::helpers::{self, add_dylib_path, add_link_lib_path, exe, linker_args};
2324
use crate::utils::helpers::{libdir, linker_flags, output, t, LldThreads};
24-
use crate::Crate;
2525
use crate::EXTRA_CHECK_CFGS;
26-
use crate::{Build, CLang, DocTests, GitRepo, Mode};
26+
use crate::{Build, CLang, Crate, DocTests, GitRepo, Mode};
2727

2828
pub use crate::Compiler;
2929

@@ -1788,6 +1788,16 @@ impl<'a> Builder<'a> {
17881788

17891789
// Enable usage of unstable features
17901790
cargo.env("RUSTC_BOOTSTRAP", "1");
1791+
1792+
if self.config.dump_bootstrap_shims {
1793+
prepare_behaviour_dump_dir(&self.build);
1794+
1795+
cargo
1796+
.env("DUMP_BOOTSTRAP_SHIMS", self.build.out.join("bootstrap-shims-dump"))
1797+
.env("BUILD_OUT", &self.build.out)
1798+
.env("CARGO_HOME", t!(home::cargo_home()));
1799+
};
1800+
17911801
self.add_rust_test_threads(&mut cargo);
17921802

17931803
// Almost all of the crates that we compile as part of the bootstrap may

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

+2
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ pub struct Config {
193193
pub cmd: Subcommand,
194194
pub incremental: bool,
195195
pub dry_run: DryRun,
196+
pub dump_bootstrap_shims: bool,
196197
/// Arguments appearing after `--` to be forwarded to tools,
197198
/// e.g. `--fix-broken` or test arguments.
198199
pub free_args: Vec<String>,
@@ -1210,6 +1211,7 @@ impl Config {
12101211
config.cmd = flags.cmd;
12111212
config.incremental = flags.incremental;
12121213
config.dry_run = if flags.dry_run { DryRun::UserSelected } else { DryRun::Disabled };
1214+
config.dump_bootstrap_shims = flags.dump_bootstrap_shims;
12131215
config.keep_stage = flags.keep_stage;
12141216
config.keep_stage_std = flags.keep_stage_std;
12151217
config.color = flags.color;

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

+3
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ pub struct Flags {
8585
#[arg(global(true), long)]
8686
/// dry run; don't build anything
8787
pub dry_run: bool,
88+
/// Indicates whether to dump the work done from bootstrap shims
89+
#[arg(global(true), long)]
90+
pub dump_bootstrap_shims: bool,
8891
#[arg(global(true), value_hint = clap::ValueHint::Other, long, value_name = "N")]
8992
/// stage to build (indicates compiler to use/test, e.g., stage 0 uses the
9093
/// bootstrap compiler, stage 1 the stage 0 rustc artifacts, etc.)

src/bootstrap/src/lib.rs

+19
Original file line numberDiff line numberDiff line change
@@ -1871,3 +1871,22 @@ pub fn generate_smart_stamp_hash(dir: &Path, additional_input: &str) -> String {
18711871

18721872
hex::encode(hasher.finalize().as_slice())
18731873
}
1874+
1875+
/// Ensures that the behavior dump directory is properly initialized.
1876+
pub fn prepare_behaviour_dump_dir(build: &Build) {
1877+
static INITIALIZED: OnceLock<bool> = OnceLock::new();
1878+
1879+
let dump_path = build.out.join("bootstrap-shims-dump");
1880+
1881+
let initialized = INITIALIZED.get().unwrap_or_else(|| &false);
1882+
if !initialized {
1883+
// clear old dumps
1884+
if dump_path.exists() {
1885+
t!(fs::remove_dir_all(&dump_path));
1886+
}
1887+
1888+
t!(fs::create_dir_all(&dump_path));
1889+
1890+
t!(INITIALIZED.set(true));
1891+
}
1892+
}

src/bootstrap/src/utils/bin_helpers.rs

+27-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22
//! dependency on the bootstrap library. This reduces the binary size and
33
//! improves compilation time by reducing the linking time.
44
5+
use std::env;
6+
use std::fs::OpenOptions;
7+
use std::io::Write;
8+
use std::process::Command;
9+
use std::str::FromStr;
10+
511
/// Parses the value of the "RUSTC_VERBOSE" environment variable and returns it as a `usize`.
612
/// If it was not defined, returns 0 by default.
713
///
814
/// Panics if "RUSTC_VERBOSE" is defined with the value that is not an unsigned integer.
915
pub(crate) fn parse_rustc_verbose() -> usize {
10-
use std::str::FromStr;
11-
12-
match std::env::var("RUSTC_VERBOSE") {
16+
match env::var("RUSTC_VERBOSE") {
1317
Ok(s) => usize::from_str(&s).expect("RUSTC_VERBOSE should be an integer"),
1418
Err(_) => 0,
1519
}
@@ -19,10 +23,29 @@ pub(crate) fn parse_rustc_verbose() -> usize {
1923
///
2024
/// If "RUSTC_STAGE" was not set, the program will be terminated with 101.
2125
pub(crate) fn parse_rustc_stage() -> String {
22-
std::env::var("RUSTC_STAGE").unwrap_or_else(|_| {
26+
env::var("RUSTC_STAGE").unwrap_or_else(|_| {
2327
// Don't panic here; it's reasonable to try and run these shims directly. Give a helpful error instead.
2428
eprintln!("rustc shim: FATAL: RUSTC_STAGE was not set");
2529
eprintln!("rustc shim: NOTE: use `x.py build -vvv` to see all environment variables set by bootstrap");
2630
std::process::exit(101);
2731
})
2832
}
33+
34+
/// Writes the command invocation to a file if `DUMP_BOOTSTRAP_SHIMS` is set during bootstrap.
35+
///
36+
/// Before writing it, replaces user-specific values to create generic dumps for cross-environment
37+
/// comparisons.
38+
pub(crate) fn maybe_dump(dump_name: String, cmd: &Command) {
39+
if let Ok(dump_dir) = env::var("DUMP_BOOTSTRAP_SHIMS") {
40+
let dump_file = format!("{dump_dir}/{dump_name}");
41+
42+
let mut file =
43+
OpenOptions::new().create(true).write(true).append(true).open(&dump_file).unwrap();
44+
45+
let cmd_dump = format!("{:?}\n", cmd);
46+
let cmd_dump = cmd_dump.replace(&env::var("BUILD_OUT").unwrap(), "${BUILD_OUT}");
47+
let cmd_dump = cmd_dump.replace(&env::var("CARGO_HOME").unwrap(), "${CARGO_HOME}");
48+
49+
file.write_all(cmd_dump.as_bytes()).expect("Unable to write file");
50+
}
51+
}

src/doc/rustc/src/linker-plugin-lto.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,15 @@ able to get around this problem by setting `-Clinker=lld-link` in RUSTFLAGS
136136
```python
137137
from collections import defaultdict
138138
import subprocess
139+
import sys
139140
140141
def minor_version(version):
141142
return int(version.split('.')[1])
142143
143144
INSTALL_TOOLCHAIN = ["rustup", "toolchain", "install", "--profile", "minimal"]
144145
subprocess.run(INSTALL_TOOLCHAIN + ["nightly"])
145146
146-
LOWER_BOUND = 65
147+
LOWER_BOUND = 73
147148
NIGHTLY_VERSION = minor_version(subprocess.run(
148149
["rustc", "+nightly", "--version"],
149150
capture_output=True,
@@ -159,6 +160,7 @@ def llvm_version(toolchain):
159160
version_map = defaultdict(lambda: [])
160161
for version in range(LOWER_BOUND, NIGHTLY_VERSION - 1):
161162
toolchain = "1.{}.0".format(version)
163+
print("Checking", toolchain, file=sys.stderr)
162164
subprocess.run(
163165
INSTALL_TOOLCHAIN + ["--no-self-update", toolchain],
164166
capture_output=True)
@@ -196,6 +198,8 @@ The following table shows known good combinations of toolchain versions.
196198
| 1.52 - 1.55 | 12 |
197199
| 1.56 - 1.59 | 13 |
198200
| 1.60 - 1.64 | 14 |
199-
| 1.65 | 15 |
201+
| 1.65 - 1.69 | 15 |
202+
| 1.70 - 1.72 | 16 |
203+
| 1.73 - 1.74 | 17 |
200204

201205
Note that the compatibility policy for this feature might change in the future.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ One-sentence description of the target (e.g. CPU, OS)
66

77
## Target maintainers
88

9-
- Some Person, `[email protected]`, https://github.com/...
9+
- Some Person, https://github.com/...
1010

1111
## Requirements
1212

src/doc/rustc/src/target-tier-policy.md

+2
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ approved by the appropriate team for that shared code before acceptance.
246246
introducing unconditional uses of features that another variation of the
247247
target may not have; use conditional compilation or runtime detection, as
248248
appropriate, to let each target run code supported by that target.
249+
- Tier 3 targets must be able to produce assembly using at least one of
250+
rustc's supported backends from any host target.
249251

250252
If a tier 3 target stops meeting these requirements, or the target maintainers
251253
no longer have interest or time, or the target shows no signs of activity and

0 commit comments

Comments
 (0)