Skip to content
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

Added SpirvBuilder API to set extra codegen arguments #998

Merged
merged 3 commits into from
Mar 14, 2023
Merged
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions crates/spirv-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ pub struct SpirvBuilder {
spirv_metadata: SpirvMetadata,
capabilities: Vec<Capability>,
extensions: Vec<String>,
extra_args: Vec<String>,

// spirv-val flags
pub relax_struct_store: bool,
Expand All @@ -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,
Expand Down Expand Up @@ -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<String>) -> 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<CompileResult, SpirvBuilderError> {
Expand Down Expand Up @@ -475,6 +485,8 @@ fn invoke_rustc(builder: &SpirvBuilder) -> Result<PathBuf, SpirvBuilderError> {

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, " ");
Expand Down