diff --git a/ReactAndroid/build.gradle b/ReactAndroid/build.gradle index 89eda0f2923..a33ac24ff22 100644 --- a/ReactAndroid/build.gradle +++ b/ReactAndroid/build.gradle @@ -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 { diff --git a/ReactAndroid/cmake-utils/Android-prebuilt.cmake b/ReactAndroid/cmake-utils/Android-prebuilt.cmake index 67ca5a9fa3e..371943eb984 100644 --- a/ReactAndroid/cmake-utils/Android-prebuilt.cmake +++ b/ReactAndroid/cmake-utils/Android-prebuilt.cmake @@ -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 diff --git a/ReactAndroid/cmake-utils/ReactNative-application.cmake b/ReactAndroid/cmake-utils/ReactNative-application.cmake index 2b9d315e8b1..bf1b141fe19 100644 --- a/ReactAndroid/cmake-utils/ReactNative-application.cmake +++ b/ReactAndroid/cmake-utils/ReactNative-application.cmake @@ -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() diff --git a/ReactAndroid/cmake-utils/folly-flags.cmake b/ReactAndroid/cmake-utils/folly-flags.cmake new file mode 100644 index 00000000000..510196a8ce7 --- /dev/null +++ b/ReactAndroid/cmake-utils/folly-flags.cmake @@ -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 + ) \ No newline at end of file diff --git a/ReactCommon/react/nativemodule/samples/platform/android/CMakeLists.txt b/ReactCommon/react/nativemodule/samples/platform/android/CMakeLists.txt index fd5f627983b..bf4abadd8a9 100644 --- a/ReactCommon/react/nativemodule/samples/platform/android/CMakeLists.txt +++ b/ReactCommon/react/nativemodule/samples/platform/android/CMakeLists.txt @@ -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)