Skip to content

Add dart/flutter bindings to livekit-uniffi#1183

Open
jhugman wants to merge 5 commits into
mainfrom
jhugman/dart-bindings
Open

Add dart/flutter bindings to livekit-uniffi#1183
jhugman wants to merge 5 commits into
mainfrom
jhugman/dart-bindings

Conversation

@jhugman

@jhugman jhugman commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Before you submit your PR

Make sure the following is true before submitting your PR:

  • I have read the contributing guidelines and validated that this PR will be accepted.
  • I have read and followed the principles regarding breaking changes, testing, and code quality.

PR description

Added Dart bindings with the uniffi-dart bindgen. This generates a Native Assets API. Exercise with cargo make bindgen-dart.

This adds a uniffi-bindgen-dart feature to the livekit-uniffi crate: followup would be to separate out the uniffi-tooling binaries in to a workspace centred tooling crate.

Added consumable package, with a hook/build.dart. This works both locally, and by downloading a prebuilt cdylib.

Added CI which builds the cdylibs per OS/architecture on release.

Breaking changes

No changes breaking changes are made, however:

  • uniffi-dart bindgen needed a bug fix which means the version of uniffi-dart is from main (pinned to the hash).
  • the version of uniffi is incremented to 0.31. This is unlikely to cause breakage in the Swift, Python, Kotlin bindings, but may cause problems for uniffi-bindgen-node. Followup: move uniffi-bindgen-node to uniffi-bindgen-react-native.

MSRV

No changes. uniffi 0.31 requires >= 1.85

Testing

  • Dart package tests (support/dart/tests): a smoke test including a negative case.
  • CI build & hook/build.dart tested via dry run.

Async

We want the project to be runtime-agnostic, so please reuse what's already in livekit-runtime and feel free to add anything missing. It's ok to use Tokio directly, when writing unit tests, if necessary. When testing, do not use artificial delays for the state to "catch up"; instead, respect the event flow and subscribe properly using channels or other mechanisms.

@jhugman jhugman requested review from ladvoc and pblazej as code owners June 23, 2026 13:11
@github-actions

Copy link
Copy Markdown
Contributor

Changeset

The following package versions will be affected by this PR:

Package Bump
livekit-uniffi minor

jhugman added 4 commits June 23, 2026 16:50
Release/multi-platform delivery for the Dart package:
- uniffi-cdylib.yml builds liblivekit_uniffi for desktop + mobile targets and
  attaches build-<triple>.zip (+ .sha256) to the livekit-uniffi release; wired
  into uniffi-packages.yml. Validated across all 10 targets via CI dry-run.
- hook/build.dart.tera gains a download mode: fetches and SHA-256-verifies the
  prebuilt library for the target when no local build is present.
Ship tests in support/dart/test, copied into the generated package by the
dart-package flow. Covers the FFI smoke path (buildVersion) and a real
JWT/HMAC round-trip (generate -> verify -> decode, plus wrong-secret rejection)
to exercise Rust logic across the boundary.
uniffi-dart-test.yml builds the Dart package (host cdylib + bindings via
cargo make dart-package) and runs dart test on PRs/pushes touching
livekit-uniffi or its dependencies. The dart build keeps symbols
(CARGO_PROFILE_RELEASE_STRIP=false) so library-mode bindgen can read the
UNIFFI_META_* metadata, which the release strip removes on Linux.
@jhugman jhugman force-pushed the jhugman/dart-bindings branch from cdd271c to c60ae51 Compare June 23, 2026 15:50
@jhugman jhugman requested review from 1egoman and hiroshihorie June 23, 2026 15:51

@1egoman 1egoman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A few high level thoughts. I am deferring an official review approval to folks with more first hand flutter experience.

}

Future<List<int>> _downloadAndVerify(Uri zipUrl) async {
final zipResp = await http.get(zipUrl);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

thought: Does this request have a default timeout? I'm assuming so but it would be worth confirming.

thought: Also, does this http.get follow 3xx redirects properly? If not, I think it would be worth making sure it does, that opens up a lot of future flexibility.

Comment on lines +95 to +97
if (zipResp.statusCode != 200) {
throw Exception('Failed to download $zipUrl: HTTP ${zipResp.statusCode}');
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nitpick: Also in the aim of future flexibility, maybe making this verify 2xx not strictly 200 might be a good idea.

Comment thread livekit-uniffi/Cargo.toml
Comment on lines +41 to +49
output.assets.code.add(
CodeAsset(
package: input.packageName,
// Dart prefixes this with `package:<packageName>/`.
name: 'uniffi:$_cdylibName',
linkMode: DynamicLoadingBundled(),
file: libFile,
),
);

@1egoman 1egoman Jun 29, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

thought: An interesting related blog post I came across in my research: https://www.simonbinder.eu/posts/native_assets/

I'm not sure how much of this applies since this is a net new package, but the thing that stood out to me was that it seems like by using native assets (I think that's what you are doing here?) you potentially force consumers to also enable the native assets feature. Maybe that's fine but could be problematic once this gets folded into the dart sdk and could maybe break existing users

(Feel free to ignore this if it's not relevant, you're probably done more research into dart packaging than I have at this point)

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.

2 participants