Skip to content

Commit 792b719

Browse files
committed
remove target dir after successful rustc_codegen_spirv build, saves 200MiB
1 parent 961a78f commit 792b719

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

crates/cargo-gpu/src/args.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ pub struct InstallArgs {
7171
#[clap(long, action)]
7272
pub auto_install_rust_toolchain: bool,
7373

74+
/// Clear target dir of `rustc_codegen_spirv` build after a successful build, saves about
75+
/// 200MiB of disk space.
76+
#[clap(long = "no-clear-target", default_value = "true", action = clap::ArgAction::SetFalse)]
77+
pub clear_target: bool,
78+
7479
/// There is a tricky situation where a shader crate that depends on workspace config can have
7580
/// a different `Cargo.lock` lockfile version from the the workspace's `Cargo.lock`. This can
7681
/// 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)