Skip to content

feat(spirv-builder): add RUSTGPU_ENCODED_RUSTFLAGS and RUSTGPU_ENCODED_CARGOFLAGS - #696

Closed
sorinirimies wants to merge 3 commits into
Rust-GPU:mainfrom
sorinirimies:feat/spirv-builder-encoded-env-flags
Closed

sorinirimies wants to merge 3 commits into
Rust-GPU:mainfrom
sorinirimies:feat/spirv-builder-encoded-env-flags

Conversation

@sorinirimies

Copy link
Copy Markdown

Stacked on #693 (uses its EnvOverrides); only the last commit is new here. Will rebase once #693 lands.

Summary

RUSTGPU_RUSTFLAGS and RUSTGPU_CARGOFLAGS are split on whitespace, so no flag can contain a space — e.g. --remap-path-prefix=/Users/me/My Projects=/src or a --config value. Cargo solved the same problem for RUSTFLAGS with CARGO_ENCODED_RUSTFLAGS; this mirrors it:

variable split on precedence
RUSTGPU_ENCODED_RUSTFLAGS \x1f wins over RUSTGPU_RUSTFLAGS
RUSTGPU_ENCODED_CARGOFLAGS \x1f wins over RUSTGPU_CARGOFLAGS

Empty encoded value = no flags (as in Cargo). Both new vars emit cargo:rerun-if-env-changed.

RUSTGPU_CODEGEN_ARGS gets no encoded variant: codegen args are passed space-joined in -Cllvm-args=..., so they can't contain spaces anyway.

 EnvOverrides {
-  rustflags:  Option<String>,         // split_whitespace at use site
-  cargoflags: Option<String>,
+  rustflags:  Option<Vec<String>>,    // split_env_flags(ENCODED, plain)
+  cargoflags: Option<Vec<String>>,
 }

Evidence

New tests::env_flags:

unset                                        ok
plain_splits_on_whitespace                   ok
encoded_keeps_spaces_and_takes_precedence    ok
empty_encoded_means_no_flags                 ok

cargo test -p spirv-builder --features watch,clap: 12 passed. Clippy -D warnings clean.

Merge Danger

Door: two-way (new opt-in env vars; easy to remove before a release)

Blast Radius: none unless the new variables are set.

Sorin Albu-Irimies added 3 commits November 7, 2026 16:26
`invoke_rustc` was ~270 lines mixing env var reads, flag building and
running cargo, so flag building was only tested through difftests.

- `RUSTGPU_*` env vars are read once into `EnvOverrides`.
- New pure `rustflags`, `llvm_args` and `target_features` methods,
  with unit tests.

No behavior change: the resulting rustc invocation is identical.
…D_CARGOFLAGS

`RUSTGPU_RUSTFLAGS` / `RUSTGPU_CARGOFLAGS` are split on whitespace, so a
single flag can't contain a space (e.g. a path). Like Cargo's
`CARGO_ENCODED_RUSTFLAGS`, the new `RUSTGPU_ENCODED_*` variants are split
on `\x1f` and take precedence over the plain ones.
@Firestar99 Firestar99 closed this Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants