Merge branch 'main' into uniffi-macros-new

This commit is contained in:
imWildCat 2023-09-20 21:11:54 -07:00
commit 2aca451e5b
5 changed files with 27 additions and 32 deletions

View File

@ -2,7 +2,11 @@
Full documentation of the UniFFI crates can be found [here](https://mozilla.github.io/uniffi-rs/Overview.html).
Working in progress
Another demo including building Rust for WASM (WebAssembly): <https://github.com/imWildCat/rust-mobile-web-demo>
## Questions?
<https://github.com/imWildCat/uniffi-rs-fullstack-examples/discussions>
## Prerequisites

View File

@ -5,7 +5,11 @@ name = "hello"
version = "0.1.0"
[lib]
crate-type = ["staticlib", "rlib", "cdylib"]
crate-type = [
"staticlib", # must for iOS
"rlib",
"cdylib", # must for Android
]
# staticlib would be good enough.
# adding "rlib" here just in case that we need to call these public interfaces directly from another Rust crate
name = "hello"
@ -18,5 +22,13 @@ uniffi = { workspace = true }
# uniffi_bindgen = { workspace = true }
# uniffi_macros = { workspace = true }
[build-dependencies]
uniffi = { workspace = true, features = ["build"] }
[profile.release]
codegen-units = 1 # Reduce number of codegen units to increase optimizations.
lto = true # Enable Link Time Optimization
opt-level = 'z' # Optimize for size.
# panic = 'abort' # Abort on panic
debug = true # Enable debug symbols. For example, we can use `dwarfdump` to check crash traces.

View File

@ -7,15 +7,20 @@ plugins {
apply plugin: 'org.mozilla.rust-android-gradle.rust-android'
cargo {
module = "../../../.." // Or whatever directory contains your Cargo.toml
prebuiltToolchains = true
targetDirectory = "$projectDir/../../../../../target" // because of workspace
module = "$projectDir/../../../.." // Or whatever directory contains your Cargo.toml
libname = "hello" // Or whatever matches Cargo.toml's [package] name.
targets = ["arm", "x86", "x86_64", "arm64"]
pythonCommand = 'python3'
profile = 'debug'
targets = ["x86_64", "arm64", "arm", "x86"]
extraCargoBuildArguments = ["--lib"]
verbose = true
}
android {
compileSdk 31
ndkVersion "25.2.9519653"
ndkVersion System.getenv("ANDROID_NDK_VERSION")
defaultConfig {
applicationId "com.demo.mobile.uniffirustexample"
@ -70,7 +75,5 @@ afterEvaluate {
}
def buildType = "${variant.buildType.name.capitalize()}"
tasks["generate${productFlavor}${buildType}Assets"].dependsOn(tasks["cargoBuild"])
}
}

View File

@ -1,24 +0,0 @@
package com.example.mobile.demo.uniffirustexample
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.example.mobile.demo.uniffirustexample", appContext.packageName)
}
}

View File

@ -11,7 +11,7 @@ plugins {
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"
id "org.mozilla.rust-android-gradle.rust-android" version "0.9.3"
}