diff --git a/Library/Homebrew/extend/ENV/std.rb b/Library/Homebrew/extend/ENV/std.rb index f03e56c86eecd..d61c75d7d3feb 100644 --- a/Library/Homebrew/extend/ENV/std.rb +++ b/Library/Homebrew/extend/ENV/std.rb @@ -34,7 +34,7 @@ def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_a self["PKG_CONFIG_LIBDIR"] = determine_pkg_config_libdir self["MAKEFLAGS"] = "-j#{make_jobs}" - self["RUSTFLAGS"] = Hardware.rustflags_target_cpu + self["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 diff --git a/Library/Homebrew/extend/ENV/super.rb b/Library/Homebrew/extend/ENV/super.rb index 6be9069013ebd..b3629b790b585 100644 --- a/Library/Homebrew/extend/ENV/super.rb +++ b/Library/Homebrew/extend/ENV/super.rb @@ -62,7 +62,7 @@ def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_a self["HOMEBREW_ENV"] = "super" self["MAKEFLAGS"] ||= "-j#{determine_make_jobs}" - self["RUSTFLAGS"] = Hardware.rustflags_target_cpu + self["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 diff --git a/Library/Homebrew/hardware.rb b/Library/Homebrew/hardware.rb index c5b1eab07d67f..1d50182560c46 100644 --- a/Library/Homebrew/hardware.rb +++ b/Library/Homebrew/hardware.rb @@ -226,16 +226,16 @@ def oldest_cpu(_version = nil) # Returns a Rust flag to set the target CPU if necessary. # Defaults to nil. - sig { returns(T.nilable(String)) } - def rustflags_target_cpu + sig { params(arch: Symbol).returns(T.nilable(String)) } + def rustflags_target_cpu(arch) # Rust already defaults to the oldest supported cpu for each target-triplet # so it's safe to ignore generic archs such as :armv6 here. # Rust defaults to apple-m1 since Rust 1.71 for aarch64-apple-darwin. - @target_cpu ||= case (cpu = oldest_cpu) + @target_cpu ||= case arch when :core :prescott when :native, :ivybridge, :sandybridge, :westmere, :nehalem, :core2 - cpu + arch end return if @target_cpu.blank?