Skip to content

Commit f1c614b

Browse files
cortinicofacebook-github-bot
authored andcommitted
Build RN Tester with CMake (#33937)
Summary: Pull Request resolved: #33937 This moves the build of RNTester from Unix Make to CMake This will serve as a blueprint for users that are looking into using CMake end-to-end in their buildls. In order to make this possible I had to: * Add an `Android-prebuilt.cmake` file that works similar to the `Android-prebuilt.mk` for feeding prebuilt .so files to the consumer build. * Update the codegen to use `JSI_EXPORT` on several objects/classes as CMake has stricter visibility rules than Make * Update the sample native module in `nativemodule/samples/platform/android/` to use CMake instead of Make Changelog: [Internal] [Changed] - Build RN Tester with CMake Reviewed By: cipolleschi Differential Revision: D36760309 fbshipit-source-id: b99449a4b824b6c0064e833d4bcd5969b141df70
1 parent a9659ce commit f1c614b

File tree

17 files changed

+545
-181
lines changed

17 files changed

+545
-181
lines changed
Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
#
3+
# This source code is licensed under the MIT license found in the
4+
# LICENSE file in the root directory of this source tree.
5+
6+
# This configuration provides access to most common React Native prebuilt .so files
7+
# to avoid recompiling each of the libraries outside of ReactAndroid NDK compilation.
8+
# Hosting app's/library's CMakeLists.txt can include this Android-prebuilt.cmake file to
9+
# get access to those libraries to depend on.
10+
# NOTES:
11+
# * Currently, it assumes building React Native from source.
12+
# * Not every .so is listed here (yet).
13+
# * Static libs are not covered here (yet).
14+
15+
cmake_minimum_required(VERSION 3.13)
16+
set(CMAKE_VERBOSE_MAKEFILE on)
17+
18+
# FIRST_PARTY_NDK_DIR contains vendored source code from other FB frameworks
19+
# like Yoga, FBJNI, etc.
20+
set(FIRST_PARTY_NDK_DIR ${REACT_ANDROID_DIR}/src/main/jni/first-party)
21+
# THIRD_PARTY_NDK_DIR is where we're downloading third-party native
22+
# frameworks such as libevent, boost, etc.
23+
set(THIRD_PARTY_NDK_DIR ${REACT_ANDROID_BUILD_DIR}/third-party-ndk)
24+
# REACT_ANDROID_SRC_DIR is the root of ReactAndroid source code (Java & JNI)
25+
set(REACT_ANDROID_SRC_DIR ${REACT_ANDROID_DIR}/src/main)
26+
# REACT_COMMON_DIR is the root of ReactCommon source code (C++ only)
27+
set(REACT_COMMON_DIR ${REACT_ANDROID_DIR}/../ReactCommon)
28+
# REACT_GENERATED_SRC_DIR is the folder where the codegen for rncore will output
29+
set(REACT_GENERATED_SRC_DIR ${REACT_ANDROID_BUILD_DIR}/generated/source)
30+
# REACT_NDK_EXPORT_DIR is the folder where the .so will be copied for being inported
31+
# in the local project by the packageReactDebugNdkLibs/packageReactReleaseNdkLibs
32+
set(REACT_NDK_EXPORT_DIR ${PROJECT_BUILD_DIR}/react-ndk/exported)
33+
34+
## fb
35+
add_library(fb SHARED IMPORTED GLOBAL)
36+
set_target_properties(fb
37+
PROPERTIES
38+
IMPORTED_LOCATION
39+
${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libfb.so)
40+
target_include_directories(fb
41+
INTERFACE
42+
${FIRST_PARTY_NDK_DIR}/fb/include)
43+
44+
## folly_runtime
45+
add_library(folly_runtime SHARED IMPORTED GLOBAL)
46+
set_target_properties(folly_runtime
47+
PROPERTIES
48+
IMPORTED_LOCATION
49+
${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libfolly_runtime.so)
50+
target_include_directories(folly_runtime
51+
INTERFACE
52+
${THIRD_PARTY_NDK_DIR}/boost/boost_1_76_0
53+
${THIRD_PARTY_NDK_DIR}/double-conversion
54+
${THIRD_PARTY_NDK_DIR}/folly)
55+
target_compile_options(folly_runtime
56+
INTERFACE
57+
-DFOLLY_NO_CONFIG=1
58+
-DFOLLY_HAVE_CLOCK_GETTIME=1
59+
-DFOLLY_HAVE_MEMRCHR=1
60+
-DFOLLY_USE_LIBCPP=1
61+
-DFOLLY_MOBILE=1
62+
-DFOLLY_HAVE_XSI_STRERROR_R=1)
63+
64+
## glog
65+
add_library(glog SHARED IMPORTED GLOBAL)
66+
set_target_properties(glog
67+
PROPERTIES
68+
IMPORTED_LOCATION
69+
${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libglog.so)
70+
target_include_directories(glog INTERFACE ${THIRD_PARTY_NDK_DIR}/glog/exported)
71+
72+
## yoga
73+
add_library(yoga SHARED IMPORTED GLOBAL)
74+
set_target_properties(yoga
75+
PROPERTIES
76+
IMPORTED_LOCATION
77+
${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libyoga.so)
78+
target_include_directories(yoga
79+
INTERFACE
80+
${FIRST_PARTY_NDK_DIR}/yogajni/jni
81+
${REACT_COMMON_DIR}/yoga)
82+
target_compile_options(yoga
83+
INTERFACE
84+
-fvisibility=hidden
85+
-fexceptions
86+
-frtti
87+
-O3)
88+
target_link_libraries(yoga INTERFACE log android)
89+
90+
## react_nativemodule_core
91+
add_library(react_nativemodule_core SHARED IMPORTED GLOBAL)
92+
set_target_properties(react_nativemodule_core
93+
PROPERTIES
94+
IMPORTED_LOCATION
95+
${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libreact_nativemodule_core.so)
96+
target_include_directories(react_nativemodule_core
97+
INTERFACE
98+
${REACT_ANDROID_SRC_DIR}/jni
99+
${REACT_COMMON_DIR}
100+
${REACT_COMMON_DIR}/callinvoker
101+
${REACT_COMMON_DIR}/jsi
102+
${REACT_COMMON_DIR}/react/nativemodule/core
103+
${REACT_COMMON_DIR}/react/nativemodule/core/platform/android)
104+
target_link_libraries(react_nativemodule_core INTERFACE folly_runtime)
105+
106+
## turbomodulejsijni
107+
add_library(turbomodulejsijni SHARED IMPORTED GLOBAL)
108+
set_target_properties(turbomodulejsijni
109+
PROPERTIES
110+
IMPORTED_LOCATION
111+
${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libturbomodulejsijni.so)
112+
target_include_directories(turbomodulejsijni
113+
INTERFACE
114+
${REACT_ANDROID_SRC_DIR}/java/com/facebook/react/turbomodule/core/jni)
115+
116+
## react_render_core
117+
add_library(react_render_core SHARED IMPORTED GLOBAL)
118+
set_target_properties(react_render_core
119+
PROPERTIES
120+
IMPORTED_LOCATION
121+
${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libreact_render_core.so)
122+
target_include_directories(react_render_core
123+
INTERFACE
124+
${REACT_COMMON_DIR}
125+
${REACT_COMMON_DIR}/react/renderer/core)
126+
127+
## react_render_debug
128+
add_library(react_render_debug SHARED IMPORTED GLOBAL)
129+
set_target_properties(react_render_debug
130+
PROPERTIES
131+
IMPORTED_LOCATION
132+
${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libreact_render_debug.so)
133+
target_include_directories(react_render_debug INTERFACE ${REACT_COMMON_DIR}/react/renderer/debug)
134+
135+
## react_debug
136+
add_library(react_debug SHARED IMPORTED GLOBAL)
137+
set_target_properties(react_debug
138+
PROPERTIES
139+
IMPORTED_LOCATION
140+
${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libreact_debug.so)
141+
target_include_directories(react_debug INTERFACE ${REACT_COMMON_DIR}/react/debug)
142+
target_link_libraries(react_nativemodule_core INTERFACE folly_runtime)
143+
144+
## react_render_graphics
145+
add_library(react_render_graphics SHARED IMPORTED GLOBAL)
146+
set_target_properties(react_render_graphics
147+
PROPERTIES
148+
IMPORTED_LOCATION
149+
${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libreact_render_graphics.so)
150+
target_include_directories(react_render_graphics
151+
INTERFACE
152+
${REACT_COMMON_DIR}/react/renderer/graphics
153+
${REACT_COMMON_DIR}/react/renderer/graphics/platform/cxx)
154+
155+
## react_render_imagemanager
156+
add_library(react_render_imagemanager SHARED IMPORTED GLOBAL)
157+
set_target_properties(react_render_imagemanager
158+
PROPERTIES
159+
IMPORTED_LOCATION
160+
${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libreact_render_imagemanager.so)
161+
target_include_directories(react_render_imagemanager
162+
INTERFACE
163+
${REACT_COMMON_DIR}/react/renderer/imagemanager
164+
${REACT_COMMON_DIR}/react/renderer/imagemanager/platform/cxx)
165+
166+
## react_render_mounting
167+
add_library(react_render_mounting SHARED IMPORTED GLOBAL)
168+
set_target_properties(react_render_mounting
169+
PROPERTIES
170+
IMPORTED_LOCATION
171+
${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libreact_render_mounting.so)
172+
target_include_directories(react_render_mounting INTERFACE ${REACT_COMMON_DIR}/react/renderer/mounting)
173+
174+
## react_render_mapbuffer
175+
add_library(react_render_mapbuffer SHARED IMPORTED GLOBAL)
176+
set_target_properties(react_render_mapbuffer
177+
PROPERTIES
178+
IMPORTED_LOCATION
179+
${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libreact_render_mapbuffer.so)
180+
target_include_directories(react_render_mapbuffer INTERFACE ${REACT_COMMON_DIR}/react/renderer/mapbuffer)
181+
182+
## rrc_view
183+
add_library(rrc_view SHARED IMPORTED GLOBAL)
184+
set_target_properties(rrc_view
185+
PROPERTIES
186+
IMPORTED_LOCATION
187+
${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/librrc_view.so)
188+
target_include_directories(rrc_view INTERFACE ${REACT_COMMON_DIR}/react/renderer/components/view)
189+
190+
## fabricjni
191+
add_library(fabricjni SHARED IMPORTED GLOBAL)
192+
set_target_properties(fabricjni
193+
PROPERTIES
194+
IMPORTED_LOCATION
195+
${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libfabricjni.so)
196+
target_include_directories(fabricjni INTERFACE ${REACT_ANDROID_SRC_DIR}/java/com/facebook/react/fabric/jni)
197+
198+
## react_render_componentregistry
199+
add_library(react_render_componentregistry SHARED IMPORTED GLOBAL)
200+
set_target_properties(react_render_componentregistry
201+
PROPERTIES
202+
IMPORTED_LOCATION
203+
${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libreact_render_componentregistry.so)
204+
target_include_directories(react_render_componentregistry INTERFACE ${REACT_COMMON_DIR}/react/renderer/componentregistry)
205+
206+
## jsi
207+
add_library(jsi SHARED IMPORTED GLOBAL)
208+
set_target_properties(jsi
209+
PROPERTIES
210+
IMPORTED_LOCATION
211+
${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libjsi.so)
212+
target_include_directories(jsi INTERFACE ${REACT_COMMON_DIR}/jsi)
213+
214+
## react_codegen_rncore
215+
add_library(react_codegen_rncore SHARED IMPORTED GLOBAL)
216+
set_target_properties(react_codegen_rncore
217+
PROPERTIES
218+
IMPORTED_LOCATION
219+
${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libreact_codegen_rncore.so)
220+
target_include_directories(react_codegen_rncore INTERFACE ${REACT_GENERATED_SRC_DIR}/codegen/jni)
221+
222+
## runtimeexecutor
223+
add_library(runtimeexecutor SHARED IMPORTED GLOBAL)
224+
set_target_properties(runtimeexecutor
225+
PROPERTIES
226+
IMPORTED_LOCATION
227+
${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libruntimeexecutor.so)
228+
target_include_directories(runtimeexecutor INTERFACE ${REACT_COMMON_DIR}/runtimeexecutor)
229+
230+
## fbjni
231+
add_subdirectory(${FIRST_PARTY_NDK_DIR}/fbjni fbjni_build)

ReactCommon/react/nativemodule/samples/platform/android/Android.mk

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
#
3+
# This source code is licensed under the MIT license found in the
4+
# LICENSE file in the root directory of this source tree.
5+
6+
cmake_minimum_required(VERSION 3.13)
7+
set(CMAKE_VERBOSE_MAKEFILE on)
8+
9+
add_compile_options(-fexceptions -frtti -std=c++17 -Wall -DLOG_TAG=\"ReactNative\")
10+
11+
file(GLOB sampleturbomodule_SRC CONFIGURE_DEPENDS ReactCommon/*.cpp)
12+
add_library(sampleturbomodule STATIC ${sampleturbomodule_SRC})
13+
14+
target_include_directories(sampleturbomodule PUBLIC .)
15+
16+
target_link_libraries(sampleturbomodule
17+
fbjni
18+
jsi
19+
react_nativemodule_core)

0 commit comments

Comments
 (0)