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

Prebuild React Native iOS binaries with cmake #3649

Merged
merged 3 commits into from
Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,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/
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ NOTE: Bump file format version to 21. NO DOWNGRADE PATH IS AVAILABLE.
### Internal
* Bump the Realm Sync protocol version to 3.
* Bump Realm File Format version to 21.
* Prebuild the React Native iOS variant and bundle it in the npm tarball. ([#3649](https://github.com/realm/realm-js/pull/3649))

10.2.0 Release notes (2021-2-5)
=============================================================
Expand Down
48 changes: 34 additions & 14 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
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'
kneth marked this conversation as resolved.
Show resolved Hide resolved

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)
15 changes: 15 additions & 0 deletions examples/ReactExample/ios/ReactExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@
remoteGlobalIDString = F60690131CA2766F0003FB26;
remoteInfo = RealmReact;
};
85B3590C25FF85EE003A02D4 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 73AD103601A44EB291AC2117 /* RealmReact.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 85B358BB25FF8070003A02D4;
remoteInfo = GCDWebServer;
};
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -194,6 +201,7 @@
isa = PBXGroup;
children = (
859609611E23C0AB009C7E43 /* libRealmReact.a */,
85B3590D25FF85EE003A02D4 /* libGCDWebServer.a */,
);
name = Products;
sourceTree = "<group>";
Expand Down Expand Up @@ -289,6 +297,13 @@
remoteRef = 859609601E23C0AB009C7E43 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
85B3590D25FF85EE003A02D4 /* libGCDWebServer.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
path = libGCDWebServer.a;
remoteRef = 85B3590C25FF85EE003A02D4 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
/* End PBXReferenceProxy section */

/* Begin PBXResourcesBuildPhase section */
Expand Down
Loading