Skip to content

Conversation

@chavic
Copy link
Contributor

@chavic chavic commented Oct 28, 2025

This PR brings experimental Dart bindings generation using uniffi-dart. Once the latest fixes from chavic/bdk-fixes (the callback alignment work and the optional-sequence guard) are merged into main without regressions, bdk-dart will be ready for battle testing.

To see, generate, and test out the code run:

  1. Regenerate the bindings using our helper script:
    scripts/generate_bindings.sh

  2. Run the Dart test suite
    dart test

@Johnosezele
Copy link

Awesome work @chavic!

Thankfully dart test all tests successfully pass now!

cACK! File/folder dir looks good to me, consistent with bdk-android, bdk-jvm & bdk-swift

tACK 901b09 dart bindings are successfully generated on my local.

tACK 8fdea0f all dart tests run successfully on my local.

Comment on lines 19 to 30
match language {
Some(lang) if lang == "dart" => {
uniffi_dart::gen::generate_dart_bindings(
"bdk-ffi/bdk-ffi/src/bdk.udl".into(),
None,
Some(output_dir.as_str().into()),
library_path.as_str().into(),
true,
)
.expect("Failed to generate dart bindings");
}
_ => uniffi::uniffi_bindgen_main(),

Choose a reason for hiding this comment

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

To keep the cli usable, the wrapper should only unwrap those flags when they're present and otherwise fall to uniffi::uniffi_bindgen_main().

Suggested change
match language {
Some(lang) if lang == "dart" => {
uniffi_dart::gen::generate_dart_bindings(
"bdk-ffi/bdk-ffi/src/bdk.udl".into(),
None,
Some(output_dir.as_str().into()),
library_path.as_str().into(),
true,
)
.expect("Failed to generate dart bindings");
}
_ => uniffi::uniffi_bindgen_main(),
if let Some(lang) = language {
if lang == "dart" {
match (library_path, output_dir) {
(Some(lib), Some(out)) => {
uniffi_dart::gen::generate_dart_bindings(
"bdk-ffi/bdk-ffi/src/bdk.udl".into(),
None,
Some(out.as_str().into()),
lib.as_str().into(),
true,
)
.expect("Failed to generate dart bindings");
return;
}
(Some(_), None) => {
eprintln!("--out-dir is required when using --library; falling back to uniffi CLI");
}
_ => {}
}
}
}
uniffi::uniffi_bindgen_main();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This seems more complicated 🤔

Copy link
Contributor Author

@chavic chavic Oct 30, 2025

Choose a reason for hiding this comment

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

Is there a specific reason to use this approach? @Johnosezele

Choose a reason for hiding this comment

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

Agreed, it looks more verbose. The new if let Some(lang) = language { … } branch only calls uniffi_dart::gen::generate_dart_bindings when all flags are present... otherwise it falls back to standard cli, and we log a message if --out-dir is missing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I understand the central idea behind the comments now...

The key assumption is centered around whether other users or CI tools expect the uniffi-rs CLI interface on third party implementations

If possible, before the PR is out of draft, check out some third parties to help align expectations for how bdk-dart may be consumed 🤔

run: dart format --output=none --set-exit-if-changed .

- name: Analyze
run: dart analyze --fatal-infos --fatal-warnings || true

Choose a reason for hiding this comment

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

wouldn't || true hide analyzer failures?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep... it should be removed later... Keeping it in for now till the example has no errors...

Choose a reason for hiding this comment

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

ok, great!

Copy link
Collaborator

Choose a reason for hiding this comment

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

wanted to check back in on this, does the example still have errors or can we remove || true now?

@reez
Copy link
Collaborator

reez commented Nov 3, 2025

This PR brings experimental Dart bindings generation using uniffi-dart. Once the latest fixes from chavic/bdk-fixes (the callback alignment work and the optional-sequence guard) are merged into main without regressions, bdk-dart will be ready for battle testing.

To see, generate, and test out the code run:

  1. Regenerate the bindings using our helper script:
    scripts/generate_bindings.sh
  2. Run the Dart test suite
    dart test

Awesome work! I regenerated the bindings, ran dart test, and wired them into a macOS Flutter desktop demo and everything loaded correctly. I'll do a deeper look at the pr this week now too.

@chavic chavic marked this pull request as ready for review November 4, 2025 09:19
@chavic
Copy link
Contributor Author

chavic commented Nov 4, 2025

The unifi-dart fixes have been merged, and we now point to main with the newest rev.

We're ready for review and testing.

.iter()
.position(|arg| arg == "--library")
.and_then(|idx| args.get(idx + 1))
.expect("specify the library path with --library");
Copy link
Collaborator

Choose a reason for hiding this comment

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

should this parsing happen inside lang == "dart" branch so --help or others dont panic here?

- name: Analyze
run: dart analyze --fatal-infos --fatal-warnings || true

- name: Run tests (expected to fail until bindings fixed)
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we drop (expected to fail until bindings fixed) now?

@reez
Copy link
Collaborator

reez commented Nov 4, 2025

made some additional comemnts/questions, looks like some of it was discussed already but just wanted to ask again or from a different angle of how I was thinking about it.

another broad question that doesnt need to be addressed in this PR necessarily is is there a follow up pr where we support mobile (xcframework, etc), right now I think im only seeing linux/macOS support but let me know if I'm wrong.

otherwise I think this pr looks really great, none of my questions are big blockers either, so good stuff and good job by you!

@Johnosezele
Copy link

another broad question that doesnt need to be addressed in this PR necessarily is is there a follow up pr where we support mobile (xcframework, etc), right now I think im only seeing linux/macOS support but let me know if I'm wrong.

true! xcframework, android AAR... isn't covered yet. I think it exceeds the scope of this pr. See a follow up issue here

@reez
Copy link
Collaborator

reez commented Nov 5, 2025

another broad question that doesnt need to be addressed in this PR necessarily is is there a follow up pr where we support mobile (xcframework, etc), right now I think im only seeing linux/macOS support but let me know if I'm wrong.

true! xcframework, android AAR... isn't covered yet. I think it exceeds the scope of this pr. See a follow up issue here

cool, totally agree doesn't need to be in the scope of this PR I just wanted to mention/ask about it

@chavic chavic force-pushed the chavic/bdk-x-uniffi-dart-fixes branch from fbd7d01 to da17b49 Compare November 16, 2025 12:29
@chavic chavic requested review from Johnosezele and reez November 16, 2025 12:34
@reez reez merged commit f845653 into bitcoindevkit:main Nov 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants