-
Notifications
You must be signed in to change notification settings - Fork 906
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add support for C++ TurboModules Autolinking #2296
Conversation
So happy to see this! Let me know if we can help anyhow |
This works in conjusction with: |
Co-authored-by: Szymon Rybczak <[email protected]>
@cortinico did you maybe check what was needed for the autolinking to work in this PR: software-mansion/react-native-gesture-handler#2708? Would be nice to cover all the needed parts 🎉 |
@WoLewicki I've briefly checked and it seems like Gesture Handler would fit the current setup for TM CXX Autolinking I'm proposing here (we'll have to adapt the setup a bit) |
… from RNCLI (facebook#43049) Summary: This connects the OnLoad.cpp file used by OSS apps with the `rncli_cxxModuleProvider`. This method is created by the CLI and takes care of querying all the TM CXX Modules discovered and returning them. This PR is currently waiting on react-native-community/cli#2296 Changelog: [Internal] [Changed] - Hook the default-app-setup OnLoad.cpp file with the cxxModuleProvider from RNCLI Reviewed By: cipolleschi Differential Revision: D53812109
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
… from RNCLI (facebook#43049) Summary: Pull Request resolved: facebook#43049 This connects the OnLoad.cpp file used by OSS apps with the `rncli_cxxModuleProvider`. This method is created by the CLI and takes care of querying all the TM CXX Modules discovered and returning them. This PR is currently waiting on react-native-community/cli#2296 Changelog: [Internal] [Changed] - Hook the default-app-setup OnLoad.cpp file with the cxxModuleProvider from RNCLI Reviewed By: cipolleschi Differential Revision: D53812109
… from RNCLI (facebook#43049) Summary: Pull Request resolved: facebook#43049 This connects the OnLoad.cpp file used by OSS apps with the `rncli_cxxModuleProvider`. This method is created by the CLI and takes care of querying all the TM CXX Modules discovered and returning them. This PR is currently waiting on react-native-community/cli#2296 Changelog: [Internal] [Changed] - Hook the default-app-setup OnLoad.cpp file with the cxxModuleProvider from RNCLI Reviewed By: cipolleschi Differential Revision: D53812109
… from RNCLI (#43049) Summary: Pull Request resolved: #43049 This connects the OnLoad.cpp file used by OSS apps with the `rncli_cxxModuleProvider`. This method is created by the CLI and takes care of querying all the TM CXX Modules discovered and returning them. This PR is currently waiting on react-native-community/cli#2296 Changelog: [Internal] [Changed] - Hook the default-app-setup OnLoad.cpp file with the cxxModuleProvider from RNCLI Reviewed By: cipolleschi Differential Revision: D53812109 fbshipit-source-id: 47bc0ea699516993070cfa0127de97853acf8890
… from RNCLI (#43049) Summary: Pull Request resolved: #43049 This connects the OnLoad.cpp file used by OSS apps with the `rncli_cxxModuleProvider`. This method is created by the CLI and takes care of querying all the TM CXX Modules discovered and returning them. This PR is currently waiting on react-native-community/cli#2296 Changelog: [Internal] [Changed] - Hook the default-app-setup OnLoad.cpp file with the cxxModuleProvider from RNCLI Reviewed By: cipolleschi Differential Revision: D53812109 fbshipit-source-id: 47bc0ea699516993070cfa0127de97853acf8890
Is there any example C++ TurboModule that autolinks? I can't seem to get the CMakeLists configuration right for react-native-mmkv... |
Sadly not. I had it working on my local setup, and I haven't had the time to work on samples or further docs. |
Is my understanding correct that there are 3 CMakeLists.txt files per CxxTurboModule?
And then my react-native.config.js should look like this: // https://github.com/react-native-community/cli/blob/main/docs/dependencies.md
module.exports = {
dependency: {
platforms: {
/**
* @type {import('@react-native-community/cli-types').IOSDependencyParams}
*/
ios: {},
/**
* @type {import('@react-native-community/cli-types').AndroidDependencyParams}
*/
android: {
cxxModuleCMakeListsModuleName: 'reactnativemmkv',
cxxModuleCMakeListsPath: './CMakeLists.txt',
cxxModuleHeaderName: 'NativeMmkvModule',
},
},
},
}; Not sure what I'm missing, but I can't seem to get that to build/link properly... Code is here: react-native-mmkv ( The error I'm seeing right now is this:
..which seems to happen in |
Summary:
This adds support for C++ TurboModules Autolinking on Android.
I added those properties in the config command:
platforms.android.cxxModuleCMakeListsModuleName
The name of the CMake target that is building the C++ Turbo Module. This is generally
different from the codegen target which is called
react_codegen_<yourlibrary>
.You will need to create a custom
CMakeLists.txt
, which defines a target, depends onreact_codegen_<yourlibrary>
and builds your C++ Turbo Module.Specify the name of the target here so that it can be properly linked to the rest of the app project.
platforms.android.cxxModuleCMakeListsPath
A relative path to a custom CMakeLists.txt file that is used to build a C++ TurboModule. Relative to
sourceDir
.platforms.android.cxxModuleHeaderName
The name of the C++ TurboModule. Your C++ TurboModule generally should implement one of the JSI interface generated by Codegen. You need to specify the name of the class that is implementing the generated interface here, so that it can properly be linked in the rest of the app project.
We expect that your module exposes a filed called
kModuleName
which is a string that contains the name of the module. This field is properly populated by codegen, but if you don't use codegen, you will have to make sure that this field is present.Say your module name is
NativeCxxModuleExample
, it will be included in the autolinking logic as follows:Test Plan:
I had to test it manually in a nightly project by tampering the
node_modules
folder and I managed to make it work. Not sure how I can test it more.Checklist