Skip to content

Conversation

MikeMcQuaid
Copy link
Member

@MikeMcQuaid MikeMcQuaid commented Aug 5, 2025

Summary

Implementation Details

  • Added rustc_wrapper shim in shims/super/ that clears RUSTFLAGS and prepends HOMEBREW_RUSTFLAGS
  • Updated both std and super environments to use RUSTC_WRAPPER pointing to the shim
  • Changed from setting RUSTFLAGS to HOMEBREW_RUSTFLAGS to avoid direct environment conflicts

Test plan

  • Test building Rust formulae that previously failed due to RUSTFLAGS conflicts
  • Verify optimization flags are still applied when appropriate
  • Ensure .cargo/config.toml settings are respected

🤖 Generated with Claude Code

Copy link
Member

@p-linnane p-linnane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks!

Copy link
Member

@carlocab carlocab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems worth a try, but note that some formulae builds also set RUSTC_WRAPPER, and it's not clear how those will interact with this.

As mentioned below, probably also worth actually testing on a Rust build first before merging.

@MikeMcQuaid
Copy link
Member Author

Seems worth a try, but note that some formulae builds also set RUSTC_WRAPPER, and it's not clear how those will interact with this.

@carlocab How would you suggest we solve this without using RUSTC_WRAPPER?

It might also be worth adding RUSTFLAGS here too, so that formulae can do

My reading of #18556 is that this would just result in that issue not being fixed because then the formula would be overriding .cargo/config.toml rather than superenv/stdenv.

It sounds instead like we should actively discourage ever setting RUSTFLAGS in a formula (perhaps with an audit/rubocop) for that reason as it will prevent upstream projects from reliably setting RUSTFLAGS

@carlocab
Copy link
Member

carlocab commented Aug 6, 2025

Seems worth a try, but note that some formulae builds also set RUSTC_WRAPPER, and it's not clear how those will interact with this.

@carlocab How would you suggest we solve this without using RUSTC_WRAPPER?

We could try CARGO_ENCODED_RUSTFLAGS, but that's not necessarily guaranteed to be safer.

We may not even need to solve this, as I did say I don't know how the interaction would happen (and it could happen entirely favourably).

My reading of #18556 is that this would just result in that issue not being fixed because then the formula would be overriding .cargo/config.toml rather than superenv/stdenv.

It sounds instead like we should actively discourage ever setting RUSTFLAGS in a formula (perhaps with an audit/rubocop) for that reason as it will prevent upstream projects from reliably setting RUSTFLAGS

Yes, point taken. Formulae will have to work with HOMEBREW_RUSTFLAGS instead. I only suggested this initially because we don't like it when formulae touch HOMEBREW_* environment variables because they're meant to be implementation details. Maybe, instead, formulae can use

ENV.rustflags

instead? With methods like

ENV.rustflags << "..."

for appending, etc.

@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue Aug 6, 2025
@MikeMcQuaid MikeMcQuaid removed this pull request from the merge queue due to a manual request Aug 6, 2025
@MikeMcQuaid
Copy link
Member Author

Thanks for review @carlocab. Adjusted based on your comments and added ENV.append_rustflags for use in formulae. Tested locally with some Rust formulae and all seems to be working as expected. Opening homebrew/core PR after this is merged.

@MikeMcQuaid MikeMcQuaid enabled auto-merge August 6, 2025 16:00
Copy link
Member

@carlocab carlocab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Fixes #18556 by using RUSTC_WRAPPER instead of setting RUSTFLAGS directly.
This allows Homebrew's optimization flags to coexist with .cargo/config.toml
settings, preventing build failures when projects have their own Rust
configuration.

- Add rustc_wrapper shim that clears RUSTFLAGS and prepends HOMEBREW_RUSTFLAGS
- Update both std and super environments to use RUSTC_WRAPPER
- Store Homebrew's rustflags in HOMEBREW_RUSTFLAGS instead of RUSTFLAGS

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-authored-by: Carlo Cabrera <github@carlo.cab>
@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue Aug 6, 2025
Merged via the queue into main with commit 2bc10f6 Aug 6, 2025
36 checks passed
@MikeMcQuaid MikeMcQuaid deleted the rustc_wrapper branch August 6, 2025 16:39
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.

RUSTFLAGS override .cargo/config.toml and result in manual workarounds
3 participants