Skip to content
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 .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[alias]
xtask = "run -p xtask --bin xtask --"
uniffi-bindgen = "run -p uniffi-bindgen --"
uniffi-bindgen-swift = "run -p uniffi-bindgen-swift --"
116 changes: 114 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,121 @@ jobs:
- run: npm --workspaces run format

bindings:
runs-on: macos-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- run: rustup target add aarch64-apple-ios aarch64-apple-ios-sim
- run: cargo xtask generate-bindings
- uses: actions/upload-artifact@v4
with:
name: ios-bindings
path: packages/app-mobile/ios/uniffi/
- uses: actions/upload-artifact@v4
with:
name: android-bindings
path: packages/app-mobile/android/src/main/java/uniffi/

build-ios:
if: false
runs-on: macos-26
needs: bindings
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- run: rustup target add aarch64-apple-ios aarch64-apple-ios-sim
- uses: actions/download-artifact@v4
with:
name: ios-bindings
path: packages/app-mobile/ios/uniffi/
- run: cargo xtask build-ios
- uses: actions/setup-node@v4
with:
node-version-file: .node-version
cache: npm
- run: npm ci
- name: Cache CocoaPods
uses: actions/cache@v4
with:
path: |
~/Library/Caches/CocoaPods
~/.cocoapods
key: pods-${{ runner.os }}-${{ github.ref_name }}
restore-keys: |
pods-${{ runner.os }}-main
pods-${{ runner.os }}-
- name: Cache iOS prebuild
uses: actions/cache@v4
with:
path: packages/app-mobile/example/ios
key: prebuild-ios-${{ runner.os }}-${{ hashFiles('packages/app-mobile/ios/AppMobile.podspec', 'packages/app-mobile/example/app.json', 'packages/app-mobile/example/package.json') }}-${{ github.sha }}
restore-keys: |
prebuild-ios-${{ runner.os }}-${{ hashFiles('packages/app-mobile/ios/AppMobile.podspec', 'packages/app-mobile/example/app.json', 'packages/app-mobile/example/package.json') }}-
- name: Prebuild
working-directory: packages/app-mobile/example
run: npx expo prebuild -p ios
- name: Build iOS simulator app
working-directory: packages/app-mobile/example
run: |
xcodebuild \
-workspace ios/appmobileexample.xcworkspace \
-scheme appmobileexample \
-configuration Release \
-sdk iphonesimulator \
-arch arm64 \
-derivedDataPath ios/build \
-parallelizeTargets \
-quiet \
CODE_SIGNING_ALLOWED=NO
- name: Package .app
working-directory: packages/app-mobile/example
run: |
mkdir -p artifact
cp -r ios/build/Build/Products/Release-iphonesimulator/appmobileexample.app artifact/
cd artifact && zip -r appmobileexample.zip appmobileexample.app
- uses: actions/upload-artifact@v4
with:
name: appmobileexample-ios-simulator
path: packages/app-mobile/example/artifact/appmobileexample.zip

build-android:
runs-on: ubuntu-latest
needs: bindings
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- uses: taiki-e/install-action@v2
with:
tool: cargo-ndk
- run: >-
rustup target add
aarch64-linux-android
armv7-linux-androideabi
x86_64-linux-android
i686-linux-android
- uses: actions/download-artifact@v4
with:
name: android-bindings
path: packages/app-mobile/android/src/main/java/uniffi/
- run: cargo xtask build-android
- uses: actions/setup-node@v4
with:
node-version-file: .node-version
cache: npm
- run: npm ci
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
- uses: gradle/actions/setup-gradle@v4
with:
cache-read-only: false
- name: Prebuild
working-directory: packages/app-mobile/example
run: npx expo prebuild -p android
- name: Build Android APK
working-directory: packages/app-mobile/example/android
run: ./gradlew assembleDebug
- uses: actions/upload-artifact@v4
with:
name: appmobileexample-android
path: packages/app-mobile/example/android/app/build/outputs/apk/debug/app-debug.apk
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ target/

### Generated bindings ###
packages/app-mobile/ios/uniffi/
packages/app-mobile/ios/AppMobile.xcframework/
packages/app-mobile/android/src/main/java/uniffi/

.vscode
7 changes: 7 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ members = [
"crates/app-mobile",
"crates/app-web",
"tools/uniffi-bindgen",
"tools/uniffi-bindgen-swift",
"xtask",
]
default-members = [
Expand Down
2 changes: 1 addition & 1 deletion crates/app-mobile/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition.workspace = true
rust-version.workspace = true

[lib]
crate-type = ["cdylib", "staticlib", "lib"]
crate-type = ["cdylib", "staticlib"]

[dependencies]
app-core.workspace = true
Expand Down
4 changes: 4 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
setup:
rustup target add aarch64-apple-ios aarch64-apple-ios-sim
rustup target add aarch64-linux-android armv7-linux-androideabi x86_64-linux-android i686-linux-android

run *args:
cargo run -p server {{ args }}
Expand All @@ -16,3 +17,6 @@ verify-js:

generate-bindings:
cargo xtask generate-bindings

build-android:
cargo xtask build-android
4 changes: 4 additions & 0 deletions packages/app-mobile/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ android {
abortOnError false
}
}

dependencies {
implementation "net.java.dev.jna:jna:5.18.1@aar"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package expo.modules.appmobile

import expo.modules.kotlin.functions.Coroutine
import expo.modules.kotlin.modules.Module
import expo.modules.kotlin.modules.ModuleDefinition
import uniffi.app_mobile.BackgroundTaskCallback
Expand Down Expand Up @@ -33,7 +34,7 @@ class AppMobileModule : Module() {
divide(left.toULong(), right.toULong())?.toLong()
}

AsyncFunction("delayedAdd") { left: Long, right: Long, delayMs: Long ->
AsyncFunction("delayedAdd") Coroutine { left: Long, right: Long, delayMs: Long ->
delayedAdd(left.toULong(), right.toULong(), delayMs.toULong()).toLong()
}

Expand Down
7 changes: 5 additions & 2 deletions packages/app-mobile/ios/AppMobile.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ Pod::Spec.new do |s|
'DEFINES_MODULE' => 'YES',
}

s.source_files = "**/*.{h,m,mm,swift,hpp,cpp}"
s.vendored_frameworks = "uniffi/AppMobile.xcframework"
s.source_files = [
"*.swift",
"uniffi/**/*.{swift,h}"
]
s.vendored_frameworks = "AppMobile.xcframework"
end
10 changes: 7 additions & 3 deletions packages/app-mobile/ios/AppMobileModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,21 @@ public class AppMobileModule: Module {
Function("stopBackgroundTask") {
stopBackgroundTask()
}

OnDestroy {
stopBackgroundTask()
}
}
}

class AppMobileBackgroundCallback: BackgroundTaskCallback {
private weak var module: AppMobileModule?
final class AppMobileBackgroundCallback: BackgroundTaskCallback {
nonisolated(unsafe) private let module: AppMobileModule

init(module: AppMobileModule) {
self.module = module
}

func onTick(count: UInt64) {
module?.sendEvent("onTick", ["count": Int(count)])
module.sendEvent("onTick", ["count": Int(count)])
}
}
11 changes: 11 additions & 0 deletions tools/uniffi-bindgen-swift/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "uniffi-bindgen-swift"
version.workspace = true
edition.workspace = true
rust-version.workspace = true

[dependencies]
uniffi = { workspace = true, features = ["cli"] }

[lints]
workspace = true
3 changes: 3 additions & 0 deletions tools/uniffi-bindgen-swift/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
uniffi::uniffi_bindgen_swift();
}
Loading