Skip to content

Commit eef51fe

Browse files
committed
remove target dir after successful rustc_codegen_spirv build, saves 200MiB
1 parent 3935805 commit eef51fe

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

crates/cargo-gpu/src/args.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ pub struct BuildArgs {
3737

3838
/// Args for an install
3939
#[derive(clap::Parser, Debug, Clone, serde::Deserialize, serde::Serialize)]
40+
#[expect(
41+
clippy::struct_excessive_bools,
42+
reason = "cmdline args have many bools"
43+
)]
4044
pub struct InstallArgs {
4145
/// path to the `rustc_codegen_spirv` dylib
4246
#[clap(long, hide(true), default_value = "INTERNALLY_SET")]
@@ -71,6 +75,11 @@ pub struct InstallArgs {
7175
#[clap(long, action)]
7276
pub auto_install_rust_toolchain: bool,
7377

78+
/// Clear target dir of `rustc_codegen_spirv` build after a successful build, saves about
79+
/// 200MiB of disk space.
80+
#[clap(long = "no-clear-target", default_value = "true", action = clap::ArgAction::SetFalse)]
81+
pub clear_target: bool,
82+
7483
/// There is a tricky situation where a shader crate that depends on workspace config can have
7584
/// a different `Cargo.lock` lockfile version from the the workspace's `Cargo.lock`. This can
7685
/// prevent builds when an old Rust toolchain doesn't recognise the newer lockfile version.

crates/cargo-gpu/src/install.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,18 @@ package = "rustc_codegen_spirv"
188188
})
189189
.context("running build command")?;
190190

191-
let dylib_path = checkout
192-
.join("target")
193-
.join("release")
194-
.join(&dylib_filename);
191+
let target = checkout.join("target");
192+
let dylib_path = target.join("release").join(&dylib_filename);
195193
if dylib_path.is_file() {
196194
log::info!("successfully built {}", dylib_path.display());
197195
if !source_is_path {
198196
std::fs::rename(&dylib_path, &dest_dylib_path)
199197
.context("renaming dylib path")?;
198+
199+
if self.spirv_install.clear_target {
200+
log::warn!("clearing target dir {}", target.display());
201+
std::fs::remove_dir_all(&target).context("clearing target dir")?;
202+
}
200203
}
201204
} else {
202205
log::error!("could not find {}", dylib_path.display());

0 commit comments

Comments
 (0)