Skip to content

Conversation

@jmagman
Copy link
Member

@jmagman jmagman commented Oct 13, 2020

Description

On macOS ARM machines run Xcode outside Rosetta without x86 translation by prepending commands with arch -arm64.

Only update the iOS xcodebuild code paths. More research needed to see what changes flutter build macos needs.

Related Issues

Fixes #65133

Tests

xcrun runs natively on arm64 test, updated xcrun tests.

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.

@flutter-dashboard flutter-dashboard bot added tool Affects the "flutter" command-line tool. See also t: labels. work in progress; do not review labels Oct 13, 2020
@google-cla google-cla bot added the cla: yes label Oct 13, 2020
Copy link
Member Author

Choose a reason for hiding this comment

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

I checked again, it exits 1 on x86 macOS 11, too.

Copy link
Member Author

Choose a reason for hiding this comment

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

This check is overkill. If Xcode and xcrun is installed, xcdevice is installed.

Copy link
Member Author

Choose a reason for hiding this comment

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

This test is new.

Copy link
Member Author

Choose a reason for hiding this comment

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

This section looks like a big change, but it's mostly whitespace due to the the new group indentation. The changes in this file:

  1. Remove xcrun --find xcdevice commands.
  2. Use FakePlatform instead of MockPlatform.
  3. Add the sysctl ARM check command where needed.

@jmagman jmagman force-pushed the xcodebuild-arch branch 4 times, most recently from 7964014 to 52203ef Compare October 14, 2020 01:50
@jmagman jmagman marked this pull request as ready for review October 14, 2020 18:44
@jmagman jmagman self-assigned this Oct 14, 2020
@jmagman jmagman added the platform-mac Building on or for macOS specifically label Oct 14, 2020
Copy link
Contributor

@christopherfujino christopherfujino left a comment

Choose a reason for hiding this comment

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

LGTM!

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

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: doc comment please

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@jmagman jmagman merged commit a82807d into flutter:master Oct 14, 2020
@jmagman jmagman deleted the xcodebuild-arch branch October 14, 2020 22:44
@jmagman
Copy link
Member Author

jmagman commented Oct 14, 2020

@alexmarkley I know you've been offering to help out with ARM support. If you are still willing, it would be awesome if you could to take this change for a test drive and see where else the flutter command line tool falls down when running against a physical iOS device...

@alexmarkley
Copy link

@jmagman thanks for tagging me! I will take a look later tonight.

@alexmarkley
Copy link

@jmagman first impressions. Ran flutter upgrade in flutter channel master. Here's the output of flutter doctor -v:

DTK:~ alex$ flutter doctor -v
[✓] Flutter (Channel master, 1.23.0-19.0.pre.41, on macOS 11.0 20A5395g darwin-arm, locale en-US)
    • Flutter version 1.23.0-19.0.pre.41 at /Users/alex/Development/Flutter/flutter
    • Framework revision ed2a4809da (17 minutes ago), 2020-10-14 20:02:04 -0400
    • Engine revision ce75dda492
    • Dart version 2.11.0 (build 2.11.0-218.0.dev)

[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.


⣽Error executing simctl: 1
arch: posix_spawnp: xcrun: Bad CPU type in executable


[!] Xcode - develop for iOS and macOS (Xcode 12.2)
    • Xcode at /Applications/Xcode-beta.app/Contents/Developer
    • Xcode 12.2, Build version 12B5035g
    ✗ Xcode requires additional components to be installed in order to run.
      Launch Xcode and install additional required components when prompted or run:
        sudo xcodebuild -runFirstLaunch
    • CocoaPods version 1.9.3

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).

[✓] Connected device (1 available)
    • macOS (desktop) • macos • darwin-x64 • macOS 11.0 20A5395g darwin-arm

! Doctor found issues in 3 categories.
DTK:~ alex$ 

Not sure what's going on with simctl. Running xcrun simctl --help yields:

DTK:~ alex$ xcrun simctl --help
usage: simctl [--set <path>] [--profiles <path>] <subcommand> ...
       simctl help [subcommand]
Command line utility to control the Simulator

For subcommands that require a <device> argument, you may specify a device UDID
or the special "booted" string which will cause simctl to pick a booted device.
If multiple devices are booted when the "booted" device is selected, simctl
will choose one of them.

Subcommands:
	create              Create a new device.
	clone               Clone an existing device.
	upgrade             Upgrade a device to a newer runtime.
	delete              Delete spcified devices, unavailable devices, or all devices.
	pair                Create a new watch and phone pair.
	unpair              Unpair a watch and phone pair.
	pair_activate       Set a given pair as active.
	erase               Erase a device's contents and settings.
	boot                Boot a device.
	shutdown            Shutdown a device.
	rename              Rename a device.
	getenv              Print an environment variable from a running device.
	openurl             Open a URL in a device.
	addmedia            Add photos, live photos, videos, or contacts to the library of a device.
	install             Install an app on a device.
	uninstall           Uninstall an app from a device.
	get_app_container   Print the path of the installed app's container
	install_app_data    Install an xcappdata package to a device, replacing the current contents of the container.
	launch              Launch an application by identifier on a device.
	terminate           Terminate an application by identifier on a device.
	spawn               Spawn a process by executing a given executable on a device.
	list                List available devices, device types, runtimes, or device pairs.
	icloud_sync         Trigger iCloud sync on a device.
	pbsync              Sync the pasteboard content from one pasteboard to another.
	pbcopy              Copy standard input onto the device pasteboard.
	pbpaste             Print the contents of the device's pasteboard to standard output.
	help                Prints the usage for a given subcommand.
	io                  Set up a device IO operation.
	diagnose            Collect diagnostic information and logs.
	logverbose          enable or disable verbose logging for a device
	status_bar          Set or clear status bar overrides
	ui                  Get or Set UI options
	push                Send a simulated push notification
	privacy             Grant, revoke, or reset privacy and permissions
	keychain            Manipulate a device's keychain
DTK:~ alex$ 

@alexmarkley
Copy link

Seems like the simctl issue is preventing flutter from detecting physical devices plugged into the machine. Flutter doctor reports "No devices available" and flutter run in a hello world project yields:

DTK:helloWorldThree alex$ flutter run
Error executing simctl: 1
arch: posix_spawnp: xcrun: Bad CPU type in executable


No supported devices connected.
DTK:helloWorldThree alex$ 

@alexmarkley
Copy link

@jmagman uh oh, this is tricky:

DTK:~ alex$ xcrun simctl --version
@(#)PROGRAM:simctl  PROJECT:CoreSimulator-732.18.0.2
DTK:~ alex$ /Applications/Xcode-beta.app/Contents/Developer/usr/bin/simctl --version
@(#)PROGRAM:simctl  PROJECT:CoreSimulator-732.18.0.2
DTK:~ alex$ arch -arm64 /Applications/Xcode-beta.app/Contents/Developer/usr/bin/simctl
arch: posix_spawnp: /Applications/Xcode-beta.app/Contents/Developer/usr/bin/simctl: Bad CPU type in executable
DTK:~ alex$ lipo -detailed_info /Applications/Xcode-beta.app/Contents/Developer/usr/bin/simctl
fatal error: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: can't figure out the architecture type of: /Applications/Xcode-beta.app/Contents/Developer/usr/bin/simctl
DTK:~ alex$ file /Applications/Xcode-beta.app/Contents/Developer/usr/bin/simctl
/Applications/Xcode-beta.app/Contents/Developer/usr/bin/simctl: Bourne-Again shell script text executable, ASCII text
DTK:~ alex$ 
DTK:~ alex$ 
DTK:~ alex$ head -n 5 /Applications/Xcode-beta.app/Contents/Developer/usr/bin/simctl
#!/bin/bash
DEVELOPER_USR_BIN_DIR=${0%/*}
DEVELOPER_USR_BIN_DIR=${DEVELOPER_USR_BIN_DIR%/local/bin}
DEVELOPER_USR_BIN_DIR=${DEVELOPER_USR_BIN_DIR%/bin}
DEVELOPER_USR_BIN_DIR=${DEVELOPER_USR_BIN_DIR}/bin
DTK:~ alex$ 

@alexmarkley
Copy link

alexmarkley commented Oct 15, 2020

Oh! @jmagman I think you want this:

DTK:~ alex$ arch -arm64e xcrun simctl --version
@(#)PROGRAM:simctl  PROJECT:CoreSimulator-732.18.0.2
DTK:~ alex$ 

As per this:

DTK:~ alex$ lipo -info /usr/bin/xcrun 
Architectures in the fat file: /usr/bin/xcrun are: x86_64 arm64e 
DTK:~ alex$ 

This leads to some interesting behavior like this (running inside of iTerm, which is running under Rosetta):

image

(And no, I have no idea why arch reports the running architecture as arm64 but expects you to pass arm64e when specifying a runtime architecture. 🤷‍♂️ )

@jmagman
Copy link
Member Author

jmagman commented Oct 15, 2020

Hm, I was trying to figure out where arm64e was needed... on my dtk it only worked with -arm64 not -arm64e

On this commit flutter run works:
Screen Shot 2020-10-14 at 6 34 48 PM
and flutter devices:
Screen Shot 2020-10-14 at 6 35 57 PM

$ lipo -info /usr/bin/xcrun
Architectures in the fat file: /usr/bin/xcrun are: x86_64 arm64e
$ arch -arm64 xcrun simctl --version
@(#)PROGRAM:simctl  PROJECT:CoreSimulator-732.18
$ arch -arm64e xcrun simctl --version
arch: Unknown architecture: arm64e
$ arch -arm64 /Applications/Xcode-12.2.beta2.app/Contents/Developer/usr/bin/simctl --version
@(#)PROGRAM:simctl  PROJECT:CoreSimulator-732.18
$ arch -arm64e /Applications/Xcode-12.2.beta2.app/Contents/Developer/usr/bin/simctl --version
arch: Unknown architecture: arm64e

@alexmarkley
Copy link

@jmagman that is somewhat baffling. I am on Beta 10 as of this afternoon, I wonder if that could factor in somehow?

I assume Apple's intention in the long term is for the xcrun to spawn ARM processes because the caller is also an ARM process. I guess that's not going to be possible with Dart in the short term?

@alexmarkley
Copy link

@jmagman are you still running the image that it shipped with? https://betawiki.net/wiki/MacOS_Big_Sur_build_20A5299w

I noticed some pretty significant changes around Beta 7 and following, so maybe an update is in order. 😉

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-mac Building on or for macOS 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.

"flutter build ios" fails on ARM macOS, ibtoold crashes compiling xcassets/storyboards

4 participants