Skip to content

Add --mergeable option to the iOS prebuild scripts - #60328

Merged
chrfalch merged 1 commit into
mainfrom
ios-merge-build-option
Nov 29, 2026
Merged

chrfalch merged 1 commit into
mainfrom
ios-merge-build-option

Conversation

@chrfalch

Copy link
Copy Markdown
Collaborator

Summary:

React Native's iOS prebuild scripts cannot build React and ReactNativeDependencies as mergeable frameworks. Xcode can merge a mergeable framework into the app executable, where the linker can remove unused code. Today the scripts only build plain dynamic frameworks.

This PR adds an opt-in --mergeable option to both scripts:

  1. packages/react-native/scripts/ios-prebuild (React) and scripts/releases/prepare-ios-prebuilds.js (ReactNativeDependencies) accept --mergeable.
  2. With the option, the Release xcodebuild command gets 'MERGEABLE_LIBRARY=$(MERGEABLE_LIBRARY_$(MACH_O_TYPE))' MERGEABLE_LIBRARY_mh_dylib=YES. This marks only dynamic libraries as mergeable. A plain MERGEABLE_LIBRARY=YES also applies to the static dependencies and breaks their link.
  3. Debug builds, and every build without the option, run the same command as before.
  4. Output names do not change. Hermes is not touched.
  5. Both __docs__/README.md files document the option.

Nothing builds or ships mergeable frameworks by default. Publishing them, and letting apps opt in through SwiftPM or CocoaPods, are separate follow-up changes.

Changelog:

[INTERNAL] [ADDED] - Add a --mergeable option to the iOS prebuild scripts to build mergeable Release frameworks

Test Plan:

Unit tests (new tests for the build command and option parsing):

yarn test packages/react-native/scripts/ios-prebuild scripts/releases/ios-prebuild

13 suites, 114 tests pass. Before the change, the 6 new tests failed because the option was missing.

Release build with the option, device and simulator:

node scripts/releases/prepare-ios-prebuilds.js -s -w -b -c -r Release -p ios ios-simulator --mergeable
cd packages/react-native && node scripts/ios-prebuild -s -b -c -f Release -p ios ios-simulator --mergeable

Both builds succeed. Every slice of React.xcframework and ReactNativeDependencies.xcframework carries the LC_ATOM_INFO load command that marks a mergeable binary (otool -l <binary> | grep -c LC_ATOM_INFO prints 1 for ios-arm64 and 2 for ios-arm64_x86_64-simulator). The 0.88.1 release frameworks print 0.

yarn flow-check, ESLint and Prettier pass on the changed files. Not run: Mac Catalyst slices.

The iOS prebuild scripts cannot build React and ReactNativeDependencies
as mergeable frameworks, which Xcode can merge into an app executable.

--mergeable adds MERGEABLE_LIBRARY (for dynamic libraries only) to the
Release xcodebuild command in both scripts. Debug builds and builds
without the option are unchanged.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 27, 2026
@github-actions github-actions Bot added the Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. label Nov 27, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Nov 27, 2026
@chrfalch
chrfalch merged commit 51ac727 into main Nov 29, 2026
112 of 116 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. p: Expo Partner: Expo Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants