From c344a3ff3dbde3db05edb802d8951924689d1d65 Mon Sep 17 00:00:00 2001 From: Tokarak <63452145+Tokarak@users.noreply.github.com> Date: Tue, 13 Jun 2023 11:35:45 +0100 Subject: [PATCH 01/17] Apply cpu-optimisation to Rust projects (hardcoded) --- Library/Homebrew/formula.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index a80ff7ac25a4b..14c710ff3127e 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1543,7 +1543,11 @@ def std_configure_args # Standard parameters for cargo builds. sig { params(root: T.any(String, Pathname), path: String).returns(T::Array[T.any(String, Pathname)]) } def std_cargo_args(root: prefix, path: ".") - ["--locked", "--root", root, "--path", path] + ["--locked", "--root", root, "--path", path, + "--config", "target.x86_64-apple-darwin.rustflags=['-Ctarget-cpu=nehalem']", + "--config", "target.aarch64-apple-darwin.rustflags=['-Ctarget-cpu=apple-m1']", + # Default target-cpu is apple-m1 since Rust 1.71.0 + ] end # Standard parameters for CMake builds. From a0725083f10ab39ed4ddc0a7c2f61be94a999d93 Mon Sep 17 00:00:00 2001 From: Tokarak <63452145+Tokarak@users.noreply.github.com> Date: Tue, 13 Jun 2023 19:17:28 +0100 Subject: [PATCH 02/17] Revert "Apply cpu-optimisation to Rust projects (hardcoded)" This reverts commit c344a3ff3dbde3db05edb802d8951924689d1d65. --- Library/Homebrew/formula.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 14c710ff3127e..a80ff7ac25a4b 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1543,11 +1543,7 @@ def std_configure_args # Standard parameters for cargo builds. sig { params(root: T.any(String, Pathname), path: String).returns(T::Array[T.any(String, Pathname)]) } def std_cargo_args(root: prefix, path: ".") - ["--locked", "--root", root, "--path", path, - "--config", "target.x86_64-apple-darwin.rustflags=['-Ctarget-cpu=nehalem']", - "--config", "target.aarch64-apple-darwin.rustflags=['-Ctarget-cpu=apple-m1']", - # Default target-cpu is apple-m1 since Rust 1.71.0 - ] + ["--locked", "--root", root, "--path", path] end # Standard parameters for CMake builds. 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 03/17] 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 cbe49c842466e..db7b4957b5d1f 100644 --- a/Library/Homebrew/extend/os/mac/hardware.rb +++ b/Library/Homebrew/extend/os/mac/hardware.rb @@ -24,4 +24,20 @@ def self.oldest_cpu(version = nil) 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 22bebf626b9bd..1db819bbecb91 100644 --- a/Library/Homebrew/hardware.rb +++ b/Library/Homebrew/hardware.rb @@ -214,6 +214,18 @@ def oldest_cpu(_version = nil) 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 From b4dd6391891b91ce87b67fe8bc44cec2ed05ceca Mon Sep 17 00:00:00 2001 From: Tokarak <63452145+Tokarak@users.noreply.github.com> Date: Tue, 13 Jun 2023 19:28:53 +0100 Subject: [PATCH 04/17] Use rustflags_target_cpu --- Library/Homebrew/formula.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index a80ff7ac25a4b..d2cea2d606e23 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1543,7 +1543,8 @@ def std_configure_args # Standard parameters for cargo builds. sig { params(root: T.any(String, Pathname), path: String).returns(T::Array[T.any(String, Pathname)]) } def std_cargo_args(root: prefix, path: ".") - ["--locked", "--root", root, "--path", path] + ["--locked", "--root", root, "--path", path, "--config", + "build.rustflags=['#{Hardware::CPU.rustflags_target_cpu}']"] end # Standard parameters for CMake builds. From d4bfbb1d02706910c312532052f854c20feb123a Mon Sep 17 00:00:00 2001 From: Tokarak <63452145+Tokarak@users.noreply.github.com> Date: Tue, 13 Jun 2023 19:32:18 +0100 Subject: [PATCH 05/17] Remove FIXMEs --- Library/Homebrew/extend/os/mac/hardware.rb | 2 +- Library/Homebrew/hardware.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/extend/os/mac/hardware.rb b/Library/Homebrew/extend/os/mac/hardware.rb index db7b4957b5d1f..d7c3f76d95326 100644 --- a/Library/Homebrew/extend/os/mac/hardware.rb +++ b/Library/Homebrew/extend/os/mac/hardware.rb @@ -27,7 +27,7 @@ def self.oldest_cpu(version = nil) # Override # Mirrors version-dependent logic of oldest_cpu - sig { params(version: T.nilable(Version)).returns(String) } # FIXME: Version, String or Symbol? + sig { params(version: T.nilable(Version)).returns(String) } def self.rustflags_target_cpu(version = nil) version = if version MacOSVersion.new(version.to_s) diff --git a/Library/Homebrew/hardware.rb b/Library/Homebrew/hardware.rb index 1db819bbecb91..e10a548fd038d 100644 --- a/Library/Homebrew/hardware.rb +++ b/Library/Homebrew/hardware.rb @@ -221,7 +221,7 @@ def oldest_cpu(_version = nil) # 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? + sig { params(_version: T.nilable(Version)).returns(String) } def rustflags_target_cpu(_version = nil) "" end From 2bd20eaa1534603b119a0ce6ad0b9f766f9c8c80 Mon Sep 17 00:00:00 2001 From: Tokarak <63452145+Tokarak@users.noreply.github.com> Date: Tue, 13 Jun 2023 19:45:52 +0100 Subject: [PATCH 06/17] Fix --- Library/Homebrew/formula.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index d2cea2d606e23..46a68eb38f601 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1544,7 +1544,7 @@ def std_configure_args sig { params(root: T.any(String, Pathname), path: String).returns(T::Array[T.any(String, Pathname)]) } def std_cargo_args(root: prefix, path: ".") ["--locked", "--root", root, "--path", path, "--config", - "build.rustflags=['#{Hardware::CPU.rustflags_target_cpu}']"] + "build.rustflags=['#{Hardware.rustflags_target_cpu}']"] end # Standard parameters for CMake builds. From c69817420028f9610346d2b4600a3da4229fe708 Mon Sep 17 00:00:00 2001 From: Tokarak <63452145+Tokarak@users.noreply.github.com> Date: Tue, 13 Jun 2023 20:40:23 +0100 Subject: [PATCH 07/17] Fix error on empty target-cpu --- Library/Homebrew/extend/os/mac/hardware.rb | 2 +- Library/Homebrew/formula.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/extend/os/mac/hardware.rb b/Library/Homebrew/extend/os/mac/hardware.rb index d7c3f76d95326..1bfd2feea075c 100644 --- a/Library/Homebrew/extend/os/mac/hardware.rb +++ b/Library/Homebrew/extend/os/mac/hardware.rb @@ -35,7 +35,7 @@ def self.rustflags_target_cpu(version = nil) MacOS.version end if Hardware::CPU.intel? && version >= :mojave - "-Ctarget-cpu=nehalem" + "'-Ctarget-cpu=nehalem'" else generic_rustflags_target_cpu end diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 46a68eb38f601..0ddd74cc6c442 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1544,7 +1544,7 @@ def std_configure_args sig { params(root: T.any(String, Pathname), path: String).returns(T::Array[T.any(String, Pathname)]) } def std_cargo_args(root: prefix, path: ".") ["--locked", "--root", root, "--path", path, "--config", - "build.rustflags=['#{Hardware.rustflags_target_cpu}']"] + "build.rustflags=[#{Hardware.rustflags_target_cpu}]"] end # Standard parameters for CMake builds. From cccad3e7d858e1dd68afa9e033e20b674fd678e1 Mon Sep 17 00:00:00 2001 From: Tokarak <63452145+Tokarak@users.noreply.github.com> Date: Wed, 14 Jun 2023 16:46:12 +0100 Subject: [PATCH 08/17] Line break --- Library/Homebrew/extend/os/mac/hardware.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/Library/Homebrew/extend/os/mac/hardware.rb b/Library/Homebrew/extend/os/mac/hardware.rb index 1bfd2feea075c..3cc0dab17d557 100644 --- a/Library/Homebrew/extend/os/mac/hardware.rb +++ b/Library/Homebrew/extend/os/mac/hardware.rb @@ -34,6 +34,7 @@ def self.rustflags_target_cpu(version = nil) else MacOS.version end + if Hardware::CPU.intel? && version >= :mojave "'-Ctarget-cpu=nehalem'" else From 261f55a526d23366204ac243c6029564a5ce81c3 Mon Sep 17 00:00:00 2001 From: Tokarak <63452145+Tokarak@users.noreply.github.com> Date: Wed, 14 Jun 2023 17:14:05 +0100 Subject: [PATCH 09/17] Prepare to migrate to RUSTFLAGS --- Library/Homebrew/extend/os/mac/hardware.rb | 2 +- Library/Homebrew/formula.rb | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/extend/os/mac/hardware.rb b/Library/Homebrew/extend/os/mac/hardware.rb index 3cc0dab17d557..2cc0d30b7eae4 100644 --- a/Library/Homebrew/extend/os/mac/hardware.rb +++ b/Library/Homebrew/extend/os/mac/hardware.rb @@ -36,7 +36,7 @@ def self.rustflags_target_cpu(version = nil) end if Hardware::CPU.intel? && version >= :mojave - "'-Ctarget-cpu=nehalem'" + "-Ctarget-cpu=nehalem" else generic_rustflags_target_cpu end diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 0ddd74cc6c442..a80ff7ac25a4b 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1543,8 +1543,7 @@ def std_configure_args # Standard parameters for cargo builds. sig { params(root: T.any(String, Pathname), path: String).returns(T::Array[T.any(String, Pathname)]) } def std_cargo_args(root: prefix, path: ".") - ["--locked", "--root", root, "--path", path, "--config", - "build.rustflags=[#{Hardware.rustflags_target_cpu}]"] + ["--locked", "--root", root, "--path", path] end # Standard parameters for CMake builds. From 2133da85971c81332a1ca7cbe00661b2134df0bd Mon Sep 17 00:00:00 2001 From: Tokarak <63452145+Tokarak@users.noreply.github.com> Date: Wed, 14 Jun 2023 17:26:01 +0100 Subject: [PATCH 10/17] Set target-cpu through RUSTFLAGS --- Library/Homebrew/extend/ENV/shared.rb | 1 + Library/Homebrew/extend/ENV/std.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/Library/Homebrew/extend/ENV/shared.rb b/Library/Homebrew/extend/ENV/shared.rb index bef56363bc21d..fb25328cf7945 100644 --- a/Library/Homebrew/extend/ENV/shared.rb +++ b/Library/Homebrew/extend/ENV/shared.rb @@ -28,6 +28,7 @@ module SharedEnvExtension CMAKE_PREFIX_PATH CMAKE_INCLUDE_PATH CMAKE_FRAMEWORK_PATH GOBIN GOPATH GOROOT PERL_MB_OPT PERL_MM_OPT LIBRARY_PATH LD_LIBRARY_PATH LD_PRELOAD LD_RUN_PATH + RUSTFLAGS ].freeze private_constant :SANITIZED_VARS diff --git a/Library/Homebrew/extend/ENV/std.rb b/Library/Homebrew/extend/ENV/std.rb index b1bdb5424da55..19cec7ad88e50 100644 --- a/Library/Homebrew/extend/ENV/std.rb +++ b/Library/Homebrew/extend/ENV/std.rb @@ -36,6 +36,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 if HOMEBREW_PREFIX.to_s != "/usr/local" # /usr/local is already an -isystem and -L directory so we skip it From 9a99b932e839428dd4b188fd11777ee69f6efc4f Mon Sep 17 00:00:00 2001 From: Tokarak <63452145+Tokarak@users.noreply.github.com> Date: Sat, 17 Jun 2023 10:16:53 +0100 Subject: [PATCH 11/17] Add RUSTFLAGS to ENV/super --- Library/Homebrew/extend/ENV/super.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/Library/Homebrew/extend/ENV/super.rb b/Library/Homebrew/extend/ENV/super.rb index 734eccb95d266..c5bbe02caecb8 100644 --- a/Library/Homebrew/extend/ENV/super.rb +++ b/Library/Homebrew/extend/ENV/super.rb @@ -63,6 +63,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["PATH"] = determine_path self["PKG_CONFIG_PATH"] = determine_pkg_config_path self["PKG_CONFIG_LIBDIR"] = determine_pkg_config_libdir From 9a19f5bcd2a352446868ac51873b3ddc1becf2a1 Mon Sep 17 00:00:00 2001 From: Tokarak <63452145+Tokarak@users.noreply.github.com> Date: Sat, 17 Jun 2023 10:38:32 +0100 Subject: [PATCH 12/17] Refactor to use oldest_cpu --- Library/Homebrew/extend/os/mac/hardware.rb | 17 ----------------- Library/Homebrew/hardware.rb | 15 +++++++++++---- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/Library/Homebrew/extend/os/mac/hardware.rb b/Library/Homebrew/extend/os/mac/hardware.rb index 2cc0d30b7eae4..cbe49c842466e 100644 --- a/Library/Homebrew/extend/os/mac/hardware.rb +++ b/Library/Homebrew/extend/os/mac/hardware.rb @@ -24,21 +24,4 @@ def self.oldest_cpu(version = nil) generic_oldest_cpu end end - - # Override - # Mirrors version-dependent logic of oldest_cpu - sig { params(version: T.nilable(Version)).returns(String) } - 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 e10a548fd038d..6033f92aa5b1f 100644 --- a/Library/Homebrew/hardware.rb +++ b/Library/Homebrew/hardware.rb @@ -41,6 +41,14 @@ def optimization_flags end alias generic_optimization_flags optimization_flags + def rust_optimisation_flags + # Only give values where it is an improvement over rust cpu defaults + @rust_optimisation_flags ||= { + native: "-Ctarget-cpu=native", + nehalem: "-Ctarget-cpu=nehalem", + }.freeze + end + sig { returns(Symbol) } def arch_32_bit if arm? @@ -221,11 +229,10 @@ def oldest_cpu(_version = nil) # 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) } - def rustflags_target_cpu(_version = nil) - "" + sig { returns(String) } + def rustflags_target_cpu + CPU.rust_optimisation_flags.fetch(oldest_cpu, "") end - alias generic_rustflags_target_cpu rustflags_target_cpu end end From 73c339d82b2e7b43843f6b3f1b94ac610bbfda04 Mon Sep 17 00:00:00 2001 From: Tokarak <63452145+Tokarak@users.noreply.github.com> Date: Sat, 17 Jun 2023 10:51:48 +0100 Subject: [PATCH 13/17] Style changes --- Library/Homebrew/hardware.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/hardware.rb b/Library/Homebrew/hardware.rb index 6033f92aa5b1f..3ec3e3599da6b 100644 --- a/Library/Homebrew/hardware.rb +++ b/Library/Homebrew/hardware.rb @@ -41,8 +41,10 @@ def optimization_flags end alias generic_optimization_flags optimization_flags + # Only give values where it is an improvement over rust cpu defaults + # Rust already defaults to the oldest supported cpu for each target-triple + # Including apple-m1 since Rust 1.71 for aarch64-apple-darwin. def rust_optimisation_flags - # Only give values where it is an improvement over rust cpu defaults @rust_optimisation_flags ||= { native: "-Ctarget-cpu=native", nehalem: "-Ctarget-cpu=nehalem", @@ -224,11 +226,7 @@ def oldest_cpu(_version = nil) 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. + # Defaults to empty string sig { returns(String) } def rustflags_target_cpu CPU.rust_optimisation_flags.fetch(oldest_cpu, "") From 40aa41929f33ce7f6172b82315e6687fa5c93406 Mon Sep 17 00:00:00 2001 From: Tokarak <63452145+Tokarak@users.noreply.github.com> Date: Sat, 17 Jun 2023 12:14:21 +0100 Subject: [PATCH 14/17] More cpus in rust_optimisation_flags --- Library/Homebrew/hardware.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/hardware.rb b/Library/Homebrew/hardware.rb index 3ec3e3599da6b..43ecb7268d056 100644 --- a/Library/Homebrew/hardware.rb +++ b/Library/Homebrew/hardware.rb @@ -41,13 +41,17 @@ def optimization_flags end alias generic_optimization_flags optimization_flags - # Only give values where it is an improvement over rust cpu defaults # Rust already defaults to the oldest supported cpu for each target-triple - # Including apple-m1 since Rust 1.71 for aarch64-apple-darwin. + # 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: "-Ctarget-cpu=native", - nehalem: "-Ctarget-cpu=nehalem", + 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 @@ -227,9 +231,9 @@ def oldest_cpu(_version = nil) # Returns a _full_ rustflag to set target cpu, if necessary; # Defaults to empty string - sig { returns(String) } + sig { returns(T.nilable(String)) } def rustflags_target_cpu - CPU.rust_optimisation_flags.fetch(oldest_cpu, "") + CPU.rust_optimisation_flags.fetch(oldest_cpu, nil) end end end 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 15/17] 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 43ecb7268d056..942915bd15b6c 100644 --- a/Library/Homebrew/hardware.rb +++ b/Library/Homebrew/hardware.rb @@ -41,20 +41,6 @@ def optimization_flags 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 @@ def oldest_cpu(_version = nil) 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 From 55bdbabaae8b8abd1db7670ab661795c122d888e Mon Sep 17 00:00:00 2001 From: Tokarak <63452145+Tokarak@users.noreply.github.com> Date: Tue, 20 Jun 2023 23:48:10 +0100 Subject: [PATCH 16/17] brew style --fix --- Library/Homebrew/hardware.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/hardware.rb b/Library/Homebrew/hardware.rb index 942915bd15b6c..13920d61dad3d 100644 --- a/Library/Homebrew/hardware.rb +++ b/Library/Homebrew/hardware.rb @@ -229,7 +229,7 @@ def rustflags_target_cpu cpu end return if @target_cpu.blank? - + "--codegen target-cpu=#{@target_cpu}" end end From 521fdcb506118d34a03c8d377def2ad6cb045abf Mon Sep 17 00:00:00 2001 From: Nazar <63452145+Tokarak@users.noreply.github.com> Date: Sat, 24 Jun 2023 11:09:28 +0100 Subject: [PATCH 17/17] Wording Co-authored-by: Alexander Bayandin --- Library/Homebrew/hardware.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/hardware.rb b/Library/Homebrew/hardware.rb index 13920d61dad3d..ed4034c48ad43 100644 --- a/Library/Homebrew/hardware.rb +++ b/Library/Homebrew/hardware.rb @@ -219,8 +219,8 @@ def oldest_cpu(_version = nil) # Defaults to nil. sig { returns(T.nilable(String)) } def rustflags_target_cpu - # 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 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) when :core