Merge pull request #20380 from Homebrew/rustc_wrapper

Add rustc wrapper shim to fix RUSTFLAGS conflicts
This commit is contained in:
Mike McQuaid 2025-08-06 16:20:55 +00:00 committed by GitHub
commit 2bc10f6a52
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 24 additions and 2 deletions

View File

@ -113,6 +113,11 @@ module SharedEnvExtension
self[key] = PATH.new(self[key]).append(path)
end
sig { params(rustflags: String).void }
def append_to_rustflags(rustflags)
append("HOMEBREW_RUSTFLAGS", rustflags)
end
# Prepends a directory to `PATH`.
# Is the formula struggling to find the pkgconfig file? Point it to it.
# This is done automatically for keg-only formulae.

View File

@ -34,7 +34,8 @@ module Stdenv
self["PKG_CONFIG_LIBDIR"] = determine_pkg_config_libdir
self["MAKEFLAGS"] = "-j#{make_jobs}"
self["RUSTFLAGS"] = Hardware.rustflags_target_cpu(effective_arch)
self["RUSTC_WRAPPER"] = "#{HOMEBREW_SHIMS_PATH}/super/rustc_wrapper"
self["HOMEBREW_RUSTFLAGS"] = Hardware.rustflags_target_cpu(effective_arch)
if HOMEBREW_PREFIX.to_s != "/usr/local"
# /usr/local is already an -isystem and -L directory so we skip it

View File

@ -62,7 +62,8 @@ module Superenv
self["HOMEBREW_ENV"] = "super"
self["MAKEFLAGS"] ||= "-j#{determine_make_jobs}"
self["RUSTFLAGS"] = Hardware.rustflags_target_cpu(effective_arch)
self["RUSTC_WRAPPER"] = "#{HOMEBREW_SHIMS_PATH}/super/rustc_wrapper"
self["HOMEBREW_RUSTFLAGS"] = Hardware.rustflags_target_cpu(effective_arch)
self["PATH"] = determine_path
self["PKG_CONFIG_PATH"] = determine_pkg_config_path
self["PKG_CONFIG_LIBDIR"] = determine_pkg_config_libdir || ""

View File

@ -0,0 +1,15 @@
#!/bin/bash
# Prepend HOMEBREW_RUSTFLAGS to rustc arguments if set.
# This allows Homebrew to pass optimization flags while still respecting
# .cargo/config.toml (which sets RUSTFLAGS).
# rustc is passed as the first argument to RUSTC_WRAPPER
# https://doc.rust-lang.org/cargo/reference/environment-variables.html
RUSTC="${1}"
shift
# Prepend HOMEBREW_RUSTFLAGS to the arguments if set.
# HOMEBREW_RUSTFLAGS is set in extend/ENV/{std,super}.rb
# shellcheck disable=SC2086,SC2154
exec "${RUSTC}" ${HOMEBREW_RUSTFLAGS} "$@"