Adding Discord-only TurboModule support #34
Merged
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.
In This PR..
Adding Support for building only Discord TurboModules.
How It's Done
We accomplish in two parts (TL;DRs in bold)
ReactPlugin.kt
to codegen only modules with a package name starting withcom.discord
. Codegen is the "third pillar" of "The New Architecture". It allows us to define the schema of what's communicated through the JSI, and have the Makefiles/Java/etc. generated for us, to the point where all we need to do is include and implement their generated interface on the native side, and call the generated interface from the JS side. The vanilla way to codegen is by running thegenerateCodegenArtifactsFromSchema
gradle task withnewArchEnabled=true
, normally this task is added as part of the build whennewArchEnabled=true
, so it's not normally run standalone, though it can be. This task is problematic because some of our third party dependencies, likereact-native-reanimated
orreact-native-gesture-handler
have codegen support, and this task will codegen every module that has codegen support. If we run codegen, then run a build withnewArchEnabled=false
, it creates build issues with these third party dependencies because their generated schemas share the same class name as their legacy-module-schema equivalents, thus we get class name duplicate errors. The fix for this is to add in a new project level gradle option:onlyDiscordTurboModulesEnabled
. This creates an extra condition during the codegen process to only codegen modules that begin withcom.discord
, we can then run (at thereact-native/ReactAndroid
level)This runs the task with both
newArchEnabled
andonlyDiscordTurboModulesEnabled
set totrue
, codegen-ing only Discord TurboModules.CMakeLists.txt
describing how to compile the generated.h
and.cpp
files, which are the JSI layer of the TurboModule. In order to compile against the JSI layer, we need a handful of libraries (*.so
) and their associated headers. These resources are assumed to be available, but they aren't when compiling withnewArchEnabled=false
. These new options allow us to pass in a couple extra CMake options:PREBUILT_CMAKE
, which is a.cmake
file that includes library definitions for the needed JSI*.so
s.EXTRA_INCLUDE_DIRECTORIES
, which allows us to define an extra set of header directories, so the compiled source knows where<fbjni/fbjni.h>
and all of the other includes are.Assumptions
For the moment, we must build React Native from source if we're building out these Discord-only-TurboModules. We can fix this in the future, but there's two versions of
react-native-codegen
in this repository. One inpackages/
for when building React Native from source, and one provided via yarn, which'll eventually end up innode_modules
, for when providing a pre-built React Native artifact. This PR only includes the impl for the build-from-source approach while we stand up the initial Discord TurboModules. A future PR will provide the impl for the prebuilt approach.