Skip to content

Commit 0a11dcf

Browse files
committed
feat(opt-dist): new flag --benchmark-cargo-config
The flag propagates cargo configs to `rustc-perf --cargo-config`, which is particularly useful when the environment is air-gapped, and you want to use the default set of training crates vendored in the rustc-src tarball.
1 parent e9c4eb3 commit 0a11dcf

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

src/tools/opt-dist/src/environment.rs

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ pub struct Environment {
1717
host_llvm_dir: Utf8PathBuf,
1818
/// List of test paths that should be skipped when testing the optimized artifacts.
1919
skipped_tests: Vec<String>,
20+
/// Arguments passed to `rustc-perf --cargo-config <value>` when running benchmarks.
21+
#[builder(default)]
22+
benchmark_cargo_config: Vec<String>,
2023
/// Directory containing a pre-built rustc-perf checkout.
2124
#[builder(default)]
2225
prebuilt_rustc_perf: Option<Utf8PathBuf>,
@@ -94,6 +97,10 @@ impl Environment {
9497
pub fn skipped_tests(&self) -> &[String] {
9598
&self.skipped_tests
9699
}
100+
101+
pub fn benchmark_cargo_config(&self) -> &[String] {
102+
&self.benchmark_cargo_config
103+
}
97104
}
98105

99106
/// What is the extension of binary executables on this platform?

src/tools/opt-dist/src/main.rs

+6
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ enum EnvironmentCmd {
9090

9191
#[clap(flatten)]
9292
shared: SharedArgs,
93+
94+
/// Arguments passed to `rustc-perf --cargo-config <value>` when running benchmarks.
95+
#[arg(long)]
96+
benchmark_cargo_config: Vec<String>,
9397
},
9498
/// Perform an optimized build on Linux CI, from inside Docker.
9599
LinuxCi {
@@ -119,6 +123,7 @@ fn create_environment(args: Args) -> anyhow::Result<(Environment, Vec<String>)>
119123
llvm_shared,
120124
use_bolt,
121125
skipped_tests,
126+
benchmark_cargo_config,
122127
shared,
123128
} => {
124129
let env = EnvironmentBuilder::default()
@@ -132,6 +137,7 @@ fn create_environment(args: Args) -> anyhow::Result<(Environment, Vec<String>)>
132137
.shared_llvm(llvm_shared)
133138
.use_bolt(use_bolt)
134139
.skipped_tests(skipped_tests)
140+
.benchmark_cargo_config(benchmark_cargo_config)
135141
.build()?;
136142

137143
(env, shared.build_args)

src/tools/opt-dist/src/training.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn init_compiler_benchmarks(
3636
// Run rustc-perf benchmarks
3737
// Benchmark using profile_local with eprintln, which essentially just means
3838
// don't actually benchmark -- just make sure we run rustc a bunch of times.
39-
cmd(&[
39+
let mut cmd = cmd(&[
4040
env.cargo_stage_0().as_str(),
4141
"run",
4242
"-p",
@@ -61,7 +61,17 @@ fn init_compiler_benchmarks(
6161
.env("RUST_LOG", "collector=debug")
6262
.env("RUSTC", env.rustc_stage_0().as_str())
6363
.env("RUSTC_BOOTSTRAP", "1")
64-
.workdir(&env.rustc_perf_dir())
64+
.workdir(&env.rustc_perf_dir());
65+
66+
// This propagates cargo configs to `rustc-perf --cargo-config`,
67+
// which is particularly useful when the environment is air-gapped,
68+
// and you want to use the default set of training crates vendored
69+
// in the rustc-src tarball.
70+
for config in env.benchmark_cargo_config() {
71+
cmd = cmd.arg("--cargo-config").arg(config);
72+
}
73+
74+
cmd
6575
}
6676

6777
/// Describes which `llvm-profdata` binary should be used for merging PGO profiles.

0 commit comments

Comments
 (0)