Upgrade to latest uniffi (0.23.0) (#7)

* Upgrade to latest uniffi (0.23.0)

* upgrade gradle and simplify android ci
This commit is contained in:
0xh3rman 2023-06-09 13:59:42 +08:00 committed by GitHub
parent 987cc3f8a5
commit 2087e90861
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 35 additions and 38 deletions

View File

@ -33,17 +33,12 @@ jobs:
- uses: actions/checkout@v2
with:
lfs: true
- uses: actions/setup-java@v2
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 11
java-version: '17'
cache: 'gradle'
# Reference: https://github.com/mozilla/rust-android-gradle/blob/master/.github/workflows/check.yml
- name: Setup Android SDK
uses: android-actions/setup-android@v2
- uses: nttld/setup-ndk@v1
with:
ndk-version: r21e
- uses: actions-rs/toolchain@v1
# Reference: https://github.com/rust-windowing/android-ndk-rs/blob/master/.github/workflows/rust.yml
with:
@ -54,8 +49,5 @@ jobs:
run: |
make prepare-android
- name: "Build Android library"
env:
ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
run: |
cd hello
make android
run: make android
working-directory: hello

View File

@ -3,7 +3,6 @@ prepare-apple:
rustup toolchain install nightly
rustup target add aarch64-apple-ios-sim --toolchain nightly && rustup target add aarch64-apple-ios x86_64-apple-ios
rustup component add rust-src --toolchain nightly
make install-uniffi-bindgen
prepare-android:
rustup toolchain install stable
@ -12,7 +11,3 @@ prepare-android:
rustup target add aarch64-linux-android
rustup target add armv7-linux-androideabi
rustup target add i686-linux-android
make install-uniffi-bindgen
install-uniffi-bindgen:
cargo install uniffi_bindgen --version 0.17.0

View File

@ -17,7 +17,7 @@ Please read <https://www.rust-lang.org/tools/install>.
### iOS
1. Latest Xcode (13.x)
1. Latest Xcode (14.3)
1. Rust toolchains for iOS: `make prepare-apple` or `rustup target add aarch64-apple-ios-sim --toolchain nightly && rustup target add aarch64-apple-ios x86_64-apple-ios`. Check installaion:
```shell
$ rustup target list --installed | grep ios

View File

@ -8,14 +8,18 @@ version = "0.1.0"
crate-type = ["staticlib", "cdylib"]
name = "hello"
[[bin]]
name = "uniffi-bindgen"
path = "bin/uniffi-bindgen.rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
uniffi = "0.22.0"
uniffi_macros = "0.22.0"
uniffi = "0.23.0"
uniffi_macros = "0.23.0"
[build-dependencies]
uniffi_build = "0.22.0"
uniffi = { version = "0.23.0", features = [ "build" ] }
[profile.release]
codegen-units = 1 # Reduce number of codegen units to increase optimizations.

View File

@ -8,18 +8,18 @@ apple:
@make cp-xcframeowrk-source
build-targets:
cargo build --release --target x86_64-apple-ios
cargo +nightly build --release --target aarch64-apple-ios-sim
cargo +nightly build -Z build-std --release --target aarch64-apple-ios-macabi
cargo +nightly build -Z build-std --release --target x86_64-apple-ios-macabi
cargo build --release --target aarch64-apple-ios
cargo build --lib --release --target x86_64-apple-ios
cargo +nightly build --lib --release --target aarch64-apple-ios-sim
cargo +nightly build -Z build-std --lib --release --target aarch64-apple-ios-macabi
cargo +nightly build -Z build-std --lib --release --target x86_64-apple-ios-macabi
cargo build --lib --release --target aarch64-apple-ios
bindgen-swift:
uniffi-bindgen generate src/hello.udl --language swift
cargo run --features=uniffi/cli --bin uniffi-bindgen generate src/hello.udl --language swift
sed -i '' 's/module\ HelloFFI/framework\ module\ HelloFFI/' src/HelloFFI.modulemap
bindgen-kotlin:
uniffi-bindgen generate src/hello.udl --language kotlin -o platforms/android/UniffiRustExample/app/src/main/java
cargo run --features=uniffi/cli --bin uniffi-bindgen generate src/hello.udl --language kotlin -o platforms/android/UniffiRustExample/app/src/main/java
sed -i '' 's/return "uniffi_Hello"/return "hello"/' platforms/android/UniffiRustExample/app/src/main/java/uniffi/Hello/Hello.kt
assemble-frameworks:

View File

@ -0,0 +1,3 @@
fn main() {
uniffi::uniffi_bindgen_main()
}

View File

@ -1,3 +1,3 @@
fn main() {
uniffi_build::generate_scaffolding("./src/hello.udl").unwrap();
uniffi::generate_scaffolding("./src/hello.udl").unwrap();
}

View File

@ -10,11 +10,12 @@ cargo {
module = "../../../.." // Or whatever directory contains your Cargo.toml
libname = "hello" // Or whatever matches Cargo.toml's [package] name.
targets = ["arm", "x86", "x86_64", "arm64"]
extraCargoBuildArguments = ["--lib"]
}
android {
compileSdk 31
// ndkVersion rootProject.ext.ndkVersion
ndkVersion "25.2.9519653"
defaultConfig {
applicationId "com.demo.mobile.uniffirustexample"
@ -42,6 +43,7 @@ android {
buildFeatures {
viewBinding true
}
namespace 'com.example.mobile.demo.uniffirustexample'
}
dependencies {

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mobile.demo.uniffirustexample">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:allowBackup="true"

View File

@ -8,9 +8,9 @@ buildscript {
}
plugins {
id 'com.android.application' version '7.1.2' apply false
id 'com.android.library' version '7.1.2' apply false
id 'org.jetbrains.kotlin.android' version '1.5.30' apply false
id 'com.android.application' version '8.0.2' apply false
id 'com.android.library' version '8.0.2' apply false
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
id "org.mozilla.rust-android-gradle.rust-android" version "0.9.2"
}

View File

@ -20,4 +20,6 @@ kotlin.code.style=official
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.nonTransitiveRClass=true
android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false

View File

@ -1,6 +1,6 @@
#Mon Mar 07 11:58:42 CST 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

View File

@ -21,7 +21,7 @@ let package = Package(
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "Hello",
dependencies: []
dependencies: ["HelloFFI"]
),
.binaryTarget(name: "HelloFFI", path: "Sources/HelloFFI.xcframework"),
.testTarget(