Skip to content

Commit a6ccd77

Browse files
committed
target_dir_path: add SpirvBuilder::target_dir_path to set the target dir explicitly
1 parent 05042d1 commit a6ccd77

File tree

1 file changed

+18
-1
lines changed
  • crates/spirv-builder/src

1 file changed

+18
-1
lines changed

crates/spirv-builder/src/lib.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ pub struct SpirvBuilder {
306306
rustc_codegen_spirv_location: Option<std::path::PathBuf>,
307307
// Optional location of a known "target-spec" file
308308
path_to_target_spec: Option<PathBuf>,
309+
target_dir_path: Option<String>,
309310

310311
// `rustc_codegen_spirv::linker` codegen args
311312
pub shader_panic_strategy: ShaderPanicStrategy,
@@ -337,6 +338,7 @@ impl SpirvBuilder {
337338
extra_args: Vec::new(),
338339
rustc_codegen_spirv_location: None,
339340
path_to_target_spec: None,
341+
target_dir_path: None,
340342

341343
shader_panic_strategy: ShaderPanicStrategy::SilentExit,
342344

@@ -514,6 +516,14 @@ impl SpirvBuilder {
514516
self
515517
}
516518

519+
/// Set the target dir path within `./target` to use for building shaders. Defaults to `spirv-builder`, resulting
520+
/// in the path `./target/spirv-builder`.
521+
#[must_use]
522+
pub fn target_dir_path(mut self, name: impl Into<String>) -> Self {
523+
self.target_dir_path = Some(name.into());
524+
self
525+
}
526+
517527
/// Builds the module. If `print_metadata` is [`MetadataPrintout::Full`], you usually don't have to inspect the path
518528
/// in the result, as the environment variable for the path to the module will already be set.
519529
pub fn build(mut self) -> Result<CompileResult, SpirvBuilderError> {
@@ -790,7 +800,14 @@ fn invoke_rustc(builder: &SpirvBuilder) -> Result<PathBuf, SpirvBuilderError> {
790800
};
791801
// FIXME(eddyb) use `crate metadata` to always be able to get the "outer"
792802
// (or "default") `--target-dir`, to append `/spirv-builder` to it.
793-
let target_dir = outer_target_dir.map(|outer| outer.join("spirv-builder"));
803+
let target_dir = outer_target_dir.map(|outer| {
804+
outer.join(
805+
builder
806+
.target_dir_path
807+
.as_deref()
808+
.unwrap_or("spirv-builder"),
809+
)
810+
});
794811

795812
let profile = if builder.release { "release" } else { "dev" };
796813

0 commit comments

Comments
 (0)