-
Notifications
You must be signed in to change notification settings - Fork 237
Initial UniFFI C++ Bindgen #1389
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
alan-george-lk
wants to merge
7
commits into
main
Choose a base branch
from
alan/feature-uniffi-cpp
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.
+91
−1
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
89ad039
Cpp bingden done right (hopefully)
alan-george-lk e7bc2c4
Merge branch 'main' of github.com:livekit/client-sdk-rust into alan/f…
alan-george-lk ae7899d
Merge branch 'main' of github.com:livekit/client-sdk-rust into alan/f…
alan-george-lk 02eb8c3
Undo AI comment
alan-george-lk bbee2d4
Tokio
alan-george-lk 235ba5a
Merge branch 'main' of github.com:livekit/client-sdk-rust into alan/f…
alan-george-lk 8fc8585
Move to official fork location
alan-george-lk 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
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,5 @@ | ||
| --- | ||
| livekit-ffi: patch | ||
| --- | ||
|
|
||
| Add a workspace-owned command for generating C++ bindings from `livekit-ffi` with the pinned LiveKit UniFFI C++ generator. |
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 |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| // Copyright 2026 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. | ||
|
|
||
| //! The pinned UniFFI C++ bindgen CLI used by LiveKit SDK consumers. | ||
| //! | ||
| //! The C++ generator is a binary-only crate, so this workspace command installs | ||
| //! the pinned revision into the workspace target directory and forwards all | ||
| //! arguments to it. Generate C++ bindings from `livekit-ffi`, for example: | ||
| //! `cargo run -p bindgens --bin uniffi-bindgen-cpp -- \ | ||
| //! --library target/debug/liblivekit_ffi.dylib --out-dir <dir>` | ||
|
|
||
| use std::{ | ||
| env, | ||
| path::{Path, PathBuf}, | ||
| process::{Command, ExitCode}, | ||
| }; | ||
|
|
||
| const REPOSITORY: &str = "https://github.com/livekit/uniffi-bindgen-cpp.git"; | ||
| const REVISION: &str = "7d54c1c56e0e4c46772ef4c2b5be3cb26396cbdb"; | ||
|
|
||
| fn main() -> ExitCode { | ||
| match run() { | ||
| Ok(code) => code, | ||
| Err(error) => { | ||
| eprintln!("uniffi-bindgen-cpp: {error}"); | ||
| ExitCode::FAILURE | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fn run() -> Result<ExitCode, String> { | ||
| let install_root = install_root(); | ||
| let executable = | ||
| install_root.join("bin").join(format!("uniffi-bindgen-cpp{}", env::consts::EXE_SUFFIX)); | ||
|
|
||
| if !executable.is_file() { | ||
| install(&install_root)?; | ||
| } | ||
|
|
||
| let status = Command::new(&executable) | ||
| .args(env::args_os().skip(1)) | ||
| .status() | ||
| .map_err(|error| format!("failed to run {}: {error}", executable.display()))?; | ||
|
|
||
| match status.code() { | ||
| Some(code) if (0..=u8::MAX as i32).contains(&code) => Ok(ExitCode::from(code as u8)), | ||
| Some(code) => Err(format!("generator exited with unsupported status {code}")), | ||
| None => Err("generator terminated without an exit status".to_owned()), | ||
| } | ||
| } | ||
|
|
||
| fn install_root() -> PathBuf { | ||
| Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| .join("../..") | ||
| .join("target") | ||
| .join("uniffi-bindgen-cpp") | ||
| .join(REVISION) | ||
| } | ||
|
|
||
| fn install(install_root: &Path) -> Result<(), String> { | ||
| let cargo = env::var_os("CARGO").unwrap_or_else(|| "cargo".into()); | ||
| let status = Command::new(cargo) | ||
| .args(["install", "--locked", "--git", REPOSITORY, "--rev", REVISION, "--root"]) | ||
| .arg(install_root) | ||
| .arg("uniffi-bindgen-cpp") | ||
| .status() | ||
| .map_err(|error| format!("failed to install pinned C++ generator: {error}"))?; | ||
|
|
||
| if status.success() { | ||
| Ok(()) | ||
| } else { | ||
| Err(format!("installing pinned C++ generator failed with {status}")) | ||
| } | ||
| } | ||
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.
🟡 Custom target directories break installation
With a custom Cargo target directory,
install_rootstill writes inside the source checkout. Read-only checkouts fail before the generator runs.Learn more
Cargo can place build output outside the workspace through
CARGO_TARGET_DIRor Cargo configuration. The wrapper instead derives its installation directory exclusively fromCARGO_MANIFEST_DIR, so generator installation always writes to the checkout'stargetdirectory. A checkout can be readable while the configured Cargo target directory is writable, which allowscargo runto build the wrapper but prevents the wrapper from installing its generator.Example: A Nix build mounts the repository read-only and sets
CARGO_TARGET_DIR=/tmp/build-target. Cargo builds the wrapper under/tmp/build-target, butinstall()tries to create<checkout>/target/uniffi-bindgen-cpp/...and exits with failure.Recommended fix: Resolve Cargo's effective target directory, including
CARGO_TARGET_DIRand.cargo/config.toml, then appenduniffi-bindgen-cpp/<revision>. Usingcargo metadata --format-version 1 --no-depsand itstarget_directoryfield preserves Cargo configuration semantics.Was this helpful? React with 👍 or 👎 to provide feedback.