Skip to content

Commit

Permalink
Added Sample Build
Browse files Browse the repository at this point in the history
  • Loading branch information
alvinosh committed Jul 2, 2024
1 parent 1c69832 commit 1daecf5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ cross build -p drop_core --target x86_64-linux-android
Generate the bindings using uniffi for kotlin

```sh
cargo run -p uniffi-bingen generate --library target/x86_64-linux-android/debug/libark_drop_lib.so --language=kotlin --out-dir ./bindings
cargo run -p uniffi-bingen generate --library target/x86_64-linux-android/debug/libdrop_core.so --language=kotlin --out-dir ./bindings
```
38 changes: 38 additions & 0 deletions bindings/uniffi/drop_core/drop_core.kt
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,8 @@ internal interface UniffiForeignFutureCompleteVoid : com.sun.jna.Callback {








Expand All @@ -705,6 +707,8 @@ internal interface UniffiLib : Library {

}

fun uniffi_drop_core_fn_func_add(`a`: Int,`b`: Int,uniffi_out_err: UniffiRustCallStatus,
): Int
fun ffi_drop_core_rustbuffer_alloc(`size`: Long,uniffi_out_err: UniffiRustCallStatus,
): RustBuffer.ByValue
fun ffi_drop_core_rustbuffer_from_bytes(`bytes`: ForeignBytes.ByValue,uniffi_out_err: UniffiRustCallStatus,
Expand Down Expand Up @@ -817,6 +821,8 @@ internal interface UniffiLib : Library {
): Unit
fun ffi_drop_core_rust_future_complete_void(`handle`: Long,uniffi_out_err: UniffiRustCallStatus,
): Unit
fun uniffi_drop_core_checksum_func_add(
): Short
fun ffi_drop_core_uniffi_contract_version(
): Int

Expand All @@ -834,6 +840,9 @@ private fun uniffiCheckContractApiVersion(lib: UniffiLib) {

@Suppress("UNUSED_PARAMETER")
private fun uniffiCheckApiChecksums(lib: UniffiLib) {
if (lib.uniffi_drop_core_checksum_func_add() != 36557.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
}

// Async support
Expand Down Expand Up @@ -874,6 +883,26 @@ inline fun <T : Disposable?, R> T.use(block: (T) -> R) =
/** Used to instantiate an interface without an actual pointer, for fakes in tests, mostly. */
object NoPointer

public object FfiConverterInt: FfiConverter<Int, Int> {
override fun lift(value: Int): Int {
return value
}

override fun read(buf: ByteBuffer): Int {
return buf.getInt()
}

override fun lower(value: Int): Int {
return value
}

override fun allocationSize(value: Int) = 4UL

override fun write(value: Int, buf: ByteBuffer) {
buf.putInt(value)
}
}

public object FfiConverterULong: FfiConverter<ULong, Long> {
override fun lift(value: Long): ULong {
return value.toULong()
Expand Down Expand Up @@ -1049,5 +1078,14 @@ public object FfiConverterSequenceString: FfiConverterRustBuffer<List<kotlin.Str
FfiConverterString.write(it, buf)
}
}
} fun `add`(`a`: kotlin.Int, `b`: kotlin.Int): kotlin.Int {
return FfiConverterInt.lift(
uniffiRustCall() { _status ->
UniffiLib.INSTANCE.uniffi_drop_core_fn_func_add(
FfiConverterInt.lower(`a`),FfiConverterInt.lower(`b`),_status)
}
)
}



5 changes: 5 additions & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ pub struct FileTransfer {
pub total: u64,
}

#[uniffi::export]
fn add(a: i32, b: i32) -> i32 {
a + b
}

impl IrohInstance {
pub async fn new() -> IrohResult<Self> {
let node = Node::memory().spawn().await?;
Expand Down

0 comments on commit 1daecf5

Please sign in to comment.