Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
kraenhansen committed Nov 25, 2021
1 parent ed6cb64 commit 2ce0394
Show file tree
Hide file tree
Showing 23 changed files with 2,260 additions and 1,387 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
10.20.0-alpha.2 Release notes (2021-??-??)
=============================================================
NOTE: DO NOT USE THIS RELEASE IN PRODUCTION!
NOTE: This is an early (alpha) release with Hermes/JSI support: We expect crashes and bugs.

### Enhancements
* None.

### Fixed
* Hot reloading on Android no longer crash the app.

### Compatibility
* MongoDB Realm Cloud.
* Realm Studio v11.0.0.
* APIs are backwards compatible with all previous releases of Realm JavaScript in the 10.5.x series.
* File format: generates Realms with format v22 (reads and upgrades file format v5 or later for non-synced Realm, upgrades file format v10 or later for synced Realms).

### Internal
* None.

10.20.0-alpha.1 Release notes (2021-9-22)
=============================================================
NOTE: DO NOT USE THIS RELEASE IN PRODUCTION!
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ ENV LD_LIBRARY_PATH /opt/rh/httpd24/root/usr/lib64:/opt/rh/python27/root/usr/lib

# Ensure a new enough version of CMake is available.
RUN cd /opt \
&& curl -O -J https://cmake.org/files/v3.15/cmake-3.15.2-Linux-x86_64.tar.gz \
&& tar zxf cmake-3.15.2-Linux-x86_64.tar.gz
ENV PATH "/opt/cmake-3.15.2-Linux-x86_64/bin:$PATH"
&& curl -O -J https://cmake.org/files/v3.21/cmake-3.21.3-linux-x86_64.tar.gz \
&& tar zxf cmake-3.21.3-linux-x86_64.tar.gz
ENV PATH "/opt/cmake-3.21.3-linux-x86_64/bin/:$PATH"
12 changes: 6 additions & 6 deletions Dockerfile.android
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ RUN echo 'Installing Android SDK' && \
"platform-tools" \
"build-tools;${ANDROID_BUILD_TOOLS_VERSION}" \
"platforms;android-26" \
"cmake;3.10.2.4988404"\
"cmake;3.18.1"\
"system-images;android-29;default;x86" && \
\
echo 'Installing Android NDK' && \
Expand All @@ -75,8 +75,8 @@ RUN mkdir -p $NVM_DIR \
&& chmod a+rwX -R $NVM_DIR

# Ensure a new enough version of CMake is available.
RUN mkdir -p /home/jenkins/cmake && \
cd /home/jenkins/cmake && \
curl -O -J https://cmake.org/files/v3.17/cmake-3.17.5-Linux-x86_64.tar.gz &&\
tar zxf cmake-3.17.5-Linux-x86_64.tar.gz
ENV PATH "/home/jenkins/cmake/cmake-3.17.5-Linux-x86_64/bin:$PATH"
RUN mkdir -p /home/jenkins/cmake \
&& cd /home/jenkins/cmake \
&& curl -O -J https://cmake.org/files/v3.21/cmake-3.21.3-linux-x86_64.tar.gz \
&& tar zxf cmake-3.21.3-linux-x86_64.tar.gz
ENV PATH "/home/jenkins/cmake/cmake-3.21.3-linux-x86_64/bin/:$PATH"
1 change: 1 addition & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ def buildWindows(nodeVersion, arch) {

def buildiOS() {
return buildMacOS {
sh 'npm ci'
sh './scripts/build-iOS.sh -c Release'
dir('react-native/ios') {
// Uncomment this when testing build changes if you want to be able to download pre-built artifacts from Jenkins.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.m */; };
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
375107B1CEC322A5F727A381 /* libPods-RealmReactNativeTests-RealmReactNativeTestsTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = AA2A032A4CADCC321F5F8C8B /* libPods-RealmReactNativeTests-RealmReactNativeTestsTests.a */; };
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; };
F7BEFC8033C76CBEC124044B /* libPods-RealmReactNativeTests-RealmReactNativeTestsTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = AA2A032A4CADCC321F5F8C8B /* libPods-RealmReactNativeTests-RealmReactNativeTestsTests.a */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -52,7 +52,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
F7BEFC8033C76CBEC124044B /* libPods-RealmReactNativeTests-RealmReactNativeTestsTests.a in Frameworks */,
375107B1CEC322A5F727A381 /* libPods-RealmReactNativeTests-RealmReactNativeTestsTests.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,21 @@ public RealmReactModule(ReactApplicationContext reactContext) {
setDefaultRealmFileDirectory(fileDir, assetManager);

// Get the javascript runtime and install our native module with it

// TODO: Update this to use reactContext.getRuntimeExecutor() instead (since this is calling a deprecated method underneath)
// Using the RuntimeExecutor however, requires that we link our native module against fbjni.

JavaScriptContextHolder jsContext = reactContext.getJavaScriptContextHolder();
synchronized(jsContext) {
install(jsContext.get());
}
}

@Override
public void invalidate() {
invalidateCaches();
}

@Override
public String getName() {
return NAME;
Expand All @@ -89,4 +98,6 @@ public Map<String, Object> getConstants() {
private native void setDefaultRealmFileDirectory(String fileDir, AssetManager assets);

private native void install(long runtimePointer);

private native void invalidateCaches();
}
1 change: 1 addition & 0 deletions scripts/build-ios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ fi
DESTINATIONS=()
LIBRARIES=()
BUILD_LIB_CMDS=()

for platform in "${PLATFORMS[@]}"; do
case "$platform" in
ios)
Expand Down
7 changes: 6 additions & 1 deletion src/android/io_realm_react_RealmReactModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ JNIEXPORT void JNICALL Java_io_realm_react_RealmReactModule_setDefaultRealmFileD
realm::default_realm_file_directory().c_str());
}


JNIEXPORT void JNICALL Java_io_realm_react_RealmReactModule_install(JNIEnv*, jclass, jlong runtimePointer)
{
__android_log_print(ANDROID_LOG_VERBOSE, "JSRealm", "install");
Expand All @@ -105,3 +104,9 @@ JNIEXPORT void JNICALL Java_io_realm_react_RealmReactModule_install(JNIEnv*, jcl
realm_hermes_init(*runtime, exports);
}
}

JNIEXPORT void JNICALL Java_io_realm_react_RealmReactModule_invalidateCaches(JNIEnv*, jclass)
{
__android_log_print(ANDROID_LOG_VERBOSE, "JSRealm", "invalidateCaches");
realm_hermes_invalidate_caches();
}
8 changes: 8 additions & 0 deletions src/android/io_realm_react_RealmReactModule.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 3 additions & 10 deletions src/hermes/hermes_class.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,6 @@ inline void copyProperty(JsiEnv env, const jsi::Object& from, const jsi::Object&

inline constexpr const char g_internal_field[] = "__Realm_internal";

#if 0
inline jsi::Symbol ExternalSymbol;
jsi::Symbol ext = jsi::Symbol::New(env, "_external");
ExternalSymbol = hermes::Protected<jsi::Symbol>(env, ext);
ExternalSymbol.SuppressDestruct();
#endif

template <typename T>
using ClassDefinition = js::ClassDefinition<js::hermes::Types, T>;

Expand Down Expand Up @@ -254,14 +247,14 @@ class ObjectWrap {
.call(env, "nativeFunc",
util::format(R"(
return function %1(...args) {
//"use strict";
if (!nativeFunc && false) // XXX only disable for Realm.Object
// "use strict";
if (!nativeFunc && false) // XXX only disable check for Realm.Object
throw TypeError("%1() cannot be constructed directly from javascript");
if (!new.target && false) { // XXX find another way to detect this correctly
throw TypeError("%1() must be called as a constructor");
}
if (nativeFunc)
nativeFunc(this, ...args);
nativeFunc(this, ...args);
if ('_proxyWrapper' in %1)
return %1._proxyWrapper(this);
Expand Down
46 changes: 44 additions & 2 deletions src/hermes/hermes_return_value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,50 @@ class ReturnValue<hermes::Types> {
if (!c_str) {
set_null();
}
else {
m_value = str(m_env, c_str).get();

void set(JsiVal value)
{
m_value = std::move(value.get());
}

void set(const std::string& string)
{
m_value = str(m_env, string).get();
}

void set(const char* c_str)
{
if (!c_str) {
set_null();
}
else {
m_value = str(m_env, c_str).get();
}
}

void set(bool boolean)
{
m_value = jsi::Value(boolean);
}

void set(double number)
{
m_value = jsi::Value(number);
}

void set(int32_t number)
{
set(double(number));
}

void set(uint32_t number)
{
set(double(number));
}

void set(realm::Mixed mixed)
{
m_value = Value<hermes::Types>::from_mixed(m_env, nullptr, mixed).get();
}
}

Expand Down
17 changes: 0 additions & 17 deletions src/hermes/hermes_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ class JsiEnv {
return *m_rt;
}

inline JsiFunc globalType(const char* name);

JsiVal operator()(const jsi::Value&) const;
JsiVal operator()(jsi::Value&&) const;
JsiObj operator()(const jsi::Object&) const;
Expand Down Expand Up @@ -261,11 +259,6 @@ inline JsiFunc JsiEnv::operator()(jsi::Function&& val) const
return {*this, std::move(val)};
}

inline JsiFunc JsiEnv::globalType(const char* name)
{
return (*this)(get().global().getPropertyAsFunction(*this, name));
}

inline JsiVal JsiEnv::null() const
{
return {*this, jsi::Value::null()};
Expand Down Expand Up @@ -322,16 +315,6 @@ struct Types {
using JsiStringPropertyGetterCallback = JsiFunctionCallback;
using JsiStringPropertySetterCallback = JsiFunctionCallback;
using JsiStringPropertyEnumeratorCallback = JsiFunctionCallback;
#if 0
using JsiIndexGetterCallback = jsi::Value(*)(const jsi::CallbackInfo& info, const jsi::Object& instance, uint32_t index);
using JsiIndexSetterCallback = jsi::Value(*)(const jsi::CallbackInfo& info, const jsi::Object& instance, uint32_t index, const jsi::Value& value);
using JsiPropertyGetterCallback = jsi::Value(*)(const jsi::CallbackInfo& info);
using JsiPropertySetterCallback = void(*)(const jsi::CallbackInfo& info, const jsi::Value& value);

using JsiStringPropertyGetterCallback = jsi::Value(*)(const jsi::CallbackInfo& info, const jsi::Object& instance, const jsi::String& property);
using JsiStringPropertySetterCallback = jsi::Value(*)(const jsi::CallbackInfo& info, const jsi::Object& instance, const jsi::String& property, const jsi::Value& value);
using JsiStringPropertyEnumeratorCallback = jsi::Value(*)(const jsi::CallbackInfo& info, const jsi::Object& instance);
#endif

using ConstructorCallback = JsiFunctionCallback;
using FunctionCallback = JsiFunctionCallback;
Expand Down
7 changes: 3 additions & 4 deletions tests/ReactTestApp/.flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ node_modules/react-native/flow/
[options]
emoji=true

esproposal.optional_chaining=enable
esproposal.nullish_coalescing=enable

exact_by_default=true

format.bracket_spacing=false

module.file_ext=.js
module.file_ext=.json
module.file_ext=.ios.js
Expand Down Expand Up @@ -63,4 +62,4 @@ untyped-import
untyped-type-import

[version]
^0.137.0
^0.158.0
1 change: 1 addition & 0 deletions tests/ReactTestApp/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ build/
.gradle
local.properties
*.iml
*.hprof

# node.js
#
Expand Down
3 changes: 1 addition & 2 deletions tests/ReactTestApp/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
//noinspection GradleDynamicVersion

// implementation "com.facebook.react:react-native:+" // From node_modules
implementation project(':ReactAndroid')
implementation "com.facebook.react:react-native:+" // From node_modules

// We need to add realm manually, because it is not in the package.json
implementation project(":realm")
Expand Down
9 changes: 0 additions & 9 deletions tests/ReactTestApp/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ buildscript {
}
dependencies {
classpath("com.android.tools.build:gradle:4.2.2")
classpath('de.undercouch:gradle-download-task:4.0.0')
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand All @@ -36,12 +35,4 @@ allprojects {
google()
maven { url 'https://www.jitpack.io' }
}

configurations.all {
resolutionStrategy {
dependencySubstitution {
substitute module("com.facebook.react:react-native:+") with project(":ReactAndroid")
}
}
}
}
10 changes: 0 additions & 10 deletions tests/ReactTestApp/android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,4 @@ apply from: file("../node_modules/@react-native-community/cli-platform-android/n
include ':realm'
project(':realm').projectDir = new File(settingsDir, '../../../react-native/android')

include ':ReactAndroid'
project(':ReactAndroid').projectDir = new File(
rootProject.projectDir, '../node_modules/react-native/ReactAndroid')

// Includes codegen and its plugin into Gradle project. Required by `:ReactAndroid` project configuration.
include ':packages:react-native-codegen:android'
project(':packages:react-native-codegen:android').projectDir = new File(rootProject.projectDir,
'../node_modules/react-native/packages/react-native-codegen/android')
includeBuild('../node_modules/react-native/packages/react-native-codegen/android')

include ':app'
3 changes: 2 additions & 1 deletion tests/ReactTestApp/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '10.0'
platform :ios, '11.0'

target 'ReactTestApp' do
config = use_native_modules!
Expand Down Expand Up @@ -30,6 +30,7 @@ target 'ReactTestApp' do

post_install do |installer|
react_native_post_install(installer)
__apply_Xcode_12_5_M1_post_install_workaround(installer)
installer.pods_project.targets.each do |target|
# Fix bundle targets' 'Signing Certificate' to 'Sign to Run Locally'
if target.respond_to?(:product_type) and target.product_type == "com.apple.product-type.bundle"
Expand Down
Loading

0 comments on commit 2ce0394

Please sign in to comment.