diff --git a/collector/README.md b/collector/README.md index 9241cda2a..4a14d6c37 100644 --- a/collector/README.md +++ b/collector/README.md @@ -115,6 +115,10 @@ The following options alter the behaviour of the `bench_local` subcommand. by `rustup` will be used. This is usually fine, though in rare cases it may cause local results to not exactly match production results, because Cargo sometimes begins passing (or stops passing) various flags to rustc. +- `--cargo-config `: a Cargo configuration value or a path to a Cargo + configuration file. This flag can be specified multiple times, and will be + passed to the Cargo executable as the value of the flag + [`--config`](https://doc.rust-lang.org/nightly/cargo/commands/cargo.html#option-cargo---config). - `--db `: a path (relative or absolute) to a sqlite database file in which the timing data will be placed. It will be created if it does not 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 you can use this to speed up the runtime benchmarking or profiling commands. The `bench_runtime_local` command also shares some options with the `bench_local` command, notably -`--id`, `--db`, `--cargo`, `--include`, `--exclude` and `--iterations`. +`--id`, `--db`, `--cargo`, `--cargo-config`, `--include`, `--exclude` and `--iterations`. ### How to view the measurements on your own machine @@ -465,6 +469,7 @@ fashion to the one chosen for `bench_local`. The following options alter the behaviour of the `profile_local` subcommand. - `--cargo `: as for `bench_local`. +- `--cargo-config `: as for `bench_local`. - `--exclude `: as for `bench_local`. - `--id `: an identifer that will form part of the output filenames. - `--include `: as for `bench_local`. diff --git a/collector/src/artifact_stats.rs b/collector/src/artifact_stats.rs index ea2d7912e..723609caf 100644 --- a/collector/src/artifact_stats.rs +++ b/collector/src/artifact_stats.rs @@ -164,6 +164,9 @@ pub fn compile_and_get_stats( let mut cmd = Command::new(&toolchain.components.cargo); cmd.arg("build").arg("--target-dir").arg(tempdir.path()); + for config in &toolchain.components.cargo_configs { + cmd.arg("--config").arg(config); + } match profile { CargoProfile::Debug => {} CargoProfile::Release => { diff --git a/collector/src/bin/collector.rs b/collector/src/bin/collector.rs index f0a419031..3f4e0767d 100644 --- a/collector/src/bin/collector.rs +++ b/collector/src/bin/collector.rs @@ -313,6 +313,10 @@ struct LocalOptions { #[arg(long)] cargo: Option, + /// Arguments passed to `cargo --config `. + #[arg(long)] + cargo_config: Vec, + /// Exclude all benchmarks matching a prefix in this comma-separated list #[arg(long, value_delimiter = ',')] exclude: Vec, @@ -845,7 +849,7 @@ fn main_result() -> anyhow::Result { *ToolchainConfig::default() .rustdoc(opts.rustdoc.as_deref()) .clippy(opts.clippy.as_deref()) - .cargo(local.cargo.as_deref()) + .cargo(local.cargo.as_deref(), local.cargo_config.as_slice()) .id(local.id.as_deref()), "", target_triple, @@ -1070,7 +1074,7 @@ fn main_result() -> anyhow::Result { *ToolchainConfig::default() .rustdoc(opts.rustdoc.as_deref()) .clippy(opts.clippy.as_deref()) - .cargo(local.cargo.as_deref()) + .cargo(local.cargo.as_deref(), local.cargo_config.as_slice()) .id(local.id.as_deref()), suffix, target_triple.clone(), @@ -1228,7 +1232,7 @@ fn binary_stats_compile( &[codegen_backend], &local.rustc, *ToolchainConfig::default() - .cargo(local.cargo.as_deref()) + .cargo(local.cargo.as_deref(), local.cargo_config.as_slice()) .id(local.id.as_deref()), "", target_triple.to_string(), @@ -1240,7 +1244,7 @@ fn binary_stats_compile( &[codegen_backend2], &rustc, *ToolchainConfig::default() - .cargo(local.cargo.as_deref()) + .cargo(local.cargo.as_deref(), local.cargo_config.as_slice()) .id(local.id.as_deref()), "", target_triple.to_string(), @@ -1484,7 +1488,7 @@ fn get_local_toolchain_for_runtime_benchmarks( &[CodegenBackend::Llvm], &local.rustc, *ToolchainConfig::default() - .cargo(local.cargo.as_deref()) + .cargo(local.cargo.as_deref(), local.cargo_config.as_slice()) .id(local.id.as_deref()), "", target_triple.to_string(), diff --git a/collector/src/compile/execute/mod.rs b/collector/src/compile/execute/mod.rs index 9bb71dbf3..a6d26ac6b 100644 --- a/collector/src/compile/execute/mod.rs +++ b/collector/src/compile/execute/mod.rs @@ -180,6 +180,10 @@ impl<'a> CargoProcess<'a> { if let Some(c) = &self.toolchain.components.clippy { cmd.env("CLIPPY", &*FAKE_CLIPPY).env("CLIPPY_REAL", c); } + + for config in &self.toolchain.components.cargo_configs { + cmd.arg("--config").arg(config); + } cmd } diff --git a/collector/src/runtime/benchmark.rs b/collector/src/runtime/benchmark.rs index 81ce0eea5..3568b297d 100644 --- a/collector/src/runtime/benchmark.rs +++ b/collector/src/runtime/benchmark.rs @@ -337,6 +337,10 @@ fn start_cargo_build( #[cfg(feature = "precise-cachegrind")] command.arg("--features").arg("benchlib/precise-cachegrind"); + for config in &toolchain.components.cargo_configs { + command.arg("--config").arg(config); + } + CargoArtifactIter::from_cargo_cmd(command) .map_err(|error| anyhow::anyhow!("Failed to start cargo: {:?}", error)) } diff --git a/collector/src/toolchain.rs b/collector/src/toolchain.rs index 249693ebb..d7731afa3 100644 --- a/collector/src/toolchain.rs +++ b/collector/src/toolchain.rs @@ -253,6 +253,7 @@ pub struct ToolchainComponents { pub rustdoc: Option, pub clippy: Option, pub cargo: PathBuf, + pub cargo_configs: Vec, pub lib_rustc: Option, pub lib_std: Option, pub lib_test: Option, @@ -329,6 +330,8 @@ pub struct ToolchainConfig<'a> { rustdoc: Option<&'a Path>, clippy: Option<&'a Path>, cargo: Option<&'a Path>, + /// For `cargo --config `. + cargo_configs: &'a [String], id: Option<&'a str>, } @@ -343,8 +346,9 @@ impl<'a> ToolchainConfig<'a> { self } - pub fn cargo(&mut self, cargo: Option<&'a Path>) -> &mut Self { + pub fn cargo(&mut self, cargo: Option<&'a Path>, configs: &'a [String]) -> &mut Self { self.cargo = cargo; + self.cargo_configs = configs; self } @@ -520,13 +524,13 @@ pub fn get_local_toolchain( debug!("found cargo: {:?}", &cargo); cargo }; - let lib_dir = get_lib_dir_from_rustc(&rustc).context("Cannot find libdir for rustc")?; + let mut components = + ToolchainComponents::from_binaries_and_libdir(rustc, rustdoc, clippy, cargo, &lib_dir)?; + components.cargo_configs = toolchain_config.cargo_configs.to_vec(); Ok(Toolchain { - components: ToolchainComponents::from_binaries_and_libdir( - rustc, rustdoc, clippy, cargo, &lib_dir, - )?, + components, id, triple: target_triple, })