- Notifications
You must be signed in to change notification settings - Fork29.3k
Enhance macOS build process to support architecture specification via dartDefines#176606
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Enhance macOS build process to support architecture specification via dartDefines#176606
Conversation
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.
Code Review
This pull request enhances the macOS build process by allowing developers to specify the target architecture throughdartDefines
. This is achieved by parsing aDarwinArchs
value fromdartDefines
and adjusting thexcodebuild
destination parameter accordingly. The changes correctly fall back to building a universal binary ifDarwinArchs
is not specified in a release build, preserving backward compatibility. The pull request also includes comprehensive tests for the new functionality.
for (finalString definein buildInfo.dartDefines) { | ||
if (define.startsWith('DarwinArchs=')) { | ||
darwinArchs= define.substring('DarwinArchs='.length); | ||
break; | ||
} | ||
} |
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.
This loop can be written more concisely usingfirstWhere
with atry-catch
block, which is a common Dart idiom for finding the first element that satisfies a condition. This also provides an opportunity to use thekDarwinArchs
constant frombuild_info.dart
to avoid a magic string, improving maintainability.
for (finalString definein buildInfo.dartDefines) { | |
if (define.startsWith('DarwinArchs=')) { | |
darwinArchs= define.substring('DarwinArchs='.length); | |
break; | |
} | |
} | |
try { | |
finalString prefix='$kDarwinArchs='; | |
finalString define= buildInfo.dartDefines.firstWhere( | |
(String d)=> d.startsWith(prefix), | |
); | |
darwinArchs= define.substring(prefix.length); | |
}onStateError { | |
// No DarwinArchs define found. | |
} |
abdelaziz-mahdy commentedOct 7, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
tested on the main issue and it didnt work correctly, seems like swift package manager builds both of the archs, but for some reason for debug it works correctly |
An existing Git SHA, To re-trigger presubmits after closing or re-opeing a PR, or pushing a HEAD commit (i.e. with |
This pull request has been changed to a draft. The currently pending flutter-gold status will not be able to resolve until a new commit is pushed or the change is marked ready for review again. For more guidance, visitWriting a golden file test for Reviewers: Read theTree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
the issue is that flutter tools was cached, so after removing the cache now it works correctly |
Uh oh!
There was an error while loading.Please reload this page.
Description
This PR adds support for single-architecture macOS release builds by respecting the
DarwinArchs
dart-define flag when setting the xcodebuild destination.Problem
Currently, Flutter's
build_macos.dart
hardcodes the xcodebuild destination for release builds togeneric/platform=macOS
, which forces universal binaries (arm64 + x86_64). This causes build failures forplugins with architecture-specific dependencies that only support one architecture.
Example: ExecuTorch only provides arm64 binaries for macOS. Debug builds work perfectly because they use
-destination platform=macOS,arch=arm64
, but release builds fail because they attempt to compile forboth architectures.
Solution
This PR modifies the destination logic to check if
DarwinArchs
is defined inbuildInfo.dartDefines
. When present, it uses the architecture-specific destination (same behavior as debug builds). Whenabsent, it maintains the current behavior of using the generic platform for universal binaries (backward compatibility).
Usage
Build for arm64 only
flutter build macos --release --dart-define=DarwinArchs=arm64
Build for x86_64 only
flutter build macos --release --dart-define=DarwinArchs=x86_64
Default behavior (universal binary)
flutter build macos --release
Tests Added
All 26 tests passing.
Related Issues
Fixes#176605
Breaking Changes
None. This change is backward compatible - existing builds without the DarwinArchs flag will continue to produce universal binaries as before.
If you had to change anything in theflutter/tests repo, include a link to the migration guide as per thebreaking change policy.
Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel onDiscord.
Note: The Flutter team is currently trialing the use ofGemini Code Assist for GitHub. Comments from the
gemini-code-assist
bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.