Conversation
Autolinking writes one symlink per self-managed library into build/generated/autolinking/libs/<Name>, and Xcode holds each as a loaded local package root. The generator deleted and re-created that whole tree on every run, even when the generated output was byte-identical, so an Xcode build failed with "Missing package product" for every such library. The sync ran on every IDE build because its staleness check walked each library's directory with `find -newer`, and Xcode writes its own per-user scheme state under <lib>/.swiftpm. That write marked the next build stale, which triggered the destructive re-sync, which broke that build. Keep unchanged entries in place and prune only the ones that are no longer autolinked, and skip .swiftpm when probing for changes. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
@shwanton has imported this pull request. If you are a Meta employee, you can view this in D120740029. |
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
Building an app in Xcode fails when it autolinks a library that ships its own
Package.swift, with one error per such library:The same project builds fine from the command line. Two problems combine.
The sync destroys package roots Xcode has already loaded. Autolinking writes one symlink per self-managed library into
build/generated/autolinking/libs/<Name>, and Xcode treats each as a local Swift package root. The generator deleted that whole directory and recreated it on every run, even when the generated output was byte-for-byte identical. Measured on a real app, across one no-op sync: thelibs/inode changed from 1913513750 to 1913930645,libs/ReactNativeSkiafrom 1913513937 to 1913930649, while the generatedPackage.swiftkept the same MD5. Recreating a package root that Xcode has already resolved is what produces the error above.Xcode's own bookkeeping made the sync run every time. The "Sync SPM Autolinking" build phase re-syncs when a watched input looks newer than its stamp, and it checked each library's whole directory with
find <dir> -newer <stamp>. Xcode writes its per-user scheme state inside that directory, at<lib>/.swiftpm/xcode/xcuserdata/<user>.xcuserdatad/xcschemes/xcschememanagement.plist. So Xcode's own write marked the next build stale, which triggered the destructive re-sync, which broke that build.xcodebuilddoes not write that file, which is why command-line builds were never affected.This change makes the
libs/tree idempotent — unchanged entries keep their inode, and entries that are no longer autolinked are pruned instead of wiped — and makes the staleness check skip.swiftpm.How to verify
In an app that autolinks a library shipping its own
Package.swift, build in Xcode twice in a row. Both builds should succeed. Before this change the second build fails withMissing package product.Changelog
[IOS] [FIXED] - Stop SwiftPM autolinking from recreating library package roots on every sync, which broke Xcode builds of apps using libraries that ship their own Package.swift
Test Plan
Unit tests.
yarn test packages/react-native/scripts/spm— 21 suites, 1009 tests pass.New tests, written and seen failing before the fix:
libs/inode and each entry's inode. Failed before the fix with the same inode churn measured on the real app.libs/./bin/bash -cwithset -euo pipefailagainst a temporary tree. A write under.swiftpm/is ignored; a real source change is still detected.Real app. A React Native 0.87.1 app on Xcode 27 autolinking
@shopify/react-native-skiaandreact-native-safe-area-context, both self-managed. Before:xcodebuildsucceeded, Xcode failed in about 5 seconds with the two errors above, on nearly every build.Not run: the full CI matrix, and no Android-side check — this touches iOS SwiftPM tooling only.
Scope
Deliberately minimal.
One case still re-syncs: the first time Xcode creates
.swiftpminside a library, that bumps the library directory's own mtime, so the build after a fresh checkout reports stale once per library. That is harmless now that the sync is idempotent.One related item is left alone: the aggregate
Package.swiftis still rewritten on every sync even when its content is unchanged, which bumps its mtime and can make Xcode re-resolve. That is wasteful but not destructive, and it is no longer reached on an ordinary IDE build now that.swiftpmwrites do not mark the sync stale.