Skip to content

SwiftPM autolinking: judge mixed languages by podspec sources - #59577

Open
chrfalch wants to merge 1 commit into
mainfrom
chrfalch/spm-mixed-lang-check
Open

chrfalch wants to merge 1 commit into
mainfrom
chrfalch/spm-mixed-lang-check

Conversation

@chrfalch

Copy link
Copy Markdown
Collaborator

Summary:

When a library has no Package.swift, SwiftPM autolinking stops the build with an error. If the library mixes Swift and Objective-C, the error says to opt the library out. Otherwise, it says to run npx react-native spm scaffold.

To decide, the check scanned every file in the library on disk. A Swift file that the podspec never compiles still counted. Example: @react-native-google-signin/google-signin compiles only ios/**/*.{h,m,mm}, but it also ships expo/ios/ExpoAdapterGoogleSignIn/GoogleSignInAppDelegate.swift. So the build told users to opt out an Objective-C library that spm scaffold can handle.

The scaffolder already decides from the files the podspec compiles. This change makes the autolinker use the same rule:

  1. The autolinker reads the podspec the scaffolder would read: the podspecPath from the autolinking config, else the first podspec in the package root.
  2. It expands source_files from the package root and removes exclude_files, using the same code as the scaffolder (moved into a shared podspecSourceFiles helper).
  3. It decides "mixed" with the same predicate as the scaffolder (shared isMixedLanguageSourceList).
  4. If there is no podspec, or the podspec cannot be read, it falls back to the disk scan as before.
  5. The podspec is read only on this error path, so normal builds do not change.
  6. spm.modules (app-local code, no podspec) keep the disk scan.

Changelog:

[IOS] [FIXED] - SwiftPM autolinking no longer reports a library as mixed Swift/Objective-C because of Swift files its podspec does not compile

Test Plan:

New tests in generate-spm-autolinking-test.js: a library with an Objective-C podspec and a stray Swift file (must say "run spm scaffold"), a podspec that compiles Swift and Objective-C (must say mixed), exclude_files removing the only Swift file, a configured podspecPath next to another podspec, a podspec in ios/ with a nested sourceDir, and unit tests for the predicate. These failed before the change.

yarn jest packages/react-native/scripts/spm
# Test Suites: 25 passed, 25 total
# Tests:       1205 passed, 1205 total

yarn eslint --max-warnings 0 packages/react-native/scripts/spm
# no warnings

Not run locally: yarn flow-check. My local Flow version did not match the repo's required version, so I rely on CI for Flow.

The missing-manifest check scanned every file in a library on disk. A Swift
file the podspec never compiles (for example an Expo adapter) marked an
Objective-C library as mixed-language, so the build said to opt the library
out instead of running `spm scaffold`.

The check now reads the same podspec as the scaffolder, expands its
source_files from the same root and applies exclude_files. It falls back to
the disk scan when there is no podspec or it cannot be read. spm.modules keep
the disk scan.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 28, 2026
@facebook-github-tools facebook-github-tools Bot added p: Expo Partner: Expo Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Oct 28, 2026
@chrfalch
chrfalch requested a review from cipolleschi October 28, 2026 15:39

This branch has not been deployed

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

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Expo Partner: Expo Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant