From 314242783ebfefe9d8fe0356d8e2a439a3e0bf63 Mon Sep 17 00:00:00 2001 From: Firestar99 Date: Sun, 30 Mar 2025 15:50:27 +0200 Subject: [PATCH] target_dir_path: add `SpirvBuilder::target_dir_path` to set the target dir explicitly --- crates/spirv-builder/src/lib.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/crates/spirv-builder/src/lib.rs b/crates/spirv-builder/src/lib.rs index 7d98ceaaa1..488f71508e 100644 --- a/crates/spirv-builder/src/lib.rs +++ b/crates/spirv-builder/src/lib.rs @@ -306,6 +306,7 @@ pub struct SpirvBuilder { rustc_codegen_spirv_location: Option, // Optional location of a known "target-spec" file path_to_target_spec: Option, + target_dir_path: Option, // `rustc_codegen_spirv::linker` codegen args pub shader_panic_strategy: ShaderPanicStrategy, @@ -337,6 +338,7 @@ impl SpirvBuilder { extra_args: Vec::new(), rustc_codegen_spirv_location: None, path_to_target_spec: None, + target_dir_path: None, shader_panic_strategy: ShaderPanicStrategy::SilentExit, @@ -514,6 +516,14 @@ impl SpirvBuilder { self } + /// Set the target dir path within `./target` to use for building shaders. Defaults to `spirv-builder`, resulting + /// in the path `./target/spirv-builder`. + #[must_use] + pub fn target_dir_path(mut self, name: impl Into) -> Self { + self.target_dir_path = Some(name.into()); + self + } + /// Builds the module. If `print_metadata` is [`MetadataPrintout::Full`], you usually don't have to inspect the path /// in the result, as the environment variable for the path to the module will already be set. pub fn build(mut self) -> Result { @@ -790,7 +800,14 @@ fn invoke_rustc(builder: &SpirvBuilder) -> Result { }; // FIXME(eddyb) use `crate metadata` to always be able to get the "outer" // (or "default") `--target-dir`, to append `/spirv-builder` to it. - let target_dir = outer_target_dir.map(|outer| outer.join("spirv-builder")); + let target_dir = outer_target_dir.map(|outer| { + outer.join( + builder + .target_dir_path + .as_deref() + .unwrap_or("spirv-builder"), + ) + }); let profile = if builder.release { "release" } else { "dev" };