-
Notifications
You must be signed in to change notification settings - Fork 40
UniFFI C++ Bindgen Initial Integration #249
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
base: main
Are you sure you want to change the base?
Changes from all commits
46a4fab
f916cf2
96d64da
d088131
65cb23b
c7250a7
fdad12a
2ce640a
8ba7486
ed1adf6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
alan-george-lk marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| # 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. | ||
|
|
||
| set(LIVEKIT_UNIFFI_CPP_GENERATED_DIR "${LIVEKIT_BINARY_DIR}/generated/uniffi") | ||
| set(LIVEKIT_UNIFFI_CPP_SOURCE | ||
| "${LIVEKIT_UNIFFI_CPP_GENERATED_DIR}/livekit_ffi.cpp") | ||
| set(LIVEKIT_UNIFFI_CPP_HEADER | ||
| "${LIVEKIT_UNIFFI_CPP_GENERATED_DIR}/livekit_ffi.hpp") | ||
| set(LIVEKIT_UNIFFI_CPP_SCAFFOLDING_HEADER | ||
| "${LIVEKIT_UNIFFI_CPP_GENERATED_DIR}/livekit_ffi_scaffolding.hpp") | ||
|
|
||
| # Release Linux builds strip the UniFFI metadata symbols, so generate from a | ||
| # separate unstripped Debug library there. PE and Mach-O retain the metadata, | ||
| # allowing Windows and macOS to reuse the livekit-ffi library already built for | ||
| # the selected CMake configuration. | ||
| if(UNIX AND NOT APPLE) | ||
| set(LIVEKIT_UNIFFI_METADATA_TARGET_DIR | ||
| "${RUST_ROOT}/target/uniffi-cpp-metadata") | ||
| set(LIVEKIT_UNIFFI_METADATA_LIBRARY | ||
| "${LIVEKIT_UNIFFI_METADATA_TARGET_DIR}/debug/liblivekit_ffi.so") | ||
| endif() | ||
|
|
||
| file(GLOB_RECURSE LIVEKIT_UNIFFI_RUST_SOURCES CONFIGURE_DEPENDS | ||
| "${RUST_ROOT}/livekit-ffi/src/*.rs" | ||
| "${RUST_ROOT}/livekit-ffi/Cargo.toml" | ||
| ) | ||
| list(APPEND LIVEKIT_UNIFFI_RUST_SOURCES | ||
| "${RUST_ROOT}/Cargo.toml" | ||
| "${RUST_ROOT}/Cargo.lock" | ||
| "${RUST_ROOT}/rust-toolchain.toml" | ||
| ) | ||
|
|
||
| file(GLOB_RECURSE LIVEKIT_UNIFFI_BINDGEN_SOURCES CONFIGURE_DEPENDS | ||
| "${RUST_ROOT}/tools/bindgens/src/*.rs" | ||
| "${RUST_ROOT}/tools/bindgens/Cargo.toml" | ||
| ) | ||
|
|
||
| if(UNIX AND NOT APPLE) | ||
| add_custom_command( | ||
| OUTPUT "${LIVEKIT_UNIFFI_METADATA_LIBRARY}" | ||
| COMMAND "${CMAKE_COMMAND}" | ||
| -DCFG=Debug | ||
| -DRUST_ROOT=${RUST_ROOT} | ||
| -DCARGO=${CARGO_EXECUTABLE} | ||
| -DPROTOC_PATH=${Protobuf_PROTOC_EXECUTABLE} | ||
| -DGCC_LIB_DIR=${GCC_LIB_DIR} | ||
| -DCARGO_TARGET_DIR=${LIVEKIT_UNIFFI_METADATA_TARGET_DIR} | ||
| -P "${RUN_CARGO_SCRIPT}" | ||
| WORKING_DIRECTORY "${RUST_ROOT}" | ||
| DEPENDS ${LIVEKIT_UNIFFI_RUST_SOURCES} | ||
| COMMENT "Building unstripped livekit-ffi metadata library" | ||
| VERBATIM | ||
| ) | ||
| add_custom_target(build_livekit_ffi_metadata | ||
| DEPENDS "${LIVEKIT_UNIFFI_METADATA_LIBRARY}") | ||
| else() | ||
| set(LIVEKIT_UNIFFI_METADATA_LIBRARY "$<TARGET_FILE:livekit_ffi>") | ||
| add_custom_target(build_livekit_ffi_metadata) | ||
| endif() | ||
|
|
||
| # Keep Cargo invocations serialized on fresh runners, and ensure the selected | ||
| # livekit-ffi library exists before it is inspected on Windows and macOS. | ||
| add_dependencies(build_livekit_ffi_metadata build_rust_ffi) | ||
|
|
||
| add_custom_command( | ||
| OUTPUT | ||
| "${LIVEKIT_UNIFFI_CPP_SOURCE}" | ||
| "${LIVEKIT_UNIFFI_CPP_HEADER}" | ||
| "${LIVEKIT_UNIFFI_CPP_SCAFFOLDING_HEADER}" | ||
| COMMAND "${CMAKE_COMMAND}" -E make_directory | ||
| "${LIVEKIT_UNIFFI_CPP_GENERATED_DIR}" | ||
| COMMAND "${CMAKE_COMMAND}" -E env | ||
| "CARGO_TARGET_DIR=${RUST_ROOT}/target/bindgens" | ||
| "CARGO_ENCODED_RUSTFLAGS=" | ||
| "RUSTFLAGS=" | ||
|
devin-ai-integration[bot] marked this conversation as resolved.
|
||
| "${CARGO_EXECUTABLE}" run --locked | ||
| --package bindgens | ||
| --bin uniffi-bindgen-cpp | ||
| -- | ||
| --library "${LIVEKIT_UNIFFI_METADATA_LIBRARY}" | ||
| --out-dir "${LIVEKIT_UNIFFI_CPP_GENERATED_DIR}" | ||
| WORKING_DIRECTORY "${RUST_ROOT}" | ||
| DEPENDS | ||
| build_livekit_ffi_metadata | ||
| ${LIVEKIT_UNIFFI_RUST_SOURCES} | ||
| ${LIVEKIT_UNIFFI_BINDGEN_SOURCES} | ||
| COMMENT "Generating UniFFI C++ bindings" | ||
| VERBATIM | ||
| ) | ||
| add_custom_target(generate_livekit_ffi_uniffi_cpp | ||
| DEPENDS | ||
| "${LIVEKIT_UNIFFI_CPP_SOURCE}" | ||
| "${LIVEKIT_UNIFFI_CPP_HEADER}" | ||
| "${LIVEKIT_UNIFFI_CPP_SCAFFOLDING_HEADER}" | ||
| ) | ||
|
|
||
| set_source_files_properties( | ||
| "${LIVEKIT_UNIFFI_CPP_SOURCE}" | ||
| "${LIVEKIT_UNIFFI_CPP_HEADER}" | ||
| "${LIVEKIT_UNIFFI_CPP_SCAFFOLDING_HEADER}" | ||
| PROPERTIES GENERATED TRUE | ||
| ) | ||
|
|
||
| add_library(livekit_uniffi_cpp OBJECT | ||
| "${LIVEKIT_UNIFFI_CPP_SOURCE}" | ||
| ) | ||
|
devin-ai-integration[bot] marked this conversation as resolved.
|
||
| set_target_properties(livekit_uniffi_cpp PROPERTIES | ||
| CXX_VISIBILITY_PRESET hidden | ||
| C_VISIBILITY_PRESET hidden | ||
| VISIBILITY_INLINES_HIDDEN ON | ||
| ) | ||
| add_dependencies(livekit_uniffi_cpp generate_livekit_ffi_uniffi_cpp) | ||
| target_include_directories(livekit_uniffi_cpp | ||
| PUBLIC "${LIVEKIT_UNIFFI_CPP_GENERATED_DIR}" | ||
| ) | ||
| target_link_libraries(livekit_uniffi_cpp PRIVATE livekit_ffi) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| #include "uniffi_bindgen_adapter.h" | ||
|
|
||
| namespace livekit { | ||
| namespace { | ||
|
|
||
| TEST(UniFfiTest, BuildVersion) { | ||
| const auto version = uniffiBindgenBuildVersion(); | ||
|
|
||
| ASSERT_TRUE(version.has_value()) << "Generated UniFFI binding did not return a build version"; | ||
|
|
||
| EXPECT_FALSE(version.value().empty()); | ||
| EXPECT_NE(version.value(), "unknown"); | ||
| } | ||
|
|
||
| } // namespace | ||
| } // namespace livekit |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| #include "uniffi_bindgen_adapter.h" | ||
|
|
||
| #include "livekit_ffi.hpp" | ||
|
|
||
| namespace livekit { | ||
|
|
||
| std::optional<std::string> uniffiBindgenBuildVersion() { | ||
| auto version = livekit_ffi::build_version(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i.e. is this the "Secret Sauce"
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is currently the only-available This is the secret sauce in the sense that I tested all of this infra against https://github.com/livekit/rust-sdks/blob/main/livekit-uniffi/src/access_token.rs#L185-L189 and https://github.com/livekit/rust-sdks/blob/main/livekit-uniffi/src/log_forward.rs#L27-L32 (removed from this branch for PR but part of history)
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sweet thanks!
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't we expoe the ffi version via the public livekit header instead ? livekit_ffi.hpp seems internal to me. |
||
| if (version.empty() || version == "unknown") { | ||
| return std::nullopt; | ||
| } | ||
| return version; | ||
| } | ||
|
|
||
| } // namespace livekit | ||
Uh oh!
There was an error while loading. Please reload this page.