Skip to content

Fix Xcode prepare's logic to assume iOS target architecture#154585

Closed
loic-sharma wants to merge 4 commits into
flutter:masterfrom
loic-sharma:spm_post_submit_x64_host
Closed

Fix Xcode prepare's logic to assume iOS target architecture#154585
loic-sharma wants to merge 4 commits into
flutter:masterfrom
loic-sharma:spm_post_submit_x64_host

Conversation

@loic-sharma
Copy link
Copy Markdown
Member

@loic-sharma loic-sharma commented Sep 3, 2024

⚠️ TODO: Verify test fails: #154589
⚠️ TODO: Update SPM umbrella issue to remove the pre action test
⚠️ TODO: Update this description to explain the new test.

Problem

Enabling the Swift Package Manager feature caused post-submit tests to fail on Mac x64 hosts:

Example error...

https://ci.chromium.org/ui/p/flutter/builders/prod/Mac_ios%20rrect_blur_perf_ios__timeline_summary/575/overview

♦ ... flutter --verbose assemble ... -dIosArchs=x86_64 ... profile_unpack_ios

Target profile_unpack_ios failed:
Exception: Binary ... build/ios/Profile-iphoneos/Flutter.framework/Flutter does not contain x86_64.

Running lipo -info:
Non-fat file: ... build/ios/Profile-iphoneos/Flutter.framework/Flutter is architecture: arm64

#0      UnpackIOS._thinFramework (package:flutter_tools/src/build_system/targets/ios.dart:351:7)
<asynchronous suspension>
#1      UnpackIOS.build (package:flutter_tools/src/build_system/targets/ios.dart:298:5)
<asynchronous suspension>
...

Background

As part of the Swift Package Manager project, an Xcode Scheme Pre-Action was added to unpack the Flutter framework. This ensures the Flutter framework is available before Swift Package Manager builds packages.

#150052 improved the performance of builds using Swift Package Manager:

When using SwiftPM, we use flutter assemble in an Xcode Pre-action to run the debug_unpack_macos (or profile/release) target. This target is also later used in a Run Script build phase. Depending on ARCHS build setting, the Flutter/FlutterMacOS binary is thinned. In the Run Script build phase, ARCHS is filtered to the active arch. However, in the Pre-action it doesn't always filter to the active arch. As a workaround, assume arm64 if the NATIVE_ARCH is arm, otherwise assume x86_64.

However, NATIVE_ARCH is the architecture of the host machine, not the target machine. As a result, Mac x86_64 hosts attempted to unpack the Flutter iOS framework using the x86_64 architecture when it is Arm64 only.

Solution

This updates the Xcode Pre-Action's logic: instead of using the host machine's architecture, it uses the build's SDKROOT. If the SDK root isn't a simulator, the pre-action assumes an Arm64 target build.

This change also adds a new ios_prepare_pre_action_test test project. This allows us to test the Xcode Scheme Pre-Action even if the Swift Package Manager feature is disabled.

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@github-actions github-actions Bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Sep 3, 2024
@loic-sharma loic-sharma force-pushed the spm_post_submit_x64_host branch 2 times, most recently from 56082e7 to 73d4767 Compare September 3, 2024 21:49
@loic-sharma loic-sharma force-pushed the spm_post_submit_x64_host branch from 73d4767 to 8182a2d Compare September 3, 2024 22:04
@loic-sharma loic-sharma force-pushed the spm_post_submit_x64_host branch from 4b90e9b to 1eecaf0 Compare September 3, 2024 23:16
@loic-sharma
Copy link
Copy Markdown
Member Author

After further research, I found that the optimization is correct if build settings follow Apple's documentation. However, flutter run incorrectly sets ONLY_ACTIVE_ARCH=YES on x64 hosts targeting arm64 devices. Instead of switching which build settings we use to apply this optimization, I fixed flutter run to set ONLY_ARCHIVE_ARCH correctly. See: #154645

@loic-sharma loic-sharma closed this Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant