Repository navigation
Conversation
Xcode applies its compilation cache to Swift package targets only through the per-user workspace setting CompilationCachingSetting. Project and xcconfig build settings do not reach them. The Sync SPM Autolinking build phase now writes CompilationCachingSetting=Enable to the user's WorkspaceSettings.xcsettings when the key is missing. It keeps other keys, leaves an explicit value or a malformed file alone, never fails the build, and is turned off with RCT_SPM_SKIP_COMPILATION_CACHE_SETTING=1. Signed-off-by: Christian Falch <christian.falch@gmail.com>
chrfalch
force-pushed
the
spm-compile-cache-workspace-setting
branch
from
December 3, 2026 22:11
becf804 to
6265176
Compare
This branch has not been deployed
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
Xcode's compilation cache makes a warm clean build of a React Native SwiftPM app much faster. In a test app on Xcode 27.2, a Debug build went from 43.6 s to 12.9 s. But Xcode applies the cache to Swift package targets only through a per-user workspace setting,
CompilationCachingSetting. Project and xcconfig build settings, the shared workspace settings andPackage.swiftflags do not reach the package targets.This change makes the "Sync SPM Autolinking" build phase turn the setting on:
<App>.xcodeproj/project.xcworkspace/xcuserdata/<user>.xcuserdatad/WorkspaceSettings.xcsettings.CompilationCachingSetting=Enable.plutiland keeps the other keys.Disable, the phase leaves it.RCT_SPM_SKIP_COMPILATION_CACHE_SETTING=1in the build environment turns the step off.spm deinitleaves the setting in place.Xcode reads the setting from the next build on. The build that writes it does not use the cache. The next build fills the cache, and later builds hit it. Existing apps get the step on their next
react-native spm update, which regenerates the sync script.Results
A SwiftPM test app (RN 0.89.0-rc.4, Xcode 27.2, iOS simulator, Apple Silicon Mac). Three runs for each column. "Without cache" is the median of 3 runs. "Cache, empty" is run 1, which starts with an empty cache. "Cache, filled" is the mean of runs 2 and 3. A clean build is
xcodebuild cleanand thenbuild.xcodebuild cleandoes not delete the compilation cache.AppDelegate.swift, DebugCOMPILATION_CACHE_ENABLE_CACHING=YESon thexcodebuildcommand line. The Test Plan below shows that the per-user setting from this change gives the same cache hits.Changelog:
[IOS] [ADDED] - SwiftPM: the sync build phase turns on Xcode compilation caching for Swift package targets in the per-user workspace settings
Test Plan
node_modules/.bin/jest --no-cache -i packages/react-native/scripts/spm: 1270 of 1270 tests pass. The new tests run the generated script in a temp folder. They cover: create the file, keep other keys, keep a user's value, leave a malformed file, and the opt-out variable. One lifecycle test runs the realsync-autolinking.sh. The test that needsplutil -insertskips on non-macOS hosts.yarn flow-check: 0 errors. ESLint and Prettier pass on the changed files.xcodebuild -projectand no compilation-cache setting on the command line or in the project: