Skip to content

Commit

Permalink
feat: react native 0.71.x and Expo support (#186)
Browse files Browse the repository at this point in the history
Signed-off-by: blu3beri <blu3beri@proton.me>
  • Loading branch information
berendsliedrecht authored May 25, 2023
1 parent 4c54a62 commit 8730c1e
Show file tree
Hide file tree
Showing 12 changed files with 357 additions and 220 deletions.
20 changes: 9 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: "Indy-VDR"

env:
RUST_VERSION: "1.63.0"
RUST_VERSION: "1.65.0"
CROSS_VERSION: "0.2.4"

on:
Expand Down Expand Up @@ -283,16 +283,14 @@ jobs:
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
# First version with support for cdylib: https://github.com/rust-lang/rust/pull/100636
toolchain: "1.65.0"
toolchain: ${{ env.RUST_VERSION }}
targets: ${{ matrix.target }}

# Not useful unless the toolchain version matches the default
# - name: Cache cargo resources
# uses: Swatinem/rust-cache@v2
# with:
# shared-key: deps
# save-if: false
- name: Cache cargo resources
uses: Swatinem/rust-cache@v2
with:
shared-key: deps
save-if: false

- name: Build
run: |
Expand All @@ -302,7 +300,7 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: library-${{ matrix.target}}
path: target/${{ matrix.target }}/release/libindy_vdr.dylib
path: target/${{ matrix.target }}/release/libindy_vdr.a

create-ios-xcframework:
name: Create iOS xcframework
Expand All @@ -313,7 +311,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Fetch dynamic libraries
- name: Fetch static libraries
uses: actions/download-artifact@v3

- run: >
Expand Down
23 changes: 12 additions & 11 deletions build-xcframework.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@
set -eo pipefail

# Check if lipo and xcodebuild exist
if [ -z `command -v lipo` ] || [ -z `command -v xcodebuild` ]
if [ -z `command -v lipo` ] || [ -z `command -v xcodebuild` ] || [ -z `command -v sed` ]

then
echo "!!! lipo or xcodebuild could not be found !!!"
echo "!!! lipo, xcodebuild or sed could not be found !!!"
help
fi

NAME="indy_vdr"
BUNDLE_NAME="indy-vdr"
VERSION=$(cargo generate-lockfile && cargo pkgid indy-vdr | sed -e "s/^.*[#@]//")
echo $VERSION
BUNDLE_IDENTIFIER="org.hyperledger.$NAME"
LIBRARY_NAME="lib$NAME.dylib"
BUNDLE_IDENTIFIER="org.hyperledger.$BUNDLE_NAME"
LIBRARY_NAME="lib$NAME.a"
XC_FRAMEWORK_NAME="$NAME.xcframework"
FRAMEWORK_LIBRARY_NAME=$NAME
FRAMEWORK_NAME="$FRAMEWORK_LIBRARY_NAME.framework"
HEADER_NAME="lib$NAME.h"
OUT_PATH="out"
MIN_IOS_VERSION="12.0"

# Setting some default paths
AARCH64_APPLE_IOS_PATH="./target/aarch64-apple-ios/release"
Expand All @@ -33,9 +36,9 @@ Help() {
echo " - xcodebuild"
echo "To build an xcframework with underlying Frameworks"
echo "the following can be passed in as positional arguments"
echo " 1. Path to the aarch64-apple-ios directory where the $LIBRARY is stored"
echo " 2. Path to the aarch64-apple-ios-sim directory where the $LIBRARY is stored"
echo " 3. Path to the x86_64-apple-ios directory where the $LIBRARY is stored"
echo " 1. Path to the aarch64-apple-ios directory where the $LIBRARY_NAME is stored"
echo " 2. Path to the aarch64-apple-ios-sim directory where the $LIBRARY_NAME is stored"
echo " 3. Path to the x86_64-apple-ios directory where the $LIBRARY_NAME is stored"
echo " 4. Path to the header file, excluding the header"
echo "Make sure to add the 'release' section of the path for a"
echo "release build."
Expand Down Expand Up @@ -156,6 +159,8 @@ cat <<EOT >> Info.plist
<string>$VERSION</string>
<key>NSPrincipalClass</key>
<string></string>
<key>MinimumOSVersion</key>
<string>$MIN_IOS_VERSION</string>
</dict>
</plist>
EOT
Expand All @@ -179,8 +184,4 @@ xcodebuild -create-xcframework \
echo "cleaning up..."
rm -rf $FRAMEWORK_NAME real sim

echo "Fixing the identifiers of the dylib..."
install_name_tool -id @rpath/$NAME.framework/$FRAMEWORK_LIBRARY_NAME $XC_FRAMEWORK_NAME/ios-arm64/$FRAMEWORK_NAME/$FRAMEWORK_LIBRARY_NAME
install_name_tool -id @rpath/$NAME.framework/$FRAMEWORK_LIBRARY_NAME $XC_FRAMEWORK_NAME/ios-arm64_x86_64-simulator/$FRAMEWORK_NAME/$FRAMEWORK_LIBRARY_NAME

echo "Framework written to $OUT_PATH/$XC_FRAMEWORK_NAME"
196 changes: 154 additions & 42 deletions wrappers/javascript/indy-vdr-react-native/android/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
cmake_minimum_required(VERSION 3.9.0)
project(indyvdrreactnative)
cmake_minimum_required(VERSION 3.4.1)

set (PACKAGE_NAME "indyvdrreactnative")
set (LIB_NAME "indyvdr")
file (GLOB LIBINDY_VDR_DIR "${CMAKE_SOURCE_DIR}/../native/mobile/android/${ANDROID_ABI}")

set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_STANDARD 14)

if(${REACT_NATIVE_VERSION} GREATER_EQUAL 71)
include("${NODE_MODULES_DIR}/react-native/ReactAndroid/cmake-utils/folly-flags.cmake")
add_compile_options(${folly_FLAGS})
else()
set (CMAKE_CXX_FLAGS "-DFOLLY_NO_CONFIG=1 -DFOLLY_HAVE_CLOCK_GETTIME=1 -DFOLLY_HAVE_MEMRCHR=1 -DFOLLY_USE_LIBCPP=1 -DFOLLY_MOBILE=1 -DON_ANDROID -DONANDROID -DFOR_HERMES=${FOR_HERMES}")
endif()

set (BUILD_DIR ${CMAKE_SOURCE_DIR}/build)
if(${REACT_NATIVE_VERSION} GREATER_EQUAL 71)
find_package(fbjni REQUIRED CONFIG)
find_package(ReactAndroid REQUIRED CONFIG)
else()
set (RN_SO_DIR ${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/jni/first-party/react/jni)
endif()

file (GLOB LIBFBJNI_INCLUDE_DIR "${BUILD_DIR}/fbjni-*-headers.jar/")
file (GLOB LIBRN_DIR "${BUILD_DIR}/react-native-0*/jni/${ANDROID_ABI}")
file (GLOB LIBVDR_DIR "${CMAKE_SOURCE_DIR}/../native/mobile/android/${ANDROID_ABI}")
if(${REACT_NATIVE_VERSION} LESS 66)
set (INCLUDE_JSI_CPP "${NODE_MODULES_DIR}/react-native/ReactCommon/jsi/jsi/jsi.cpp")
set (INCLUDE_JSIDYNAMIC_CPP "${NODE_MODULES_DIR}/react-native/ReactCommon/jsi/jsi/JSIDynamic.cpp")
endif()

include_directories(
../cpp
../cpp/include
"${LIBVDR_DIR}"
"${LIBFBJNI_INCLUDE_DIR}"
"${NODE_MODULES_DIR}/react-native/React"
"${NODE_MODULES_DIR}/react-native/React/Base"
"${NODE_MODULES_DIR}/react-native/ReactCommon"
"${NODE_MODULES_DIR}/react-native/ReactCommon/jsi"
"${NODE_MODULES_DIR}/react-native/ReactCommon/callinvoker"
"${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/jni"
"${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni"
"${LIBINDY_VDR_DIR}"
)

add_library(
Expand All @@ -32,56 +43,157 @@ add_library(
../cpp/indyVdr.cpp
)

set_target_properties(
${PACKAGE_NAME}
PROPERTIES
CXX_STANDARD 17
CXX_EXTENSION OFF
POSITION_INDEPENDENT_CODE ON
)
if(${REACT_NATIVE_VERSION} GREATER_EQUAL 71)
target_include_directories(
${PACKAGE_NAME}
PRIVATE
"${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/jni/react/turbomodule"
"${NODE_MODULES_DIR}/react-native/ReactCommon"
"${NODE_MODULES_DIR}/react-native/ReactCommon/callinvoker"
"${NODE_MODULES_DIR}/react-native/ReactCommon/jsi"
"${NODE_MODULES_DIR}/react-native/ReactCommon/react/renderer/graphics/platform/cxx"
"${NODE_MODULES_DIR}/react-native/ReactCommon/runtimeexecutor"
"${NODE_MODULES_DIR}/react-native/ReactCommon/yoga"
)
else()
file (GLOB LIBFBJNI_INCLUDE_DIR "${BUILD_DIR}/fbjni-*-headers.jar/")

target_include_directories(
${PACKAGE_NAME}
PRIVATE
"${LIBFBJNI_INCLUDE_DIR}"
"${NODE_MODULES_DIR}/react-native/React"
"${NODE_MODULES_DIR}/react-native/React/Base"
"${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/jni"
"${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni"
"${NODE_MODULES_DIR}/react-native/ReactCommon"
"${NODE_MODULES_DIR}/react-native/ReactCommon/callinvoker"
"${NODE_MODULES_DIR}/react-native/ReactCommon/jsi"
"${NODE_MODULES_DIR}/hermes-engine/android/include/"
${INCLUDE_JSI_CPP} # only on older RN versions
${INCLUDE_JSIDYNAMIC_CPP} # only on older RN versions
)
endif()

file (GLOB LIBRN_DIR "${BUILD_DIR}/react-native-0*/jni/${ANDROID_ABI}")

find_library(
LOG_LIB
log
)
if(${FOR_HERMES})
string(APPEND CMAKE_CXX_FLAGS " -DFOR_HERMES=1")

find_library(
FBJNI_LIB
fbjni
PATHS ${LIBRN_DIR}
NO_CMAKE_FIND_ROOT_PATH
)
if(${REACT_NATIVE_VERSION} GREATER_EQUAL 71)
find_package(hermes-engine REQUIRED CONFIG)
elseif(${REACT_NATIVE_VERSION} GREATER_EQUAL 69)
# Bundled Hermes from module `com.facebook.react:hermes-engine` or project `:ReactAndroid:hermes-engine`
target_include_directories(
${PACKAGE_NAME}
PRIVATE
"${JS_RUNTIME_DIR}/API"
"${JS_RUNTIME_DIR}/public"
)
else()
# From `hermes-engine` npm package
target_include_directories(
${PACKAGE_NAME}
PRIVATE
"${JS_RUNTIME_DIR}/android/include"
)
endif()

if(${REACT_NATIVE_VERSION} GREATER_EQUAL 71)
target_link_libraries(
${PACKAGE_NAME}
"hermes-engine::libhermes"
)
else()
target_link_libraries(
${PACKAGE_NAME}
"${BUILD_DIR}/third-party-ndk/hermes/jni/${ANDROID_ABI}/libhermes.so"
)
endif()
else()
file (GLOB LIBJSC_DIR "${BUILD_DIR}/android-jsc*.aar/jni/${ANDROID_ABI}")

if(${REACT_NATIVE_VERSION} GREATER_EQUAL 71)
set(JS_ENGINE_LIB ReactAndroid::jscexecutor)
else()
# Use JSC
find_library(
JS_ENGINE_LIB
jscexecutor
PATHS ${LIBRN_DIR}
NO_CMAKE_FIND_ROOT_PATH
)
endif()
target_link_libraries(
${PACKAGE_NAME}
${JS_ENGINE_LIB}
)
endif()

if(${REACT_NATIVE_VERSION} LESS 71)
find_library(
FBJNI_LIB
fbjni
PATHS ${LIBRN_DIR}
NO_CMAKE_FIND_ROOT_PATH
)
endif()

if(${REACT_NATIVE_VERSION} LESS 71)
find_library(
REACT_NATIVE_JNI_LIB
reactnativejni
PATHS ${LIBRN_DIR}
NO_CMAKE_FIND_ROOT_PATH
)
endif()

if(${REACT_NATIVE_VERSION} GREATER_EQUAL 71)
target_link_libraries(
${PACKAGE_NAME}
ReactAndroid::jsi
ReactAndroid::reactnativejni
fbjni::fbjni
)
elseif(${REACT_NATIVE_VERSION} LESS 66)
# JSI lib didn't exist on RN 0.65 and before. Simply omit it.
set (JSI_LIB "")
else()
# RN 0.66 distributes libjsi.so, can be used instead of compiling jsi.cpp manually.
find_library(
JSI_LIB
jsi
PATHS ${LIBRN_DIR}
NO_CMAKE_FIND_ROOT_PATH
)
endif()

find_library(
REACT_NATIVE_JNI_LIB
reactnativejni
PATHS ${LIBRN_DIR}
REANIMATED_LIB
reanimated
PATHS ${LIBREANIMATED_DIR}
NO_CMAKE_FIND_ROOT_PATH
)

find_library(
JSI_LIB
jsi
PATHS ${LIBRN_DIR}
NO_CMAKE_FIND_ROOT_PATH
LOG_LIB
log
)

find_library(
VDR_LIB
INDY_VDR_LIB
indy_vdr
paths ${LIBVDR_DIR}
paths ${LIBINDY_VDR_DIR}
NO_CMAKE_FIND_ROOT_PATH
)

if (NOT VDR_LIB)
message(FATAL_ERROR "Could not find VDR_LIB at: ${LIBVDR_DIR}")
if (NOT INDY_VDR_LIB)
message(FATAL_ERROR "Could not find INDY_VDR_LIB at: ${LIBINDY_VDR_DIR}")
endif()

target_link_libraries(
${PACKAGE_NAME}
${VDR_LIB}
${INDY_VDR_LIB}
${LOG_LIB}
${JSI_LIB}
${REACT_NATIVE_JNI_LIB}
Expand Down
Loading

0 comments on commit 8730c1e

Please sign in to comment.