From 87158acfe0e72b30c0e55124a72668c08e0bcc93 Mon Sep 17 00:00:00 2001 From: Nazar <63452145+Tokarak@users.noreply.github.com> Date: Tue, 20 Jun 2023 23:44:25 +0100 Subject: [PATCH] Improve logic (code review) Co-authored-by: Mike McQuaid --- Library/Homebrew/hardware.rb | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/Library/Homebrew/hardware.rb b/Library/Homebrew/hardware.rb index 43ecb7268d..942915bd15 100644 --- a/Library/Homebrew/hardware.rb +++ b/Library/Homebrew/hardware.rb @@ -41,20 +41,6 @@ module Hardware end alias generic_optimization_flags optimization_flags - # Rust already defaults to the oldest supported cpu for each target-triple - # so it's safe to ignore generic archs such as :armv6, etc., here. - # Rust defaults to apple-m1 since Rust 1.71 for aarch64-apple-darwin. - def rust_optimisation_flags - @rust_optimisation_flags ||= { - native: "--codegen target-cpu=native", - ivybridge: "--codegen target-cpu=ivybridge", - sandybridge: "--codegen target-cpu=sandybridge", - nehalem: "--codegen target-cpu=nehalem", - core2: "--codegen target-cpu=core2", - core: "--codegen target-cpu=prescott", - }.freeze - end - sig { returns(Symbol) } def arch_32_bit if arm? @@ -229,11 +215,22 @@ module Hardware end alias generic_oldest_cpu oldest_cpu - # Returns a _full_ rustflag to set target cpu, if necessary; - # Defaults to empty string + # Returns a Rust flag to set the target CPU if necessary. + # Defaults to nil. sig { returns(T.nilable(String)) } def rustflags_target_cpu - CPU.rust_optimisation_flags.fetch(oldest_cpu, nil) + # Rust already defaults to the oldest supported cpu for each target-triple + # so it's safe to ignore generic archs such as :armv6, etc., here. + # Rust defaults to apple-m1 since Rust 1.71 for aarch64-apple-darwin. + @target_cpu ||= case (cpu = oldest_cpu) + when :core + :prescott + when :native, :ivybridge, :sandybridge, :nehalem, :core2 + cpu + end + return if @target_cpu.blank? + + "--codegen target-cpu=#{@target_cpu}" end end end