From 17ff16f645c407aa97d27778a9263a7613de3e71 Mon Sep 17 00:00:00 2001 From: Sylvester Hesp Date: Tue, 14 Mar 2023 14:39:12 +0100 Subject: [PATCH] Added SpirvBuilder API to set extra codegen arguments --- crates/spirv-builder/src/lib.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/spirv-builder/src/lib.rs b/crates/spirv-builder/src/lib.rs index 56fd9529f5..b76a05b2f1 100644 --- a/crates/spirv-builder/src/lib.rs +++ b/crates/spirv-builder/src/lib.rs @@ -159,6 +159,7 @@ pub struct SpirvBuilder { spirv_metadata: SpirvMetadata, capabilities: Vec, extensions: Vec, + extra_args: Vec, // spirv-val flags pub relax_struct_store: bool, @@ -184,6 +185,7 @@ impl SpirvBuilder { spirv_metadata: SpirvMetadata::None, capabilities: Vec::new(), extensions: Vec::new(), + extra_args: Vec::new(), relax_struct_store: false, relax_logical_pointer: false, @@ -304,6 +306,14 @@ impl SpirvBuilder { self } + /// Set additional "codegen arg". Note: the `RUSTGPU_CODEGEN_ARGS` environment variable + /// takes precedence over any set arguments using this function. + #[must_use] + pub fn extra_arg(mut self, arg: impl Into) -> Self { + self.extra_args.push(arg.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 { @@ -475,6 +485,8 @@ fn invoke_rustc(builder: &SpirvBuilder) -> Result { if let Ok(extra_codegen_args) = tracked_env_var_get("RUSTGPU_CODEGEN_ARGS") { llvm_args.extend(extra_codegen_args.split_whitespace().map(|s| s.to_string())); + } else { + llvm_args.extend(builder.extra_args.iter().cloned()); } let llvm_args = join_checking_for_separators(llvm_args, " ");