Skip to content

Commit e6ba71c

Browse files
MikeMcQuaidclaudecarlocab
committed
Add rustc wrapper shim to fix RUSTFLAGS conflicts
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 <[email protected]> Co-authored-by: Carlo Cabrera <[email protected]>
1 parent 5e1fd26 commit e6ba71c

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

Library/Homebrew/extend/ENV/shared.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ def append_path(key, path)
113113
self[key] = PATH.new(self[key]).append(path)
114114
end
115115

116+
sig { params(rustflags: String).void }
117+
def append_to_rustflags(rustflags)
118+
append("HOMEBREW_RUSTFLAGS", rustflags)
119+
end
120+
116121
# Prepends a directory to `PATH`.
117122
# Is the formula struggling to find the pkgconfig file? Point it to it.
118123
# This is done automatically for keg-only formulae.

Library/Homebrew/extend/ENV/std.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_a
3434
self["PKG_CONFIG_LIBDIR"] = determine_pkg_config_libdir
3535

3636
self["MAKEFLAGS"] = "-j#{make_jobs}"
37-
self["RUSTFLAGS"] = Hardware.rustflags_target_cpu(effective_arch)
37+
self["RUSTC_WRAPPER"] = "#{HOMEBREW_SHIMS_PATH}/super/rustc_wrapper"
38+
self["HOMEBREW_RUSTFLAGS"] = Hardware.rustflags_target_cpu(effective_arch)
3839

3940
if HOMEBREW_PREFIX.to_s != "/usr/local"
4041
# /usr/local is already an -isystem and -L directory so we skip it

Library/Homebrew/extend/ENV/super.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_a
6262

6363
self["HOMEBREW_ENV"] = "super"
6464
self["MAKEFLAGS"] ||= "-j#{determine_make_jobs}"
65-
self["RUSTFLAGS"] = Hardware.rustflags_target_cpu(effective_arch)
65+
self["RUSTC_WRAPPER"] = "#{HOMEBREW_SHIMS_PATH}/super/rustc_wrapper"
66+
self["HOMEBREW_RUSTFLAGS"] = Hardware.rustflags_target_cpu(effective_arch)
6667
self["PATH"] = determine_path
6768
self["PKG_CONFIG_PATH"] = determine_pkg_config_path
6869
self["PKG_CONFIG_LIBDIR"] = determine_pkg_config_libdir || ""
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
# Prepend HOMEBREW_RUSTFLAGS to rustc arguments if set.
4+
# This allows Homebrew to pass optimization flags while still respecting
5+
# .cargo/config.toml (which sets RUSTFLAGS).
6+
7+
# rustc is passed as the first argument to RUSTC_WRAPPER
8+
# https://doc.rust-lang.org/cargo/reference/environment-variables.html
9+
RUSTC="${1}"
10+
shift
11+
12+
# Prepend HOMEBREW_RUSTFLAGS to the arguments if set.
13+
# HOMEBREW_RUSTFLAGS is set in extend/ENV/{std,super}.rb
14+
# shellcheck disable=SC2086,SC2154
15+
exec "${RUSTC}" ${HOMEBREW_RUSTFLAGS} "$@"

0 commit comments

Comments
 (0)