Skip to content

Commit

Permalink
Merge commit 'dec88548b45fcb2c0484ef5fc7b02aa8e3e13127' of github.com…
Browse files Browse the repository at this point in the history
…:realm/realm-js into kneth/cmake-and-monorepo
  • Loading branch information
kneth committed Mar 17, 2021
2 parents 0e461ab + dec8854 commit a7a2626
Show file tree
Hide file tree
Showing 60 changed files with 1,263 additions and 2,011 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,4 @@ integration-tests/tests/dist/
/react-native/android/src/main/jniLibs/
/realm*.tgz
/tests/js/realm-tests*.tgz
/react-native/ios/realm-js-ios.xcframework/
17 changes: 15 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,20 @@
"protocol": "inspector",
"address": "localhost",
"port": 5858
}
},
{
"type": "lldb",
"request": "launch",
"name": "LLDB Launch Unit Tests",
"program": "node",
"args": [
"--expose_gc",
"${workspaceFolder}/tests/node_modules/jasmine/bin/jasmine.js",
"spec/unit_tests.js",
"--filter=."
],
"cwd": "${workspaceFolder}/tests"
},
],
"compounds": [
{
Expand All @@ -93,4 +106,4 @@
]
}
]
}
}
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ x.x.x Release notes (yyyy-MM-dd)
* Switch to unified releases of Realm Core, Realm Sync and Realm Object Store.'
* Upgraded to Realm Core v10.5.4.

10.2.0 Release notes (2021-2-5)

10.2.0 Release notes (2021-2-5)
=============================================================
### Enhancements
>>>>>>> dec88548b45fcb2c0484ef5fc7b02aa8e3e13127
* Adding sync-logging support to Android/iOS. ([#2491](https://github.com/realm/realm-js/issues/2491))

### Fixed
Expand Down
50 changes: 35 additions & 15 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ stage('build') {
parallelExecutors["Windows x64 NAPI ${nodeTestVersion}"] = buildWindows(nodeTestVersion, 'x64')

parallelExecutors["Android RN"] = buildAndroid()
parallelExecutors["iOS RN"] = buildiOS()

parallel parallelExecutors
}
Expand All @@ -139,8 +140,8 @@ stage('test') {
parallelExecutors["Windows node ${nodeTestVersion}"] = testWindows(nodeTestVersion)

parallelExecutors["React Native Android Release"] = inAndroidContainer { testAndroid('test-android') }
// parallelExecutors["React Native iOS Release"] = testMacOS('react-tests Release')
// parallelExecutors["React Native iOS Example Release"] = testMacOS('react-example Release')
parallelExecutors["React Native iOS Release"] = testMacOS('react-tests Release')
parallelExecutors["React Native iOS Example Release"] = testMacOS('react-example Release')

parallelExecutors["macOS Electron Debug"] = testMacOS('electron Debug')
parallelExecutors["macOS Electron Release"] = testMacOS('electron Release')
Expand Down Expand Up @@ -170,9 +171,7 @@ stage('integration tests') {
'Electron on Linux': buildLinux { electronIntegrationTests(electronTestVersion, it) },

'React Native on Android': inAndroidContainer { reactNativeIntegrationTests('android') },

//TODO: uncomment when RN iOS build with cmake is ready
// 'React Native on iOS': buildMacOS { reactNativeIntegrationTests('ios') },
'React Native on iOS': buildMacOS { reactNativeIntegrationTests('ios') },
)
}

Expand Down Expand Up @@ -254,15 +253,22 @@ def reactNativeIntegrationTests(targetPlatform) {
nvm = "${env.WORKSPACE}/scripts/nvm-wrapper.sh ${nodeVersion}"
}

dir('integration-tests') {
if (targetPlatform == "android") {
unstash 'android-package'
} else {
// Pack up Realm JS into a .tar
sh "${nvm} npm pack .."
if (targetPlatform == "android") {
dir('react-native/android/src/main') {
unstash 'android-jnilibs'
}
} else {
dir('react-native/ios') {
unstash 'realm-js-ios.xcframework'
}
}

// Pack up Realm JS into a .tar
sh "${nvm} npm pack"

dir('integration-tests') {
// Renaming the package to avoid having to specify version in the apps package.json
sh 'mv realm-*.tgz realm.tgz'
sh 'mv ../realm-*.tgz realm.tgz'
// Unstash the integration tests package
unstash 'integration-tests-tgz'
}
Expand Down Expand Up @@ -386,6 +392,17 @@ def buildWindows(nodeVersion, arch) {
}
}

def buildiOS() {
return buildMacOS {
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.
// archiveArtifacts('realm-js-ios.xcframework/**')
stash includes: 'realm-js-ios.xcframework/**', name: 'realm-js-ios.xcframework'
}
}
}

def inAndroidContainer(workerFunction) {
return {
myNode('docker-cph-03') {
Expand Down Expand Up @@ -423,8 +440,11 @@ def buildAndroid() {
// Using --ignore-scripts to skip building for node
sh "./scripts/nvm-wrapper.sh ${nodeTestVersion} npm ci --ignore-scripts"
sh "./scripts/nvm-wrapper.sh ${nodeTestVersion} node scripts/build-android.js"
sh "./scripts/nvm-wrapper.sh ${nodeTestVersion} npm pack ."
stash includes: 'realm-*.*.*.tgz', name: 'android-package'
}
dir('react-native/android/src/main') {
// Uncomment this when testing build changes if you want to be able to download pre-built artifacts from Jenkins.
// archiveArtifacts('jniLibs/**')
stash includes: 'jniLibs/**', name: 'android-jnilibs'
}
}
}
Expand Down Expand Up @@ -578,7 +598,7 @@ def testLinux(target, postStep = null, Boolean enableSync = false) {
// see https://github.com/realm/ci/tree/master/realm/docker/mongodb-realm
// we refrain from using "latest" here to optimise docker pull cost due to a new image being built every day
// if there's really a new feature you need from the latest stitch, upgrade this manually
withRealmCloud(version: coreDependencies.MDBREALM_TEST_SERVER_TAG, appsToImport: ['auth-integration-tests': "${env.WORKSPACE}/tests/mongodb"]) { networkName ->
withRealmCloud(version: dependencies.MDBREALM_TEST_SERVER_TAG, appsToImport: ['auth-integration-tests': "${env.WORKSPACE}/tests/mongodb"]) { networkName ->
buildSteps("-e MONGODB_REALM_ENDPOINT=\"http://mongodb-realm\" --network=${networkName}")
}
} else {
Expand Down
3 changes: 0 additions & 3 deletions Realm.xcworkspace/contents.xcworkspacedata

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

72 changes: 17 additions & 55 deletions RealmJS.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -41,67 +41,29 @@ Pod::Spec.new do |s|
# @see https://github.com/react-native-community/cli/blob/master/docs/autolinking.md#platform-ios
s.source = { :http => 'https://github.com/realm/realm-js/blob/master/CONTRIBUTING.md#how-to-debug-react-native-podspec' }

# We run the download-realm.js script both:
# 1) As "prepare_command" (executed when running `pod install`), to have the files available when to modify the XCode project correctly.
# 2) As "script_phase" (executed by XCode when building), to allow developers to commit their `ios/Pods` directory to their repository (and not run `pod install` after cloning it).
# Note: It leaves a lock file, ensuring it will only download the archive once.
s.prepare_command = './scripts/xcode-download-realm.sh ./scripts'
s.script_phase = { :name => 'Download Realm Core & Sync',
:script => '${PODS_TARGET_SRCROOT}/scripts/xcode-download-realm.sh ${PODS_TARGET_SRCROOT}/scripts',
:execution_position => :before_compile }

s.source_files = 'src/*.cpp',
'src/jsc/*.cpp',
'src/ios/*.mm',
'src/object-store/src/*.cpp',
'src/object-store/src/sync/*.cpp',
'src/object-store/src/sync/impl/*.cpp',
'src/object-store/src/sync/impl/apple/*.cpp',
'src/object-store/src/impl/*.cpp',
'src/object-store/src/impl/apple/*.cpp',
'src/object-store/src/util/*.cpp',
'src/object-store/src/util/apple/*.cpp',
'src/object-store/src/util/bson/*.cpp',
'react-native/ios/RealmReact/*.mm',
'vendor/*.cpp'
s.source_files = 'react-native/ios/RealmReact/*.mm'

s.frameworks = uses_frameworks ? ['JavaScriptCore', 'React'] : ['JavaScriptCore']

s.library = 'c++', 'z'
s.compiler_flags = '-DREALM_HAVE_CONFIG -DREALM_ENABLE_SYNC'
s.pod_target_xcconfig = { # Ensures ccache is used if installed on the users machine
'CC' => '$(PODS_TARGET_SRCROOT)/scripts/ccache-clang.sh',
'CXX' => '$(PODS_TARGET_SRCROOT)/scripts/ccache-clang++.sh',
# Setting up clang
'CLANG_CXX_LANGUAGE_STANDARD' => 'c++17',
'CLANG_CXX_LIBRARY' => 'libc++',
# Disabling warnings that object store, core and sync has a lot of
'CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF' => 'NO',
'CLANG_WARN_DOCUMENTATION_COMMENTS' => 'NO',
# Setting the current project version and versioning system to get a symbol for analytics
'CURRENT_PROJECT_VERSION' => s.version,
'VERSIONING_SYSTEM' => 'apple-generic',
# Disable C++17 features for unsupported platforms
'OTHER_CPLUSPLUSFLAGS[arch=armv7]' => '-fno-aligned-new',
# Header search paths are prefixes to the path specified in #include macros
'HEADER_SEARCH_PATHS' => [
'"$(PODS_TARGET_SRCROOT)/src/"',
'"$(PODS_TARGET_SRCROOT)/src/jsc/"',
'"$(PODS_TARGET_SRCROOT)/src/object-store/src/"',
'"$(PODS_TARGET_SRCROOT)/src/object-store/external/json/"',
'"$(PODS_TARGET_SRCROOT)/vendor/"',
'"$(PODS_TARGET_SRCROOT)/vendor/realm-ios/include/"',
'"$(PODS_TARGET_SRCROOT)/vendor/realm-ios/include/realm/"',
'"$(PODS_TARGET_SRCROOT)/react-native/ios/RealmReact/"',
'"$(PODS_ROOT)/Headers/Public/React-Core/"'
# "'#{app_path}/ios/Pods/Headers/Public/React-Core'" # Use this line instead of 👆 while linting
].join(' ')
}

s.pod_target_xcconfig = {
# Setting up clang
'CLANG_CXX_LANGUAGE_STANDARD' => 'c++17',
'CLANG_CXX_LIBRARY' => 'libc++',
# Setting the current project version and versioning system to get a symbol for analytics
'CURRENT_PROJECT_VERSION' => s.version,
'VERSIONING_SYSTEM' => 'apple-generic',
# Header search paths are prefixes to the path specified in #include macros
'HEADER_SEARCH_PATHS' => [
'"$(PODS_TARGET_SRCROOT)/react-native/ios/RealmReact/"',
'"$(PODS_ROOT)/Headers/Public/React-Core/"'
#"'#{app_path}/ios/Pods/Headers/Public/React-Core'" # Use this line instead of 👆 while linting
].join(' ')
}

# TODO: Consider providing an option to build with the -dbg binaries instead
s.ios.vendored_libraries = 'vendor/realm-ios/librealm-sync-ios.a', 'vendor/realm-ios/librealm-parser-ios.a'
# s.watchos.vendored_libraries = 'vendor/realm-ios/librealm-sync-watchos.a', 'vendor/realm-ios/librealm-parser-watchos.a'
# s.tvos.vendored_libraries = 'vendor/realm-ios/librealm-sync-tvos.a', 'vendor/realm-ios/librealm-parser-tvos.a'
s.ios.vendored_frameworks = 'react-native/ios/realm-js-ios.xcframework'

s.dependency 'React'
# TODO: Ensure the same version of GCDWebServer is used for Android
Expand Down
5 changes: 5 additions & 0 deletions cmake/ios.toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include("${CMAKE_CURRENT_LIST_DIR}/../vendor/realm-core/tools/cmake/ios.toolchain.cmake")

set(CMAKE_SYSTEM_NAME iOS)
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
Binary file added contrib/assets/debugIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added contrib/assets/debugRunTab.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added contrib/assets/metBreakpoint.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added contrib/assets/pushBreakpoint.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
74 changes: 74 additions & 0 deletions contrib/vscode-debugging.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# VSCode Debugging

## Setup

First make sure your environment is setup by following the [building instructions](./building.md)

Then you will need the following plugins for VSCode:
* [C/C++ by Microsoft](https://github.com/Microsoft/vscode-cpptools)
* [CodeLLDB](https://github.com/vadimcn/vscode-lldb)

## Building

In order to debug C++, you must first build the project in debug mode. This can be done with the command

```bash
$ npm run rebuild --debug
```

After this is completed there should be a `debug` folder visible in your `compiled` directory. If not, perhaps delete the `compiled` directory and try again.

## Debugging Realm Unit Tests through Example

First lets take a look at `.vscode/launch.json`. This contains various ways to launch commands from vscode. For this example we will look at the command `LLDB Launch Unit Tests`.

```json
{
"type": "lldb",
"request": "launch",
"name": "LLDB Launch Unit Tests",
"program": "node",
"args": [
"--expose_gc",
"${workspaceFolder}/tests/node_modules/jasmine/bin/jasmine.js",
"spec/unit_tests.js",
"--filter=."
],
"cwd": "${workspaceFolder}/tests"
}
```

A quick read through this code shows that the launch type is `lldb` provided by the CodeLLDB extension, and it is using the `node` command to invoke the `jasmine` test framework with our `spec/unit_tests.js`. The filter option is currently running all tests. To make things easier, let's modify that parameter to take a single test (`testListPush` from `tests/list-tests.js`).

```json
{
"type": "lldb",
"request": "launch",
"name": "LLDB Launch Unit Tests",
"program": "node",
"args": [
"--expose_gc",
"${workspaceFolder}/tests/node_modules/jasmine/bin/jasmine.js",
"spec/unit_tests.js",
"--filter=testListPush"
],
"cwd": "${workspaceFolder}/tests"
}
```

As we are fairly certain this will perform a `push` command on a realm list, we can place a breakpoint in the push function in `src/js_list.hpp` by locating the push function and clicking next to the desired line number (see example below)

![Breakpoint in Code](./assets/pushBreakpoint.png)

Now we can run the test and see what happens. Click on the debug tab in the left bar of vscode:

![Debug Icon](./assets/debugIcon.png)

Select the `LLDB Launch Unit Tests` from the run tab:

![Debug Run Tab](./assets/debugRunTab.png)

Now press play and we should arrive at our new breakpoint.


![Met Breakpoint](./assets/metBreakpoint.png)
3 changes: 3 additions & 0 deletions docs/realm.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,9 @@ class Realm {
}
/**
* This describes the different options used to create a {@link Realm} instance.
*
* See {@tutorial http-proxy} for details on how use an HTTP forward proxy with this library.
*
* @typedef Realm~Configuration
* @type {Object}
* @property {ArrayBuffer|ArrayBufferView} [encryptionKey] - The 512-bit (64-byte) encryption
Expand Down
29 changes: 29 additions & 0 deletions docs/tutorials/http-proxy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
The Realm JavaScript SDK has limited support for running behind an HTTP proxy:

Current limitations:
- This is currently only supported on Realm JS v10.3.0 or higher running on Node.js.
- You must install the [`fetch-with-proxy`](https://www.npmjs.com/package/fetch-with-proxy) package manually.
- You must set the `HTTPS_PROXY` environment variable, hence the proxy cannot be set at runtime or on a per-app basis.
- HTTPS connections from the client to the proxy server, is not supported. I.e. the URL specified in the `HTTPS_PROXY` must start with `http://`.

## Installing `fetch-with-proxy`

In the time of writing this tutorial a manual step is required to switch out the node-fetch package used by the network transport layer. NPM CLI v6.9.0 or higher is required.

After installing Realm JS, run the following command to install a different package into our Network Transport package:

```
npm install node-fetch@npm:fetch-with-proxy --prefix node_modules/realm-network-transport
```

## Setting `HTTPS_PROXY` and running a script

Let's say you have a `index.js` script that you want to run, while routing all of Realm JS's requests through an HTTP proxy located at `http://127.0.0.1:3128`.

On a Unix system you can simply prefix the assignment of an environment variable before the command, like this:

```
HTTPS_PROXY=http://127.0.0.1:3128 node index.js
```

On a Windows system you have to configure the variable through "Advanced system settings" > "Environment Variables" > "Edit System Variable".
13 changes: 8 additions & 5 deletions docs/tutorials/tutorials.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"query-language": {
"title": "Query language"
}
}
{
"query-language": {
"title": "Query language"
},
"http-proxy": {
"title": "Using Realm JS behind an HTTP Proxy"
}
}
Loading

0 comments on commit a7a2626

Please sign in to comment.