Skip to content

Commit

Permalink
Refactor ios builds
Browse files Browse the repository at this point in the history
* build from core prebuilds
* phase script only called when input and outputs have changes
* reinstalling pods will wipe build files, forcing a rebuild
* generate input file list so that core can be rebuilt on changes
* generate dummy libraries so that libraries can be generated
* create build option which forces core to build from source
* build from source if prebuild url is not reachable
  • Loading branch information
takameyer committed Jan 24, 2024
1 parent 8fbc36f commit bb71bb4
Show file tree
Hide file tree
Showing 16 changed files with 173 additions and 481 deletions.
47 changes: 6 additions & 41 deletions .github/workflows/pr-realm-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ jobs:
- { os: android, runner: ubuntu-latest, arch: x86, artifact-path: packages/realm/react-native/android/src/main/jniLibs }
- { os: darwin, runner: macos-latest, arch: x64, artifact-path: packages/realm/prebuilds, test-node: true, test-electron: true }
- { os: darwin, runner: macos-latest, arch: arm64, artifact-path: packages/realm/prebuilds, test-node: true, test-electron: true }
- { os: ios, runner: macos-latest-xlarge, arch: simulator, artifact-path: packages/realm/react-native/ios/realm-js-ios.xcframework }
- { os: ios, runner: macos-latest-xlarge, arch: catalyst, artifact-path: packages/realm/react-native/ios/realm-js-ios.xcframework }
- { os: ios, runner: macos-latest-xlarge, arch: ios, artifact-path: packages/realm/react-native/ios/realm-js-ios.xcframework }
- { os: ios, runner: macos-latest-xlarge, arch: simulator, artifact-path: packages/realm/react-native/shared/jsi_init.cpp }
- { os: ios, runner: macos-latest-xlarge, arch: catalyst, artifact-path: packages/realm/react-native/shared/jsi_init.cpp }
- { os: ios, runner: macos-latest-xlarge, arch: ios, artifact-path: packages/realm/react-native/shared/jsi_init.cpp }
steps:
- name: Checkout code
uses: actions/checkout@v3
Expand Down Expand Up @@ -187,15 +187,9 @@ jobs:
if: ${{ (matrix.variant.os != 'ios') && (matrix.variant.os != 'android') }}
run: npm run build:node:prebuild:${{matrix.variant.arch}} --workspace realm

# build the c++ library for IOS
# the Info.plist needs to be regenerated with all libraries in place
- name: Build iOS
if: ${{ (matrix.variant.os == 'ios') }}
- name: Generate JSI
run: |
npm run build:ios --workspace realm
rm -vf ${{ matrix.variant.artifact-path }}/Info.plist
env:
PLATFORMS: ${{ matrix.variant.arch }}
npm run bindgen:generate:jsi --workspace realm
# build the c++ library for Android
- name: Build Android
Expand All @@ -212,38 +206,9 @@ jobs:
README.md
${{ matrix.variant.artifact-path }}
ios-xcframework:
name: Generate Info.plist with all frameworks in place
needs: [build]
if: ${{ success() || failure() }}
runs-on: macos-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
submodules: "recursive"

- name: Download prebuilds
uses: actions/download-artifact@v3
with:
name: realm-js-prebuilds

- name: Regenerate Info.plist
run: scripts/regen-info-plist.sh packages/realm/react-native/ios/realm-js-ios.xcframework

# Due to a limitation in upload-artifact a redundant file is needed to force
# preserving paths (https://github.com/actions/upload-artifact/issues/174)
- name: Upload prebuild artifact
uses: actions/upload-artifact@v3
with:
name: realm-js-prebuilds
path: |
README.md
packages/realm/react-native/ios/realm-js-ios.xcframework/Info.plist
integration-tests:
name: Test ${{ matrix.variant.environment }} on ${{ matrix.variant.os }} (${{matrix.variant.target}})
needs: [bundle, build, ios-xcframework]
needs: [bundle, build]
if: ${{ success() || failure() }}
env:
REALM_DISABLE_ANALYTICS: 1
Expand Down
9 changes: 3 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,9 @@ coverage/
**/realm-config

#Ignore symlinked directories (otherwise on Windows they are shown as untracked files)
/react-native/android/src/main/jni/vendor/
/react-native/android/src/main/jni/src/
/build-tmp*/
/cmakebuild/
/react-native/android/src/main/java/io/realm/react/Version.java
/react-native/android/src/main/jniLibs/
/realm*.tgz
/react-native/ios/realm-js-ios.xcframework/

# Ignore template package-lock.json files
/templates/*/package-lock.json
Expand All @@ -119,7 +114,9 @@ coverage/
/packages/realm/prebuilds/
/packages/realm/react-native/android/src/main/java/io/realm/react/Version.java
/packages/realm/react-native/android/src/main/jniLibs/
/packages/realm/react-native/ios/realm-js-ios.xcframework/
/packages/realm/react-native/ios/lib/
/packages/realm/react-native/ios/input-files.xcfilelist
/packages/realm/react-native/shared/

# Wireit repo caches
.wireit
Expand Down
9 changes: 2 additions & 7 deletions contrib/debug-rn-examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,9 @@ Since we want to keep the simplicity for our users, changes made in order to deb

## Common Issues

### Android or iOS doesn't find Realm.
### Android doesn't find Realm.

Make sure to build binaries for Android and iOS in packages/realm by running:

```
npm run build:ios --workspace=realm
```
or
Make sure to build binaries for Android in packages/realm by running:

```
npm run build:android --workspace=realm
Expand Down
6 changes: 6 additions & 0 deletions integration-tests/environments/react-native/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ target 'RealmReactNativeTests' do
# Applying https://github.com/facebook/folly/issues/1470#issuecomment-943123653
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'FOLLY_HAVE_CLOCK_GETTIME=1']
end

if target.name == "RealmJS"
target.build_configurations.each do |config|
config.build_settings['BUILD_CORE'] = 'true'
end
end
end
end
end
Expand Down
24 changes: 6 additions & 18 deletions integration-tests/environments/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,9 @@
},
"pod-install:simulator": {
"command": "pod-install || (cd ios && bundle install && bundle exec pod install)",
"dependencies": [
{
"script": "../../../packages/realm:build:ios:debug:simulator",
"cascade": false
}
],
"clean": "if-file-deleted",
"files": [
"ios/Podfile",
"../../../packages/realm/react-native/ios/realm-js-ios.xcframework"
"ios/Podfile"
],
"output": [
"ios/Pods",
Expand All @@ -57,15 +50,8 @@
},
"pod-install:catalyst": {
"command": "pod-install || (cd ios && bundle install && bundle exec pod install)",
"dependencies": [
{
"script": "../../../packages/realm:build:ios:debug:catalyst",
"cascade": false
}
],
"files": [
"ios/Podfile",
"../../../packages/realm/react-native/ios/realm-js-ios.xcframework"
"ios/Podfile"
],
"output": [
"ios/Pods",
Expand Down Expand Up @@ -116,6 +102,7 @@
"test:ios": {
"command": "npm run common",
"dependencies": [
"../../../packages/realm:bindgen:generate:jsi",
"pod-install:simulator",
"../../../packages/realm:bundle",
"../../../packages/mocha-reporter:bundle",
Expand All @@ -129,6 +116,7 @@
"test:catalyst": {
"command": "npm run common",
"dependencies": [
"../../../packages/realm:bindgen:generate:jsi",
"pod-install:catalyst",
"../../../packages/realm:bundle",
"../../../packages/mocha-reporter:bundle",
Expand Down Expand Up @@ -170,8 +158,8 @@
"watch:ios": {
"command": "npm run common",
"dependencies": [
"../../../packages/realm:bindgen:generate:jsi",
"pod-install:simulator",
"../../../packages/realm:build:ios:debug:simulator",
"../../../packages/realm:bundle",
"../../../packages/mocha-reporter:bundle",
"../../../packages/realm-network-transport:bundle"
Expand All @@ -184,8 +172,8 @@
"watch:catalyst": {
"command": "npm run common",
"dependencies": [
"../../../packages/realm:bindgen:generate:jsi",
"pod-install:catalyst",
"../../../packages/realm:build:ios:debug:catalyst",
"../../../packages/realm:bundle",
"../../../packages/mocha-reporter:bundle",
"../../../packages/realm-network-transport:bundle"
Expand Down
52 changes: 28 additions & 24 deletions packages/realm/RealmJS.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,63 +33,67 @@ Pod::Spec.new do |s|

s.authors = package['author']
s.homepage = package['homepage']
s.platform = :ios, '13.4'
s.platform = :ios, '9.0'

# The source field is a required field in the podspec, but it is not meant to be used.
# This is because the Podspec is not meant to be published into a CocoaPod repository, instead React Native uses a :path style dependency when adding this to the users projects Podfile.
# @see https://guides.cocoapods.org/using/the-podfile.html#using-the-files-from-a-folder-local-to-the-machine
# @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/main/CONTRIBUTING.md#how-to-debug-react-native-podspec' }

s.source_files = 'react-native/ios/RealmReact/*.mm'
s.source_files = 'react-native/ios/RealmReact/*.mm',
'react-native/shared/*.cpp',
'binding/ios/platform.mm'

s.public_header_files = 'react-native/ios/RealmReact/*.h'
s.public_header_files = 'react-native/ios/RealmReact/*.h',
'react-native/ios/build/include/**/*.{h,hpp}'

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

s.library = 'c++', 'z', 'compression'

s.pod_target_xcconfig = {
# Setting up clang
'CLANG_CXX_LANGUAGE_STANDARD' => 'c++17',
#'GCC_CXX_LANGUAGE_STANDARD' => 'c++17',
'CLANG_CXX_LANGUAGE_STANDARD' => 'c++20',
'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',
'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) REALM_ENABLE_SYNC=1',
'GCC_SYMBOLS_PRIVATE_EXTERN' => 'YES',
# Header search paths are prefixes to the path specified in #include macros
'HEADER_SEARCH_PATHS' => [
'"$(PODS_TARGET_SRCROOT)/react-native/ios/RealmReact/"',
'"$(PODS_TARGET_SRCROOT)/react-native/ios/build/_include"',
'"$(PODS_ROOT)/Headers/Public/React-Core/"'
#"'#{app_path}/ios/Pods/Headers/Public/React-Core'" # Use this line instead of 👆 while linting
'"$(PODS_TARGET_SRCROOT)/react-native/ios/build/include/"',
'"$(PODS_TARGET_SRCROOT)/binding/"',
'"$(PODS_TARGET_SRCROOT)/bindgen/src/"',
'"$(PODS_TARGET_SRCROOT)/bindgen/vendor/realm-core/bindgen/src/"'
].join(' ')
}
# Create placeholders for vendored_libraries, so they are added to the xcode project
s.prepare_command = <<-EOS
source "#{__dir__}/scripts/generate-dummy-libs.sh"
source "#{__dir__}/scripts/generate-input-list.sh"
EOS

lib_location = "react-native/ios/build/libs"

# TODO: Consider providing an option to build with the -dbg binaries instead
s.vendored_libraries = "#{lib_location}/librealm.a",
"#{lib_location}/librealm-js-ios.a",
"#{lib_location}/librealm-object-store.a",
"#{lib_location}/librealm-parser.a",
"#{lib_location}/librealm-sync.a"
s.vendored_libraries = "react-native/ios/lib/librealm.a",
"react-native/ios/lib/librealm-object-store.a",
"react-native/ios/lib/librealm-parser.a",
"react-native/ios/lib/librealm-sync.a"

s.dependency 'React'

script_location = "#{__dir__}/scripts/build-ios-on-install.sh"

CMAKE_PATH = Pod::Executable::which!('cmake')
NODE_PATH = Pod::Executable::which!('node')

# Post install script
#Post install script
s.script_phase = {
:name => 'Generate Realm xcframework',
:name => 'Retrieve libraries and headers',
:execution_position => :before_compile,
:input_file_lists => ["#{__dir__}/react-native/ios/input-files.xcfilelist"],
:output_file_lists => ["#{__dir__}/react-native/ios/output-files.xcfilelist"],
:script => <<-EOS
export CMAKE_PATH=#{CMAKE_PATH}
export NODE_PATH=#{NODE_PATH}
/bin/sh -c \"#{script_location} -c $CONFIGURATION $PLATFORM_NAME\"
CMAKE_PATH="#{CMAKE_PATH}"
source "#{__dir__}/scripts/generate-ios-libs.sh"
EOS
}
end
62 changes: 19 additions & 43 deletions packages/realm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"bundle:coverage": "ENABLE_TEST_COVERAGE_INSTRUMENTATION=true npm run bundle",
"bindgen:configure": "wireit",
"bindgen:build:node": "wireit",
"bindgen:generate:jsi": "wireit",
"bindgen:generate:typescript": "wireit",
"bindgen:generate:wrappers": "wireit",
"bindgen:generate:spec-schema": "wireit",
Expand All @@ -82,10 +83,6 @@
"build:node:prebuild:x64": "wireit",
"build:node:prebuild:ia32": "wireit",
"build:android": "wireit",
"build:ios": "wireit",
"build:ios:debug:simulator": "wireit",
"build:ios:debug:ios": "wireit",
"build:ios:debug:catalyst": "wireit",
"install": "prebuild-install --runtime napi || echo 'Failed to download prebuild for Realm'",
"docs": "wireit",
"postinstall": "node ./scripts/submit-analytics.mjs"
Expand Down Expand Up @@ -131,6 +128,24 @@
"bindgen:configure"
]
},
"bindgen:generate:jsi": {
"command": "realm-bindgen --template bindgen/src/templates/jsi.ts --spec bindgen/vendor/realm-core/bindgen/spec.yml --spec bindgen/js_spec.yml --opt-in bindgen/js_opt_in_spec.yml --output ./react-native/shared",
"dependencies": [
"bindgen:generate:spec-schema"
],
"files": [
"bindgen/vendor/realm-core/bindgen/spec.yml",
"bindgen/vendor/realm-core/bindgen/src",
"bindgen/js_spec.yml",
"bindgen/js_opt_in_spec.yml",
"bindgen/src",
"!bindgen/src/templates",
"bindgen/src/templates/jsi.ts"
],
"output": [
"react-native/shared/jsi_init.cpp"
]
},
"bindgen:generate:typescript": {
"command": "realm-bindgen --template bindgen/src/templates/typescript.ts --spec bindgen/vendor/realm-core/bindgen/spec.yml --spec bindgen/js_spec.yml --opt-in bindgen/js_opt_in_spec.yml --output ./generated/ts",
"dependencies": [
Expand Down Expand Up @@ -229,45 +244,6 @@
"bindgen/src/**/*.h"
]
},
"build:ios": {
"command": "../../scripts/build-ios.sh -c ${CONFIGURATION:=Release} ${PLATFORMS}",
"files": [
"../../src/ios/**",
"bindgen/src/**/*.ts",
"bindgen/vendor/realm-core/bindgen/src/**/*.ts",
"bindgen/vendor/realm-core/bindgen/src/**/*.h",
"bindgen/src/**/*.h"
],
"env": {
"PLATFORMS": {
"external": true
},
"CONFIGURATION": {
"external": true
}
}
},
"build:ios:debug:simulator": {
"command": "npm run build:ios",
"env": {
"PLATFORMS": "simulator",
"CONFIGURATION": "Debug"
}
},
"build:ios:debug:ios": {
"command": "npm run build:ios",
"env": {
"PLATFORMS": "ios",
"CONFIGURATION": "Debug"
}
},
"build:ios:debug:catalyst": {
"command": "npm run build:ios",
"env": {
"PLATFORMS": "catalyst",
"CONFIGURATION": "Debug"
}
},
"docs": {
"command": "typedoc",
"dependencies": [
Expand Down
2 changes: 1 addition & 1 deletion packages/realm/react-native/ios/RealmReact/RealmReact.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#import "RealmReact.h"

#import <realm-js-ios/jsi_init.h>
#import <jsi/jsi_init.h>

#import <React/RCTBridge+Private.h>
#import <React/RCTInvalidating.h>
Expand Down
5 changes: 5 additions & 0 deletions packages/realm/react-native/ios/output-files.xcfilelist
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

$(SRCROOT)/react-native/ios/build/lib/librealm.a
$(SRCROOT)/react-native/ios/build/lib/librealm-sync.a
$(SRCROOT)/react-native/ios/build/lib/librealm-parser.a
$(SRCROOT)/react-native/ios/build/lib/librealm-object-store.a
Loading

0 comments on commit bb71bb4

Please sign in to comment.