Skip to content
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

fix: Prioritise local cpp (use default as fallback) #48340

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

timbocole
Copy link

@timbocole timbocole commented Dec 19, 2024

Summary:

#47379 removed local cpp sources from the sources being built with the app. This resulted in a local android/app/src/main/jni/OnLoad.cpp file being ignored at build time. I have therefore added logic to the cmake file to prioritise local cpp files and fallback to ${REACT_ANDROID_DIR}/cmake-utils/default-app-setup/*.cpp if none exist.

This resolves #48298

Changelog:

[ANDROID] [FIXED] - Prioritise local OnLoad.cpp, falling back to default-app-setup

Test Plan:

@facebook-github-bot
Copy link
Contributor

Hi @timbocole!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@timbocole timbocole changed the title Prioritise local cpp (use default as fallback) fix: Prioritise local cpp (use default as fallback) Dec 19, 2024
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Dec 19, 2024
Copy link
Contributor

@cipolleschi cipolleschi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a stab at this.
However, I'm not sure that this is the right solution.

I'll try to explain:

  • We have one case where we want to load the OnLoad.cpp provided by the app, for example when we have local Cxx modules, as described by the issue #48298
  • We also have one case where we always want to load the OnLoad.cpp file provided by React Native, for example for issue #47352 that was fixed by @cortinico's commit 3956955

The proposed solution will fix the first case, but it will break the second again.

I think that the right solution should be to enhance the autolinking codegen not only to consider the dependencies in the node_modules but also to consider the modules provided by the app in the codegenConfig property of the package.json.

In that way, the default OnLoad.cpp will load autolinking that, at this point, will also have the information of the local modules provided by the app.

However, this is an architectural and delicate change that should be evaluated also by @cortinico once he is back from PTO.

@timbocole
Copy link
Author

timbocole commented Dec 19, 2024

Thanks for taking a stab at this. However, I'm not sure that this is the right solution.

I'll try to explain:

  • We have one case where we want to load the OnLoad.cpp provided by the app, for example when we have local Cxx modules, as described by the issue #48298
  • We also have one case where we always want to load the OnLoad.cpp file provided by React Native, for example for issue #47352 that was fixed by @cortinico's commit 3956955

The proposed solution will fix the first case, but it will break the second again.

I think that the right solution should be to enhance the autolinking codegen not only to consider the dependencies in the node_modules but also to consider the modules provided by the app in the codegenConfig property of the package.json.

In that way, the default OnLoad.cpp will load autolinking that, at this point, will also have the information of the local modules provided by the app.

However, this is an architectural and delicate change that should be evaluated also by @cortinico once he is back from PTO.

Actually this solution does consider issue #47352 (thanks to the else() which is entered when the override_cpp_SRC returns empty) - I have checked this by running the reproduction with my fix.

Having said that, I agree that the cleaner longterm approach would be to make the autolinking codegen more intelligent.
Will have to just utilise my patch to use local TMs until a better solution is implemented as without, local Android TMs (including the sample listed in the docs) are completely broken.

@cipolleschi
Copy link
Contributor

cipolleschi commented Dec 20, 2024

Thanks for checking the other issue as well. The code is good to me, and I agree that the current situation is bad.
However, I don't think we are going to make a release of 0.76 over Christmas time, so we can wait for Nicola to be back and validate the solution as a patch to restore all the features.

Meanwhile, I can add a warning on the website for people that are trying to create a pure C++ TurboModule in their app.

Website PR: facebook/react-native-website#4402

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issue with C++ Turbo Module in React Native 0.76.5 (Works in iOS, Not in Android)
3 participants