-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Detect ARM macOS arch with sysctl hw.optional.arm64 #67970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
jonahwilliams
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, nice!
One potential follow up is to expose this in a way that we can use for host architecture detection, and then prevent flutter run and redirect to some canned issue or documentation.
At the point we can detect the physical architecture, I think we can prepend |
| /// Physical underlying architecture. | ||
| /// | ||
| /// On ARM return arm64, even when this process is running in Rosetta. | ||
| DarwinArch get hardwareArchitecture { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per your suggestion @jonahwilliams I'm going to think one step ahead--this will be needed outside just the name to detect how certain commands will need to be run.
Created a new MacOSUtils (not _MacOSUtils since I'll want to grab the arch from other places) and expose the arch.
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to not need to know the specific subtype of os utils in order to call this function.
Instead of exposing a DarwinArch (since that is really a target architecture, we can't target 32bit arm), you could add darwin_arm64 something to the HostPlatform (
| enum HostPlatform { |
You could then augment that with a helper/extension for isArm/isX86
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of exposing a DarwinArch (since that is really a target architecture, we can't target 32bit arm), you could add darwin_arm64 something to the HostPlatform
That's way better.
jonahwilliams
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
| HostPlatform _currentHostPlatformAsHost(Platform platform) { | ||
| if (platform.isMacOS) { | ||
| return HostPlatform.darwin_x64; | ||
| return HostPlatform.darwin_x86; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think renaming this is going to inadvertently break some things
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI agrees.
Description
Detect whether we're running on an x86 or ARM Mac.
uname -mreturnsx86_64on an ARM Mac fromfluttersince it's running in Rosetta.Instead, switch to
sysctl hw.optional.arm64, which returnssysctl hw.optional.arm64: 1on an ARM mac in both Rosetta and non-Rosetta mode. On non-ARM this command failssysctl: unknown oid 'hw.optional.arm64'and and exits 1.Create a new
HostPlatform.darwin_armvalue, and expose it in OperatingSystemUtils.Related Issues
#65976
Tests
Added a test for x86 and ARM.
Checklist
///).flutter analyze --flutter-repo) does not report any problems on my PR.Breaking Change