Skip to content

Commit ba5ac46

Browse files
authored
Uniffi dart (#829)
This adds support for producing dart bindings with uniffi via https://github.com/Uniffi-Dart/uniffi-dart.git (pinned commit for now until official releases exist). The unit and integration tests in dart are passing. Note that the integration test is currently flaky due to issues with `testcontainers`, so the dart Github workflow is not introduced in this PR to keep CI reliably passing. #876 adds the workflow separately but should wait until the `testcontainers` issue is resolved.
2 parents eb5ff94 + 20fd94f commit ba5ac46

File tree

10 files changed

+675
-2
lines changed

10 files changed

+675
-2
lines changed

payjoin-ffi/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ exclude = ["tests"]
88
[features]
99
_test-utils = ["payjoin-test-utils", "tokio", "bitcoind"]
1010
_danger-local-https = ["payjoin/_danger-local-https"]
11-
uniffi = ["uniffi/cli", "bitcoin-ffi/default"]
11+
uniffi = ["uniffi/cli", "bitcoin-ffi/default", "uniffi-dart"]
1212

1313
[lib]
1414
name = "payjoin_ffi"
@@ -20,6 +20,7 @@ path = "uniffi-bindgen.rs"
2020

2121
[build-dependencies]
2222
uniffi = { version = "0.29.1", features = ["build"] }
23+
uniffi-dart = { git = "https://github.com/Uniffi-Dart/uniffi-dart.git", rev = "b6186bc", features = ["build"] }
2324

2425
[dependencies]
2526
base64 = "0.22.1"
@@ -35,6 +36,7 @@ serde_json = "1.0.128"
3536
thiserror = "1.0.58"
3637
tokio = { version = "1.38.0", features = ["full"], optional = true }
3738
uniffi = { version = "0.29.1", optional = true }
39+
uniffi-dart = { git = "https://github.com/Uniffi-Dart/uniffi-dart.git", rev = "b6186bc", optional = true}
3840
url = "2.5.0"
3941

4042
[dev-dependencies]

payjoin-ffi/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
fn main() {
22
#[cfg(feature = "uniffi")]
33
uniffi::generate_scaffolding("src/payjoin_ffi.udl").unwrap();
4+
#[cfg(feature = "uniffi")]
5+
uniffi_dart::generate_scaffolding("src/payjoin_ffi.udl".into()).unwrap();
46
}

payjoin-ffi/dart/.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.dart_tool/
2+
build/
3+
pubspec.lock
4+
doc/api/
5+
6+
.DS_Store
7+
8+
# Auto-generated shared libraries
9+
*.dylib
10+
*.so
11+
*.dll
12+
13+
# Auto-generated bindings
14+
lib/payjoin_ffi.dart
15+
lib/bitcoin.dart

payjoin-ffi/dart/pubspec.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: payjoin_dart
2+
description: Dart bindings for payjoin
3+
version: 0.24.0
4+
5+
environment:
6+
sdk: '^3.2.0'
7+
8+
dependencies:
9+
ffi: ^2.1.4
10+
dev_dependencies:
11+
test: ^1.26.2
12+
http: ^1.4.0
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
3+
#!/bin/bash
4+
chmod +x ./scripts/generate_linux.sh
5+
chmod +x ./scripts/generate_macos.sh
6+
7+
8+
# Run each script
9+
scripts/generate_linux.sh
10+
scripts/generate_macos.sh
11+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
LIBNAME=libpayjoin_ffi.so
4+
LINUX_TARGET=x86_64-unknown-linux-gnu
5+
6+
echo "Generating payjoin_ffi.dart..."
7+
cd ../
8+
# This is a test script the actual release should not include the test utils feature
9+
cargo build --profile release --features uniffi,_test-utils
10+
cargo run --profile release --features uniffi,_test-utils --bin uniffi-bindgen -- --library target/release/$LIBNAME --language dart --out-dir dart/lib/
11+
12+
echo "Generating native binaries..."
13+
rustup target add $LINUX_TARGET
14+
# This is a test script the actual release should not include the test utils feature
15+
cargo build --profile release-smaller --target $LINUX_TARGET --features uniffi,_test-utils
16+
17+
echo "Copying linux payjoin_ffi.so"
18+
cp target/$LINUX_TARGET/release-smaller/$LIBNAME dart/$LIBNAME
19+
20+
echo "All done!"
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
LIBNAME=libpayjoin_ffi.dylib
5+
6+
echo "Generating payjoin_ffi.dart..."
7+
cd ../
8+
# This is a test script the actual release should not include the test utils feature
9+
cargo build --features uniffi,_test-utils --profile release
10+
cargo run --features uniffi,_test-utils --profile release --bin uniffi-bindgen -- --library target/release/$LIBNAME --language dart --out-dir dart/lib/
11+
12+
echo "Generating native binaries..."
13+
rustup target add aarch64-apple-darwin x86_64-apple-darwin
14+
15+
# This is a test script the actual release should not include the test utils feature
16+
cargo build --profile release-smaller --target aarch64-apple-darwin --features uniffi,_test-utils
17+
echo "Done building aarch64-apple-darwin"
18+
19+
# This is a test script the actual release should not include the test utils feature
20+
cargo build --profile release-smaller --target x86_64-apple-darwin --features uniffi,_test-utils
21+
echo "Done building x86_64-apple-darwin"
22+
23+
echo "Building macos fat library"
24+
25+
lipo -create -output dart/$LIBNAME \
26+
target/aarch64-apple-darwin/release-smaller/$LIBNAME \
27+
target/x86_64-apple-darwin/release-smaller/$LIBNAME
28+
29+
echo "All done!"

0 commit comments

Comments
 (0)