Skip to content

add SpirvBuilder::target_dir_path to set the target dir explicitly #223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion crates/spirv-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ pub struct SpirvBuilder {
rustc_codegen_spirv_location: Option<std::path::PathBuf>,
// Optional location of a known "target-spec" file
path_to_target_spec: Option<PathBuf>,
target_dir_path: Option<String>,

// `rustc_codegen_spirv::linker` codegen args
pub shader_panic_strategy: ShaderPanicStrategy,
Expand Down Expand Up @@ -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,

Expand Down Expand Up @@ -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<String>) -> 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<CompileResult, SpirvBuilderError> {
Expand Down Expand Up @@ -790,7 +800,14 @@ fn invoke_rustc(builder: &SpirvBuilder) -> Result<PathBuf, SpirvBuilderError> {
};
// 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" };

Expand Down