From 374c734d9b3f8e6fa20810ad4d049ca2711e2156 Mon Sep 17 00:00:00 2001 From: Claudia Date: Wed, 8 Jul 2020 20:53:10 +0200 Subject: [PATCH] Make `Hardware.oldest_cpu` depend on architecture Starting with Xcode 12 Beta 2, builds that used to work on Apple Silicon now break due to `Hardware#oldest_cpu` returning `:nehalem` [1]. This commit is the first in a series of improvements to `Hardware#oldest_cpu`. It resolves the Xcode 12 Beta 2 issue for now. [1]: https://github.com/Homebrew/brew/issues/7857#issuecomment-655536261 --- Library/Homebrew/extend/os/mac/hardware.rb | 4 +++- Library/Homebrew/hardware.rb | 17 +++++++++-------- Library/Homebrew/os/mac/version.rb | 4 ++++ Library/Homebrew/test/os/mac/version_spec.rb | 1 + 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/extend/os/mac/hardware.rb b/Library/Homebrew/extend/os/mac/hardware.rb index b41439350f..c1edebfa6d 100644 --- a/Library/Homebrew/extend/os/mac/hardware.rb +++ b/Library/Homebrew/extend/os/mac/hardware.rb @@ -2,7 +2,9 @@ module Hardware def self.oldest_cpu(version = MacOS.version) - if version >= :mojave + if CPU.arch == :arm64 + :arm_vortex_tempest + elsif version >= :mojave :nehalem else generic_oldest_cpu diff --git a/Library/Homebrew/hardware.rb b/Library/Homebrew/hardware.rb index e056439d54..789b34fb9c 100644 --- a/Library/Homebrew/hardware.rb +++ b/Library/Homebrew/hardware.rb @@ -12,14 +12,15 @@ module Hardware class << self def optimization_flags @optimization_flags ||= { - native: arch_flag("native"), - nehalem: "-march=nehalem", - core2: "-march=core2", - core: "-march=prescott", - armv6: "-march=armv6", - armv8: "-march=armv8-a", - ppc64: "-mcpu=powerpc64", - ppc64le: "-mcpu=powerpc64le", + native: arch_flag("native"), + nehalem: "-march=nehalem", + core2: "-march=core2", + core: "-march=prescott", + arm_vortex_tempest: "", + armv6: "-march=armv6", + armv8: "-march=armv8-a", + ppc64: "-mcpu=powerpc64", + ppc64le: "-mcpu=powerpc64le", }.freeze end alias generic_optimization_flags optimization_flags diff --git a/Library/Homebrew/os/mac/version.rb b/Library/Homebrew/os/mac/version.rb index 23bf6b178c..f80c225744 100644 --- a/Library/Homebrew/os/mac/version.rb +++ b/Library/Homebrew/os/mac/version.rb @@ -43,6 +43,10 @@ module OS # For OS::Mac::Version compatibility def requires_nehalem_cpu? + unless Hardware::CPU.intel? + raise "Unexpected architecture: #{Hardware::CPU.arch}. This only works with Intel architecture." + end + Hardware.oldest_cpu(self) == :nehalem end # https://en.wikipedia.org/wiki/Nehalem_(microarchitecture) diff --git a/Library/Homebrew/test/os/mac/version_spec.rb b/Library/Homebrew/test/os/mac/version_spec.rb index 1d57fdbe0d..40c51974cb 100644 --- a/Library/Homebrew/test/os/mac/version_spec.rb +++ b/Library/Homebrew/test/os/mac/version_spec.rb @@ -50,6 +50,7 @@ describe OS::Mac::Version do end specify "#requires_nehalem_cpu?" do + expect(Hardware::CPU).to receive(:type).at_least(:twice).and_return(:intel) expect(described_class.new("10.14").requires_nehalem_cpu?).to be true expect(described_class.new("10.12").requires_nehalem_cpu?).to be false end