Skip to content

Bindings#1706

Draft
crodas wants to merge 5 commits intocashubtc:mainfrom
crodas:feature/bindings
Draft

Bindings#1706
crodas wants to merge 5 commits intocashubtc:mainfrom
crodas:feature/bindings

Conversation

@crodas
Copy link
Collaborator

@crodas crodas commented Mar 6, 2026

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

@github-project-automation github-project-automation bot moved this to Backlog in CDK Mar 6, 2026
Copy link
Collaborator

@thesimplekid thesimplekid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. I think this is generally in the right direction though I didn't try to run anything.

Comment on lines +25 to +31
# 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to define this in a nix and not use rustup

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should commit generated files and they should be added to .gitignore

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines +26 to +62
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"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should define this in a flake and not use rustup

Comment on lines +1 to +16
# 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

[dependencies]
cdk-ffi.workspace = true
uniffi = { version = "=0.30.0", features = ["cli"] }
uniffi-dart = { git = "https://github.com/Uniffi-Dart/uniffi-dart" }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@crodas crodas force-pushed the feature/bindings branch 7 times, most recently from ec78b29 to 6199ed5 Compare March 10, 2026 14:53
@thesimplekid
Copy link
Collaborator

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. nix flake lock should be run and the new lock file committed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think generated files should not be commited.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should, at least people do that in other repos.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be at the root level?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crodas crodas force-pushed the feature/bindings branch from 6199ed5 to fc1ff7f Compare March 13, 2026 00:20
@thesimplekid thesimplekid mentioned this pull request Mar 13, 2026
2 tasks
@crodas crodas force-pushed the feature/bindings branch 3 times, most recently from 8df4da8 to 67b7988 Compare March 16, 2026 22:33
@crodas crodas self-assigned this Mar 16, 2026
@crodas crodas force-pushed the feature/bindings branch 7 times, most recently from b2c5e77 to 497e283 Compare March 17, 2026 22:43
crodas added 5 commits March 18, 2026 07:17
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
@crodas crodas force-pushed the feature/bindings branch from 497e283 to 2adf0f4 Compare March 18, 2026 14:44
let tempDir = FileManager.default.temporaryDirectory
dbPath = tempDir.appendingPathComponent(UUID().uuidString + ".sqlite").path
wallet = try Wallet(
mintUrl: "https://testnut.cashu.space",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mintUrl: "https://testnut.cashu.space",
mintUrl: "https://testnut.cashudevkit.org",

@thesimplekid thesimplekid added this to the 0.16.0 milestone Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants