Repository navigation
Fix SwiftPM: native library added after setup is not compiled until a clean build - #60462
Merged
Merged
Conversation
… clean build When you add a native library to a SwiftPM app, xcodebuild resolves the package graph first. Then the "Sync SPM Autolinking" scheme pre-action adds the library to the Autolinked Package.swift. Xcode keeps the old package graph for the new manifest, so incremental builds never compile the library and the app fails at runtime (for example "RNSVGCircle is not registered"). Only a clean build fixed it. The pre-action now syncs only when the Autolinked manifest is missing. Once it exists, the "Sync SPM Autolinking" build phase syncs it. When that sync changes the manifest, the build fails once with "native modules changed. Build again." The next build compiles the library. Test: yarn jest packages/react-native/scripts/spm --no-cache -i (1264 passed, 0 failed).
chrfalch
force-pushed
the
spm-new-lib-needs-clean-build
branch
from
December 2, 2026 10:37
ae09b81 to
b8c4df3
Compare
chrfalch
marked this pull request as ready for review
December 2, 2026 10:41
cortinico
approved these changes
Dec 2, 2026
gabrieldonadel
approved these changes
Dec 2, 2026
gabrieldonadel
pushed a commit
that referenced
this pull request
Dec 2, 2026
… clean build (#60462) When you add a native library to a SwiftPM app, xcodebuild resolves the package graph first. Then the "Sync SPM Autolinking" scheme pre-action adds the library to the Autolinked Package.swift. Xcode keeps the old package graph for the new manifest, so incremental builds never compile the library and the app fails at runtime (for example "RNSVGCircle is not registered"). Only a clean build fixed it. The pre-action now syncs only when the Autolinked manifest is missing. Once it exists, the "Sync SPM Autolinking" build phase syncs it. When that sync changes the manifest, the build fails once with "native modules changed. Build again." The next build compiles the library. Test: yarn jest packages/react-native/scripts/spm --no-cache -i (1264 passed, 0 failed). (cherry picked from commit ee2d411)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
In a SwiftPM app, a native library you add after setup (for example
npm install react-native-svg) is not compiled on the next builds. The build succeeds, but the app shows a red box such as "RNSVGCircle is not registered". Only a clean build fixes it. The Xcode window has the same problem.The cause:
xcodebuildresolves the package graph first.Package.swift.Where it came from: #57332 added the pre-action on the assumption that it runs before Xcode resolves packages. The
xcodebuildlog shows it runs after. Until #58826 fixed its encoding, Xcode read the pre-action script as one line, so it did nothing and only the build phase synced; a new library was then missing for one build only. Since #58826, the pre-action runs, so 0.88.1 and later, and 0.89, are affected.This change:
Package.swiftis missing. Once the file exists, the "Sync SPM Autolinking" build phase keeps it current.Package.swift, that one build fails with:native modules changed. Build again.Known limit: if only a library's generated code or source files change, and the Autolinked
Package.swiftdoes not, one build can use the old package sources. The next build is correct. This is the same as 0.87 and 0.88.0.Changelog:
[IOS] [FIXED] - SwiftPM: a native library added after setup is now compiled on the next build, without a clean build
Test Plan:
Unit tests:
25 suites, 1264 tests passed, 0 failed. Without the fix, 2 of the 3 new tests fail: the build phase does not fail with "Build again" when its sync changes the manifest, and the pre-action syncs when the manifest exists. The third new test, "the build phase passes when the manifest is unchanged", passes with and without the fix; it guards against a build that fails every time.
App (RN 0.89.0-rc.4, CLI 21.1.0, SwiftPM app, Debug, iOS simulator):
npm install react-native-svgxcodebuildand the Xcode window)native modules changed. Build again.RNSVGCirclein the binary).Not checked: the app on a simulator after build 2.