-
Notifications
You must be signed in to change notification settings - Fork 883
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: Support autolinking C++ only TurboModules on Android #2387
base: main
Are you sure you want to change the base?
Conversation
Thanks for sending this over @atlj this is great!
I think we should not add a new property, and instead adapt the logic to work on the existing properties:
and remove the assumption that there needs to be a |
Hey @cortinico I've removed the property from the config. The CLI now treats a dependency that doesn't have a manifest or a build.gradle file (full details in the description) as a pure cxx dependency. |
Thanks for the sending this over. I'll try to review this in the next days. Just a heads up that things are slower than usual those days due to https://conf.react.dev/ |
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.
LGTM! Thank you for contribution @atlj! 🚀
I gave it a shot inside example and it retrieves all values correctly 🙌
"android": {
"sourceDir": "path/react-native-cxx-turbomodule/cpp",
"packageImportPath": null,
"packageInstance": null,
"buildTypes": [],
"libraryName": "RNCxxTurbomoduleSpec",
"componentDescriptors": [],
"cmakeListsPath": "path/react-native-cxx-turbomodule/cpp/build/generated/source/codegen/jni/CMakeLists.txt",
"cxxModuleCMakeListsModuleName": "CxxTurbomodule",
"cxxModuleCMakeListsPath": "path/react-native-cxx-turbomodule/cpp/CMakeLists.txt",
"cxxModuleHeaderName": "CxxTurbomodule",
"isPureCxxDependency": true
}
…ava packagelist This also ignores them from getting included with gradle dependencies
Just a heads up that if we merge this, the same functionality needs to be backported here: |
@cortinico is there any design doc around autolinking in the core RN repo? Does it clash somehow with RNCCLI autolinking, doing redundant work, bailing out? |
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.
@atlj thanks for sending this! We have some docs around autolinking in https://github.com/react-native-community/cli/blob/main/docs/autolinking.md which includes other cxx stuff. Would you mind extending the docs with isPureCxxDependency
and how and when to use it from a user perspective?
Nope I don't have a design doc sadly, but I just ported over all the code from We should update |
Thanks, that makes it clearer I think! So we keep autolinking until it's deployed in the core (0.75?) and once it has parity, we can start removing it from this codebase? |
We can keep it around, I was actually thinking about updating the |
Summary:
#2296 adds support for auto-linking C++ turbo modules on Android. However, you would still need a
build.gradle
file for your module to be linked. This is for a couple of reasons:AndroidManifest.xml
file or abulid.gradle
file,react-native config
returnsnull
. See the related line.packageName
,react-native config
returnsnull
. We don't need thepackageName
property since C++ projects are included by their paths. See the related line.PackageList.java
file tries to include and initialize your turbo module as a Java class. See the related line.This PR derives a property called
isPureCxxDependency
from a few factors:cxxModuleCMakeListsModuleName
as a truthy value in their configuration.cxxModuleCMakeListsPath
as a truthy value in their configuration.cxxModuleHeaderName
as a truthy value in their configuration.build.gradle
file in theirsourceDir
(This isandroid/
by default) or its subdirectories.AndroidManifest.xml
file in theirsourceDir
or its subdirectories.If all these cases are met, the CLI outputs the
isPureCxxDependency
property astrue
. This in turn causes thenative-modules.gradle
file not to include this dependency in the generatedPackageList.java
file and the dependency isn't added as a gradle dependency to the app project.Test Plan:
I have created a turbo module using create-react-native-library. Then I linked the CLI and tested the implementation. I've also added react-native-reanimated as a dependency to the project's example app to make sure this implementation doesn't break the existing support for turbo modules.
Checklist