Skip to content

Commit

Permalink
Fix build error from react-native 0.74.3 (#205)
Browse files Browse the repository at this point in the history
# Why

react-native 0.74.3 has a new `queueMicrotask` interface to jsi and break existing 0.74.3 build

# How

add no-op `queueMicrotask` implementation since it's used from new architecture. i'll add this when revisiting new architecture support.
  • Loading branch information
Kudo authored Jul 6, 2024
1 parent 970f2d7 commit 807534e
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 22 deletions.
6 changes: 4 additions & 2 deletions RNV8.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ end
if ENV["REACT_NATIVE_OVERRIDE_VERSION"]
reactNativeVersion = ENV["REACT_NATIVE_OVERRIDE_VERSION"]
end
reactNativeTargetVersion = reactNativeVersion.split('.')[1].to_i
reactNativeVersions = reactNativeVersion.split('.')
reactNativeMinorVersion = reactNativeVersions[1].to_i
reactNativePatchVersion = reactNativeVersions[2].to_i

folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -DFOLLY_CFG_NO_COROUTINES=1 -Wno-comma -Wno-shorten-64-to-32'

Expand All @@ -33,7 +35,7 @@ Pod::Spec.new do |s|
'HEADER_SEARCH_PATHS' => "\"$(PODS_ROOT)/boost\"",
}

compiler_flags = folly_compiler_flags + ' ' + "-DREACT_NATIVE_TARGET_VERSION=#{reactNativeTargetVersion}"
compiler_flags = folly_compiler_flags + ' ' + "-DREACT_NATIVE_MINOR_VERSION=#{reactNativeMinorVersion} -DREACT_NATIVE_PATCH_VERSION=#{reactNativePatchVersion}"
s.compiler_flags = compiler_flags

s.dependency 'v8-ios'
Expand Down
4 changes: 2 additions & 2 deletions android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ cmake_minimum_required(VERSION 3.13)
project(react-native-v8)

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

string(APPEND CMAKE_CXX_FLAGS " -DREACT_NATIVE_TARGET_VERSION=${REACT_NATIVE_TARGET_VERSION} -fexceptions -fno-omit-frame-pointer -frtti -Wno-sign-compare -fstack-protector-all")
string(APPEND CMAKE_CXX_FLAGS " -DREACT_NATIVE_MINOR_VERSION=${REACT_NATIVE_MINOR_VERSION} -DREACT_NATIVE_PATCH_VERSION=${REACT_NATIVE_PATCH_VERSION} -fexceptions -fno-omit-frame-pointer -frtti -Wno-sign-compare -fstack-protector-all")

include("${REACT_NATIVE_DIR}/ReactAndroid/cmake-utils/folly-flags.cmake")
add_compile_options(${folly_FLAGS})
Expand Down
4 changes: 3 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def reactNativeManifestAsJson = new JsonSlurper().parseText(reactNativeManifest.
def reactNativeVersion = reactNativeManifestAsJson.version as String
def (major, minor, patch) = reactNativeVersion.tokenize('.')
def rnMinorVersion = Integer.parseInt(minor)
def rnPatchVersion = Integer.parseInt(patch)
def extractSoDir = "${buildDir}/jniLibs"
def prefabHeadersDir = "${buildDir}/prefab-headers"

Expand Down Expand Up @@ -135,7 +136,8 @@ android {
cmake {
arguments "-DANDROID_STL=c++_shared",
"-DREACT_NATIVE_DIR=${toPlatformFileString(reactNativeDir)}",
"-DREACT_NATIVE_TARGET_VERSION=${rnMinorVersion}",
"-DREACT_NATIVE_MINOR_VERSION=${rnMinorVersion}",
"-DREACT_NATIVE_PATCH_VERSION=${rnPatchVersion}",
"-DV8_ANDROID_DIR=${v8AndroidDir}",
"-DSO_DIR=${extractSoDir}"
targets "v8executor"
Expand Down
4 changes: 2 additions & 2 deletions src/v8runtime/V8Inspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <condition_variable>
#include "v8-inspector.h"

#if REACT_NATIVE_TARGET_VERSION >= 73
#if REACT_NATIVE_MINOR_VERSION >= 73

#if __has_include(<React-jsinspector/jsinspector/InspectorInterfaces.h>)
#include <React-jsinspector/jsinspector/InspectorInterfaces.h>
Expand All @@ -23,7 +23,7 @@ namespace jsinspector = facebook::react::jsinspector_modern;
#else
#include "jsinspector/InspectorInterfaces.h"
namespace jsinspector = facebook::react;
#endif // REACT_NATIVE_TARGET_VERSION >= 73
#endif // REACT_NATIVE_MINOR_VERSION >= 73

namespace rnv8 {

Expand Down
22 changes: 14 additions & 8 deletions src/v8runtime/V8Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,12 @@ jsi::Value V8Runtime::evaluatePreparedJavaScript(
return evaluateJavaScript(sourceJs, sourceJs->sourceURL());
}

#if REACT_NATIVE_MINOR_VERSION >= 75 || (REACT_NATIVE_MINOR_VERSION >= 74 && REACT_NATIVE_PATCH_VERSION >= 3)
void V8Runtime::queueMicrotask(const jsi::Function &callback) {
// TODO: add this when we revisit new architecture support
}
#endif // REACT_NATIVE_MINOR_VERSION >= 75 || (REACT_NATIVE_MINOR_VERSION >= 74 && REACT_NATIVE_PATCH_VERSION >= 3

bool V8Runtime::drainMicrotasks(int maxMicrotasksHint) {
v8::Locker locker(isolate_);
v8::Isolate::Scope scopedIsolate(isolate_);
Expand Down Expand Up @@ -467,7 +473,7 @@ jsi::Runtime::PointerValue *V8Runtime::cloneSymbol(
return new V8PointerValue(isolate_, v8PointerValue->Get(isolate_));
}

#if REACT_NATIVE_TARGET_VERSION >= 70
#if REACT_NATIVE_MINOR_VERSION >= 70
jsi::Runtime::PointerValue *V8Runtime::cloneBigInt(
const Runtime::PointerValue *pv) {
if (!pv) {
Expand Down Expand Up @@ -572,7 +578,7 @@ jsi::PropNameID V8Runtime::createPropNameIDFromString(const jsi::String &str) {
reinterpret_cast<const uint8_t *>(*utf8), utf8.length());
}

#if REACT_NATIVE_TARGET_VERSION >= 69
#if REACT_NATIVE_MINOR_VERSION >= 69
jsi::PropNameID V8Runtime::createPropNameIDFromSymbol(
const facebook::jsi::Symbol &sym) {
v8::Locker locker(isolate_);
Expand Down Expand Up @@ -1076,7 +1082,7 @@ bool V8Runtime::hasProperty(
}

void V8Runtime::setPropertyValue(
#if REACT_NATIVE_TARGET_VERSION >= 72
#if REACT_NATIVE_MINOR_VERSION >= 72
const jsi::Object &object,
#else
jsi::Object &object,
Expand All @@ -1102,7 +1108,7 @@ void V8Runtime::setPropertyValue(
}

void V8Runtime::setPropertyValue(
#if REACT_NATIVE_TARGET_VERSION >= 72
#if REACT_NATIVE_MINOR_VERSION >= 72
const jsi::Object &object,
#else
jsi::Object &object,
Expand Down Expand Up @@ -1228,7 +1234,7 @@ jsi::WeakObject V8Runtime::createWeakObject(const jsi::Object &weakObject) {
new V8PointerValue(isolate_, std::move(weakRef)));
}

#if REACT_NATIVE_TARGET_VERSION >= 72
#if REACT_NATIVE_MINOR_VERSION >= 72
jsi::Value V8Runtime::lockWeakObject(const jsi::WeakObject &weakObject) {
#else
jsi::Value V8Runtime::lockWeakObject(jsi::WeakObject &weakObject) {
Expand Down Expand Up @@ -1314,7 +1320,7 @@ jsi::Value V8Runtime::getValueAtIndex(const jsi::Array &array, size_t i) {
}

void V8Runtime::setValueAtIndexImpl(
#if REACT_NATIVE_TARGET_VERSION >= 72
#if REACT_NATIVE_MINOR_VERSION >= 72
const jsi::Array &array,
#else
jsi::Array &array,
Expand Down Expand Up @@ -1479,7 +1485,7 @@ bool V8Runtime::strictEquals(const jsi::Symbol &a, const jsi::Symbol &b) const {
return result;
}

#if REACT_NATIVE_TARGET_VERSION >= 70
#if REACT_NATIVE_MINOR_VERSION >= 70
bool V8Runtime::strictEquals(const jsi::BigInt &a, const jsi::BigInt &b) const {
v8::Locker locker(isolate_);
v8::Isolate::Scope scopedIsolate(isolate_);
Expand Down Expand Up @@ -1552,7 +1558,7 @@ bool V8Runtime::instanceOf(const jsi::Object &o, const jsi::Function &f) {
return result;
}

#if REACT_NATIVE_TARGET_VERSION >= 74
#if REACT_NATIVE_MINOR_VERSION >= 74
void V8Runtime::setExternalMemoryPressure(const jsi::Object &obj, size_t amount) {
}
#endif
Expand Down
17 changes: 10 additions & 7 deletions src/v8runtime/V8Runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class V8Runtime : public facebook::jsi::Runtime {
const std::shared_ptr<const facebook::jsi::PreparedJavaScript> &js)
override;

#if REACT_NATIVE_MINOR_VERSION >= 75 || (REACT_NATIVE_MINOR_VERSION >= 74 && REACT_NATIVE_PATCH_VERSION >= 3)
void queueMicrotask(const facebook::jsi::Function &callback) override;
#endif // REACT_NATIVE_MINOR_VERSION >= 75 || (REACT_NATIVE_MINOR_VERSION >= 74 && REACT_NATIVE_PATCH_VERSION >= 3
bool drainMicrotasks(int maxMicrotasksHint = -1) override;

facebook::jsi::Object global() override;
Expand All @@ -83,7 +86,7 @@ class V8Runtime : public facebook::jsi::Runtime {

protected:
PointerValue *cloneSymbol(const Runtime::PointerValue *pv) override;
#if REACT_NATIVE_TARGET_VERSION >= 70
#if REACT_NATIVE_MINOR_VERSION >= 70
PointerValue *cloneBigInt(const Runtime::PointerValue *pv) override;
#endif
PointerValue *cloneString(const Runtime::PointerValue *pv) override;
Expand All @@ -98,7 +101,7 @@ class V8Runtime : public facebook::jsi::Runtime {
size_t length) override;
facebook::jsi::PropNameID createPropNameIDFromString(
const facebook::jsi::String &str) override;
#if REACT_NATIVE_TARGET_VERSION >= 69
#if REACT_NATIVE_MINOR_VERSION >= 69
facebook::jsi::PropNameID createPropNameIDFromSymbol(
const facebook::jsi::Symbol &sym) override;
#endif
Expand Down Expand Up @@ -150,7 +153,7 @@ class V8Runtime : public facebook::jsi::Runtime {
bool hasProperty(
const facebook::jsi::Object &,
const facebook::jsi::String &name) override;
#if REACT_NATIVE_TARGET_VERSION >= 72
#if REACT_NATIVE_MINOR_VERSION >= 72
void setPropertyValue(
const facebook::jsi::Object &,
const facebook::jsi::PropNameID &name,
Expand Down Expand Up @@ -179,7 +182,7 @@ class V8Runtime : public facebook::jsi::Runtime {

facebook::jsi::WeakObject createWeakObject(
const facebook::jsi::Object &) override;
#if REACT_NATIVE_TARGET_VERSION >= 72
#if REACT_NATIVE_MINOR_VERSION >= 72
facebook::jsi::Value lockWeakObject(
const facebook::jsi::WeakObject &) override;
#else
Expand All @@ -194,7 +197,7 @@ class V8Runtime : public facebook::jsi::Runtime {
uint8_t *data(const facebook::jsi::ArrayBuffer &) override;
facebook::jsi::Value getValueAtIndex(const facebook::jsi::Array &, size_t i)
override;
#if REACT_NATIVE_TARGET_VERSION >= 72
#if REACT_NATIVE_MINOR_VERSION >= 72
void setValueAtIndexImpl(
const facebook::jsi::Array &,
size_t i,
Expand Down Expand Up @@ -223,7 +226,7 @@ class V8Runtime : public facebook::jsi::Runtime {
bool strictEquals(
const facebook::jsi::Symbol &a,
const facebook::jsi::Symbol &b) const override;
#if REACT_NATIVE_TARGET_VERSION >= 70
#if REACT_NATIVE_MINOR_VERSION >= 70
bool strictEquals(
const facebook::jsi::BigInt &a,
const facebook::jsi::BigInt &b) const override;
Expand All @@ -239,7 +242,7 @@ class V8Runtime : public facebook::jsi::Runtime {
const facebook::jsi::Object &o,
const facebook::jsi::Function &f) override;

#if REACT_NATIVE_TARGET_VERSION >= 74
#if REACT_NATIVE_MINOR_VERSION >= 74
void setExternalMemoryPressure(
const facebook::jsi::Object &obj,
size_t amount) override;
Expand Down

0 comments on commit 807534e

Please sign in to comment.