Ensure more consistency in PGO flags -- fixes Cargo tests
This commit is contained in:
parent
e0c61d2262
commit
46e7352445
200
0001-bootstrap-move-all-of-rustc-s-flags-to-rustc_cargo.patch
Normal file
200
0001-bootstrap-move-all-of-rustc-s-flags-to-rustc_cargo.patch
Normal file
@ -0,0 +1,200 @@
|
||||
From 56942ed6d13d330facddbd71470a3c115a3fe0d1 Mon Sep 17 00:00:00 2001
|
||||
From: Josh Stone <jistone@redhat.com>
|
||||
Date: Fri, 5 Apr 2024 15:07:58 -0700
|
||||
Subject: [PATCH] bootstrap: move all of rustc's flags to `rustc_cargo`
|
||||
|
||||
This ensures that `RUSTFLAGS` will be consistent between all modes of
|
||||
building the compiler, so they won't trigger a rebuild by cargo. This
|
||||
kind of fix was started in #119414 just for LTO flags, but it's
|
||||
applicable to all kinds of flags that might be configured.
|
||||
|
||||
(cherry picked from commit e8fb8c36ca0de817b3d30f603d6d6b3c56e8b0be)
|
||||
---
|
||||
src/bootstrap/src/core/build_steps/check.rs | 2 +-
|
||||
src/bootstrap/src/core/build_steps/compile.rs | 107 +++++++++---------
|
||||
src/bootstrap/src/core/build_steps/doc.rs | 2 +-
|
||||
src/bootstrap/src/core/build_steps/test.rs | 2 +-
|
||||
4 files changed, 59 insertions(+), 54 deletions(-)
|
||||
|
||||
diff --git a/src/bootstrap/src/core/build_steps/check.rs b/src/bootstrap/src/core/build_steps/check.rs
|
||||
index 5f0afdb1b36c..dd866c2eb0f3 100644
|
||||
--- a/src/bootstrap/src/core/build_steps/check.rs
|
||||
+++ b/src/bootstrap/src/core/build_steps/check.rs
|
||||
@@ -263,7 +263,7 @@ fn run(self, builder: &Builder<'_>) {
|
||||
target,
|
||||
cargo_subcommand(builder.kind),
|
||||
);
|
||||
- rustc_cargo(builder, &mut cargo, target, compiler.stage);
|
||||
+ rustc_cargo(builder, &mut cargo, target, &compiler);
|
||||
|
||||
// For ./x.py clippy, don't run with --all-targets because
|
||||
// linting tests and benchmarks can produce very noisy results
|
||||
diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs
|
||||
index ddbe18ab8388..607a658617b5 100644
|
||||
--- a/src/bootstrap/src/core/build_steps/compile.rs
|
||||
+++ b/src/bootstrap/src/core/build_steps/compile.rs
|
||||
@@ -898,55 +898,10 @@ fn run(self, builder: &Builder<'_>) -> u32 {
|
||||
));
|
||||
|
||||
let mut cargo = builder.cargo(compiler, Mode::Rustc, SourceType::InTree, target, "build");
|
||||
- rustc_cargo(builder, &mut cargo, target, compiler.stage);
|
||||
+ rustc_cargo(builder, &mut cargo, target, &compiler);
|
||||
|
||||
- if builder.config.rust_profile_use.is_some()
|
||||
- && builder.config.rust_profile_generate.is_some()
|
||||
- {
|
||||
- panic!("Cannot use and generate PGO profiles at the same time");
|
||||
- }
|
||||
-
|
||||
- // With LLD, we can use ICF (identical code folding) to reduce the executable size
|
||||
- // of librustc_driver/rustc and to improve i-cache utilization.
|
||||
- //
|
||||
- // -Wl,[link options] doesn't work on MSVC. However, /OPT:ICF (technically /OPT:REF,ICF)
|
||||
- // is already on by default in MSVC optimized builds, which is interpreted as --icf=all:
|
||||
- // https://github.com/llvm/llvm-project/blob/3329cec2f79185bafd678f310fafadba2a8c76d2/lld/COFF/Driver.cpp#L1746
|
||||
- // https://github.com/rust-lang/rust/blob/f22819bcce4abaff7d1246a56eec493418f9f4ee/compiler/rustc_codegen_ssa/src/back/linker.rs#L827
|
||||
- if builder.config.lld_mode.is_used() && !compiler.host.is_msvc() {
|
||||
- cargo.rustflag("-Clink-args=-Wl,--icf=all");
|
||||
- }
|
||||
-
|
||||
- let is_collecting = if let Some(path) = &builder.config.rust_profile_generate {
|
||||
- if compiler.stage == 1 {
|
||||
- cargo.rustflag(&format!("-Cprofile-generate={path}"));
|
||||
- // Apparently necessary to avoid overflowing the counters during
|
||||
- // a Cargo build profile
|
||||
- cargo.rustflag("-Cllvm-args=-vp-counters-per-site=4");
|
||||
- true
|
||||
- } else {
|
||||
- false
|
||||
- }
|
||||
- } else if let Some(path) = &builder.config.rust_profile_use {
|
||||
- if compiler.stage == 1 {
|
||||
- cargo.rustflag(&format!("-Cprofile-use={path}"));
|
||||
- if builder.is_verbose() {
|
||||
- cargo.rustflag("-Cllvm-args=-pgo-warn-missing-function");
|
||||
- }
|
||||
- true
|
||||
- } else {
|
||||
- false
|
||||
- }
|
||||
- } else {
|
||||
- false
|
||||
- };
|
||||
- if is_collecting {
|
||||
- // Ensure paths to Rust sources are relative, not absolute.
|
||||
- cargo.rustflag(&format!(
|
||||
- "-Cllvm-args=-static-func-strip-dirname-prefix={}",
|
||||
- builder.config.src.components().count()
|
||||
- ));
|
||||
- }
|
||||
+ // NB: all RUSTFLAGS should be added to `rustc_cargo()` so they will be
|
||||
+ // consistently applied by check/doc/test modes too.
|
||||
|
||||
for krate in &*self.crates {
|
||||
cargo.arg("-p").arg(krate);
|
||||
@@ -997,7 +952,12 @@ fn run(self, builder: &Builder<'_>) -> u32 {
|
||||
}
|
||||
}
|
||||
|
||||
-pub fn rustc_cargo(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelection, stage: u32) {
|
||||
+pub fn rustc_cargo(
|
||||
+ builder: &Builder<'_>,
|
||||
+ cargo: &mut Cargo,
|
||||
+ target: TargetSelection,
|
||||
+ compiler: &Compiler,
|
||||
+) {
|
||||
cargo
|
||||
.arg("--features")
|
||||
.arg(builder.rustc_features(builder.kind))
|
||||
@@ -1008,7 +968,7 @@ pub fn rustc_cargo(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelec
|
||||
|
||||
// We currently don't support cross-crate LTO in stage0. This also isn't hugely necessary
|
||||
// and may just be a time sink.
|
||||
- if stage != 0 {
|
||||
+ if compiler.stage != 0 {
|
||||
match builder.config.rust_lto {
|
||||
RustcLto::Thin | RustcLto::Fat => {
|
||||
// Since using LTO for optimizing dylibs is currently experimental,
|
||||
@@ -1034,7 +994,52 @@ pub fn rustc_cargo(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelec
|
||||
cargo.rustflag("-Clto=off");
|
||||
}
|
||||
|
||||
- rustc_cargo_env(builder, cargo, target, stage);
|
||||
+ // With LLD, we can use ICF (identical code folding) to reduce the executable size
|
||||
+ // of librustc_driver/rustc and to improve i-cache utilization.
|
||||
+ //
|
||||
+ // -Wl,[link options] doesn't work on MSVC. However, /OPT:ICF (technically /OPT:REF,ICF)
|
||||
+ // is already on by default in MSVC optimized builds, which is interpreted as --icf=all:
|
||||
+ // https://github.com/llvm/llvm-project/blob/3329cec2f79185bafd678f310fafadba2a8c76d2/lld/COFF/Driver.cpp#L1746
|
||||
+ // https://github.com/rust-lang/rust/blob/f22819bcce4abaff7d1246a56eec493418f9f4ee/compiler/rustc_codegen_ssa/src/back/linker.rs#L827
|
||||
+ if builder.config.lld_mode.is_used() && !compiler.host.is_msvc() {
|
||||
+ cargo.rustflag("-Clink-args=-Wl,--icf=all");
|
||||
+ }
|
||||
+
|
||||
+ if builder.config.rust_profile_use.is_some() && builder.config.rust_profile_generate.is_some() {
|
||||
+ panic!("Cannot use and generate PGO profiles at the same time");
|
||||
+ }
|
||||
+ let is_collecting = if let Some(path) = &builder.config.rust_profile_generate {
|
||||
+ if compiler.stage == 1 {
|
||||
+ cargo.rustflag(&format!("-Cprofile-generate={path}"));
|
||||
+ // Apparently necessary to avoid overflowing the counters during
|
||||
+ // a Cargo build profile
|
||||
+ cargo.rustflag("-Cllvm-args=-vp-counters-per-site=4");
|
||||
+ true
|
||||
+ } else {
|
||||
+ false
|
||||
+ }
|
||||
+ } else if let Some(path) = &builder.config.rust_profile_use {
|
||||
+ if compiler.stage == 1 {
|
||||
+ cargo.rustflag(&format!("-Cprofile-use={path}"));
|
||||
+ if builder.is_verbose() {
|
||||
+ cargo.rustflag("-Cllvm-args=-pgo-warn-missing-function");
|
||||
+ }
|
||||
+ true
|
||||
+ } else {
|
||||
+ false
|
||||
+ }
|
||||
+ } else {
|
||||
+ false
|
||||
+ };
|
||||
+ if is_collecting {
|
||||
+ // Ensure paths to Rust sources are relative, not absolute.
|
||||
+ cargo.rustflag(&format!(
|
||||
+ "-Cllvm-args=-static-func-strip-dirname-prefix={}",
|
||||
+ builder.config.src.components().count()
|
||||
+ ));
|
||||
+ }
|
||||
+
|
||||
+ rustc_cargo_env(builder, cargo, target, compiler.stage);
|
||||
}
|
||||
|
||||
pub fn rustc_cargo_env(
|
||||
diff --git a/src/bootstrap/src/core/build_steps/doc.rs b/src/bootstrap/src/core/build_steps/doc.rs
|
||||
index 57e63927c95e..e10035f07c05 100644
|
||||
--- a/src/bootstrap/src/core/build_steps/doc.rs
|
||||
+++ b/src/bootstrap/src/core/build_steps/doc.rs
|
||||
@@ -794,7 +794,7 @@ fn run(self, builder: &Builder<'_>) {
|
||||
cargo.rustdocflag("-Znormalize-docs");
|
||||
cargo.rustdocflag("--show-type-layout");
|
||||
cargo.rustdocflag("--generate-link-to-definition");
|
||||
- compile::rustc_cargo(builder, &mut cargo, target, compiler.stage);
|
||||
+ compile::rustc_cargo(builder, &mut cargo, target, &compiler);
|
||||
cargo.arg("-Zunstable-options");
|
||||
cargo.arg("-Zskip-rustdoc-fingerprint");
|
||||
|
||||
diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs
|
||||
index 04728e2e00dc..c4fdda0a2606 100644
|
||||
--- a/src/bootstrap/src/core/build_steps/test.rs
|
||||
+++ b/src/bootstrap/src/core/build_steps/test.rs
|
||||
@@ -2558,7 +2558,7 @@ fn run(self, builder: &Builder<'_>) {
|
||||
}
|
||||
}
|
||||
Mode::Rustc => {
|
||||
- compile::rustc_cargo(builder, &mut cargo, target, compiler.stage);
|
||||
+ compile::rustc_cargo(builder, &mut cargo, target, &compiler);
|
||||
}
|
||||
_ => panic!("can only test libraries"),
|
||||
};
|
||||
--
|
||||
2.44.0
|
||||
|
57
rust.spec
57
rust.spec
@ -1,6 +1,6 @@
|
||||
Name: rust
|
||||
Version: 1.77.0
|
||||
Release: 2%{?dist}
|
||||
Release: 3%{?dist}
|
||||
Summary: The Rust Programming Language
|
||||
License: (Apache-2.0 OR MIT) AND (Artistic-2.0 AND BSD-3-Clause AND ISC AND MIT AND MPL-2.0 AND Unicode-DFS-2016)
|
||||
# ^ written as: (rust itself) and (bundled libraries)
|
||||
@ -144,6 +144,9 @@ Patch6: rustc-1.77.0-unbundle-sqlite.patch
|
||||
Patch7: 120529.patch
|
||||
Patch8: 121088.patch
|
||||
|
||||
# https://github.com/rust-lang/rust/pull/123520
|
||||
Patch9: 0001-bootstrap-move-all-of-rustc-s-flags-to-rustc_cargo.patch
|
||||
|
||||
### RHEL-specific patches below ###
|
||||
|
||||
# Simple rpm macros for rust-toolset (as opposed to full rust-packaging)
|
||||
@ -603,9 +606,9 @@ rm -rf %{wasi_libc_dir}/dlmalloc/
|
||||
%patch -P5 -p1
|
||||
%endif
|
||||
%patch -P6 -p1
|
||||
|
||||
%patch -P7 -p1
|
||||
%patch -P8 -p1
|
||||
%patch -P9 -p1
|
||||
|
||||
%if %with disabled_libssh2
|
||||
%patch -P100 -p1
|
||||
@ -775,31 +778,32 @@ test -r "%{profiler}"
|
||||
--release-description="%{?fedora:Fedora }%{?rhel:Red Hat }%{version}-%{release}"
|
||||
|
||||
%global __x %{__python3} ./x.py
|
||||
%global __xk %{__x} --keep-stage=0 --keep-stage=1
|
||||
|
||||
%if %with rustc_pgo
|
||||
# Build the compiler with profile instrumentation
|
||||
PROFRAW="$PWD/build/profiles"
|
||||
PROFDATA="$PWD/build/rustc.profdata"
|
||||
mkdir -p "$PROFRAW"
|
||||
%{__x} build -j "$ncpus" sysroot --rust-profile-generate="$PROFRAW"
|
||||
%define profraw $PWD/build/profiles
|
||||
%define profdata $PWD/build/rustc.profdata
|
||||
mkdir -p "%{profraw}"
|
||||
%{__x} build -j "$ncpus" sysroot --rust-profile-generate="%{profraw}"
|
||||
# Build cargo as a workload to generate compiler profiles
|
||||
env LLVM_PROFILE_FILE="$PROFRAW/default_%%m_%%p.profraw" %{__xk} build cargo
|
||||
llvm-profdata merge -o "$PROFDATA" "$PROFRAW"
|
||||
rm -r "$PROFRAW" build/%{rust_triple}/stage2*/
|
||||
# Rebuild the compiler using the profile data
|
||||
%{__x} build -j "$ncpus" sysroot --rust-profile-use="$PROFDATA"
|
||||
%else
|
||||
# Build the compiler without PGO
|
||||
%{__x} build -j "$ncpus" sysroot
|
||||
env LLVM_PROFILE_FILE="%{profraw}/default_%%m_%%p.profraw" \
|
||||
%{__x} --keep-stage=0 --keep-stage=1 build cargo
|
||||
# Finalize the profile data and clean up the raw files
|
||||
llvm-profdata merge -o "%{profdata}" "%{profraw}"
|
||||
rm -r "%{profraw}" build/%{rust_triple}/stage2*/
|
||||
# Redefine the macro to use that profile data from now on
|
||||
%global __x %{__x} --rust-profile-use="%{profdata}"
|
||||
%endif
|
||||
|
||||
# Build the compiler normally (with or without PGO)
|
||||
%{__x} build -j "$ncpus" sysroot
|
||||
|
||||
# Build everything else normally
|
||||
%{__xk} build
|
||||
%{__xk} doc
|
||||
%{__x} build
|
||||
%{__x} doc
|
||||
|
||||
for triple in %{?all_targets} ; do
|
||||
%{__xk} build --target=$triple std
|
||||
%{__x} build --target=$triple std
|
||||
done
|
||||
|
||||
%install
|
||||
@ -808,10 +812,10 @@ done
|
||||
%endif
|
||||
%{export_rust_env}
|
||||
|
||||
DESTDIR=%{buildroot} %{__xk} install
|
||||
DESTDIR=%{buildroot} %{__x} install
|
||||
|
||||
for triple in %{?all_targets} ; do
|
||||
DESTDIR=%{buildroot} %{__xk} install --target=$triple std
|
||||
DESTDIR=%{buildroot} %{__x} install --target=$triple std
|
||||
done
|
||||
|
||||
# The rls stub doesn't have an install target, but we can just copy it.
|
||||
@ -924,17 +928,17 @@ rm -rf "$TMP_HELLO"
|
||||
|
||||
# Bootstrap is excluded because it's not something we ship, and a lot of its
|
||||
# tests are geared toward the upstream CI environment.
|
||||
%{__xk} test --no-fail-fast --skip src/bootstrap || :
|
||||
%{__x} test --no-fail-fast --skip src/bootstrap || :
|
||||
rm -rf "./build/%{rust_triple}/test/"
|
||||
|
||||
%{__xk} test --no-fail-fast cargo || :
|
||||
%{__x} test --no-fail-fast cargo || :
|
||||
rm -rf "./build/%{rust_triple}/stage2-tools/%{rust_triple}/cit/"
|
||||
|
||||
%{__xk} test --no-fail-fast clippy || :
|
||||
%{__x} test --no-fail-fast clippy || :
|
||||
|
||||
%{__xk} test --no-fail-fast rust-analyzer || :
|
||||
%{__x} test --no-fail-fast rust-analyzer || :
|
||||
|
||||
%{__xk} test --no-fail-fast rustfmt || :
|
||||
%{__x} test --no-fail-fast rustfmt || :
|
||||
|
||||
|
||||
%ldconfig_scriptlets
|
||||
@ -1084,6 +1088,9 @@ rm -rf "./build/%{rust_triple}/stage2-tools/%{rust_triple}/cit/"
|
||||
|
||||
|
||||
%changelog
|
||||
* Fri Apr 05 2024 Josh Stone <jistone@redhat.com> - 1.77.0-3
|
||||
- Ensure more consistency in PGO flags -- fixes Cargo tests
|
||||
|
||||
* Thu Mar 21 2024 Davide Cavalca <dcavalca@fedoraproject.org> - 1.77.0-2
|
||||
- Add build target for aarch64-unknown-none-softfloat
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user