From 6fd83ea5e57ee593f774d24ffe90c87a9cf3b51c Mon Sep 17 00:00:00 2001 From: ognevnydemon Date: Sun, 20 Jul 2025 20:19:11 +0300 Subject: [PATCH] opt-dist: change build_dir field to be an actual build dir make it configurable so users can set build.build-dir option in bootstrap.toml --- src/tools/opt-dist/src/environment.rs | 2 +- src/tools/opt-dist/src/exec.rs | 4 ++-- src/tools/opt-dist/src/main.rs | 12 +++++++++--- src/tools/opt-dist/src/tests.rs | 2 +- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/tools/opt-dist/src/environment.rs b/src/tools/opt-dist/src/environment.rs index d41dc80e6b2af..e6e4c711c0cb3 100644 --- a/src/tools/opt-dist/src/environment.rs +++ b/src/tools/opt-dist/src/environment.rs @@ -48,7 +48,7 @@ impl Environment { } pub fn build_artifacts(&self) -> Utf8PathBuf { - self.build_root().join("build").join(&self.host_tuple) + self.build_root().join(&self.host_tuple) } pub fn artifact_dir(&self) -> Utf8PathBuf { diff --git a/src/tools/opt-dist/src/exec.rs b/src/tools/opt-dist/src/exec.rs index 56eff2ca2a7df..a8d4c93d160cc 100644 --- a/src/tools/opt-dist/src/exec.rs +++ b/src/tools/opt-dist/src/exec.rs @@ -99,7 +99,7 @@ pub struct Bootstrap { impl Bootstrap { pub fn build(env: &Environment) -> Self { - let metrics_path = env.build_root().join("build").join("metrics.json"); + let metrics_path = env.build_root().join("metrics.json"); let cmd = cmd(&[ env.python_binary(), env.checkout_path().join("x.py").as_str(), @@ -119,7 +119,7 @@ impl Bootstrap { } pub fn dist(env: &Environment, dist_args: &[String]) -> Self { - let metrics_path = env.build_root().join("build").join("metrics.json"); + let metrics_path = env.build_root().join("metrics.json"); let args = dist_args.iter().map(|arg| arg.as_str()).collect::>(); let cmd = cmd(&args).env("RUST_BACKTRACE", "full"); let mut cmd = add_shared_x_flags(env, cmd); diff --git a/src/tools/opt-dist/src/main.rs b/src/tools/opt-dist/src/main.rs index 7857f196626bc..d0e6badede6e7 100644 --- a/src/tools/opt-dist/src/main.rs +++ b/src/tools/opt-dist/src/main.rs @@ -102,6 +102,11 @@ enum EnvironmentCmd { /// Will be LLVM built during the run? #[arg(long, default_value_t = true, action(clap::ArgAction::Set))] build_llvm: bool, + + /// Set build artifacts dir. Relative to `checkout_dir`, should point to the directory set + /// in bootstrap.toml via `build.build-dir` option + #[arg(long, default_value = "build")] + build_dir: Utf8PathBuf, }, /// Perform an optimized build on Linux CI, from inside Docker. LinuxCi { @@ -138,6 +143,7 @@ fn create_environment(args: Args) -> anyhow::Result<(Environment, Vec)> shared, run_tests, build_llvm, + build_dir, } => { let env = EnvironmentBuilder::default() .host_tuple(target_triple) @@ -145,7 +151,7 @@ fn create_environment(args: Args) -> anyhow::Result<(Environment, Vec)> .checkout_dir(checkout_dir.clone()) .host_llvm_dir(llvm_dir) .artifact_dir(artifact_dir) - .build_dir(checkout_dir) + .build_dir(checkout_dir.join(build_dir)) .prebuilt_rustc_perf(rustc_perf_checkout_dir) .shared_llvm(llvm_shared) .use_bolt(use_bolt) @@ -171,7 +177,7 @@ fn create_environment(args: Args) -> anyhow::Result<(Environment, Vec)> .checkout_dir(checkout_dir.clone()) .host_llvm_dir(Utf8PathBuf::from("/rustroot")) .artifact_dir(Utf8PathBuf::from("/tmp/tmp-multistage/opt-artifacts")) - .build_dir(checkout_dir.join("obj")) + .build_dir(checkout_dir.join("obj").join("build")) .shared_llvm(true) // FIXME: Enable bolt for aarch64 once it's fixed upstream. Broken as of December 2024. .use_bolt(!is_aarch64) @@ -194,7 +200,7 @@ fn create_environment(args: Args) -> anyhow::Result<(Environment, Vec)> .checkout_dir(checkout_dir.clone()) .host_llvm_dir(checkout_dir.join("citools").join("clang-rust")) .artifact_dir(checkout_dir.join("opt-artifacts")) - .build_dir(checkout_dir) + .build_dir(checkout_dir.join("build")) .shared_llvm(false) .use_bolt(false) .skipped_tests(vec![]) diff --git a/src/tools/opt-dist/src/tests.rs b/src/tools/opt-dist/src/tests.rs index 2d2aab86eda3c..c3c45d262dde1 100644 --- a/src/tools/opt-dist/src/tests.rs +++ b/src/tools/opt-dist/src/tests.rs @@ -13,7 +13,7 @@ pub fn run_tests(env: &Environment) -> anyhow::Result<()> { // and then use that extracted rustc as a stage0 compiler. // Then we run a subset of tests using that compiler, to have a basic smoke test which checks // whether the optimization pipeline hasn't broken something. - let build_dir = env.build_root().join("build"); + let build_dir = env.build_root(); let dist_dir = build_dir.join("dist"); let unpacked_dist_dir = build_dir.join("unpacked-dist"); std::fs::create_dir_all(&unpacked_dist_dir)?;