Skip to content

Conversation

@jmagman
Copy link
Member

@jmagman jmagman commented Oct 12, 2020

Description

Detect whether we're running on an x86 or ARM Mac. uname -m returns x86_64 on an ARM Mac from flutter since it's running in Rosetta.

Instead, switch to sysctl hw.optional.arm64, which returns sysctl hw.optional.arm64: 1 on an ARM mac in both Rosetta and non-Rosetta mode. On non-ARM this command fails sysctl: unknown oid 'hw.optional.arm64' and and exits 1.

Create a new HostPlatform.darwin_arm value, and expose it in OperatingSystemUtils.

Related Issues

#65976

Tests

Added a test for x86 and ARM.

Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I signed the [CLA].
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

  • No, no existing tests failed, so this is not a breaking change.
  • Yes, this is a breaking change. If not, delete the remainder of this section.

@jmagman jmagman added the platform-ios iOS applications specifically label Oct 12, 2020
@jmagman jmagman requested a review from jonahwilliams October 12, 2020 23:19
@jmagman jmagman self-assigned this Oct 12, 2020
@flutter-dashboard flutter-dashboard bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Oct 12, 2020
@google-cla google-cla bot added the cla: yes label Oct 12, 2020
@jmagman
Copy link
Member Author

jmagman commented Oct 12, 2020

Copy link
Contributor

@jonahwilliams jonahwilliams left a 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.

@jmagman
Copy link
Member Author

jmagman commented Oct 13, 2020

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 /usr/bin/arch -arm64 and the commands will run natively, not in Rosetta. But yeah, we maybe need to bail for the simulator and tell users to run from Xcode.

/// Physical underlying architecture.
///
/// On ARM return arm64, even when this process is running in Rosetta.
DarwinArch get hardwareArchitecture {
Copy link
Member Author

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?

Copy link
Contributor

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 (

) And then have a getter on os utils to return the current host platform. If we eventually support linux arm and windows arm this will come in handy too.

You could then augment that with a helper/extension for isArm/isX86

Copy link
Member Author

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.

Copy link
Contributor

@jonahwilliams jonahwilliams left a 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;
Copy link
Contributor

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI agrees.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

platform-host-arm Building on an ARM-based platform platform-ios iOS applications specifically tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants