Skip to content

Commit 20bb3ba

Browse files
committed
feat: new arg --cargo-config for passing --config to cargo
This is another step toward making opt-dist work in sandboxed environments. `--cargo-config` is added to the following subcommands: * `binary_stats compile` * `bench_runtime_local` * `bench_local` * `profile_local` The current rustc-perf uses `tempfile::Tempdir` as the working directory when collecting profiles from some of these packages. This "tmp" working directory usage make it impossible for Cargo to pick up the correct vendor sources setting in `.cargo/config.toml` bundled in the rustc-src tarball. We can leverage [`cargo --config`][1] to specify additional Cargo's configuration. Training data then could build with correct vendored settings via the `--cargo-config` flag. [1]: https://doc.rust-lang.org/nightly/cargo/commands/cargo.html#option-cargo---config
1 parent 892c681 commit 20bb3ba

File tree

5 files changed

+29
-10
lines changed

5 files changed

+29
-10
lines changed

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)