Skip to content

Commit dd649a7

Browse files
authored
Merge pull request #1913 from weihanglo/cargo-config
feat: new arg `--cargo-config` for passing `--config` to cargo
2 parents 892c681 + 6973294 commit dd649a7

File tree

6 files changed

+35
-11
lines changed

6 files changed

+35
-11
lines changed

collector/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ The following options alter the behaviour of the `bench_local` subcommand.
115115
by `rustup` will be used. This is usually fine, though in rare cases it may
116116
cause local results to not exactly match production results, because Cargo
117117
sometimes begins passing (or stops passing) various flags to rustc.
118+
- `--cargo-config <CONFIG>`: a Cargo configuration value or a path to a Cargo
119+
configuration file. This flag can be specified multiple times, and will be
120+
passed to the Cargo executable as the value of the flag
121+
[`--config`](https://doc.rust-lang.org/nightly/cargo/commands/cargo.html#option-cargo---config).
118122
- `--db <DATABASE>`: a path (relative or absolute) to a sqlite database file in
119123
which the timing data will be placed. It will be created if it does not
120124
already exist. The default is `results.db`. Alternatively, the collector
@@ -195,7 +199,7 @@ and discover all benchmarks within them. If you only want to run benchmark(s) fr
195199
you can use this to speed up the runtime benchmarking or profiling commands.
196200

197201
The `bench_runtime_local` command also shares some options with the `bench_local` command, notably
198-
`--id`, `--db`, `--cargo`, `--include`, `--exclude` and `--iterations`.
202+
`--id`, `--db`, `--cargo`, `--cargo-config`, `--include`, `--exclude` and `--iterations`.
199203

200204
### How to view the measurements on your own machine
201205

@@ -465,6 +469,7 @@ fashion to the one chosen for `bench_local`.
465469

466470
The following options alter the behaviour of the `profile_local` subcommand.
467471
- `--cargo <CARGO>`: as for `bench_local`.
472+
- `--cargo-config <CONFIG>`: as for `bench_local`.
468473
- `--exclude <EXCLUDE>`: as for `bench_local`.
469474
- `--id <ID>`: an identifer that will form part of the output filenames.
470475
- `--include <INCLUDE>`: as for `bench_local`.

collector/src/artifact_stats.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ pub fn compile_and_get_stats(
164164

165165
let mut cmd = Command::new(&toolchain.components.cargo);
166166
cmd.arg("build").arg("--target-dir").arg(tempdir.path());
167+
for config in &toolchain.components.cargo_configs {
168+
cmd.arg("--config").arg(config);
169+
}
167170
match profile {
168171
CargoProfile::Debug => {}
169172
CargoProfile::Release => {

collector/src/bin/collector.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@ struct LocalOptions {
313313
#[arg(long)]
314314
cargo: Option<PathBuf>,
315315

316+
/// Arguments passed to `cargo --config <value>`.
317+
#[arg(long)]
318+
cargo_config: Vec<String>,
319+
316320
/// Exclude all benchmarks matching a prefix in this comma-separated list
317321
#[arg(long, value_delimiter = ',')]
318322
exclude: Vec<String>,
@@ -845,7 +849,7 @@ fn main_result() -> anyhow::Result<i32> {
845849
*ToolchainConfig::default()
846850
.rustdoc(opts.rustdoc.as_deref())
847851
.clippy(opts.clippy.as_deref())
848-
.cargo(local.cargo.as_deref())
852+
.cargo(local.cargo.as_deref(), local.cargo_config.as_slice())
849853
.id(local.id.as_deref()),
850854
"",
851855
target_triple,
@@ -1070,7 +1074,7 @@ fn main_result() -> anyhow::Result<i32> {
10701074
*ToolchainConfig::default()
10711075
.rustdoc(opts.rustdoc.as_deref())
10721076
.clippy(opts.clippy.as_deref())
1073-
.cargo(local.cargo.as_deref())
1077+
.cargo(local.cargo.as_deref(), local.cargo_config.as_slice())
10741078
.id(local.id.as_deref()),
10751079
suffix,
10761080
target_triple.clone(),
@@ -1228,7 +1232,7 @@ fn binary_stats_compile(
12281232
&[codegen_backend],
12291233
&local.rustc,
12301234
*ToolchainConfig::default()
1231-
.cargo(local.cargo.as_deref())
1235+
.cargo(local.cargo.as_deref(), local.cargo_config.as_slice())
12321236
.id(local.id.as_deref()),
12331237
"",
12341238
target_triple.to_string(),
@@ -1240,7 +1244,7 @@ fn binary_stats_compile(
12401244
&[codegen_backend2],
12411245
&rustc,
12421246
*ToolchainConfig::default()
1243-
.cargo(local.cargo.as_deref())
1247+
.cargo(local.cargo.as_deref(), local.cargo_config.as_slice())
12441248
.id(local.id.as_deref()),
12451249
"",
12461250
target_triple.to_string(),
@@ -1484,7 +1488,7 @@ fn get_local_toolchain_for_runtime_benchmarks(
14841488
&[CodegenBackend::Llvm],
14851489
&local.rustc,
14861490
*ToolchainConfig::default()
1487-
.cargo(local.cargo.as_deref())
1491+
.cargo(local.cargo.as_deref(), local.cargo_config.as_slice())
14881492
.id(local.id.as_deref()),
14891493
"",
14901494
target_triple.to_string(),

collector/src/compile/execute/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ impl<'a> CargoProcess<'a> {
180180
if let Some(c) = &self.toolchain.components.clippy {
181181
cmd.env("CLIPPY", &*FAKE_CLIPPY).env("CLIPPY_REAL", c);
182182
}
183+
184+
for config in &self.toolchain.components.cargo_configs {
185+
cmd.arg("--config").arg(config);
186+
}
183187
cmd
184188
}
185189

collector/src/runtime/benchmark.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,10 @@ fn start_cargo_build(
337337
#[cfg(feature = "precise-cachegrind")]
338338
command.arg("--features").arg("benchlib/precise-cachegrind");
339339

340+
for config in &toolchain.components.cargo_configs {
341+
command.arg("--config").arg(config);
342+
}
343+
340344
CargoArtifactIter::from_cargo_cmd(command)
341345
.map_err(|error| anyhow::anyhow!("Failed to start cargo: {:?}", error))
342346
}

collector/src/toolchain.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ pub struct ToolchainComponents {
253253
pub rustdoc: Option<PathBuf>,
254254
pub clippy: Option<PathBuf>,
255255
pub cargo: PathBuf,
256+
pub cargo_configs: Vec<String>,
256257
pub lib_rustc: Option<PathBuf>,
257258
pub lib_std: Option<PathBuf>,
258259
pub lib_test: Option<PathBuf>,
@@ -329,6 +330,8 @@ pub struct ToolchainConfig<'a> {
329330
rustdoc: Option<&'a Path>,
330331
clippy: Option<&'a Path>,
331332
cargo: Option<&'a Path>,
333+
/// For `cargo --config <value>`.
334+
cargo_configs: &'a [String],
332335
id: Option<&'a str>,
333336
}
334337

@@ -343,8 +346,9 @@ impl<'a> ToolchainConfig<'a> {
343346
self
344347
}
345348

346-
pub fn cargo(&mut self, cargo: Option<&'a Path>) -> &mut Self {
349+
pub fn cargo(&mut self, cargo: Option<&'a Path>, configs: &'a [String]) -> &mut Self {
347350
self.cargo = cargo;
351+
self.cargo_configs = configs;
348352
self
349353
}
350354

@@ -520,13 +524,13 @@ pub fn get_local_toolchain(
520524
debug!("found cargo: {:?}", &cargo);
521525
cargo
522526
};
523-
524527
let lib_dir = get_lib_dir_from_rustc(&rustc).context("Cannot find libdir for rustc")?;
525528

529+
let mut components =
530+
ToolchainComponents::from_binaries_and_libdir(rustc, rustdoc, clippy, cargo, &lib_dir)?;
531+
components.cargo_configs = toolchain_config.cargo_configs.to_vec();
526532
Ok(Toolchain {
527-
components: ToolchainComponents::from_binaries_and_libdir(
528-
rustc, rustdoc, clippy, cargo, &lib_dir,
529-
)?,
533+
components,
530534
id,
531535
triple: target_triple,
532536
})

0 commit comments

Comments
 (0)