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

Add CMakeLists to build C++ files in OSS #37969

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion packages/react-native/ReactAndroid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,23 @@ task downloadGlog(dependsOn: createNativeDepsDirectories, type: Download) {
dest(new File(downloadsDir, "glog-${GLOG_VERSION}.tar.gz"))
}

task downloadGtest(dependsOn: createNativeDepsDirectories, type: Download) {
src("https://github.com/google/googletest/archive/refs/tags/release-${GTEST_VERSION}.tar.gz")
onlyIfModified(true)
overwrite(false)
retries(5)
dest(new File(downloadsDir, "gtest.tar.gz"))
}

task prepareGtest(dependsOn: dependenciesPath ? [] : [downloadGtest], type: Copy) {
from(dependenciesPath ?: tarTree(downloadGtest.dest))
eachFile { fname -> {
fname.path = (fname.path - "googletest-release-${GTEST_VERSION}/")
}
}
into(new File(thirdPartyNdkDir,"googletest"))
}

// Prepare glog sources to be compiled, this task will perform steps that normally should've been
// executed by automake. This way we can avoid dependencies on make/automake
final def prepareGlog = tasks.register("prepareGlog", PrepareGlogTask) {
Expand All @@ -360,6 +377,7 @@ task downloadNdkBuildDependencies {
dependsOn(downloadGlog)
dependsOn(downloadFmt)
dependsOn(downloadLibevent)
dependsOn(downloadGtest)
}

/**
Expand Down Expand Up @@ -485,6 +503,10 @@ android {
targets "jsijniprofiler",
"reactnativeblob",
"reactperfloggerjni",
"bridgeless",
"rninstance",
"hermesinstancejni",
"uimanagerjni",
// prefab targets
"reactnativejni",
"react_render_debug",
Expand Down Expand Up @@ -541,7 +563,7 @@ android {
}
}

preBuild.dependsOn(prepareJSC, prepareBoost, prepareDoubleConversion, prepareFmt, prepareFolly, prepareGlog, prepareLibevent)
preBuild.dependsOn(prepareJSC, prepareBoost, prepareDoubleConversion, prepareFmt, prepareFolly, prepareGlog, prepareLibevent, prepareGtest)
preBuild.dependsOn("generateCodegenArtifactsFromSchema")
preBuild.dependsOn(preparePrefab)

Expand Down
1 change: 1 addition & 0 deletions packages/react-native/ReactAndroid/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ FMT_VERSION=6.2.1
FOLLY_VERSION=2021.07.22.00
GLOG_VERSION=0.3.5
LIBEVENT_VERSION=2.1.12
GTEST_VERSION=1.12.1

android.useAndroidX=true
android.enableJetifier=true
22 changes: 11 additions & 11 deletions packages/react-native/ReactAndroid/src/main/jni/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ add_react_third_party_ndk_subdir(fmt)
add_react_third_party_ndk_subdir(libevent)
add_react_third_party_ndk_subdir(folly)
add_react_third_party_ndk_subdir(jsc)
add_react_third_party_ndk_subdir(googletest)

# Common targets
add_react_common_subdir(yoga)
Expand Down Expand Up @@ -97,6 +98,9 @@ add_react_common_subdir(react/utils)
add_react_common_subdir(react/bridging)
add_react_common_subdir(react/renderer/mapbuffer)
add_react_common_subdir(react/nativemodule/core)
add_react_common_subdir(jserrorhandler)
add_react_common_subdir(react/bridgeless)
add_react_common_subdir(react/bridgeless/hermes)

# ReactAndroid JNI targets
add_react_build_subdir(generated/source/codegen/jni)
Expand All @@ -114,12 +118,8 @@ add_react_android_subdir(src/main/jni/react/fabric)
add_react_android_subdir(src/main/jni/react/newarchdefaults)
add_react_android_subdir(src/main/jni/react/hermes/reactexecutor)
add_react_android_subdir(src/main/jni/react/hermes/instrumentation/)

# GTest setup
set(GOOGLETEST_ROOT ${ANDROID_NDK}/sources/third_party/googletest)
add_library(gtest STATIC ${GOOGLETEST_ROOT}/src/gtest_main.cc ${GOOGLETEST_ROOT}/src/gtest-all.cc)
target_include_directories(gtest PRIVATE ${GOOGLETEST_ROOT})
target_include_directories(gtest PUBLIC ${GOOGLETEST_ROOT}/include)
add_react_android_subdir(src/main/jni/react/bridgeless/jni)
add_react_android_subdir(src/main/jni/react/bridgeless/hermes/jni)

# GTest dependencies
add_executable(reactnative_unittest
Expand Down Expand Up @@ -163,17 +163,17 @@ add_executable(reactnative_unittest
${REACT_COMMON_DIR}/react/renderer/templateprocessor/tests/UITemplateProcessorTest.cpp
${REACT_COMMON_DIR}/react/renderer/textlayoutmanager/tests/TextLayoutManagerTest.cpp
${REACT_COMMON_DIR}/react/renderer/uimanager/tests/FabricUIManagerTest.cpp

########## (COMPILE BUT FAIL ON ASSERTS) ###########
# ${REACT_COMMON_DIR}/react/renderer/animations/tests/LayoutAnimationTest.cpp
# ${REACT_COMMON_DIR}/react/renderer/mounting/tests/MountingTest.cpp
# ${REACT_COMMON_DIR}/react/renderer/mounting/tests/ShadowTreeLifeCycleTest.cpp

########## (COMPILE BUT FAIL WITH RUNTIME EXCEPTIONS) ###########
# ${REACT_COMMON_DIR}/hermes/inspector/chrome/tests/ConnectionDemuxTests.cpp
# ${REACT_COMMON_DIR}/hermes/inspector/detail/tests/SerialExecutorTests.cpp
# ${REACT_COMMON_DIR}/hermes/inspector/tests/InspectorTests.cpp

########## (DO NOT COMPILE) ###########
# ${REACT_COMMON_DIR}/react/renderer/core/tests/ShadowNodeTest.cpp
# ${REACT_COMMON_DIR}/react/renderer/core/tests/ConcreteShadowNodeTest.cpp
Expand All @@ -192,9 +192,9 @@ add_executable(reactnative_unittest
target_link_libraries(reactnative_unittest
folly_runtime
folly_futures
glog
glog
glog_init
gtest
gtest_main
hermes-engine::libhermes
hermes_inspector
jsi
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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)

file(GLOB_RECURSE hermes_instance_jni_SRC CONFIGURE_DEPENDS *.cpp)

add_library(hermesinstancejni
SHARED
${hermes_instance_jni_SRC}
)
target_compile_options(
hermesinstancejni
PRIVATE
$<$<CONFIG:Debug>:-DHERMES_ENABLE_DEBUGGER=1>
-std=c++17
-fexceptions
)
target_include_directories(hermesinstancejni PRIVATE .)
target_link_libraries(
hermesinstancejni
hermes-engine::libhermes
rninstance
fbjni
bridgelesshermes
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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)

file(GLOB_RECURSE bridgeless_jni_SRC CONFIGURE_DEPENDS *.cpp)

add_library(rninstance
SHARED
${bridgeless_jni_SRC}
)
target_compile_options(
rninstance
PRIVATE
$<$<CONFIG:Debug>:-DHERMES_ENABLE_DEBUGGER=1>
-std=c++17
-fexceptions
)
target_include_directories(rninstance PUBLIC .)
target_link_libraries(
rninstance
fabricjni
turbomodulejsijni
fb
jsi
fbjni
bridgeless
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace facebook::react {

void JJSTimerExecutor::setTimerManager(
std::weak_ptr<TimerManager> timerManager) {
assert(timerManager && "`timerManager` must not be `nullptr`.");
timerManager_ = timerManager;
}

Expand Down
22 changes: 22 additions & 0 deletions packages/react-native/ReactCommon/jserrorhandler/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)

add_compile_options(-std=c++17)

file(GLOB_RECURSE js_error_handler_SRC CONFIGURE_DEPENDS *.cpp)
add_library(
jserrorhandler
SHARED
${js_error_handler_SRC}
)
target_include_directories(jserrorhandler PUBLIC .)
target_link_libraries(jserrorhandler
jsi
folly_runtime
mapbufferjni
)
37 changes: 37 additions & 0 deletions packages/react-native/ReactCommon/react/bridgeless/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 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)

file(GLOB bridgeless_SRC "*.cpp")

add_library(bridgeless
STATIC
${bridgeless_SRC}
)
target_compile_options(
bridgeless
PRIVATE
$<$<CONFIG:Debug>:-DHERMES_ENABLE_DEBUGGER=1>
-std=c++17
-fexceptions
)
target_include_directories(bridgeless PUBLIC .)

find_library(LIBHERMES NAMES hermes-engine::libhermes)
if (LIBHERMES)
target_link_libraries(bridgeless hermes-engine::libhermes)
endif ()

target_link_libraries(
bridgeless
jserrorhandler
fabricjni
turbomodulejsijni
fb
jsi
jsireact
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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)

add_compile_options(-std=c++17)

file(GLOB_RECURSE bridgeless_hermes_SRC CONFIGURE_DEPENDS *.cpp)
add_library(
bridgelesshermes
STATIC
${bridgeless_hermes_SRC}
)
target_include_directories(bridgelesshermes PUBLIC .)

target_link_libraries(bridgelesshermes
jsireact
hermes-engine::libhermes
hermes_inspector
jsi
hermes_executor_common
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#pragma once

#include <hermes/API/hermes/hermes.h>
#include <hermes/hermes.h>
#include <jsi/jsi.h>
#include <react/config/ReactNativeConfig.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <gtest/gtest.h>

#include <ReactCommon/RuntimeExecutor.h>
#include <hermes/API/hermes/hermes.h>
#include <hermes/hermes.h>
#include <jsi/jsi.h>
#include <react/bridgeless/ReactInstance.h>
#include <react/renderer/mapbuffer/MapBuffer.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ add_library(react_bridging STATIC ${react_bridging_SRC})

target_include_directories(react_bridging PUBLIC ${REACT_COMMON_DIR})

target_link_libraries(react_bridging jsi)
target_link_libraries(react_bridging jsi callinvoker)
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ target_link_libraries(rrc_native
react_render_core
react_render_debug
react_utils
callinvoker
)