Skip to content

Commit

Permalink
Add v8 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Kudo committed Oct 10, 2021
1 parent aa6f837 commit 4b06995
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 28 deletions.
9 changes: 6 additions & 3 deletions android-npm/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def json = new JsonSlurper().parseText(inputFile.text)
def reactNativeVersion = json.version as String
def (major, minor, patch) = reactNativeVersion.tokenize('.')

def engine = "jsc"
def js_runtime = "jsc"

abstract class replaceSoTask extends DefaultTask {
public static String appName = ":app"
Expand Down Expand Up @@ -59,7 +59,10 @@ if(Integer.parseInt(minor) < 65) {
rootProject.getSubprojects().forEach({project ->
if (project.plugins.hasPlugin("com.android.application")) {
if(project.ext.react.enableHermes) {
engine = "hermes"
js_runtime = "hermes"
}
if (project.configurations.implementation.getDependencies().find { dep -> dep.name == "v8-android" }) {
js_runtime = "v8"
}

if(project.getProperties().get("android") && Integer.parseInt(minor) < 65) {
Expand Down Expand Up @@ -88,4 +91,4 @@ rootProject.getSubprojects().forEach({project ->
}
})

artifacts.add("default", file("react-native-reanimated-${minor}-${engine}.aar"))
artifacts.add("default", file("react-native-reanimated-${minor}-${js_runtime}.aar"))
32 changes: 29 additions & 3 deletions android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.5.1)

set (CMAKE_VERBOSE_MAKEFILE ON)
set (CMAKE_CXX_STANDARD 14)
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} -fexceptions -fno-omit-frame-pointer -frtti -Wno-sign-compare")
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 -fexceptions -fno-omit-frame-pointer -frtti -Wno-sign-compare")

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")
Expand Down Expand Up @@ -92,6 +92,12 @@ find_library(
PATHS ${HERMES_DIR}
NO_CMAKE_FIND_ROOT_PATH
)
find_library(
V8EXECUTOR_LIB
v8executor
PATHS ${LIBRN_DIR}
NO_CMAKE_FIND_ROOT_PATH
)
find_library(
JSEXECUTOR_LIB
jscexecutor
Expand Down Expand Up @@ -121,9 +127,9 @@ find_package(fbjni REQUIRED CONFIG)

set_target_properties(${PACKAGE_NAME} PROPERTIES LINKER_LANGUAGE CXX)

message(WARNING "CMakeLists.txt FOR_HERMES=${FOR_HERMES}")
message(WARNING "CMakeLists.txt JS_RUNTIME=${JS_RUNTIME}")

if(${FOR_HERMES})
if(${JS_RUNTIME} STREQUAL "hermes")
target_link_libraries(
${PACKAGE_NAME}
${LOG_LIB}
Expand All @@ -134,6 +140,25 @@ if(${FOR_HERMES})
${REACT_NATIVE_JNI_LIB}
android
)
string(APPEND CMAKE_CXX_FLAGS " -DJS_RUNTIME_HERMES=1")
elseif(${JS_RUNTIME} STREQUAL "v8")
target_link_libraries(
${PACKAGE_NAME}
${LOG_LIB}
${V8EXECUTOR_LIB}
${GLOG_LIB}
fbjni::fbjni
${FOLLY_JSON_LIB}
${REACT_NATIVE_JNI_LIB}
android
)
target_include_directories(
${PACKAGE_NAME}
PRIVATE
"${NODE_MODULES_DIR}/react-native-v8/src"
)

string(APPEND CMAKE_CXX_FLAGS " -DJS_RUNTIME_V8=1")
else()
target_link_libraries(
${PACKAGE_NAME}
Expand All @@ -145,6 +170,7 @@ else()
${REACT_NATIVE_JNI_LIB}
android
)
string(APPEND CMAKE_CXX_FLAGS " -DJS_RUNTIME_JSC=1")
endif()

if(${REACT_NATIVE_TARGET_VERSION} LESS 64)
Expand Down
16 changes: 9 additions & 7 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ def reactNativeThirdParty = new File("$reactNative/ReactAndroid/src/main/jni/thi

def HOME = System.getProperty("user.home")

def FOR_HERMES = "";
if(findProject(':app')) {
FOR_HERMES = project(':app').ext.react.enableHermes;
}
else {
FOR_HERMES = System.getenv("FOR_HERMES") == "True";
def JS_RUNTIME = System.getenv("JS_RUNTIME") ?: "jsc";
if (findProject(':app') && project(':app').ext.react.enableHermes) {
JS_RUNTIME = "hermes";
}

// You need to have following folders in this directory:
// - boost_1_63_0
// - double-conversion-1.1.6
Expand Down Expand Up @@ -102,7 +100,7 @@ android {
"-DREACT_NATIVE_TARGET_VERSION=${REACT_VERSION}",
"-DANDROID_TOOLCHAIN=clang",
"-DBOOST_VERSION=${BOOST_VERSION}",
"-DFOR_HERMES=${FOR_HERMES}"
"-DJS_RUNTIME=${JS_RUNTIME}"
abiFilters 'arm64-v8a', 'armeabi-v7a', 'x86', 'x86_64'
}
}
Expand Down Expand Up @@ -457,6 +455,10 @@ dependencies {
extractSO("com.facebook.fbjni:fbjni:" + FBJNI_VERSION)

def rnAAR = fileTree("${rootDir}/../node_modules/react-native/android").matching({ it.include "**/**/*.aar" }).singleFile
if (JS_RUNTIME == "v8") {
rnAAR = fileTree("${rootDir}/../node_modules/react-native-v8/dist").matching({ it.include "**/**/*.aar" }).singleFile
}

def jscAAR = fileTree("${rootDir}/../node_modules/jsc-android/dist/org/webkit/android-jsc").matching({ it.include "**/**/*.aar" }).singleFile
extractSO(files(rnAAR, jscAAR))
}
Expand Down
12 changes: 8 additions & 4 deletions android/src/main/cpp/NativeProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
#include <react/jni/ReadableNativeMap.h>
#include <jsi/JSIDynamic.h>

#if FOR_HERMES
#import <hermes/hermes.h>
#if JS_RUNTIME_HERMES
#include <hermes/hermes.h>
#elif JS_RUNTIME_V8
#include <v8runtime/V8RuntimeFactory.h>
#else
#import <jsi/JSCRuntime.h>
#include <jsi/JSCRuntime.h>
#endif

#include "NativeProxy.h"
Expand Down Expand Up @@ -94,8 +96,10 @@ void NativeProxy::installJSIBindings()
scrollTo(viewTag, x, y, animated);
};

#if FOR_HERMES
#if JS_RUNTIME_HERMES
auto animatedRuntime = facebook::hermes::makeHermesRuntime();
#elif JS_RUNTIME_V8
auto animatedRuntime = facebook::createV8Runtime("");
#else
auto animatedRuntime = facebook::jsc::makeJSCRuntime();
#endif
Expand Down
29 changes: 18 additions & 11 deletions createNPMPackage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,35 @@ ROOT=$(pwd)

unset CI

versions=("0.65.1" "0.64.1" "0.63.3" "0.62.2 --dev")
version_name=("65" "64" "63" "62")
# versions=("0.65.1" "0.64.1" "0.63.3" "0.62.2 --dev")
versions=("0.65.1" "0.64.2")
rnv8_versions=("0.65.1-patch.1" "0.64.2-patch.1")
version_name=("65" "64")

for index in {0..3}
# for index in {0..3}
for index in {0..1}
do
yarn add react-native@"${versions[$index]}"
for for_hermes in "True" "False"
for js_runtime in "hermes" "jsc" "v8"
do
engine="jsc"
if [ "$for_hermes" == "True" ]; then
engine="hermes"
echo "js_runtime=${js_runtime}"

if [ "${js_runtime}" == "v8" ]; then
yarn add react-native-v8@"${rnv8_versions[$index]}"
fi
echo "engine=${engine}"

cd android
gradle clean

FOR_HERMES=${for_hermes} gradle :assembleDebug
JS_RUNTIME=${js_runtime} gradle :assembleDebug
cd $ROOT

rm -rf android-npm/react-native-reanimated-"${version_name[$index]}-${engine}".aar
cp android/build/outputs/aar/*.aar android-npm/react-native-reanimated-"${version_name[$index]}-${engine}".aar
rm -rf android-npm/react-native-reanimated-"${version_name[$index]}-${js_runtime}".aar
cp android/build/outputs/aar/*.aar android-npm/react-native-reanimated-"${version_name[$index]}-${js_runtime}".aar

if [ "${js_runtime}" == "v8" ]; then
yarn remove react-native-v8
fi
done
done

Expand Down

0 comments on commit 4b06995

Please sign in to comment.