Skip to content

refactor(spirv-builder): split flag building out of invoke_rustc - #693

Closed
sorinirimies wants to merge 1 commit into
Rust-GPU:mainfrom
sorinirimies:refactor/spirv-builder-split-invoke-rustc
Closed

sorinirimies wants to merge 1 commit into
Rust-GPU:mainfrom
sorinirimies:refactor/spirv-builder-split-invoke-rustc

Conversation

@sorinirimies

Copy link
Copy Markdown

Summary

SpirvBuilder::invoke_rustc was ~270 lines mixing RUSTGPU_* env reads, flag building and running cargo, so the flag logic was only covered indirectly by difftests. Pure refactor, no behavior change.

 invoke_rustc
   validate crate path / target, find backend
-  build rustflags + llvm_args + target_features inline (~130 lines)
-  tracked_env_var_get(..) scattered through it
+  env_overrides = EnvOverrides { codegen_args, rustflags, cargoflags }  // read once, still rerun-if-env-changed
+  rustflags = self.rustflags(backend, &env_overrides)
+    ├── self.llvm_args(&env_overrides)   // -Cllvm-args
+    └── self.target_features()           // -Ctarget-feature
   resolve target dir, run cargo, parse output

Evidence

Same rustc invocation before/after — sky-shader via multibuilder with RUSTGPU_CARGOFLAGS=-v, diffing the Running \rustc --crate-name sky_shader ...`` line:

before: 89 args
after:  89 args
diff:   IDENTICAL

New tests::rustflags:

fixed_flags_start_with_the_backend                                    ok
silent_exit_has_no_llvm_args_or_target_features                       ok
builder_options_map_to_flags                                          ok
env_codegen_args_replace_extra_args_and_env_rustflags_are_appended    ok

cargo test -p spirv-builder --features watch,clap: 8 passed. Clippy -D warnings clean (watch,clap and --no-default-features).

Merge Danger

Door: two-way

Blast Radius: small — internal methods only; the only observable difference is that the three cargo:rerun-if-env-changed lines are now printed together before cargo runs.

`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.
@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