Repository navigation
fix(ios): guard the SwiftPM package against silent drift - #1257
Open
Naturalclar wants to merge 1 commit into
Open
Naturalclar wants to merge 1 commit into
Naturalclar wants to merge 1 commit into
Conversation
No build in this repository compiles the SwiftPM package: CI validates native code through the CocoaPods example app, and `Package.swift` can only resolve its two local dependencies inside React Native's SwiftPM autolinking layout, which the pinned React Native does not generate. So `spm-support/SwiftHeaderPin.swift` -- written to catch drift in the hand-mirrored `spm-headers/react_native_menu-Swift.h` -- is never compiled by anything, and in any case cannot catch an *addition* to the Swift API. Add `scripts/check-spm.mjs` and a `spm` CI job running the checks that are possible without that graph: - every native source CocoaPods compiles is in a SwiftPM target too, and nothing untracked leaks into one (via `swift package describe`, which evaluates the manifest without resolving dependencies); - the mirrored header still matches `FabricViewImplementationProtocol` member for member, including the required/optional split, the property attributes, the mangled `objc_runtime_name`, and class availability. Each guard was verified by breaking the thing it guards: an unmirrored protocol member, a wrong mangled name, and a dropped availability attribute each fail the check, and the tree passes. Also from the review of #1232: - name the ObjC target's source directories instead of all of `ios/`. A stray `.h`/`.m`/`.mm` anywhere under `ios/` was compiled into the target; with a planted `ios/build/Stray.mm`, `swift package describe` confirms it before this change and not after. - restore the `@available(iOS 14.0, *)` that `FabricMenuViewImplementation` carries in Swift, as `API_AVAILABLE(ios(14.0))`, and record why the mirrored interfaces flatten their superclasses. - replace the manifest's three `try!`s. A trapping manifest reports a Swift fatal error rather than a SwiftPM diagnostic. This one is hygiene: a dangling symlink under `ios/` does not actually throw on Swift 6.0.2, so the trap was not reproducible. Refs #1256 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Closes #1256 (the part that is possible today — see What this does not do).
Nothing in this repository compiles the SwiftPM package #1232 added: CI validates native code through the CocoaPods example app, and
Package.swiftcan only resolve its two local dependencies (../../../../xcframeworks,../../../ios) inside React Native's SwiftPM autolinking layout, which the pinned React Native does not generate. Sospm-support/SwiftHeaderPin.swift— written to catch drift in the hand-mirroredspm-headers/react_native_menu-Swift.h— is compiled by nothing, and could not catch an addition to the Swift API even if it were.What this adds
scripts/check-spm.mjs(yarn spm:check) and aspmCI job running the checks that are possible without that dependency graph:sources — every native source CocoaPods compiles is in a SwiftPM target too, and nothing untracked leaks into one. Uses
swift package describe --type json, which evaluates the manifest and resolves each target's source list without resolving dependencies, so it works with no React Native present.headers — the mirrored header still matches
FabricViewImplementationProtocolmember for member: names, the required/optional split, the translated ObjC type, the required property attributes (copy/strong/nullable), the mangledobjc_runtime_name(recomputed fromswiftpmConfig.name), and class availability. A Swift type the script cannot translate is a failure, not a pass — adding a new kind of prop forces a look at the header.The job needs no
yarn install: the script uses only node builtins,git, and the Swift toolchain the macOS runner already ships.Also from the review
sources: ["ios"]-> named directories. The ObjC target discovered sources by extension over the wholeios/subtree. Reproduced with a plantedios/build/Stray.mm:swift package describecompiles it intoReactNativeMenuObjCbefore this change and not after.ios/MenuViewManager.mmis listed explicitly so it is not dropped — verified that both targets resolve to byte-identical source lists before and after.API_AVAILABLE(ios(14.0))on the mirroredFabricMenuViewImplementation, matching the@available(iOS 14.0, *)it carries in Swift, and recorded why the mirrored interfaces flatten their superclasses on purpose.try!s. Hygiene, not a fixed bug: a dangling symlink underios/does not actually throw fromsubpathsOfDirectoryorresourceValueson Swift 6.0.2, so I could not reproduce a trap.Verification
Each guard was checked by breaking the thing it guards:
var imageColor: NSString?added to the Swift protocol, header untouched32->31API_AVAILABLE(ios(14.0))deleted from the headerios/build/Stray.mmwith the oldsources: ["ios"]The first row is the scenario from the review: green CI, broken SwiftPM consumers.
yarn lint,yarn typescriptandyarn testpass.What this does not do
It does not build the package. That needs React Native's SwiftPM autolinking, which arrives with #1249 (RN 0.88, itself behind #1238). Until then the
__has_includeordering assumption inios/NewArch/MenuView.mm(the last finding in #1256) stays unguarded, which is why the issue stays open.🤖 Generated with Claude Code