-
Notifications
You must be signed in to change notification settings - Fork 123
UniFFI trial #750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ladvoc
wants to merge
35
commits into
main
Choose a base branch
from
ladvoc/uniffi-trial
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
UniFFI trial #750
Changes from 30 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
64f9c96
Init livekit-uniffi crate
ladvoc 9f85820
Configure
ladvoc 24110d9
Expose access token module
ladvoc 794c5d2
Add placeholder config file
ladvoc 5736d45
Allow omitting token options
ladvoc ea7a068
Add python test
ladvoc 310b632
Use fully qualified names for macros
ladvoc 627b91f
Don't commit dylib and pycache
ladvoc eef2ad7
Implement log forwarding
ladvoc 734245e
Expose build info
ladvoc 5fbdedd
Allow multiple invocations
ladvoc c658395
Change log level in example
ladvoc 82f38c8
Remove debug
ladvoc f0173ba
Introduce Makefile
ladvoc df14e25
License check
ladvoc b3835e3
Handle multi-platform builds
ladvoc e07b2d5
Regenerate bindings
ladvoc 48385c5
Update README
ladvoc c004438
Fix typo
ladvoc ba06af5
Format
ladvoc 3faab50
Parse unverified JWT (#756)
pblazej bc14007
Fix tier3 warnings
pblazej 8612dd0
Move to cargo-swift
pblazej 0249813
Merge branch 'main' into ladvoc/uniffi-trial
pblazej c6a5f55
Expose room config
pblazej 3f9e0fd
Platforms
pblazej 347b046
Local Package.swift
pblazej 5c5af74
Remote Package.swift
pblazej 4d82c9d
Fmt
pblazej 5a4283a
Remove packages and generated code
pblazej e1df4af
Readme
pblazej 729bc10
Static lib
pblazej af133b4
feat: add node bindgen packaging code
1egoman e9e72c1
fix: swap license header block format to please hawkeye
1egoman 5f0c9da
fix: remove undefined fields thanks to https://github.com/livekit/uni…
1egoman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoibmFtZSIsInZpZGVvIjp7InJvb21Kb2luIjp0cnVlLCJyb29tIjoibXktcm9vbSIsImNhblB1Ymxpc2giOnRydWUsImNhblN1YnNjcmliZSI6dHJ1ZSwiY2FuUHVibGlzaERhdGEiOnRydWV9LCJyb29tQ29uZmlnIjp7ImFnZW50cyI6W3siYWdlbnROYW1lIjoidGVzdC1hZ2VudCIsIm1ldGFkYXRhIjoidGVzdC1tZXRhZGF0YSJ9XX0sInN1YiI6ImlkZW50aXR5IiwiaXNzIjoibXlhcGlrZXkiLCJuYmYiOjE3NDE4Njk2NzksImV4cCI6MTc0MTg5MTI3OX0.9_eOcZ1RNaRXxwdU36LTYoxsHtv_IhfhLk-kTd8MDY4 | ||
| eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoibmFtZSIsInZpZGVvIjp7InJvb21Kb2luIjp0cnVlLCJyb29tIjoibXktcm9vbSIsImNhblB1Ymxpc2giOnRydWUsImNhblN1YnNjcmliZSI6dHJ1ZSwiY2FuUHVibGlzaERhdGEiOnRydWV9LCJyb29tQ29uZmlnIjp7ImFnZW50cyI6W3siYWdlbnROYW1lIjoidGVzdC1hZ2VudCIsIm1ldGFkYXRhIjoidGVzdC1tZXRhZGF0YSJ9XX0sInN1YiI6ImlkZW50aXR5IiwiaXNzIjoibXlhcGlrZXkiLCJuYmYiOjE3NDE4Njk2NzksImV4cCI6NDEwMjQ0NDgwMH0.hmKovgw6sDbQUFZxAQ9Xjb9-VUzeBw1A6URTXFuCLMU |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| generated/ | ||
| packages/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| [lib] | ||
| crate-type = ["cdylib", "staticlib", "lib"] | ||
|
|
||
| [package] | ||
| name = "livekit-uniffi" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
| license = "Apache-2.0" | ||
| description = "Experimental FFI interface using UniFFI" | ||
| repository = "https://github.com/livekit/rust-sdks" | ||
| readme = "README.md" | ||
|
|
||
| [dependencies] | ||
| livekit-protocol = { workspace = true } | ||
| livekit-api = { workspace = true } | ||
| uniffi = { version = "0.30.0", features = ["cli", "scaffolding-ffi-buffer-fns"] } | ||
| log = "0.4.28" | ||
| tokio = { version = "1.48.0", features = ["sync"] } | ||
| once_cell = "1.21.3" | ||
|
|
||
| [build-dependencies] | ||
| uniffi = { version = "0.30.0", features = ["build", "scaffolding-ffi-buffer-fns"] } | ||
|
|
||
| [[bin]] | ||
| name = "uniffi-bindgen" | ||
| path = "bindgen.rs" | ||
|
|
||
| [profile.release] | ||
| opt-level = "z" | ||
| lto = true | ||
| codegen-units = 1 | ||
| panic = "abort" | ||
| strip = "symbols" | ||
| debug = false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,206 @@ | ||
| # Copyright 2025 LiveKit, Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| [env] | ||
| PACKAGES_DIR = "./packages" | ||
| SUPPORT_DIR = "./support" | ||
| LIB_NAME = "lib${CARGO_MAKE_CRATE_FS_NAME}" | ||
| TARGET_DIR = "${CARGO_MAKE_CRATE_TARGET_DIRECTORY}" | ||
| SPM_NAME = "LiveKitUniFFI" | ||
|
|
||
| [config] | ||
| skip_core_tasks = true | ||
|
|
||
| # MARK: - Build | ||
|
|
||
| [tasks.build.env.TARGET] | ||
| value = "${CARGO_MAKE_RUST_TARGET_TRIPLE}" | ||
| condition = { env_not_set = ["TARGET"] } | ||
| # Set to target triple of the current platform if not explicitly set. | ||
|
|
||
| [tasks.build] | ||
| clear = true | ||
| script_runner = "@duckscript" | ||
| script = """ | ||
| echo "TARGET: ${TARGET}" | ||
|
|
||
| if not ${TIER_3} | ||
| # Ensure target is installed | ||
| exec rustup target add ${TARGET} | ||
| exec cargo build --release --target ${TARGET} | ||
| else | ||
| # Ensure nightly toolchain is installed | ||
| exec rustup component add rust-src --toolchain "nightly-${CARGO_MAKE_RUST_TARGET_TRIPLE}" | ||
| exec cargo +nightly build -Zbuild-std=std,panic_abort --release --target ${TARGET} | ||
| end | ||
| """ | ||
|
|
||
| # MARK: - Build, specific platforms | ||
|
|
||
| [tasks.build-windows-x64] | ||
| extend = "build" | ||
| env = { TARGET = "x86_64-pc-windows-msvc" } | ||
|
|
||
| [tasks.build-windows-aarch64] | ||
| extend = "build" | ||
| env = { TARGET = "aarch64-pc-windows-msvc" } | ||
|
|
||
| [tasks.build-linux-aarch64] | ||
| extend = "build" | ||
| env = { TARGET = "aarch64-unknown-linux-gnu" } | ||
|
|
||
| [tasks.build-linux-x64] | ||
| extend = "build" | ||
| env = { TARGET = "x86_64-unknown-linux-gnu" } | ||
|
|
||
| [tasks.build-android-aarch64] | ||
| extend = "build" | ||
| env = { TARGET = "aarch64-linux-android" } | ||
|
|
||
| [tasks.build-android-armv7] | ||
| extend = "build" | ||
| env = { TARGET = "armv7-linux-androideabi" } | ||
|
|
||
| [tasks.build-android-x64] | ||
| extend = "build" | ||
| env = { TARGET = "x86_64-linux-android" } | ||
|
|
||
| # MARK: - Build, platform groups | ||
|
|
||
| [tasks.build-windows-platforms] | ||
| description = "Build for Windows" | ||
| dependencies = [ | ||
| "build-windows-x64", | ||
| "build-windows-aarch64" | ||
| ] | ||
|
|
||
| [tasks.build-linux-platforms] | ||
| description = "Build for generic Linux and Android" | ||
| dependencies = [ | ||
| "build-linux-aarch64", | ||
| "build-linux-x64", | ||
| "build-android-aarch64", | ||
| "build-android-armv7", | ||
| "build-android-x64" | ||
| ] | ||
|
|
||
| # MARK: - Bindgen common | ||
|
|
||
| [tasks.locate-lib.env.LIB_EXT] | ||
| source = "${CARGO_MAKE_RUST_TARGET_OS}" | ||
| mapping = { linux = "so", macos = "dylib", windows = "dll" } | ||
|
|
||
| [tasks.locate-lib] | ||
| private = true | ||
| script_runner = "@duckscript" | ||
| script = """ | ||
| path = join_path ${TARGET_DIR} ${TARGET} release/ ${LIB_NAME}.${LIB_EXT} | ||
| set_env LIB_PATH "${path}" | ||
| """ | ||
|
|
||
| [tasks.uniffi-bindgen] | ||
| private = true | ||
| description = "Generate bindings for core UniFFI languages" | ||
| dependencies = ["build", "locate-lib"] | ||
| script_runner = "@duckscript" | ||
| script = """ | ||
| out_dir = join_path ${PACKAGES_DIR} ${LANG} | ||
| exec cargo run --bin uniffi-bindgen generate \ | ||
| --language ${LANG} \ | ||
| --out-dir ${out_dir} \ | ||
| --library ${LIB_PATH} | ||
| """ | ||
|
|
||
| [tasks.bindgen] | ||
| dependencies = [ | ||
| "bindgen-kotlin", | ||
| "bindgen-python" | ||
| ] | ||
|
|
||
| # MARK: - Kotlin | ||
|
|
||
| [tasks.bindgen-kotlin] | ||
| private = false | ||
| extend = "uniffi-bindgen" | ||
| env = { LANG = "kotlin" } | ||
|
|
||
| # MARK: - Python | ||
|
|
||
| [tasks.bindgen-python] | ||
| private = false | ||
| extend = "uniffi-bindgen" | ||
| env = { LANG = "python" } | ||
|
|
||
| # MARK: - Swift | ||
|
|
||
| [tasks.swift-xcframework.env] | ||
| SWIFT_RELEASE_FLAG = { value = "--release", condition = { profiles = ["release"] } } | ||
|
|
||
| [tasks.swift-xcframework] | ||
| private = true | ||
| install_crate = { crate_name = "cargo-swift", version = "0.10.0", binary = "cargo-swift", test_arg = "--help" } | ||
| install_crate_args = ["--force"] | ||
| script_runner = "@shell" | ||
| script = """ | ||
| cargo swift package \ | ||
| --accept-all \ | ||
| --name ${SPM_NAME} \ | ||
| --xcframework-name Rust${SPM_NAME} \ | ||
| --platforms macos \ | ||
| --platforms ios \ | ||
| --platforms maccatalyst \ | ||
| --platforms visionos \ | ||
| --platforms tvos \ | ||
| --lib-type dynamic \ | ||
| ${SWIFT_RELEASE_FLAG} | ||
| """ | ||
|
|
||
| [tasks.swift-generate-manifest.env] | ||
| SPM_URL = { value = "https://dummy.com" } | ||
| SPM_CHECKSUM = { value = "1234" } | ||
|
|
||
| [tasks.swift-generate-manifest] | ||
| private = true | ||
| install_crate = { crate_name = "tera-cli", binary = "tera", test_arg = "--version" } | ||
| script_runner = "@shell" | ||
| script = """ | ||
| tera --env --file ${SUPPORT_DIR}/${LANG}/Package.swift.tera > ${SPM_NAME}/Package.swift | ||
| tera --env --file ${SUPPORT_DIR}/${LANG}/[email protected] > ${SPM_NAME}/[email protected] | ||
| """ | ||
|
|
||
| [tasks.swift-move-to-packages] | ||
| private = true | ||
| script_runner = "@shell" | ||
| script = """ | ||
| out_dir="${PACKAGES_DIR}/${LANG}" | ||
| rm -rf "${out_dir}" | ||
| mkdir -p "${out_dir}" | ||
| mv "${SPM_NAME}" "${out_dir}" | ||
| """ | ||
|
|
||
| [tasks.swift-package-flow] | ||
| private = true | ||
| dependencies = [ | ||
| "swift-xcframework", | ||
| "swift-generate-manifest", | ||
| "swift-move-to-packages" | ||
| ] | ||
|
|
||
| [tasks.swift-package] | ||
| description = "Generate Swift package using cargo-swift" | ||
| env = { LANG = "swift" } | ||
| run_task = "swift-package-flow" | ||
|
|
||
| # Add other bindgen tasks here, following the same pattern | ||
| # as above for the task name (e.g., "bindgen-<lang>"). | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # LiveKit UniFFI | ||
|
|
||
| Experimental FFI interface using [UniFFI](https://mozilla.github.io/uniffi-rs/latest/). | ||
|
|
||
| At this stage in development, this interface will not attempt to replace the existing FFI interface defined in [_livekit-ffi_](../livekit-ffi/). Instead, it will focus on exposing core business logic that can be cleanly modularized and adopted by client SDKs incrementally. | ||
|
|
||
| ## Functionality exposed | ||
|
|
||
| - [x] Access token generation and verification | ||
|
|
||
| ## Tasks | ||
|
|
||
| Binding generation and multi-platform builds are handled by [_cargo-make_](https://github.com/sagiegurari/cargo-make)—please install on your system before proceeding. For a full list of available tasks, see [_Makefile.toml_](./Makefile.toml) or run `cargo make --list-all-steps`. The most important tasks are summarized below: | ||
|
|
||
| ### Swift | ||
|
|
||
| Generate Swift bindings and build a multi-platform XCFramework: | ||
| ``` | ||
| cargo make xcframework | ||
| ``` | ||
|
|
||
| TODO: other languages |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And one more thing @ladvoc static release is still ~40MB whereas dylib ~1.8MB.
Dynamic one won't pass AppStore validation (we'd need to wrap it in a Framework).
I'd rather go for stripping the static one further, any ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iOS in
--releaseprofile:Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, looks like
DEAD_CODE_STRIPPINGdoes the job and the bundle size increase is negligible (0.1 MB), moved back tostatic729bc10It also passes 🍏 validation 👍
I'm still open to optimization ideas 😄