Skip to content

SwiftPM: nothing verifies the package, and the mirrored Swift header can drift silently #1256

Open

Description

@Naturalclar

#1232 added SwiftPM support (shipped in 2.2.0). This tracks the gap that review surfaced, plus four smaller findings.

The gap

ci.yml validates native code by compiling the CocoaPods example app (pod-install + xcodebuild, NewArch and OldArch). Nothing compiles the SwiftPM package, so nothing exercises Package.swift, spm-headers/, or spm-support/.

spm-support/SwiftHeaderPin.swift was written to be that guard, but it cannot be one on its own:

  • it catches renames, removals and type changes of the mirrored API, but not additions;
  • nothing in this repo ever compiles it — under CocoaPods it is outside the podspec's ios/**/*.{h,m,mm,swift} glob, and no CI job builds the SwiftPM target.

Concrete failure: add var imageColor: NSString? to FabricViewImplementationProtocol and set _view.imageColor in ios/NewArch/MenuView.mm. CI is green, because Xcode generates react_native_menu-Swift.h for the CocoaPods build. spm-headers/react_native_menu-Swift.h does not have the property, so every SwiftPM consumer fails with *"property 'imageColor' not found on object of type 'UIView '". The first person to find out is a downstream user.

Why there is no end-to-end build yet

A real swift build of this package is not possible at the currently pinned React Native:

  • Package.swift resolves .package(path: "../../../../xcframeworks") and .package(path: "../../../ios"), which only exist inside React Native's SwiftPM autolinking layout (<app>/ios/build/generated/autolinking/libs/<pkg>);
  • react-native@0.81.1 in node_modules has no SwiftPM autolinking at all — no consumer of the swiftpmConfig key feat(ios): add Swift Package Manager support #1232 added to package.json, and no xcframeworks pipeline.

So end-to-end SwiftPM verification is effectively blocked behind #1238 (react-native-test-app 5) -> #1249 (React Native 0.88).

Findings from the review of #1232

  • Header drift has no guard (above) — medium.
  • The mirrored @interfaces flatten their superclasses. FabricMenuViewImplementation : UIButton / FabricActionSheetView : UIView rather than MenuViewImplementation / ActionSheetView, and the pin's (UIButton & FabricViewImplementationProtocol).Type check accepts any UIButton subclass, so the divergence is invisible to it. ObjC++ reaching a member declared on the shared base but not on the protocol would build under CocoaPods and fail under SwiftPM. Checked: MenuView.mm today reaches only protocol members and UIKit ones, so this is latent. The dropped @available(iOS 14.0, *) on FabricMenuViewImplementation is the same class of drift.
  • sources: ["ios"] on the ObjC target discovers by extension over the whole ios/ subtree with no directory whitelist, unlike the Swift target. Reproduced: with a stray ios/build/Stray.mm present, swift package describe reports it compiled into ReactNativeMenuObjC. A consumer using this as a path dependency with stale codegen or a legacy Xcode build location under ios/ gets those files compiled in.
  • try! in the manifest (3 sites). A manifest that traps reports a Swift fatal error instead of a SwiftPM diagnostic. Note: I could not reproduce an actual trap — a dangling symlink under ios/ did not throw from subpathsOfDirectory or resourceValues on Swift 6.0.2 — so this is hygiene against a latent hazard (an unreadable path, or a file removed between the listing and the stat), not a demonstrated bug.
  • The __has_include fallback is an ordering assumption. ios/NewArch/MenuView.mm needs <react_native_menu/react_native_menu-Swift.h> to be absent under SwiftPM so the else branch picks up spm-headers/react_native_menu-Swift.h. But ReactNativeMenuObjC depends on the react_native_menu Swift target, and SwiftPM does expose a Swift target's generated compatibility header to dependent C-family targets. Which header wins is -I ordering, not an invariant; a Swift/SwiftPM version bump could silently switch MenuView.mm onto the generated header, which per the file's own comment cannot compile there.

Plan

Now, without an SPM build: a spm CI job running mechanical checks on the manifest and the mirrored header, plus the three code fixes. See the PR linked below.

When RN 0.88 lands (#1249): add a job that actually resolves and compiles the package through RN's SwiftPM autolinking, which is what closes the first and last findings properly.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions