Skip to content

Commit

Permalink
refactor: Split cmake and podspec for worklets (#6334)
Browse files Browse the repository at this point in the history
## Summary

This is another step towards extracting `react-native-worklets`. We
split `CMakeLists.txt` for targets `reanimated` and `worklets`, and also
split `.podspec` for two subspecs.

The native code is still a bit tangled (Worklets require headers from
Reanimated etc.), it will be tackled in future PRs.

## Test plan

Example apps build and run:
- on Paper:
  - [x] in development
  - [x] in production
- on Fabric:
  - [x] in development
  - [x] in production
  • Loading branch information
tjzel authored Jul 31, 2024
1 parent 158602b commit 485a600
Show file tree
Hide file tree
Showing 73 changed files with 320 additions and 156 deletions.
46 changes: 45 additions & 1 deletion apps/fabric-example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,50 @@ PODS:
- ReactCommon/turbomodule/core
- Yoga
- RNReanimated (3.14.0):
- DoubleConversion
- glog
- hermes-engine
- RCT-Folly (= 2024.01.01.00)
- RCTRequired
- RCTTypeSafety
- React-Codegen
- React-Core
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-ImageManager
- React-NativeModulesApple
- React-RCTFabric
- React-rendererdebug
- React-utils
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- RNReanimated/reanimated (= 3.14.0)
- RNReanimated/worklets (= 3.14.0)
- Yoga
- RNReanimated/reanimated (3.14.0):
- DoubleConversion
- glog
- hermes-engine
- RCT-Folly (= 2024.01.01.00)
- RCTRequired
- RCTTypeSafety
- React-Codegen
- React-Core
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-ImageManager
- React-NativeModulesApple
- React-RCTFabric
- React-rendererdebug
- React-utils
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- RNReanimated/worklets (3.14.0):
- DoubleConversion
- glog
- hermes-engine
Expand Down Expand Up @@ -1757,7 +1801,7 @@ SPEC CHECKSUMS:
RNCPicker: e84f13a98cbc8977870692948ccae15a389461bb
RNFlashList: c52e511c81ede0b8e44d4eb884b8a861976b111d
RNGestureHandler: 156548e18203327173a764c6932a3f52e90cb9cd
RNReanimated: 3ab1513708434e176c54fb5de2518f047765c0cb
RNReanimated: 062288a39daae5d5dcd59174b530e886a423a957
RNScreens: a68878603ae871d339f683bc683803545422986f
RNSVG: 02051bffb0b2fb2166e85009a58211643434ff63
SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d
Expand Down
46 changes: 45 additions & 1 deletion apps/paper-example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,50 @@ PODS:
- ReactCommon/turbomodule/core
- Yoga
- RNReanimated (3.14.0):
- DoubleConversion
- glog
- hermes-engine
- RCT-Folly (= 2024.01.01.00)
- RCTRequired
- RCTTypeSafety
- React-Codegen
- React-Core
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-ImageManager
- React-NativeModulesApple
- React-RCTFabric
- React-rendererdebug
- React-utils
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- RNReanimated/reanimated (= 3.14.0)
- RNReanimated/worklets (= 3.14.0)
- Yoga
- RNReanimated/reanimated (3.14.0):
- DoubleConversion
- glog
- hermes-engine
- RCT-Folly (= 2024.01.01.00)
- RCTRequired
- RCTTypeSafety
- React-Codegen
- React-Core
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-ImageManager
- React-NativeModulesApple
- React-RCTFabric
- React-rendererdebug
- React-utils
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- RNReanimated/worklets (3.14.0):
- DoubleConversion
- glog
- hermes-engine
Expand Down Expand Up @@ -1570,7 +1614,7 @@ SPEC CHECKSUMS:
RNCPicker: 3e2c37a8328f368ce14da050cdc8231deb5fc9f9
RNFlashList: e9b57a5553639f9b528cc50ab53f25831722ed62
RNGestureHandler: 2282cfbcf86c360d29f44ace393203afd5c6cff7
RNReanimated: 03a170d6b020e03de41bbc6817c665f8679248f8
RNReanimated: 771c92dd6787dd6f18889dea61ff423694bff638
RNScreens: 52f2565581af64b1b410d49784cf8342ed94ca28
RNSVG: 43b64ed39c14ce830d840903774154ca0c1f27ec
SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "LayoutAnimationsManager.h"
#include "CollectionUtils.h"
#include "Shareables.h"

#ifndef NDEBUG
#include <utility>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

#include <functional>
#include <iomanip>
#include <memory>
#include <sstream>
#include <string>
#include <thread>
#include <unordered_map>

Expand All @@ -26,7 +24,6 @@
#include "CollectionUtils.h"
#include "EventHandlerRegistry.h"
#include "FeaturesConfig.h"
#include "JSScheduler.h"
#include "ReanimatedHiddenHeaders.h"
#include "Shareables.h"
#include "UIRuntimeDecorator.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#ifdef ANDROID
#include "Logger.h"
#include "LoggerInterface.h"
#include "SpeedChecker.h"
#else
#include "Common/cpp/Worklets/hidden_headers/Logger.h"
#include "Common/cpp/Worklets/hidden_headers/LoggerInterface.h"
#include "Common/cpp/Worklets/hidden_headers/SpeedChecker.h"
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#ifdef ANDROID
#include "Logger.h"
#else
#include "Common/cpp/hidden_headers/Logger.h"
#include "Common/cpp/Worklets/hidden_headers/Logger.h"
#endif

namespace reanimated {
Expand Down
21 changes: 14 additions & 7 deletions packages/react-native-reanimated/RNReanimated.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,21 @@ Pod::Spec.new do |s|
s.platforms = { :ios => ios_min_version, :tvos => "9.0", :osx => "10.14", :visionos => "1.0" }
s.source = { :git => "https://github.com/software-mansion/react-native-reanimated.git", :tag => "#{s.version}" }

s.source_files = [
"apple/**/*.{mm,h,m}",
"Common/cpp/**/*.{cpp,h}"
]
s.subspec "reanimated" do |ss|
ss.source_files = [
"apple/**/*.{mm,h,m}",
"Common/cpp/reanimated/**/*.{cpp,h}",
]
end

s.preserve_paths = [
"Common/cpp/hidden_headers/**"
]
s.subspec "worklets" do |ss|
ss.source_files = [
"Common/cpp/worklets/**/*.{cpp,h}",
]
ss.preserve_paths = [
"Common/cpp/worklets/hidden_headers/**"
]
end

gcc_debug_definitions = "$(inherited)"
if $config[:react_native_minor_version] >= 73 || !is_release
Expand Down
151 changes: 20 additions & 131 deletions packages/react-native-reanimated/android/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
project(Reanimated)
cmake_minimum_required(VERSION 3.8)

set (CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")

set(CMAKE_VERBOSE_MAKEFILE ON)

if(${REACT_NATIVE_MINOR_VERSION} GREATER_EQUAL 73)
set (CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD 20)
else()
set (CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 17)
endif()

# default CMAKE_CXX_FLAGS: "-g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fstack-protector-all"

include("${REACT_NATIVE_DIR}/ReactAndroid/cmake-utils/folly-flags.cmake")
add_compile_options(${folly_FLAGS})

Expand All @@ -29,139 +32,25 @@ if(NOT ${CMAKE_BUILD_TYPE} MATCHES "Debug")
string(APPEND CMAKE_CXX_FLAGS " -DNDEBUG")
endif()

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")

set (PACKAGE_NAME "reanimated")
set (BUILD_DIR ${CMAKE_SOURCE_DIR}/build)
set (SRC_DIR ${CMAKE_SOURCE_DIR}/src)
set (COMMON_SRC_DIR "${CMAKE_SOURCE_DIR}/../Common")

file(GLOB_RECURSE SOURCES_COMMON CONFIGURE_DEPENDS "${COMMON_SRC_DIR}/cpp/**.cpp")
file(GLOB_RECURSE SOURCES_ANDROID CONFIGURE_DEPENDS "${SRC_DIR}/main/cpp/**.cpp")

# Consume shared libraries and headers from prefabs
find_package(fbjni REQUIRED CONFIG)
find_package(ReactAndroid REQUIRED CONFIG)
if(${JS_RUNTIME} STREQUAL "hermes")
find_package(hermes-engine REQUIRED CONFIG)
endif()

add_library(
${PACKAGE_NAME}
SHARED
${SOURCES_COMMON}
${SOURCES_ANDROID}
${INCLUDE_JSI_CPP}
${INCLUDE_JSIDYNAMIC_CPP}
)

# includes

target_include_directories(
${PACKAGE_NAME}
PRIVATE
"${COMMON_SRC_DIR}/cpp/AnimatedSensor"
"${COMMON_SRC_DIR}/cpp/Fabric"
"${COMMON_SRC_DIR}/cpp/hidden_headers"
"${COMMON_SRC_DIR}/cpp/LayoutAnimations"
"${COMMON_SRC_DIR}/cpp/NativeModules"
"${COMMON_SRC_DIR}/cpp/Tools"
"${COMMON_SRC_DIR}/cpp/Worklets/Registries"
"${COMMON_SRC_DIR}/cpp/Worklets/SharedItems"
"${COMMON_SRC_DIR}/cpp/Worklets/Tools"
"${COMMON_SRC_DIR}/cpp/Worklets/WorkletRuntime"
"${SRC_DIR}/main/cpp"
)

target_include_directories(
${PACKAGE_NAME}
PRIVATE
"${REACT_NATIVE_DIR}/ReactAndroid/src/main/jni/react/turbomodule"
"${REACT_NATIVE_DIR}/ReactCommon"
"${REACT_NATIVE_DIR}/ReactCommon/callinvoker"
"${REACT_NATIVE_DIR}/ReactCommon/react/renderer/graphics/platform/cxx"
"${REACT_NATIVE_DIR}/ReactCommon/runtimeexecutor"
"${REACT_NATIVE_DIR}/ReactCommon/yoga"
"${REACT_NATIVE_DIR}/ReactCommon/react/renderer/componentregistry"
"${REACT_NATIVE_DIR}/ReactCommon/react/renderer/core"
)

# build shared lib

set_target_properties(${PACKAGE_NAME} PROPERTIES LINKER_LANGUAGE CXX)

target_link_libraries(
${PACKAGE_NAME}
log
android
)

target_link_libraries(
${PACKAGE_NAME}
ReactAndroid::folly_runtime
ReactAndroid::glog
ReactAndroid::jsi
ReactAndroid::reactnativejni
fbjni::fbjni
)

if(${JS_RUNTIME} STREQUAL "hermes")
string(APPEND CMAKE_CXX_FLAGS " -DJS_RUNTIME_HERMES=1")
# From prefab from module `com.facebook.react:hermes-android`
set(HERMES_LIB hermes-engine::libhermes)
target_link_libraries(
${PACKAGE_NAME}
${HERMES_LIB}
)
if (${HERMES_ENABLE_DEBUGGER})
set(HERMES_EXECUTOR_LIB ReactAndroid::hermes_executor)
target_link_libraries(
${PACKAGE_NAME}
${HERMES_EXECUTOR_LIB}
)
endif()
elseif(${JS_RUNTIME} STREQUAL "v8")
string(APPEND CMAKE_CXX_FLAGS " -DJS_RUNTIME_V8=1")
target_include_directories(
${PACKAGE_NAME}
PRIVATE
"${JS_RUNTIME_DIR}/src"
)
file (GLOB V8_SO_DIR "${JS_RUNTIME_DIR}/android/build/intermediates/library_jni/*/jni/${ANDROID_ABI}")
find_library(
V8EXECUTOR_LIB
v8executor
PATHS ${V8_SO_DIR}
NO_DEFAULT_PATH
NO_CMAKE_FIND_ROOT_PATH
)
target_link_libraries(
${PACKAGE_NAME}
${V8EXECUTOR_LIB}
)
elseif(${JS_RUNTIME} STREQUAL "jsc")
string(APPEND CMAKE_CXX_FLAGS " -DJS_RUNTIME_JSC=1")
set(JSEXECUTOR_LIB ReactAndroid::jscexecutor)
target_link_libraries(${PACKAGE_NAME} ${JSEXECUTOR_LIB})
elseif(${JS_RUNTIME} STREQUAL "v8")
string(APPEND CMAKE_CXX_FLAGS " -DJS_RUNTIME_V8=1")
else()
message(FATAL_ERROR "Unknown JS runtime ${JS_RUNTIME}.")
endif()

if(${IS_NEW_ARCHITECTURE_ENABLED})
target_link_libraries(
${PACKAGE_NAME}
ReactAndroid::fabricjni
ReactAndroid::react_debug
ReactAndroid::react_render_core
ReactAndroid::react_render_mounting
ReactAndroid::react_render_componentregistry
ReactAndroid::react_render_scheduler
ReactAndroid::react_render_uimanager
ReactAndroid::rrc_view
)
endif()
# Resolves "CMake Warning: Manually-specified variables were not used by the
# project" when any of the following variables is not used in some build
# configuration.
set(ignoreMe "${JS_RUNTIME_DIR}")

set(BUILD_DIR "${CMAKE_SOURCE_DIR}/build")
set(ANDROID_SRC_DIR "${CMAKE_SOURCE_DIR}/src")
set(WORKLETS_COMMON_DIR "${CMAKE_SOURCE_DIR}/../Common/cpp/worklets")
set(REANIMATED_COMMON_DIR "${CMAKE_SOURCE_DIR}/../Common/cpp/reanimated")

# Resolves "CMake Warning: Manually-specified variables were not used by the project"
# when any of the following variables is not used in some build configuration.
set (ignoreMe "${JS_RUNTIME_DIR}")
add_subdirectory(${CMAKE_SOURCE_DIR}/src/main/worklets)
add_subdirectory(${CMAKE_SOURCE_DIR}/src/main/reanimated)
Loading

0 comments on commit 485a600

Please sign in to comment.