From 066a88855ba817aefce3ddf79264a963a84a0bb1 Mon Sep 17 00:00:00 2001 From: Tokarak <63452145+Tokarak@users.noreply.github.com> Date: Tue, 13 Jun 2023 19:22:12 +0100 Subject: [PATCH] Add rustflags_target_cpu method --- Library/Homebrew/extend/os/mac/hardware.rb | 16 ++++++++++++++++ Library/Homebrew/hardware.rb | 12 ++++++++++++ 2 files changed, 28 insertions(+) diff --git a/Library/Homebrew/extend/os/mac/hardware.rb b/Library/Homebrew/extend/os/mac/hardware.rb index cbe49c8424..db7b4957b5 100644 --- a/Library/Homebrew/extend/os/mac/hardware.rb +++ b/Library/Homebrew/extend/os/mac/hardware.rb @@ -24,4 +24,20 @@ module Hardware generic_oldest_cpu end end + + # Override + # Mirrors version-dependent logic of oldest_cpu + sig { params(version: T.nilable(Version)).returns(String) } # FIXME: Version, String or Symbol? + def self.rustflags_target_cpu(version = nil) + version = if version + MacOSVersion.new(version.to_s) + else + MacOS.version + end + if Hardware::CPU.intel? && version >= :mojave + "-Ctarget-cpu=nehalem" + else + generic_rustflags_target_cpu + end + end end diff --git a/Library/Homebrew/hardware.rb b/Library/Homebrew/hardware.rb index 22bebf626b..1db819bbec 100644 --- a/Library/Homebrew/hardware.rb +++ b/Library/Homebrew/hardware.rb @@ -214,6 +214,18 @@ module Hardware end end alias generic_oldest_cpu oldest_cpu + + # Returns a _full_ rustflag to set target cpu, if necessary; + # Falls back to empty string + # This mirrors the logic of `oldest_cpu`, + # But only where it is version dependent. + # Rust already defaults to the oldest supported cpu for the target-triple + # Including apple-m1 since 1.71. + sig { params(_version: T.nilable(Version)).returns(String) } # FIXME: Version, String or Symbol? + def rustflags_target_cpu(_version = nil) + "" + end + alias generic_rustflags_target_cpu rustflags_target_cpu end end