Conversation
thesimplekid
left a comment
There was a problem hiding this comment.
Nice. I think this is generally in the right direction though I didn't try to run anything.
| # Install targets if needed | ||
| echo "📦 Ensuring Rust targets are installed..." | ||
| rustup target add aarch64-apple-ios | ||
| rustup target add x86_64-apple-ios | ||
| rustup target add aarch64-apple-ios-sim | ||
| rustup target add aarch64-apple-darwin | ||
| rustup target add x86_64-apple-darwin |
There was a problem hiding this comment.
We need to define this in a nix and not use rustup
There was a problem hiding this comment.
I think this flutter example should live else where. We should not commit a full flutter example to the cdk repo. Instead we should have a more basic just dart example/test.
There was a problem hiding this comment.
I don't think we should commit generated files and they should be added to .gitignore
There was a problem hiding this comment.
For this to work in ci we'll need to add a new shell to the flake that has dart available.
https://github.com/cashubtc/cdk-flutter/blob/master/flake.nix
| echo "📦 Ensuring Rust targets are installed..." | ||
| rustup target add aarch64-apple-ios | ||
| rustup target add x86_64-apple-ios | ||
| rustup target add aarch64-apple-ios-sim | ||
| rustup target add aarch64-apple-darwin | ||
| rustup target add x86_64-apple-darwin | ||
|
|
||
| # Set cross-compilation toolchain for Apple targets when building on Linux. | ||
| # cc-rs (used by build scripts like secp256k1-sys) picks CC_<target> to find the C compiler. | ||
| # Without these it falls back to the host "cc" (Linux GCC) which doesn't understand | ||
| # -arch or -mmacosx-version-min flags. | ||
| if [[ "$(uname)" == "Linux" ]]; then | ||
| OSXCROSS_BIN=/usr/local/osxcross/bin | ||
| DARWIN_TRIPLE=aarch64-apple-darwin24.4 | ||
| DARWIN_X86_TRIPLE=x86_64-apple-darwin24.4 | ||
| IOS_SDK=/usr/local/ios-sdk/iPhoneOS18.4.sdk | ||
| IOS_SIM_SDK=/usr/local/ios-sdk/iPhoneSimulator18.4.sdk | ||
|
|
||
| export CC_aarch64_apple_darwin=$OSXCROSS_BIN/$DARWIN_TRIPLE-clang | ||
| export AR_aarch64_apple_darwin=$OSXCROSS_BIN/$DARWIN_TRIPLE-ar | ||
| export CC_x86_64_apple_darwin=$OSXCROSS_BIN/$DARWIN_X86_TRIPLE-clang | ||
| export AR_x86_64_apple_darwin=$OSXCROSS_BIN/$DARWIN_X86_TRIPLE-ar | ||
|
|
||
| # iOS: use system clang, NOT the osxcross darwin wrapper. | ||
| # The osxcross darwin wrapper unconditionally adds -mmacosx-version-min, which | ||
| # conflicts with -miphoneos-version-min that cc-rs adds for iOS targets. | ||
| export CC_aarch64_apple_ios=/usr/bin/clang | ||
| export AR_aarch64_apple_ios=$OSXCROSS_BIN/$DARWIN_TRIPLE-ar | ||
| export CFLAGS_aarch64_apple_ios="-isysroot $IOS_SDK -target arm64-apple-ios14.0" | ||
|
|
||
| export CC_aarch64_apple_ios_sim=/usr/bin/clang | ||
| export AR_aarch64_apple_ios_sim=$OSXCROSS_BIN/$DARWIN_TRIPLE-ar | ||
| export CFLAGS_aarch64_apple_ios_sim="-isysroot $IOS_SIM_SDK -target arm64-apple-ios14.0-simulator" | ||
|
|
||
| export CC_x86_64_apple_ios=/usr/bin/clang | ||
| export AR_x86_64_apple_ios=$OSXCROSS_BIN/$DARWIN_X86_TRIPLE-ar | ||
| export CFLAGS_x86_64_apple_ios="-isysroot $IOS_SIM_SDK -target x86_64-apple-ios14.0-simulator" |
There was a problem hiding this comment.
Should define this in a flake and not use rustup
| # CDK Bindings | ||
|
|
||
| This part of the project is heavily inspired by [Bark Bindings][1], | ||
| particularly its model for exporting a Rust codebase through FFI and making it | ||
| accessible from other languages. | ||
|
|
||
| The purpose of this project is to expose the CDK Wallet and its associated | ||
| traits so they can be consumed in target languages as abstract classes or | ||
| interfaces. This enables developers to extend or implement language-specific | ||
| functionality while relying on the shared Rust core. | ||
|
|
||
| A separate crate is provided for each target language. These crates serve as | ||
| integration layers where Rust code can be adapted to the conventions and native | ||
| capabilities of each platform or language runtime. | ||
|
|
||
| [1]: https://gitlab.com/ark-bitcoin/bark-ffi-bindings |
There was a problem hiding this comment.
Should make this more what it is and how to use it and when we need to modify it. We can credit bark at the end of the readme.
|
|
||
| /// Unified wallet storage: either a built-in Rust backend or a custom | ||
| /// foreign-language implementation of the `WalletDatabase` callback interface. | ||
| #[derive(uniffi::Enum)] |
There was a problem hiding this comment.
We use the enum because of a uniffi limitation of being able to use a trait directly, I'm guessing? Can we just add a comment explaining that?
Should we add some constructors on the enum, new_sqlite(path), new_psgl(url) for example? Think that would be easier for downstream to use.
There was a problem hiding this comment.
We use the enum because of a uniffi limitation of being able to use a trait directly, I'm guessing? Can we just add a comment explaining that?
Yeah, I'll expand on that. But that is the reason
| patch_generated(&generated_path); | ||
| } | ||
|
|
||
| /// Patches the generated cdk_ffi.dart to fix uniffi-dart codegen issues. |
There was a problem hiding this comment.
Can we just add a little more detail on why we need to patch and if it might change in the future as I understand this is required but it could be fragile, so to save us some time debugging in the future. Also if we could track what we need in order to avoid patching to get the upstream that would be great.
bindings/dart/rust/Cargo.toml
Outdated
| [dependencies] | ||
| cdk-ffi.workspace = true | ||
| uniffi = { version = "=0.30.0", features = ["cli"] } | ||
| uniffi-dart = { git = "https://github.com/Uniffi-Dart/uniffi-dart" } |
There was a problem hiding this comment.
We should pick a tag, looks like payjoin is using v0.1.0+v0.30.0, do we need main. If so whatever commit is working for us.
ec78b29 to
6199ed5
Compare
|
I notice the flake.lock is not changed after adding the dart overlay. This could be what is causing the rate limiting as this needs to be updated. |
There was a problem hiding this comment.
I think generated files should not be commited.
There was a problem hiding this comment.
I think it should, at least people do that in other repos.
There was a problem hiding this comment.
Does this need to be at the root level?
6199ed5 to
fc1ff7f
Compare
8df4da8 to
67b7988
Compare
b2c5e77 to
497e283
Compare
Introduce Dart/Flutter bindings generated via uniffi-dart, including: - Flutter example wallet app with mint, send, and receive flows - WalletStore enum (Sqlite/Postgres/Custom) replacing separate constructors, allowing both built-in Rust backends and foreign callback implementations through a single `new()` constructor - Justfile targets for building and running Dart bindings - Post-generation patches for uniffi-dart codegen issues
- Add Swift binding generation via UniFFI for iOS, iOS Simulator, and macOS - Include generate-bindings.sh script that builds universal XCFramework with support for aarch64-apple-ios, aarch64-apple-ios-sim, and aarch64-apple-darwin targets - Add Swift wrapper (CashuDevKit.swift) generated from cdk-ffi crate - Add Swift example project demonstrating wallet creation, minting, melting, and multi-mint wallet usage - Include Info.plist resources for iOS, iOS Simulator, and macOS frameworks - Add UniFFI bindgen configuration (uniffi.toml) and Swift bindgen binary - Update justfile with swift-bindings and swift-example tasks - Update Dart bindings: regenerate FFI bindings, add generate-bindings.sh, update flutter_example dependencies - Bump cdk-ffi uniffi dependency to version 0.29
- Consolidate uniffi version (0.30) in workspace root Cargo.toml - Replace per-crate version pins with workspace = true in cdk-ffi, cdk-ffi-swift, and cdk-ffi-dart - Apply rustfmt formatting to dart bindings codegen and FFI sources - Update Cargo.lock.msrv with resolved dependency versions
- Remove the Flutter example app and Swift example app - Add Dart unit tests (wallet_test.dart) and Swift tests (CdkTests.swift) that verify wallet initialization, zero balance, and mint flow against testnut.cashu.space - Add CI jobs for Dart and Swift binding tests on self-hosted/macOS runners - Add nix `bindings` devShell with Dart SDK, OpenSSL, and stable Rust toolchain (including Apple cross-compile targets) - Fix Dart build hook to forward full parent environment to cargo and extract OpenSSL paths from NIX_CFLAGS_COMPILE/NIX_LDFLAGS as fallback - Update justfile: replace `example-dart`/`example-swift` with `test-dart`/`test-swift` recipes
497e283 to
2adf0f4
Compare
| let tempDir = FileManager.default.temporaryDirectory | ||
| dbPath = tempDir.appendingPathComponent(UUID().uuidString + ".sqlite").path | ||
| wallet = try Wallet( | ||
| mintUrl: "https://testnut.cashu.space", |
There was a problem hiding this comment.
| mintUrl: "https://testnut.cashu.space", | |
| mintUrl: "https://testnut.cashudevkit.org", |
Description
Prototype to have a monorepo for all the bindings
Closes: #1539, #1670
Notes to the reviewers
Suggested CHANGELOG Updates
CHANGED
ADDED
REMOVED
FIXED
Checklist
just final-checkbefore committing