Skip to content

Commit 959eb37

Browse files
committed
Switch to Dart native assets
With the changes from Uniffi-Dart/uniffi-dart#99, the native libraries can be compiled automagically in a dart build hook.
1 parent 34ea33c commit 959eb37

File tree

7 files changed

+57
-28
lines changed

7 files changed

+57
-28
lines changed

payjoin-ffi/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ name = "uniffi-bindgen"
2222
path = "uniffi-bindgen.rs"
2323

2424
[build-dependencies]
25-
uniffi-dart = { git = "https://github.com/Uniffi-Dart/uniffi-dart.git", rev = "364b117", features = ["build"], optional = true }
25+
uniffi-dart = { git = "https://github.com/spacebear21/uniffi-dart.git", rev = "bdfc10a", features = ["build"], optional = true }
2626
uniffi = { version = "0.30.0", features = ["build", "cli"] }
2727

2828
[dependencies]
@@ -38,7 +38,7 @@ serde = { version = "1.0.219", features = ["derive"] }
3838
serde_json = "1.0.142"
3939
thiserror = "2.0.14"
4040
tokio = { version = "1.47.1", features = ["full"], optional = true }
41-
uniffi-dart = { git = "https://github.com/Uniffi-Dart/uniffi-dart.git", rev = "364b117", optional = true }
41+
uniffi-dart = { git = "https://github.com/spacebear21/uniffi-dart.git", rev = "bdfc10a", optional = true }
4242
uniffi = { version = "0.30.0" }
4343
url = "2.5.4"
4444

payjoin-ffi/dart/hook/build.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import 'package:hooks/hooks.dart';
2+
import 'package:native_toolchain_rs/native_toolchain_rs.dart';
3+
4+
void main(List<String> args) async {
5+
await build(args, (input, output) async {
6+
await const RustBuilder(
7+
assetName: 'uniffi:payjoin_ffi',
8+
cratePath: '..',
9+
features: ['dart', '_test-utils'],
10+
).run(input: input, output: output);
11+
});
12+
}

payjoin-ffi/dart/pubspec.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@ description: Dart bindings for payjoin (EXPERIMENTAL)
33
version: 0.1.0
44

55
environment:
6-
sdk: '^3.2.0'
6+
sdk: '^3.10.0'
77

88
dependencies:
99
ffi: ^2.1.4
10+
hooks: any
11+
code_assets: any
12+
native_toolchain_rs: ^1.0.0
1013
dev_dependencies:
1114
test: ^1.26.2
1215
http: ^1.4.0
16+
17+
hooks:
18+
build: hook/build.dart

payjoin-ffi/dart/scripts/generate_bindings.sh

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,4 @@ echo "Generating payjoin dart..."
2222
cargo build --features dart,_test-utils --profile dev
2323
cargo run --features dart,_test-utils --profile dev --bin uniffi-bindgen -- --library ../target/debug/$LIBNAME --language dart --out-dir dart/lib/
2424

25-
if [[ "$OS" == "Darwin" ]]; then
26-
echo "Generating native binaries..."
27-
rustup target add aarch64-apple-darwin x86_64-apple-darwin
28-
# This is a test script the actual release should not include the test utils feature
29-
cargo build --profile dev --target aarch64-apple-darwin --features dart,_test-utils &
30-
cargo build --profile dev --target x86_64-apple-darwin --features dart,_test-utils &
31-
wait
32-
33-
echo "Building macos fat library"
34-
lipo -create -output dart/$LIBNAME \
35-
../target/aarch64-apple-darwin/debug/$LIBNAME \
36-
../target/x86_64-apple-darwin/debug/$LIBNAME
37-
else
38-
echo "Generating native binaries..."
39-
rustup target add x86_64-unknown-linux-gnu
40-
# This is a test script the actual release should not include the test utils feature
41-
cargo build --profile dev --target x86_64-unknown-linux-gnu --features dart,_test-utils
42-
43-
echo "Copying payjoin_ffi binary"
44-
cp ../target/x86_64-unknown-linux-gnu/debug/$LIBNAME dart/$LIBNAME
45-
fi
46-
4725
echo "All done!"

payjoin-ffi/rust-toolchain.toml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[toolchain]
2+
channel = "1.85.1"
3+
4+
# The targets you want to support; these are the default:
5+
targets = [
6+
# Android
7+
"armv7-linux-androideabi",
8+
"aarch64-linux-android",
9+
"x86_64-linux-android",
10+
11+
# iOS (device + simulator)
12+
"aarch64-apple-ios",
13+
"aarch64-apple-ios-sim",
14+
"x86_64-apple-ios",
15+
16+
# Windows
17+
"aarch64-pc-windows-msvc",
18+
"x86_64-pc-windows-msvc",
19+
20+
# Linux
21+
"aarch64-unknown-linux-gnu",
22+
"x86_64-unknown-linux-gnu",
23+
24+
# macOS
25+
"aarch64-apple-darwin",
26+
"x86_64-apple-darwin",
27+
]

payjoin-ffi/uniffi-bindgen.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
fn main() { uniffi_bindgen() }
1+
fn main() {
2+
uniffi_bindgen()
3+
}
24

35
fn uniffi_bindgen() {
46
// uniffi_bindgen_main parses command line arguments for officially supported languages,
@@ -21,7 +23,7 @@ fn uniffi_bindgen() {
2123
.expect("--out-dir is required when using --library");
2224
uniffi_dart::gen::generate_dart_bindings(
2325
"src/payjoin.udl".into(),
24-
None,
26+
Some("uniffi.toml".into()),
2527
Some(output_dir.as_str().into()),
2628
library_path.as_str().into(),
2729
true,

payjoin-ffi/uniffi.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ cdylib_name = "payjoin_ffi"
66
cdylib_name = "payjoin_ffi"
77

88
[bindings.swift]
9-
cdylib_name = "payjoin_ffi"
9+
cdylib_name = "payjoin_ffi"
10+
11+
[bindings.dart]
12+
cdylib_name = "payjoin_ffi"
13+
package_name = "payjoin"

0 commit comments

Comments
 (0)