Skip to content

Commit

Permalink
fix: Prioritise local cpp (use default as fallback) (#48340)
Browse files Browse the repository at this point in the history
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

Pull Request resolved: #48340

Test Plan:
- Followed the https://reactnative.dev/docs/the-new-architecture/pure-cxx-modules guide (which was broken > 0.76.1)
- Applied the patch to the reproduction repository linked to #47352 to ensure no regression

Reviewed By: cipolleschi

Differential Revision: D67736012

Pulled By: cortinico

fbshipit-source-id: 87f6b8edf1613682585a94e1d1b3e6b4b792e4f5
  • Loading branch information
timbocole authored and facebook-github-bot committed Dec 31, 2024
1 parent a3c8e21 commit 8b1f049
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,19 @@ if (PROJECT_ROOT_DIR)
# variable is defined if user need to access it.
endif ()

file(GLOB input_SRC CONFIGURE_DEPENDS
${REACT_ANDROID_DIR}/cmake-utils/default-app-setup/*.cpp
${BUILD_DIR}/generated/autolinking/src/main/jni/*.cpp)
file(GLOB override_cpp_SRC CONFIGURE_DEPENDS *.cpp)
# We check if the user is providing a custom OnLoad.cpp file. If so, we pick that
# for compilation. Otherwise we fallback to using the `default-app-setup/OnLoad.cpp`
# file instead.
if(override_cpp_SRC)
file(GLOB input_SRC CONFIGURE_DEPENDS
*.cpp
${BUILD_DIR}/generated/autolinking/src/main/jni/*.cpp)
else()
file(GLOB input_SRC CONFIGURE_DEPENDS
${REACT_ANDROID_DIR}/cmake-utils/default-app-setup/*.cpp
${BUILD_DIR}/generated/autolinking/src/main/jni/*.cpp)
endif()

add_library(${CMAKE_PROJECT_NAME} SHARED ${input_SRC})

Expand Down

0 comments on commit 8b1f049

Please sign in to comment.