Skip to content

Commit

Permalink
Merge pull request #7995 from mistydemeo/add_rosetta_test
Browse files Browse the repository at this point in the history
CPU: add ability to check for Rosetta
  • Loading branch information
MikeMcQuaid authored Sep 1, 2020
2 parents 48c6dc8 + 74d3f0b commit 3b8f1b7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Library/Homebrew/extend/os/mac/hardware/cpu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ def universal_archs
[arch_64_bit, arch_32_bit].extend ArchitectureListExtension
end

# True when running under an Intel-based shell via Rosetta on an
# Apple Silicon Mac. This can be detected via seeing if there's a
# conflict between what `uname` report and the underlying `sysctl` flags,
# since the `sysctl` flags don't change behaviour under Rosetta.
def in_rosetta?
intel? && physical_cpu_arm64?
end

def features
@features ||= sysctl_n(
"machdep.cpu.features",
Expand Down Expand Up @@ -109,6 +117,12 @@ def sse4_2?

private

# Note: this is more reliable than checking uname.
# `sysctl` returns the right answer even when running in Rosetta.
def physical_cpu_arm64?
sysctl_bool("hw.optional.arm64")
end

def sysctl_bool(key)
sysctl_int(key) == 1
end
Expand Down
4 changes: 4 additions & 0 deletions Library/Homebrew/hardware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ def arch_flag(arch)

"-march=#{arch}"
end

def in_rosetta?
false
end
end
end

Expand Down

0 comments on commit 3b8f1b7

Please sign in to comment.