Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Realm Core 13.2.0 #5252

Merged
merged 17 commits into from
Feb 3, 2023
20 changes: 0 additions & 20 deletions .github/workflows/pr-realm-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,6 @@ jobs:
if: ${{ runner.os == 'Windows' }}
uses: ilammy/msvc-dev-cmd@v1

- name: Get vcpkg submodule commit sha
if: ${{ runner.os == 'Windows' }}
id: vcpkg_cache_key
working-directory: vendor/realm-core/tools/vcpkg/ports
shell: bash
run: echo "::set-output name=commit::$(git rev-parse HEAD)"

- name: Setup Vcpkg
if: ${{ runner.os == 'Windows' }}
uses: friendlyanon/setup-vcpkg@v1
with:
path: vendor/realm-core/tools/vcpkg/ports
cache-key: vcpkg-windows-${{ matrix.variant.arch }}-${{ steps.vcpkg_cache_key.outputs.commit }}-${{ hashFiles('./vendor/realm-core/tools/vcpkg/vcpkg.json') }}
cache-restore-keys: vcpkg-windows-${{ matrix.variant.arch }}-${{ steps.vcpkg_cache_key.outputs.commit }}-${{ hashFiles('./vendor/realm-core/tools/vcpkg/vcpkg.json') }}

- name: Refetch Vcpkg
if: ${{ runner.os == 'Windows' }}
run: git fetch --unshallow
working-directory: vendor/realm-core/tools/vcpkg/ports

# ninja-build is used by default if available and results in faster build times
# On linux, electron requires a connected display. We fake this by giving it a headless environment using xvfb
# Relevant issue: https://github.com/juliangruber/browser-run/issues/147
Expand Down
17 changes: 8 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
## vNext (TBD)

### Enhancements
* None
* Converting flexible sync Realms to bundled and local realms is now supported. ([realm/realm-core#6076](https://github.com/realm/realm-core/pull/6076))

### Fixed
* <How to hit and notice issue? what was the impact?> ([#????](https://github.com/realm/realm-js/issues/????), since v?.?.?)
* None
* Fixed possible segfault in sync client where async callback was using object after being deallocated. ([realm/realm-core#6053](https://github.com/realm/realm-core/issues/6053), since v10.11.0)
* Fixed crash when using client reset with recovery and flexible sync with a single subscription ([#6070](https://github.com/realm/realm-core/issues/6070), since v10.19.5)

### Compatibility
* React Native >= v0.70.0
Expand All @@ -14,12 +14,11 @@
* File format: generates Realms with format v23 (reads and upgrades file format v5 or later for non-synced Realm, upgrades file format v10 or later for synced Realms).

### Internal
* Unpin Xcode version when building locally and upgrade the Xcode version used by GHA.
* Upgraded Realm Core from v13.1.1 to v13.2.0. ([#5174](https://github.com/realm/realm-js/issues/5174) and [#5244](https://github.com/realm/realm-js/issues/5244))
* Unpin Xcode version when building locally and upgrade the Xcode version used by Github Actions.
* Enable tests for notifications on dictionary.
* Automate releasing package on GHA
<!-- * Either mention core version or upgrade -->
<!-- * Using Realm Core vX.Y.Z -->
<!-- * Upgraded Realm Core from vX.Y.Z to vA.B.C -->
* Automate releasing package on Github Actions.
* Upgrade OpenSSL v1.1.1n to v3.0.7. ([realm/realm-core#6097](https://github.com/realm/realm-core/pull/6097))

## 11.4.0 (2023-01-23)

Expand Down Expand Up @@ -476,7 +475,7 @@ realm.write(() => {

### Internal
* Updated ccache build scripts to be location agnostic. ([#4764](https://github.com/realm/realm-js/pull/4764))
* Upgraded Realm Core from v12.3.0 to v12.5.1. ([#4753](https://github.com/realm/realm-js/issues/4753 and [[#4763](https://github.com/realm/realm-js/issues/4763))
* Upgraded Realm Core from v12.3.0 to v12.5.1. ([#4753](https://github.com/realm/realm-js/issues/4753) and [[#4763](https://github.com/realm/realm-js/issues/4763))
* Upgraded React Native integration tests app to React Native v0.68.2. ([#4583](https://github.com/realm/realm-js/pull/4583))
* Upgrading `react-native-fs` to avoid a peer dependency failure. ([#4709](https://github.com/realm/realm-js/pull/4709))
* Upgraded React Native integration tests app to React Native v0.69.1. ([#4713](https://github.com/realm/realm-js/pull/4713))
Expand Down
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ include(CheckCXXCompilerFlag)
# compiling for Node.js, need to set up toolchains before project() call
if(DEFINED CMAKE_JS_VERSION)
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/vendor/realm-core/tools/vcpkg/ports/scripts/buildsystems/vcpkg.cmake")
set(VCPKG_MANIFEST_DIR "${CMAKE_SOURCE_DIR}/vendor/realm-core/tools/vcpkg")

if(NODE_ARCH STREQUAL "ia32")
set(VCPKG_TARGET_TRIPLET "x86-windows-static" CACHE STRING "")
elseif(NODE_ARCH STREQUAL "x64")
Expand Down
2 changes: 1 addition & 1 deletion dependencies.list
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PACKAGE_NAME=realm-js
VERSION=11.4.0
REALM_CORE_VERSION=13.1.2
REALM_CORE_VERSION=13.2.0
NAPI_VERSION=5
MDBREALM_TEST_SERVER_TAG=2022-06-10
74 changes: 63 additions & 11 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,40 +134,92 @@ module.exports = {
},

/**
*
* References:
* - https://github.com/facebook/react-native/blob/main/Libraries/Utilities/Platform.ios.js
* - https://github.com/facebook/react-native/blob/main/Libraries/Utilities/NativePlatformConstantsAndroid.js
*
* @returns An object with names and versions of the various components making up the context.
*/
getVersions() {
const packageJson = require("../package.json");
const packageVersion = packageJson.version;
const sdkVersion = packageJson.version;
const environment = this.getEnvironment();

const sdk = "JS";

try {
if (environment === "reactnative") {
const { Platform } = require("react-native");
let deviceName = "unknown";
let deviceVersion = "unknown";
if (Platform.OS === "ios") {
if (Platform.isPad()) {
deviceName = "iPad";
} else if (Platform.isTV()) {
Comment on lines +157 to +159
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @kneth, these caused a regression since Platform.isPad and Platform.isTV are boolean properties (not methods).

Error getting versions: TypeError: false is not a function

Please see: https://reactnative.dev/docs/platform#ispad-ios

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@appden Thank you for reporting. I have a fix in #5491.

deviceName = "AppleTV";
} else {
// RN doesn't support Apple Watch
deviceName = "iPhone";
}
deviceVersion = "unknown";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to use osVersion here:

Suggested change
deviceVersion = "unknown";
deviceVersion = Platform.osVersion;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't found a way to tell me if it is an iPhone 10 or iPhone 11. Platform.osVersion will tell me the version of iOS or Android which is unrelated to the device.

} else if (Platform.OS === "android") {
deviceName = `${Platform.constants.Manufacturer}:${Platform.constants.Brand}`;
deviceVersion = `${Platform.Model}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The react native docs on this, describes the Model as:

The end-user-visible name for the Android device.

What is the intended semantics of this property exactly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The specification split "Samsung GT-I9100" so deviceName is "Samsung" and deviceVersion is "GT-I9100", and I have interpreted deviceVersion as the model.

}

return {
packageVersion,
platformContext: environment,
platformOs: Platform.OS,
sdk,
sdkVersion,

platform: Platform.OS,
// Android reports a number ...
platformVersion: `${Platform.Version}`,

deviceName,
deviceVersion,

cpuArch: "unknown", // Detecting CPU architecture on Android and iOS is done by seperate methods in platform.{mm, cpp)

frameworkName: "react-native",
frameworkVersion: Object.values(Platform.constants.reactNativeVersion).join("."),
};
} else if (environment === "node.js" || environment === "electron") {
const frameworkName = environment.chatAt(0).toUpperCase() + environment.slice(1);
const platform = os.type(); // eslint-disable-line
const platformVersion = os.release(); // eslint-disable-line
const cpuArch = os.arch(); // eslint-disable-line

return {
packageVersion,
platformContext: environment,
platformOs: process.platform,
platformVersion: process.versions.electron || process.version,
sdk,
sdkVersion,

platform,
platformVersion,

deviceName: "unknown",
deviceVersion: "unknown",

cpuArch,

frameworkName,
frameworkVersion: process.versions.electron || process.version,
};
}
} catch (err) {
console.warn("Error getting versions:", err.stack);
}

return {
packageVersion,
platformContext: environment,
platformOs: "unknown",
platform: "unknown",
platformVersion: "?.?.?",
sdkVersion: "?.?.?",
sdk: "unknown",
cpuArch: "unknown",
deviceName: "unknown",
deviceVersion: "?.?.?",
frameworkName: "unknown",
frameworkVersion: "?.?.?",
};
},
};
1 change: 1 addition & 0 deletions src/android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ if(REALM_JS_BUILD_CORE_FROM_SOURCE AND TARGET ObjectStore)
target_compile_definitions(ObjectStore PUBLIC
REALM_PLATFORM=Android
REALM_ANDROID=1
REALM_ANDROID_ABI=${ANDROID_ABI}
)
endif()

Expand Down
16 changes: 16 additions & 0 deletions src/android/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,20 @@ void print(const char* fmt, ...)
__android_log_vprint(ANDROID_LOG_INFO, "RealmJS", fmt, vl);
va_end(vl);
}

std::string get_cpu_arch()
{
#if defined(__arm__)
return "armeabi-v7a";
#elif defined(__aarch64__)
return "arm64-v8a";
#elif defined(__i386__)
return "x86";
#elif defined(__x86_64__)
return "x86_64";
#else
return "unknown";
#endif
}

} // namespace realm
48 changes: 34 additions & 14 deletions src/ios/platform.mm
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@

#include <realm/util/to_string.hpp>

#include <string>
#include <stdarg.h>
#include <stdio.h>
#include <string>

#import <Foundation/Foundation.h>
#include <mach/machine.h>
#include <sys/sysctl.h>

static NSString *error_description(NSError *error) {
if (NSError *underlyingError = error.userInfo[NSUnderlyingErrorKey]) {
return underlyingError.localizedDescription;
}
return error.localizedDescription;
if (NSError *underlyingError = error.userInfo[NSUnderlyingErrorKey]) {
return underlyingError.localizedDescription;
}
return error.localizedDescription;
}

namespace realm {
Expand Down Expand Up @@ -151,15 +153,33 @@ void remove_directory(const std::string &path)
remove_file(path); // works for directories too
}


void print(const char* fmt, ...)
{
va_list vl;
va_start(vl, fmt);
std::string format(fmt);
format.append("\n");
vprintf(format.c_str(), vl);
va_end(vl);
void print(const char *fmt, ...) {
va_list vl;
va_start(vl, fmt);
std::string format(fmt);
format.append("\n");
vprintf(format.c_str(), vl);
va_end(vl);
}

std::string get_cpu_arch() {
std::size_t size;
cpu_type_t type;
size = sizeof(type);
sysctlbyname("hw.cputype", &type, &size, NULL, 0);

// values for cputype and cpusubtype defined in mach/machine.h
switch (type) {
case CPU_TYPE_X86:
return "x86";
case CPU_TYPE_X86_64:
return "x86_64";
case CPU_TYPE_ARM:
return "armeabi-armv7";
case CPU_TYPE_ARM64:
return "arm64";
default:
return "unknown";
}
}
}
48 changes: 36 additions & 12 deletions src/js_app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@

#include <realm/object-store/util/event_loop_dispatcher.hpp>

#include "platform.hpp"
#include "js_notifications.hpp"
#include "js_user.hpp"
#include "js_app_credentials.hpp"
#include "js_network_transport.hpp"
#include "js_email_password_auth.hpp"
#include "realm/object-store/sync/subscribable.hpp"


using SharedApp = std::shared_ptr<realm::app::App>;
using SharedUser = std::shared_ptr<realm::SyncUser>;
using AppToken = realm::Subscribable<realm::app::App>::Token;
Expand Down Expand Up @@ -89,11 +91,16 @@ class AppClass : public ClassDefinition<T, realm::js::App<T>> {
return std::make_unique<NetworkTransport>(ctx, std::move(eld));
};

// These values are overridden at runtime
static inline std::string package_version = "?.?.?";
static inline std::string platform_context = "unknown-context";
static inline std::string platform_os = "unknown-os";
// These values are overridden at runtime - from app.hpp
static inline std::string platform = "unknown";
static inline std::string platform_version = "?.?.?";
static inline std::string sdk_version = "?.?.?";
static inline std::string sdk = "unknown";
static inline std::string cpu_arch = "unknown";
static inline std::string device_name = "unknown";
static inline std::string device_version = "?.?.?";
static inline std::string framework_name = "unknown";
static inline std::string framework_version = "?.?.?";

static void constructor(ContextType, ObjectType, Arguments&);
static FunctionType create_constructor(ContextType);
Expand Down Expand Up @@ -221,9 +228,15 @@ void AppClass<T>::constructor(ContextType ctx, ObjectType this_object, Arguments
config.transport = AppClass<T>::transport_generator(Protected(Context::get_global_context(ctx)),
NetworkTransport::make_dispatcher());

config.platform = platform_os;
config.platform_version = platform_version;
config.sdk_version = "RealmJS/" + package_version;
config.device_info.platform = platform;
config.device_info.platform_version = platform_version;
config.device_info.sdk = sdk;
config.device_info.sdk_version = sdk_version;
config.device_info.cpu_arch = cpu_arch;
config.device_info.device_name = device_name;
config.device_info.device_version = device_version;
config.device_info.framework_name = framework_name;
config.device_info.framework_version = framework_version;

auto realm_file_directory = default_realm_file_directory();
ensure_directory_exists_for_file(realm_file_directory);
Expand All @@ -241,8 +254,7 @@ void AppClass<T>::constructor(ContextType ctx, ObjectType this_object, Arguments
template <typename T>
std::string AppClass<T>::get_user_agent()
{
return "RealmJS/" + package_version + " (" + platform_context + ", " + platform_os + ", v" + platform_version +
")";
return "RealmJS/" + sdk_version + " (" + platform + ", v" + platform_version + ")";
}

template <typename T>
Expand Down Expand Up @@ -380,11 +392,23 @@ void AppClass<T>::set_versions(ContextType ctx, ObjectType this_object, Argument
{
args.validate_count(1);
auto versions = Value::validated_to_object(ctx, args[0]);
AppClass<T>::package_version = Object::validated_get_string(ctx, versions, "packageVersion");
AppClass<T>::platform_context = Object::validated_get_string(ctx, versions, "platformContext");
AppClass<T>::platform_os = Object::validated_get_string(ctx, versions, "platformOs");

AppClass<T>::platform = Object::validated_get_string(ctx, versions, "platform");
AppClass<T>::platform_version = Object::validated_get_string(ctx, versions, "platformVersion");
AppClass<T>::sdk = Object::validated_get_string(ctx, versions, "sdk");
AppClass<T>::sdk_version = Object::validated_get_string(ctx, versions, "sdkVersion");
AppClass<T>::cpu_arch = Object::validated_get_string(ctx, versions, "cpuArch");
AppClass<T>::device_name = Object::validated_get_string(ctx, versions, "deviceName");
AppClass<T>::device_version = Object::validated_get_string(ctx, versions, "deviceVersion");
AppClass<T>::framework_name = Object::validated_get_string(ctx, versions, "frameworkName");
AppClass<T>::framework_version = Object::validated_get_string(ctx, versions, "frameworkVersion");

// we are likely on iOS or Android
if (AppClass<T>::cpu_arch == "unknown") {
AppClass<T>::cpu_arch = get_cpu_arch();
}
}

/**
* @brief Registers an event listener on the SharedApp that fires on various app events.
* This includes login, logout, switching users, linking users and refreshing custom data.
Expand Down
Loading