Skip to content

Commit

Permalink
Reorganize native realm dependencies into package (realm#6314)
Browse files Browse the repository at this point in the history
* Reorganize native realm dependencies into package

* Remove unused native modules for node

* Correction for ios build script

* Remove more files, fix android build, mv cmake dir

* Fix ios integration tests

* Remove unused jsi functions

* Update android build script to ts

* Reorg binding files into their own folder

* Keep ccache in the root scripts
  • Loading branch information
takameyer authored and bimusiek committed Mar 14, 2024
1 parent d2988d6 commit f45bca8
Show file tree
Hide file tree
Showing 56 changed files with 44 additions and 5,576 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ yarn.lock

# Android/IJ
/android
/react-native/android/src/main/jni/core
/react-native/android/.cxx/
/build-android/
/packages/realm/react-native/android/src/main/jni/core
/packages/realm/react-native/android/.cxx/
/packages/realm/build-android/
.idea
.gradle
local.properties
Expand Down
99 changes: 0 additions & 99 deletions CMakeLists.txt

This file was deleted.

13 changes: 0 additions & 13 deletions Realm.xcworkspace/contents.xcworkspacedata

This file was deleted.

31 changes: 0 additions & 31 deletions Realm.xcworkspace/xcshareddata/Realm.xcscmblueprint

This file was deleted.

1 change: 0 additions & 1 deletion compile_commands.json

This file was deleted.

2 changes: 1 addition & 1 deletion package-lock.json

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

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
"@typescript-eslint/eslint-plugin": "^5.60.0",
"@typescript-eslint/parser": "^5.60.0",
"clang-format": "^1.8.0",
"command-line-args": "^5.2.1",
"eslint": "^8.43.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-flowtype": "^8.0.3",
Expand Down
17 changes: 9 additions & 8 deletions packages/realm/bindgen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ if(CMAKE_GENERATOR MATCHES "^Ninja")
endif()

if(DEFINED CMAKE_JS_VERSION)
list(APPEND CMAKE_MODULE_PATH "${PACKAGE_ROOT_DIR}/cmake")
list(APPEND CMAKE_MODULE_PATH "./cmake")
include(NodeJSTargets)
endif()

Expand All @@ -100,7 +100,7 @@ if(REALM_JS_BUILD_CORE_FROM_SOURCE)

add_subdirectory(vendor/realm-core EXCLUDE_FROM_ALL)
endif()

add_library(realm-js OBJECT)

target_link_libraries(realm-js Realm::ObjectStore)
Expand All @@ -119,10 +119,11 @@ endif()

target_include_directories(realm-js PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src")

# TODO move platform.hpp and delete this line.
target_include_directories(realm-js PRIVATE "${PACKAGE_ROOT_DIR}/src")

set(SDK_DIR ${PACKAGE_ROOT_DIR}/packages/realm)
set(BINDING_DIR ${SDK_DIR}/binding)

target_include_directories(realm-js PRIVATE "${BINDING_DIR}")


file(GLOB_RECURSE SDK_TS_FILES
LIST_DIRECTORIES false
Expand Down Expand Up @@ -178,7 +179,7 @@ if(DEFINED CMAKE_JS_VERSION)
SOURCES ${SDK_TS_FILES}
)

target_sources(realm-js PRIVATE node_init.cpp ${CMAKE_JS_SRC} ${PACKAGE_ROOT_DIR}/src/node/platform.cpp)
target_sources(realm-js PRIVATE node_init.cpp ${CMAKE_JS_SRC} ${BINDING_DIR}/node/platform.cpp)
else()
include(jsi.cmake)

Expand All @@ -194,9 +195,9 @@ else()
target_sources(realm-js PRIVATE jsi_init.cpp ${CMAKE_JS_SRC})

if(ANDROID)
add_subdirectory(${PACKAGE_ROOT_DIR}/src/android android)
add_subdirectory(${BINDING_DIR}/android android)
elseif(CMAKE_SYSTEM_NAME STREQUAL iOS)
add_subdirectory(${PACKAGE_ROOT_DIR}/src/ios ios)
add_subdirectory(${BINDING_DIR}/ios ios)
else()
# disabling for now to simplify the bootstrapping process.
# message(FATAL_ERROR "Only support JSI builds for Android and iOS")
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
cmake_minimum_required(VERSION 3.18.1)

set(REACT_NATIVE_VERSION "0.71.0-rc.5")

set(REACT_NATIVE_ROOT_DIR "${PACKAGE_ROOT_DIR}/node_modules/react-native")
set(REACT_NATIVE_AAR_DIR "${CMAKE_BINARY_DIR}/../react-native-aar") # TODO: Could we use CMAKE_BINARY_DIR instead?
set(REACT_NATIVE_VERSION "0.71.0")
Expand All @@ -14,7 +12,7 @@ add_library(realm-js-android SHARED
platform.cpp
jni_utils.cpp
io_realm_react_RealmReactModule.cpp
../../node_modules/react-native/ReactAndroid/src/main/jni/react/turbomodule/ReactCommon/CallInvokerHolder.cpp
${REACT_NATIVE_ROOT_DIR}/ReactAndroid/src/main/jni/react/turbomodule/ReactCommon/CallInvokerHolder.cpp
)

set_target_properties(realm-js-android PROPERTIES
Expand Down Expand Up @@ -110,9 +108,9 @@ endif()
find_library(FBJNI_LIBRARY fbjni PATHS ${FBJNI_LIB_DIR} NO_CMAKE_FIND_ROOT_PATH)
target_include_directories(realm-js-android PUBLIC
${FBJNI_INCLUDE_DIR}
../../node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni/
../../node_modules/react-native/ReactAndroid/src/main/jni/react/turbomodule/
../../node_modules/react-native/ReactCommon/callinvoker/
${REACT_NATIVE_ROOT_DIR}/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni/
${REACT_NATIVE_ROOT_DIR}/ReactAndroid/src/main/jni/react/turbomodule/
${REACT_NATIVE_ROOT_DIR}/ReactCommon/callinvoker/
)

target_link_libraries(realm-js-android
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 4 additions & 3 deletions packages/realm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -220,17 +220,17 @@
}
},
"build:android": {
"command": "node ../../scripts/build-android.js",
"command": "tsx ./scripts/build-android.ts",
"files": [
"../../src/android/**",
"bindgen/android/**",
"bindgen/src/**/*.ts",
"bindgen/vendor/realm-core/bindgen/src/**/*.ts",
"bindgen/vendor/realm-core/bindgen/src/**/*.h",
"bindgen/src/**/*.h"
]
},
"build:ios": {
"command": "../../scripts/build-ios.sh -c ${CONFIGURATION:=Release} ${PLATFORMS}",
"command": "scripts/build-ios.sh -c ${CONFIGURATION:=Release} ${PLATFORMS}",
"files": [
"../../src/ios/**",
"bindgen/src/**/*.ts",
Expand Down Expand Up @@ -297,6 +297,7 @@
"@types/mocha": "^10.0.0",
"@types/node": "^18.15.10",
"@types/path-browserify": "^1.0.0",
"command-line-args": "^5.2.1",
"chai": "4.3.6",
"cmake-js": "6.3.2",
"cross-env": "^7.0.3",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2021 Realm Inc.
// Copyright 2023 Realm Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,19 +15,25 @@
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////
/* eslint-disable no-console */

const commandLineArgs = require("command-line-args");
const fs = require("fs-extra");
const path = require("path");
const exec = require("child_process").execFileSync;

const { version } = require("realm/package.json");
import commandLineArgs from "command-line-args";
import fs from "node:fs";
import path from "node:path";
import { execFileSync as exec } from "node:child_process";
import { version } from "../package.json";

const packageRoot = path.resolve(__dirname, "..");

const NDK_VERSION = "25.1.8937393";

const { ANDROID_HOME } = process.env;

if (!ANDROID_HOME) {
console.error(`Missing env variable ANDROID_HOME`);
process.exit(1);
}

if (!fs.existsSync(ANDROID_HOME)) {
console.error(`Missing the Android SDK ${ANDROID_HOME}`);
process.exit(1);
Expand Down Expand Up @@ -66,11 +72,11 @@ const cmakePath = process.platform === "win32" ? "cmake.exe" : "cmake";
const buildPath = path.resolve(packageRoot, "build-android");
if (options.clean) {
if (fs.existsSync(buildPath)) {
fs.removeSync(buildPath);
fs.rmSync(buildPath, { recursive: true, force: true });
}
}

fs.ensureDirSync(buildPath, { recursive: true });
fs.mkdirSync(buildPath, { recursive: true });

for (const arch of architectures) {
console.log(`\nBuilding Realm JS Android for ${arch} (${buildType})`);
Expand All @@ -91,7 +97,7 @@ for (const arch of architectures) {
"-DANDROID_NATIVE_API_LEVEL=16",
`-DCMAKE_BUILD_TYPE=${buildType}`,
"-DANDROID_STL=c++_shared",
path.resolve(packageRoot, "packages/realm/bindgen"),
path.resolve(packageRoot, "./bindgen"),
];
exec(cmakePath, args, { cwd: archBuildDir, stdio: "inherit" });

Expand All @@ -105,8 +111,6 @@ generateVersionFile();
function generateVersionFile() {
const targetFile = path.resolve(
packageRoot,
"packages",
"realm",
"react-native",
"android",
"src",
Expand Down
Loading

0 comments on commit f45bca8

Please sign in to comment.