Add rustflags_target_cpu method

This commit is contained in:
Tokarak 2023-06-13 19:22:12 +01:00
parent a0725083f1
commit 066a88855b
2 changed files with 28 additions and 0 deletions

View File

@ -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

View File

@ -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