Repository navigation
Commit 84e60bc
SwiftPM: declare ReactAppHeaders in the codegen placeholder package (#59293)
Summary:
A SwiftPM app can get stuck when setup skips codegen. Setup skips codegen when you pass `--skipCodegen`, when codegen fails ("Continuing anyway"), or when the codegen script is missing. In each case `spm add` / `spm update` writes a placeholder `build/generated/ios/Package.swift`, which the "Sync SPM Autolinking" hook replaces during the build.
The placeholder declared only `ReactCodegen` and `ReactAppDependencyProvider`. Every autolinked or scaffolded library manifest also depends on `ReactAppHeaders` from that package. So Xcode fails package resolution:
```
product 'ReactAppHeaders' required by package 'reactnativesafeareacontext' target 'ReactNativeSafeAreaContext' not found in package 'React-GeneratedCode'.
```
Xcode resolves packages before the scheme pre-action and the build phases, so neither hook runs, and every later build fails the same way. The only way out is to run setup again with codegen, and the error does not say so.
This change makes the placeholder declare `ReactAppHeaders` (every entry of `REACT_CODEGEN_PRODUCTS`) too. `SPM_PRODUCT_PACKAGES` is unchanged, because it also decides which products the app target links, and the app must not link `ReactAppHeaders`.
Known limit, not changed here: after this fix the first build still fails once, because the hook generates the library's codegen headers during that build, after the package graph is resolved (for example `'react/renderer/components/safeareacontext/Props.h' file not found`). The next build succeeds with no other change.
## Changelog:
[IOS] [FIXED] - SwiftPM: a project set up with skipped codegen no longer fails package resolution on `ReactAppHeaders`
Pull Request resolved: #59293
Test Plan:
Unit tests: two new tests for `ensureStubPackages` in `generate-spm-xcodeproj-test.js`. One checks that the placeholder declares each codegen product exactly once. One checks that an existing `Package.swift` is not changed.
```
yarn jest --no-cache -i packages/react-native/scripts/spm/__tests__/generate-spm-xcodeproj-test.js
```
- Without the source change: 1 failed (`ReactAppHeaders` declared 0 times).
- With the source change: 66 passed, 66 total.
- ESLint (`--max-warnings 0`) and Prettier pass on both files.
Fresh app (Xcode 27.1): `0.89.0-nightly-20261021-c7429b0e9` + `react-native-safe-area-context` 5.10.1, `npx react-native spm add --deintegrate --skipCodegen`, then `xcodebuild -resolvePackageDependencies` and `xcodebuild build`:
- Without the fix: resolution fails with the error above; the build stops at resolution (exit 74) and no hook runs.
- With the fix applied to the app's copy of the script: resolution passes; the first build runs the sync hook, which replaces the placeholder, and then fails on the missing library codegen headers (exit 65); the second build succeeds.
Not run: full `yarn flow-check` (a scoped Flow check showed no errors in the changed files).
Reviewed By: andrewdacenko
Differential Revision: D126658850
Pulled By: cipolleschi
fbshipit-source-id: 0ef10c5180f5932cfd761b16418e9a368401550b
(cherry picked from commit e3aa9a1)1 parent a25ec46 commit 84e60bc
2 files changed
Lines changed: 63 additions & 0 deletions
File tree
- packages/react-native/scripts/spm
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
895 | 896 | | |
896 | 897 | | |
897 | 898 | | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
| |||
1136 | 1137 | | |
1137 | 1138 | | |
1138 | 1139 | | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
1139 | 1152 | | |
1140 | 1153 | | |
1141 | 1154 | | |
| |||
0 commit comments