Expose folly flags and make folly_runtime available to be consumed via prefab

Summary:
This removes the old way of consuming `libfolly_runtime.so` from
`Android-prebuilt.cmake` to using Prefab which is natively supported
by the Android pipeline.

Moreover, I've exposed a `folly-flags.cmake` file which can be used by libraries
to know which lists of flags they need to use for Folly.

Changelog:
[Internal] [Changed] - Move `folly_runtime` to be consumed via prefab

Reviewed By: cipolleschi

Differential Revision: D39928571

fbshipit-source-id: 4864c37813ec681a6a464c97de6dfc078f5553f1
This commit is contained in:
Nicola Corti authored and Facebook GitHub Bot committed 2022-09-29 07:44:56 -07:00
1 parent 8bb9717faa
commit 427ce5f2d2
5 files changed
+47 -22

No files matched your search

+13 -1
View File
@@ -128,6 +128,14 @@ final def preparePrefab = tasks.register("preparePrefab", PreparePrefabHeadersTa
new Pair("src/main/jni/first-party/yogajni/jni", "")
]
),
new PrefabPreprocessingEntry(
"folly_runtime",
[
new Pair(new File(buildDir, "third-party-ndk/folly/").absolutePath, ""),
new Pair(new File(buildDir, "third-party-ndk/boost/boost_1_76_0/").absolutePath, ""),
new Pair(new File(buildDir, "third-party-ndk/double-conversion/").absolutePath, ""),
]
),
]
)
it.outputDir.set(prefabHeadersDir)
@@ -395,7 +403,8 @@ android {
"glog",
"fabricjni",
"react_render_mapbuffer",
"yoga"
"yoga",
"folly_runtime"
}
}
ndk {
@@ -511,6 +520,9 @@ android {
yoga {
headers(new File(prefabHeadersDir, "yoga").absolutePath)
}
folly_runtime {
headers(new File(prefabHeadersDir, "folly_runtime").absolutePath)
}
}
publishing {
@@ -41,26 +41,6 @@ target_include_directories(fb
INTERFACE
${FIRST_PARTY_NDK_DIR}/fb/include)
## folly_runtime
add_library(folly_runtime SHARED IMPORTED GLOBAL)
set_target_properties(folly_runtime
PROPERTIES
IMPORTED_LOCATION
${REACT_NDK_EXPORT_DIR}/${ANDROID_ABI}/libfolly_runtime.so)
target_include_directories(folly_runtime
INTERFACE
${THIRD_PARTY_NDK_DIR}/boost/boost_1_76_0
${THIRD_PARTY_NDK_DIR}/double-conversion
${THIRD_PARTY_NDK_DIR}/folly)
target_compile_options(folly_runtime
INTERFACE
-DFOLLY_NO_CONFIG=1
-DFOLLY_HAVE_CLOCK_GETTIME=1
-DFOLLY_HAVE_MEMRCHR=1
-DFOLLY_USE_LIBCPP=1
-DFOLLY_MOBILE=1
-DFOLLY_HAVE_XSI_STRERROR_R=1)
## react_nativemodule_core
add_library(react_nativemodule_core SHARED IMPORTED GLOBAL)
set_target_properties(react_nativemodule_core
@@ -17,6 +17,8 @@
cmake_minimum_required(VERSION 3.13)
set(CMAKE_VERBOSE_MAKEFILE on)
include(${CMAKE_CURRENT_LIST_DIR}/folly-flags.cmake)
# If you have ccache installed, we're going to honor it.
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
@@ -56,11 +58,12 @@ add_library(glog ALIAS ReactAndroid::glog)
add_library(fabricjni ALIAS ReactAndroid::fabricjni)
add_library(react_render_mapbuffer ALIAS ReactAndroid::react_render_mapbuffer)
add_library(yoga ALIAS ReactAndroid::yoga)
add_library(folly_runtime ALIAS ReactAndroid::folly_runtime)
target_link_libraries(${CMAKE_PROJECT_NAME}
fabricjni # prefab ready
fbjni
folly_runtime
folly_runtime # prefab ready
glog # prefab ready
jsi # prefab ready
react_codegen_rncore # prefab ready
@@ -77,8 +80,15 @@ target_link_libraries(${CMAKE_PROJECT_NAME}
turbomodulejsijni # prefab ready
yoga) # prefab ready
# We use an interface targe to propagate flags to all the generated targets
# such as the folly flags or others.
add_library(common_flags INTERFACE)
target_compile_options(common_flags INTERFACE ${folly_FLAGS})
target_link_libraries(ReactAndroid::react_codegen_rncore INTERFACE common_flags)
# If project is on RN CLI v9, then we can use the following lines to link against the autolinked 3rd party libraries.
if(EXISTS ${PROJECT_BUILD_DIR}/generated/rncli/src/main/jni/Android-rncli.cmake)
include(${PROJECT_BUILD_DIR}/generated/rncli/src/main/jni/Android-rncli.cmake)
target_link_libraries(${CMAKE_PROJECT_NAME} ${AUTOLINKED_LIBRARIES})
target_link_libraries(${AUTOLINKED_LIBRARIES} PRIVATE common_flags)
endif()
@@ -0,0 +1,22 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
cmake_minimum_required(VERSION 3.13)
set(CMAKE_VERBOSE_MAKEFILE on)
# This CMake file exposes the Folly Flags that all the libraries should use when
# compiling/linking against a dependency which requires folly.
SET(folly_FLAGS
-DFOLLY_NO_CONFIG=1
-DFOLLY_HAVE_CLOCK_GETTIME=1
-DFOLLY_USE_LIBCPP=1
-DFOLLY_MOBILE=1
-DFOLLY_HAVE_RECVMMSG=1
-DFOLLY_HAVE_PTHREAD=1
# Once we target android-23 above, we can comment
# the following line. NDK uses GNU style stderror_r() after API 23.
-DFOLLY_HAVE_XSI_STRERROR_R=1
)
@@ -13,6 +13,7 @@ add_compile_options(
-Wall
-Wpedantic
-Wno-gnu-zero-variadic-macro-arguments
-DFOLLY_NO_CONFIG=1
-DLOG_TAG=\"ReactNative\")
file(GLOB sampleturbomodule_SRC CONFIGURE_DEPENDS ReactCommon/*.cpp)