[RN][iOS] Update SwiftPM to build from source - #52909
Draft
cipolleschi wants to merge 42 commits into
Draft
Conversation
cipolleschi
force-pushed
the
cipolleschi/use-spm-for-rntester
branch
2 times, most recently
from
July 31, 2025 16:36
a751861 to
dee403e
Compare
cipolleschi
force-pushed
the
cipolleschi/use-spm-for-rntester
branch
3 times, most recently
from
September 4, 2025 14:30
0d6ca8e to
0b5026f
Compare
Contributor
|
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this in D81765871. |
1 similar comment
Contributor
|
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this in D81765871. |
… prepare the HelloWorld app
…_IN_FRAMEWORK_MODULES settings
cipolleschi
force-pushed
the
cipolleschi/use-spm-for-rntester
branch
from
September 9, 2025 14:15
2750c31 to
482dda6
Compare
Contributor
|
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this in D81765871. |
Collaborator
|
This PR is stale because it has been open for 180 days with no activity. It will be closed in 7 days unless you comment on it or remove the "Stale" label. |
Collaborator
|
This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
Collaborator
|
This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
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:
30/07/2025
Prepare SwiftPM to build RNTester and HelloWorld from source.
The first step has been to create a new iOS app (which won't be committed in the end) and to update the Package.swift file.
I had to split the React-FabricComponent in subpackages because the automatically generated modulemap of React-Fabric and React-FabricComponent where overlapping, and the build was failing.
Once fixed that, I had to add a couple of hardcoded search paths in the porjects:
31/07/2025
To create the Packages for ReactCodegen and ReactAppDependencyProvider, I first needed a project with them.
To get there, I started by integrating the SwiftPM build from source in the HelloWorld app, which is configured to have codegen already.
HelloWorld was failing due to Swift incompatibility.
Swift incompatibility was due to 2 reasons:
@import React, but we don't have aReactmodule. We have aReact_Coremodule.Fix
@import ReactThis got fixed by renaming the
reactCoremodule's name fromReact-Coreto justReactFix C++ headers being visible to Swift
To fix this, I created a script in the
react-native/scripts/swiftpmfolder to create symlinks in aincludes/Reactfolder inside thereact-native/Reactfolder.For the time being, I'm using an hardcoded list of headers, taken from the same
React-umbrella.hfile we use for the prebuilds.The includes folder is gitignored.
unfortunately, the includes folder is not the default way to build prebuilds yet. So, I introduced a BUILD_FROM_SOURCE variable that can be toggled in the
Package.swiftfile to decide how to build.Current state
This brought HelloWorld to build the React module properly and to being able to import it in the app.
Hello world is still failing because it can't build the ReactAppDependencyProvider and the ReactCodegen packages.
01/08/2025
I managed to have HelloWorld building and running using only SwiftPM! 🎉 🎉 🎉
The process is still very manual and I need to work on automating it as it is quite complicated.
To build and run Helloworld, I had to first create a Pacake.swift file for
ReactCodegenand forReactAppDependencyProvider, make sure that the packages can be built in isolation, connect the packages with the app, fix the Xcodeproject.Create the Package.swift for React-Codegenerated code
The code that is generated by codegen has a structure that is not aligned with the iOS standard.
In fact, all the code is generated inside the
build/generated/iosfolder and it is flat.However, SwiftPM requires for each target to live in its own folder.
The changes that I have to apply are:
RCTAppDependecyProvider.hRCTAppDependecyProvider.mand theReactAppDependencyProvider.podspecin aReactAppDependencyProviderfolder.ReactCodegenfolder.build/generated/iosfolderDetails
Notice that the path to react-native is hardcoded locally to Helloworld, and it would have to be computed when generating it.
These manual changes needs to be ported to codegen, as codegen is the part of the infrastructure responsible for generating all these files.
Swift Packages should build in isolation. The search path should be relative to the package.
This is the part that concerns me the most, as it might affect how we build React Native apps also with prebuilds.
A Swift PM package should be able to build in isolation.
Packages that depends on other packages needs visibility over the public headers of those packages. However, when building all the packages from source, the headers of a dependency are not automatically visible to the package that depends on them.
There are several questions and post on SwiftPM about this problem:
Unfortunately,
headerSearchPathsin SwiftPM must be relative to the package itself, or SwiftPM will not build.This forces us to replicate the
headersthat we need inside aheadersfolder of the packages (soReactCodegen/headersandReactAppDependencyProvider/headers) and set theheaderSerachPathapproprietely.This can be a big problem for third party libraries: if
react-native-reanimatedexposes a Package.swift file, they will also have to "add" aheadersfolder and "add" symlinks to the react-native headers.Solution: we can probably fix this issue with the script that prepare an iOS project. When we run autolinking, we can inspect the dependencies of the library and create hard links to the required headers in all the dependencies.
We would have to verify how time consuming this process would be.
Building and running.
At this point, I only had to turn on the build from source and adjust the
REACT_NATIVE_PATHbuild setting because it was computed starting from thePodsfolder, which does not exists anymore, instead of using the$(PROJECT_DIR)folder04/08/2025
I updated codegen to properly generate the files in the ReactCodegen and in the ReactAppDependencyProvider folders.
I also add the codegen code to generate the Package.swift for ReactCodegen and ReactAppDependencyProvider.
We are missing the code that creates links to the header files.
14/08/2024
These couple of days, I worked on automating the process to prepare an app to be built with SPM.
I created various scripts to do so.
What's left to do is to properly integrate Xcode with the Package.swift files
15/08/2025
I implemented a step to modify the Xcodeproj. What is missing is a bit of cleanup and making sure not to duplicate the entries we already have.
18/08/2025
Fixed the generation of the Xcodeproj so that we don't use a json format.
20/08/2025
Started working with the integration in RNTester
There are some other headers-related failures:
TODO:
$(PROJECT_DIR)/build/generated/iosfolder in the header search path of the project.)@import Reactin the AppDelegate that will probably fail due to 4 below.@import Reactdoesn't work.@import React_Corefails for C++ symbols. We probably will have to split the reactCore package in subpackages.)Changelog:
[iOS][Changed] - Prepare SwiftPM to build from source
Test Plan:
Build locally