From 0d7de07c507365e09e2c0700bf64e0435c54b54e Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 16 Oct 2026 08:26:18 -0700 Subject: [PATCH 1/3] quest: claim m1/cpp-generated-shape Co-Authored-By: Claude Opus 5.5 From 02ae636834bc0cfa7dc14398098f33631e775745 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 16 Oct 2026 09:00:16 -0700 Subject: [PATCH 2/3] feat(cpp)!: generate unprefixed names and one moq::expected uniffi.toml sets the generator fork's new `strip_type_prefix = "Moq"`, so moq-ffi's `MoqClient` is generated as `moq::Client` and moq.hpp drops its alias list and the `just cpp check` audit of it. The fork also makes `uniffi::expected` the bundled `tl::expected` at every C++ standard, so the MOQ_ABI link guard and the "C++ standard" docs go away, and `value()` on an error aborts with a message instead of being undefined. The check now builds the probe at C++23 over bindings at C++17 to prove they link. The generator pin is the head of kixelated/uniffi-bindgen-cpp#4 until that PR is released as v0.11.0-kixelated.5+v0.32.2. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/cpp.yml | 2 +- .github/workflows/platform.yml | 4 +- .github/workflows/release-cpp.yml | 2 +- cpp/moq/CMakeLists.txt | 3 +- cpp/moq/README.md | 14 +-- cpp/moq/cmake/moq-cpp-config.cmake.in | 4 +- cpp/moq/cmake/moq-cpp.pc.in | 2 +- cpp/moq/include/moq/moq.hpp | 136 +------------------------- cpp/moq/src/moq.cpp | 4 +- cpp/moq/test/CMakeLists.txt | 9 +- cpp/moq/uniffi.toml | 2 + doc/lib/cpp/index.md | 33 ++----- flake.nix | 18 ++-- quest/m1/README.md | 1 - quest/m1/cpp-generated-shape.md | 36 ------- quest/m1/cpp-package-check.md | 1 - quest/m1/ffi-shape/README.md | 9 +- quest/m1/ffi-shape/layers-guide.md | 5 +- quest/m1/uniffi-fork.md | 3 +- quest/m2/release/cpp-release.md | 1 - rs/moq-ffi/build.sh | 2 +- sh/cpp/check.sh | 24 ++--- 22 files changed, 58 insertions(+), 257 deletions(-) delete mode 100644 quest/m1/cpp-generated-shape.md diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.yml index ce2fdc0cead..760c5f70015 100644 --- a/.github/workflows/cpp.yml +++ b/.github/workflows/cpp.yml @@ -50,7 +50,7 @@ jobs: - uses: ./.github/actions/just - name: Install uniffi-bindgen-cpp - run: cargo install uniffi-bindgen-cpp --locked --git https://github.com/kixelated/uniffi-bindgen-cpp --tag v0.11.0-kixelated.4+v0.32.2 + run: cargo install uniffi-bindgen-cpp --locked --git https://github.com/kixelated/uniffi-bindgen-cpp --rev 40c99525a125acd3ac0f2eb792c452640dbae388 - name: Check run: just cpp check diff --git a/.github/workflows/platform.yml b/.github/workflows/platform.yml index 509bb7894aa..3343b7d72a6 100644 --- a/.github/workflows/platform.yml +++ b/.github/workflows/platform.yml @@ -98,7 +98,7 @@ jobs: - name: Install uniffi-bindgen-cpp if: needs.scope.outputs.cpp == 'true' || needs.scope.outputs.obs == 'true' shell: bash - run: cargo install uniffi-bindgen-cpp --locked --git https://github.com/kixelated/uniffi-bindgen-cpp --tag v0.11.0-kixelated.4+v0.32.2 + run: cargo install uniffi-bindgen-cpp --locked --git https://github.com/kixelated/uniffi-bindgen-cpp --rev 40c99525a125acd3ac0f2eb792c452640dbae388 - name: Rust compile and tests if: needs.scope.outputs.rs == 'true' shell: bash @@ -137,7 +137,7 @@ jobs: tool: nextest@0.9.146 - name: Install uniffi-bindgen-cpp if: needs.scope.outputs.obs == 'true' - run: cargo install uniffi-bindgen-cpp --locked --git https://github.com/kixelated/uniffi-bindgen-cpp --tag v0.11.0-kixelated.4+v0.32.2 + run: cargo install uniffi-bindgen-cpp --locked --git https://github.com/kixelated/uniffi-bindgen-cpp --rev 40c99525a125acd3ac0f2eb792c452640dbae388 - name: Rust compile and tests if: needs.scope.outputs.rs == 'true' env: diff --git a/.github/workflows/release-cpp.yml b/.github/workflows/release-cpp.yml index f75d88d5428..7f8a11b6737 100644 --- a/.github/workflows/release-cpp.yml +++ b/.github/workflows/release-cpp.yml @@ -54,7 +54,7 @@ jobs: # The tag flake.nix pins; see the comment there. - name: Install uniffi-bindgen-cpp shell: bash - run: cargo install uniffi-bindgen-cpp --locked --git https://github.com/kixelated/uniffi-bindgen-cpp --tag v0.11.0-kixelated.4+v0.32.2 + run: cargo install uniffi-bindgen-cpp --locked --git https://github.com/kixelated/uniffi-bindgen-cpp --rev 40c99525a125acd3ac0f2eb792c452640dbae388 # The package version lives in cpp/moq/VERSION; a tag that disagrees is a mistake. - name: Check version diff --git a/cpp/moq/CMakeLists.txt b/cpp/moq/CMakeLists.txt index fe85ed35ec1..35bcf77a42d 100644 --- a/cpp/moq/CMakeLists.txt +++ b/cpp/moq/CMakeLists.txt @@ -83,8 +83,7 @@ foreach(_line IN LISTS _lines) endforeach() # The bindings compile here at the including project's CMAKE_CXX_STANDARD (else the compiler's -# default, at least C++17) and with its flags; see src/moq.cpp. A standard raised only on a -# consumer's own target does not reach this library. +# default, at least C++17) and with its flags. # Named moq-cpp so an in-tree build can sit beside moq-c's `moq` target. add_library(moq-cpp STATIC src/moq.cpp) add_library(moq::cpp ALIAS moq-cpp) diff --git a/cpp/moq/README.md b/cpp/moq/README.md index ca184c07690..ca559d99ea7 100644 --- a/cpp/moq/README.md +++ b/cpp/moq/README.md @@ -1,6 +1,6 @@ # moq C++ package -C++17 bindings for [rs/moq-ffi](../../rs/moq-ffi): the sources `uniffi-bindgen-cpp` generates, plus `include/moq/moq.hpp`, a thin layer that renames them (`moq::MoqClient` is also `moq::Client`) and adds the executor, shutdown, and `co_await` glue. Nothing here re-implements a method; a shape problem is fixed in moq-ffi, where every binding benefits. User docs: [doc/lib/cpp](../../doc/lib/cpp/index.md). +C++17 bindings for [rs/moq-ffi](../../rs/moq-ffi): the sources `uniffi-bindgen-cpp` generates, plus `include/moq/moq.hpp`, a thin layer that adds the executor, shutdown, and `co_await` glue. `uniffi.toml` strips moq-ffi's `Moq` type prefix, so `MoqClient` is generated as `moq::Client`. Nothing here re-implements a method; a shape problem is fixed in moq-ffi, where every binding benefits. User docs: [doc/lib/cpp](../../doc/lib/cpp/index.md). ## Layout @@ -12,14 +12,14 @@ C++17 bindings for [rs/moq-ffi](../../rs/moq-ffi): the sources `uniffi-bindgen-c ## Checking -`just cpp check` builds and installs the package, builds the probe against it with `find_package` at C++17 and C++23 and, outside Windows, with pkg-config at C++17, runs each, compiles the doc samples (also outside Windows), and fails if a generated type lacks its short alias. The probe builds with exceptions and RTTI disabled. +`just cpp check` builds and installs the package, builds the probe against it with `find_package` at C++17 and C++23 and, outside Windows, with pkg-config at C++17, runs each, and compiles the doc samples (also outside Windows). It also builds the probe at C++23 over bindings at C++17, to prove the two link. The probe builds with exceptions and RTTI disabled. -The generator is a fork, [kixelated/uniffi-bindgen-cpp](https://github.com/kixelated/uniffi-bindgen-cpp). It carries LiveKit's async support ported to uniffi 0.32, plus the `error_style = "expected"` option `uniffi.toml` turns on. The dev shell provides it. Without Nix: +The generator is a fork, [kixelated/uniffi-bindgen-cpp](https://github.com/kixelated/uniffi-bindgen-cpp). It carries LiveKit's async support ported to uniffi 0.32, plus the `error_style = "expected"` and `strip_type_prefix` options `uniffi.toml` turns on. The dev shell provides it. Without Nix: ```bash cargo install uniffi-bindgen-cpp --locked \ --git https://github.com/kixelated/uniffi-bindgen-cpp \ - --tag v0.11.0-kixelated.4+v0.32.2 + --rev 40c99525a125acd3ac0f2eb792c452640dbae388 ``` `flake.nix` pins the same tag and lists every other place that names it. @@ -28,15 +28,11 @@ cargo install uniffi-bindgen-cpp --locked \ Every generated type lives in `namespace moq`. Objects are `std::shared_ptr`; records and enums are values. -- A fallible call returns `moq::expected`, which is `std::expected` on C++23 and a bundled `tl::expected` below it. The generated sources and every includer must agree on which, so `moq/moq.hpp` references a symbol named for the one it sees and `src/moq.cpp` defines the one it was built with: a mismatch fails to link. +- A fallible call returns `moq::expected`, the bundled `tl::expected` at every standard, so bindings built at C++17 link with code built at C++23. With exceptions off, `value()` on an error aborts with a message. - An async call returns `moq::Future`. Block on it with `get()` or `wait_for()`, attach a continuation with `std::move(future).then(executor, callback)`, which returns a `moq::Continuation`, or `co_await` it on C++20. - `moq::Error` is a value holding a `std::variant` of its cases, and `to_string()` gives Rust's `Display` message. Nothing throws. A Rust panic inside a call aborts with a message on stderr, and so does reading an invalid future (see [Cancellation](#cancellation)). A panic in owned background work reaches the next call on that object as a task error; other objects keep running. - Futures are polled on one process-wide executor thread unless the application installs its own with `moq::set_executor` before the first async call. The executor passed to `then()` dispatches only the continuation. `moq::shutdown()` stops the moq-ffi runtime workers (`moq_ffi_shutdown`), then the executor, before unloading the code a continuation could call into. -## C++ standard - -The installed package compiles `moq.cpp` inside the consumer's project, at its `CMAKE_CXX_STANDARD` (else the compiler's default, at least C++17). To use C++23, set `CMAKE_CXX_STANDARD 23` before `find_package(moq-cpp)`, or pass `-DCMAKE_CXX_STANDARD=23`. `target_compile_features(app PRIVATE cxx_std_23)` alone does not reach the separate `moq-cpp` library, so `` and the bindings pick different `expected` types and the link fails on `moq_abi_std_expected` or `moq_abi_tl_expected`. `just cpp check` builds the probe at C++23 both ways. - ## Cancellation Cancelling a future (`cancel()`, destroying it, destroying the `moq::Continuation` returned by `then`, or destroying a coroutine suspended on it) drops the Rust future. Most async calls run in place, on the thread that polls the future, so cancelling stops the work at once: it never finishes unobserved or takes data the next call is waiting for. The few calls spawned onto the moq-ffi runtime are aborted at their next await point. The continuation of a cancelled future never runs. diff --git a/cpp/moq/cmake/moq-cpp-config.cmake.in b/cpp/moq/cmake/moq-cpp-config.cmake.in index e49d90440af..7d0bde7eb06 100644 --- a/cpp/moq/cmake/moq-cpp-config.cmake.in +++ b/cpp/moq/cmake/moq-cpp-config.cmake.in @@ -15,9 +15,7 @@ if(NOT TARGET moq::cpp) ) # The generated bindings compile here, in the consumer's project, at its CMAKE_CXX_STANDARD - # (else the compiler's default, at least C++17) and with its flags. A standard raised only - # on the consumer's own target does not reach this library, so and the - # bindings disagree on uniffi::expected and the link fails: set CMAKE_CXX_STANDARD instead. + # (else the compiler's default, at least C++17) and with its flags. add_library(moq-cpp STATIC "@PACKAGE_CMAKE_INSTALL_DATADIR@/moq-cpp/moq.cpp") target_compile_features(moq-cpp PUBLIC cxx_std_17) target_include_directories(moq-cpp PUBLIC "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@") diff --git a/cpp/moq/cmake/moq-cpp.pc.in b/cpp/moq/cmake/moq-cpp.pc.in index 4c59f60249f..48b3d59c4e0 100644 --- a/cpp/moq/cmake/moq-cpp.pc.in +++ b/cpp/moq/cmake/moq-cpp.pc.in @@ -1,5 +1,5 @@ # The generated bindings ship as source: compile `pkg-config --variable=sources moq-cpp` with the -# same standard and flags as the code that includes . +# same flags as the code that includes . prefix=${pcfiledir}/../.. libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@ includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ diff --git a/cpp/moq/include/moq/moq.hpp b/cpp/moq/include/moq/moq.hpp index 67a403ee551..61edac384b0 100644 --- a/cpp/moq/include/moq/moq.hpp +++ b/cpp/moq/include/moq/moq.hpp @@ -1,6 +1,5 @@ -// The moq C++ package: the generated moq-ffi bindings under short names, plus the -// executor, shutdown, and coroutine glue they need. Every type and method is generated; -// this header only renames and wires them. +// The moq C++ package: the generated moq-ffi bindings, plus the executor, shutdown, and +// coroutine glue they need. Every type and method is generated; this header only wires them. #pragma once #include @@ -22,138 +21,9 @@ // Not a uniffi export, so the generated bindings do not declare it; see moq::shutdown. extern "C" void moq_ffi_shutdown(void); -// uniffi::expected is std::expected or tl::expected depending on the standard, and the -// generated sources (src/moq.cpp) and every includer must agree. The bindings define the -// symbol for the type they saw and every includer references the one it sees, so a mismatch -// fails to link instead of corrupting memory. -#if defined(__cpp_lib_expected) && __cpp_lib_expected >= 202211L -#define MOQ_ABI moq_abi_std_expected -#define MOQ_ABI_NAME "moq_abi_std_expected" -#else -#define MOQ_ABI moq_abi_tl_expected -#define MOQ_ABI_NAME "moq_abi_tl_expected" -#endif -extern "C" const int MOQ_ABI; -#if defined(MOQ_IMPLEMENTATION) -extern "C" const int MOQ_ABI = 1; -#elif defined(_MSC_VER) -#pragma comment(linker, "/include:" MOQ_ABI_NAME) -#else -namespace moq::detail { -[[maybe_unused]] __attribute__((used)) static const int *const abi = &MOQ_ABI; -} // namespace moq::detail -#endif - namespace moq { -// Every generated `moq::MoqFoo` is also `moq::Foo`. `just cpp check` fails when one is missing. -using AnnounceConsumer = MoqAnnounceConsumer; -using AnnouncedBroadcast = MoqAnnouncedBroadcast; -using AudioCodec = MoqAudioCodec; -using AudioConsumer = MoqAudioConsumer; -using AudioProducer = MoqAudioProducer; -using Bandwidth = MoqBandwidth; -using BroadcastConsumer = MoqBroadcastConsumer; -using BroadcastDynamic = MoqBroadcastDynamic; -using BroadcastProducer = MoqBroadcastProducer; -using BroadcastRequest = MoqBroadcastRequest; -using Client = MoqClient; -using FlateSnapshotProducer = MoqFlateSnapshotProducer; -using FlateStreamProducer = MoqFlateStreamProducer; -using GroupConsumer = MoqGroupConsumer; -using GroupDemand = MoqGroupDemand; -using GroupProducer = MoqGroupProducer; -using GroupRequest = MoqGroupRequest; -using JsonSnapshotConsumer = MoqJsonSnapshotConsumer; -using JsonSnapshotProducer = MoqJsonSnapshotProducer; -using JsonStreamConsumer = MoqJsonStreamConsumer; -using JsonStreamProducer = MoqJsonStreamProducer; -using MediaCatalogConsumer = MoqMediaCatalogConsumer; -using MediaCatalogProducer = MoqMediaCatalogProducer; -/// Shares one source timestamp offset without keeping its broadcast open. -using MediaTimebase = MoqMediaTimebase; -using MediaTrackConsumer = MoqMediaTrackConsumer; -using MediaGroupConsumer = MoqMediaGroupConsumer; -using MediaContainerProducer = MoqMediaContainerProducer; -using MediaContainerStreamProducer = MoqMediaContainerStreamProducer; -using MediaTrackProducer = MoqMediaTrackProducer; -using MediaTrackStreamProducer = MoqMediaTrackStreamProducer; -using OriginConsumer = MoqOriginConsumer; -using OriginDynamic = MoqOriginDynamic; -using OriginProducer = MoqOriginProducer; -using Request = MoqRequest; -using Reservation = MoqReservation; -using Server = MoqServer; -using Session = MoqSession; -using TrackConsumer = MoqTrackConsumer; -using TrackDemand = MoqTrackDemand; -using TrackDynamic = MoqTrackDynamic; -using TrackProducer = MoqTrackProducer; -using TrackRequest = MoqTrackRequest; -using VideoConsumer = MoqVideoConsumer; -using VideoProducer = MoqVideoProducer; -using Announce = MoqAnnounce; -using AnnounceConfig = MoqAnnounceConfig; -using Audio = MoqAudio; -using AudioDecoderOutput = MoqAudioDecoderOutput; -using AudioEncoderInput = MoqAudioEncoderInput; -using AudioEncoderOutput = MoqAudioEncoderOutput; -using AudioFrame = MoqAudioFrame; -using AudioInit = MoqAudioInit; -using Backoff = MoqBackoff; -using Catalog = MoqCatalog; -using ClientConfig = MoqClientConfig; -using ClientTls = MoqClientTls; -using ConnectionStats = MoqConnectionStats; -using ContainerInit = MoqContainerInit; -/// A byte-stream container format and an optional shared source timebase. -using ContainerStreamInit = MoqContainerStreamInit; -using Datagram = MoqDatagram; -using Dimensions = MoqDimensions; -using FetchGroupOptions = MoqFetchGroupOptions; -using FlateConfig = MoqFlateConfig; -using Frame = MoqFrame; -using JsonSnapshotConfig = MoqJsonSnapshotConfig; -using JsonStreamConfig = MoqJsonStreamConfig; -using MediaTrackConfig = MoqMediaTrackConfig; -using MediaGroupConfig = MoqMediaGroupConfig; -using MediaFrame = MoqMediaFrame; -using OriginConfig = MoqOriginConfig; -using ProtocolError = MoqProtocolError; -using QuicConfig = MoqQuicConfig; -using Route = MoqRoute; -using ServerConfig = MoqServerConfig; -using ServerTls = MoqServerTls; -using Subscription = MoqSubscription; -using TrackInfo = MoqTrackInfo; -using Video = MoqVideo; -using VideoDecodedFrame = MoqVideoDecodedFrame; -using VideoDecoderOutput = MoqVideoDecoderOutput; -using VideoEncoderInput = MoqVideoEncoderInput; -using VideoEncoderOutput = MoqVideoEncoderOutput; -using VideoFrame = MoqVideoFrame; -using VideoHint = MoqVideoHint; -using VideoInit = MoqVideoInit; -using VideoProperties = MoqVideoProperties; -using WebSocketConfig = MoqWebSocketConfig; -using AnnounceEvent = MoqAnnounceEvent; -using AudioFormat = MoqAudioFormat; -using AudioSampleFormat = MoqAudioSampleFormat; -using ConnectionStatus = MoqConnectionStatus; -using Container = MoqContainer; -using ContainerFormat = MoqContainerFormat; -using Error = MoqError; -using ErrorScope = MoqErrorScope; -using MediaTarget = MoqMediaTarget; -using ProtocolKind = MoqProtocolKind; -using Transport = MoqTransport; -using VideoCodec = MoqVideoCodec; -using VideoEncoderKind = MoqVideoEncoderKind; -using VideoFormat = MoqVideoFormat; -using VideoPixelFormat = MoqVideoPixelFormat; -using VideoSurface = MoqVideoSurface; - -// The value of a fallible call, or the Error that stopped it. std::expected on C++23. +// The value of a fallible call, or the Error that stopped it. tl::expected at every standard. template using expected = ::uniffi::expected; diff --git a/cpp/moq/src/moq.cpp b/cpp/moq/src/moq.cpp index 7502a9f3ee4..3c00723a790 100644 --- a/cpp/moq/src/moq.cpp +++ b/cpp/moq/src/moq.cpp @@ -1,6 +1,4 @@ -// Compiles the generated bindings. Build it with the same C++ standard as the code that -// includes ; the MOQ_ABI symbol below turns a mismatch into a link error. -#define MOQ_IMPLEMENTATION +// Compiles the generated bindings. #include #include diff --git a/cpp/moq/test/CMakeLists.txt b/cpp/moq/test/CMakeLists.txt index 440d6e93b0b..8ff7542d445 100644 --- a/cpp/moq/test/CMakeLists.txt +++ b/cpp/moq/test/CMakeLists.txt @@ -1,13 +1,10 @@ # A consumer of the installed package: `just cpp check` installs cpp/moq to a prefix, then -# builds this with find_package(moq-cpp) at C++17 and C++23, the standard given as -# -DCMAKE_CXX_STANDARD or as -DPROBE_CXX_STANDARD, which sets it in the project and also -# requires it on the app's own target, the way a consumer following doc/lib/cpp would. +# builds this with find_package(moq-cpp) at the -DCMAKE_CXX_STANDARD it is given. +# -DPROBE_CXX_STANDARD raises only the probe's own target, leaving the bindings, which +# compile in this project, at CMAKE_CXX_STANDARD. cmake_minimum_required(VERSION 3.21) project(moq-probe LANGUAGES CXX) -if(PROBE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD ${PROBE_CXX_STANDARD}) -endif() if(NOT CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 17) endif() diff --git a/cpp/moq/uniffi.toml b/cpp/moq/uniffi.toml index 3dccc7caa84..1f910872903 100644 --- a/cpp/moq/uniffi.toml +++ b/cpp/moq/uniffi.toml @@ -2,3 +2,5 @@ # bindings build with exceptions disabled (Unreal's default). [bindings.cpp] error_style = "expected" +# moq-ffi prefixes its types for languages without namespaces; C++ has `moq::`. +strip_type_prefix = "Moq" diff --git a/doc/lib/cpp/index.md b/doc/lib/cpp/index.md index 2b5e1beae87..ee8510e07ab 100644 --- a/doc/lib/cpp/index.md +++ b/doc/lib/cpp/index.md @@ -10,9 +10,9 @@ description: RAII objects, futures, and moq::expected over the Rust core ``: every `moq-ffi` object as a `std::shared_ptr`, every async call as a cancellable future, and every error as a returned `moq::expected` value, so it builds with exceptions and RTTI disabled (Unreal's defaults). -C++17 is the floor; C++20 adds `co_await` on a future, and C++23 makes -`moq::expected` a `std::expected`. The bindings are generated from the same -[UniFFI](https://mozilla.github.io/uniffi-rs/) crate as the other wrappers, so +C++17 is the floor, and C++20 adds `co_await` on a future. The bindings are +generated from the same [UniFFI](https://mozilla.github.io/uniffi-rs/) crate as +the other wrappers, so a method means the same thing here as in Python or Go. For a plain C ABI, use [moq-c](/lib/c/). @@ -25,7 +25,6 @@ and `moq-cpp.pc`. Targets: Linux x86\_64 and aarch64, macOS arm64, Windows x64. No Rust toolchain is needed to consume it. ```cmake ignore -set(CMAKE_CXX_STANDARD 23) # optional; see "C++ standard" below find_package(moq-cpp REQUIRED) # with CMAKE_PREFIX_PATH at the unpacked archive target_link_libraries(app PRIVATE moq::cpp) ``` @@ -38,22 +37,9 @@ c++ -std=c++17 app.cpp $(pkg-config --variable=sources moq-cpp) $(pkg-config --c The Windows archive is built for MSVC, so use the CMake package there. The generated bindings ship as source (`share/moq-cpp/moq.cpp`) and compile inside -your build, because `uniffi::expected` is `std::expected` or a bundled -`tl::expected` depending on the standard. On MSVC, link the release runtime +your build, with your compiler and flags. On MSVC, link the release runtime (`/MD`), which the Rust library uses in every configuration. -### C++ standard - -The bindings compile at your project's `CMAKE_CXX_STANDARD`, or the compiler's -default (at least C++17) when it is unset, and must match the code that -includes ``. To use C++23, set it before `find_package`, or pass -`-DCMAKE_CXX_STANDARD=23`. Raising the standard only on your own target -(`target_compile_features(app PRIVATE cxx_std_23)`) does not reach the -bindings, so the two disagree on `moq::expected` and the link fails with an -undefined `moq_abi_std_expected` or `moq_abi_tl_expected` symbol rather than -corrupting memory. With pkg-config, pass the same `-std` to the bindings -source and to your code. - From source, `add_subdirectory(cpp/moq)` in a checkout builds `moq-ffi` with cargo and renders the bindings with the pinned `uniffi-bindgen-cpp` (see [`cpp/moq`](https://github.com/moq-dev/moq/tree/main/cpp/moq)), then exposes @@ -224,13 +210,14 @@ the simultaneous announcements or subscriptions, or ask the relay operator to adjust the [session limits](/bin/relay/config#session-and-peer), before reconnecting with the same workload. -Check a result before reading it. With exceptions off below C++23, reading the -value of an error is undefined, through `*result` and `value()` alike, since -the bundled `tl::expected` has nothing to throw. +Check a result before reading it. `moq::expected` is a bundled `tl::expected` +at every standard, with the same members as `std::expected`. With exceptions +off, `value()` on an error aborts with a message, while `*result` on an error +is undefined. Everything else maps one to one onto the -[shared feature list](/lib/#what-every-binding-can-do): each generated -`moq::MoqFoo` is also `moq::Foo`, and each Rust method keeps its name. The +[shared feature list](/lib/#what-every-binding-can-do): moq-ffi's `MoqFoo` is +`moq::Foo`, and each Rust method keeps its name. The header is the reference; every method carries its doc comment. - Source: [`cpp/moq`](https://github.com/moq-dev/moq/tree/main/cpp/moq); `just cpp check` builds, installs, and tests it locally diff --git a/flake.nix b/flake.nix index 0af367e48fe..68d700070d2 100644 --- a/flake.nix +++ b/flake.nix @@ -362,16 +362,20 @@ # # Like uniffi-bindgen-go, the tag pairs the generator's version with the # uniffi release it reads, so it moves with the `uniffi` dependency in - # rs/moq-ffi/Cargo.toml. Five other places name the same tag and must be + # rs/moq-ffi/Cargo.toml. Other places name the same tag and must be # bumped together: the `cargo install` lines in rs/moq-ffi/build.sh, # cpp/moq/README.md, .github/workflows/cpp.yml, - # .github/workflows/obs.yml, and .github/workflows/release-cpp.yml. + # .github/workflows/platform.yml, and .github/workflows/release-cpp.yml. # # This points at a fork of LiveKit's async branch (livekit/uniffi-bindgen-cpp # PR #1): neither LiveKit nor NordSecurity has a uniffi 0.32 generator, - # and the fork adds `error_style = "expected"`, which cpp/moq/uniffi.toml - # turns on. Its tags add a `-kixelated.N` pre-release so they never - # collide with upstream's. Move back upstream once one tags both. + # and the fork adds `error_style = "expected"` and `strip_type_prefix`, + # which cpp/moq/uniffi.toml turns on. Its tags add a `-kixelated.N` + # pre-release so they never collide with upstream's. Move back upstream + # once one tags both. + # + # TODO: pin v0.11.0-kixelated.5+v0.32.2 once kixelated/uniffi-bindgen-cpp#4 + # is released; until then this is that PR's head. uniffi-bindgen-cpp = pkgs.rustPlatform.buildRustPackage rec { pname = "uniffi-bindgen-cpp"; version = "0.11.0-kixelated.4+v0.32.2"; @@ -379,8 +383,8 @@ src = pkgs.fetchFromGitHub { owner = "kixelated"; repo = "uniffi-bindgen-cpp"; - rev = "v${version}"; - hash = "sha256-pmk9M5Wt6DYlXZYPjJ2Nn0tbDi1ve3wCH0Lel9xomCY="; + rev = "40c99525a125acd3ac0f2eb792c452640dbae388"; + hash = "sha256-x39ZeM4mh96FjUKXCgPBSWVojvcPiUpSLcTFr/hNvnM="; }; cargoHash = "sha256-/DRrwhJiKFCzibiJU2D3QaBM3XTmieRgUNc7tHDiGXI="; diff --git a/quest/m1/README.md b/quest/m1/README.md index c589857182b..a8504a32bc3 100644 --- a/quest/m1/README.md +++ b/quest/m1/README.md @@ -109,7 +109,6 @@ above them. - [No made-up Dropped](/quest/m1/dropped-internal.md) - internal code names the real cause instead of `Dropped`, which then only means an app dropped a producer unfinished - [Client settings parity](/quest/m1/obs-client-config.md) - moq-ffi offers moq-c's client knobs, and the OBS Advanced settings get back the ones the C++ migration dropped - [Session report parity](/quest/m1/obs-session-report.md) - a session reports its negotiated draft and reconnect failures, so the OBS dock shows them again -- [Generated C++ shape](/quest/m1/cpp-generated-shape.md) - `moq::Client` is the generated type itself and `moq::expected` is one type at every C++ standard - [Generated C bindings](/quest/m1/c/README.md) - C generated from moq-ffi ships as `moq-c` 0.8.0 and replaces the hand-written libmoq - [BoltFFI or UniFFI](/quest/m1/boltffi.md) - BoltFFI vs UniFFI on a moq-ffi slice in Python, Kotlin, and Swift decides which one the moq-dev fork starts from - [Hard-fork the binding generator](/quest/m1/uniffi-fork.md) - one moq-dev repo holds the chosen generator's core and every language backend, released under one tag and one pin diff --git a/quest/m1/cpp-generated-shape.md b/quest/m1/cpp-generated-shape.md deleted file mode 100644 index 454ac74df48..00000000000 --- a/quest/m1/cpp-generated-shape.md +++ /dev/null @@ -1,36 +0,0 @@ -# [S] One expected type and unprefixed names in the generated C++ - -## Goal - -Before the first `cpp-v*` release, `cpp/moq` gives each type one name and -`moq::expected` one type. `moq::Client` is the generated type itself, not an -alias of `moq::MoqClient`. `moq::expected` is the bundled `tl::expected` at -every C++ standard, so a consumer built at C++23 links against bindings built -at C++17. - -## Plan - -Decided while iterating on #4079: both changes are breaking once a release -ships, and both need the generator fork -([kixelated/uniffi-bindgen-cpp](https://github.com/kixelated/uniffi-bindgen-cpp)), -so they share one fork release and one pin bump. `flake.nix` lists every -place that names the pin. - -- **Names**: the fork gains a rename option that strips a type prefix, and - `cpp/moq/uniffi.toml` strips `Moq`. Delete the alias list in - `cpp/moq/include/moq/moq.hpp` and the `just cpp check` audit of it, and - drop the "each generated `moq::MoqFoo` is also `moq::Foo`" lines from - `doc/lib/cpp/index.md` and `cpp/moq/README.md`. Then update the C++ note - in [The bindings mirror Rust's layers](/quest/m1/ffi-shape/README.md), - which keeps C++ flat with `Media*` names until this lands. -- **expected**: the fork gains an option that always uses the bundled - `tl::expected`. Delete the `MOQ_ABI` guard in `moq.hpp` and - `src/moq.cpp`, the "C++ standard" sections of `doc/lib/cpp/index.md` and - `cpp/moq/README.md`, and the `test-target-23` build in `sh/cpp/check.sh`, - which only exercises the guard. Keep its C++17 and C++23 probe builds, - which prove the bindings compile at both. C++23 users lose - `std::expected`, which costs little: Unreal is C++20, and `tl::expected` - has the same members. With exceptions off, the bundled `tl::expected` - makes `value()` on an error `__builtin_unreachable`; patch it to abort - with a message, like a misused future, and drop the "undefined" warning - from the Errors section of `doc/lib/cpp/index.md`. diff --git a/quest/m1/cpp-package-check.md b/quest/m1/cpp-package-check.md index 78170f457ec..788a2948852 100644 --- a/quest/m1/cpp-package-check.md +++ b/quest/m1/cpp-package-check.md @@ -19,6 +19,5 @@ Public API: none beyond the binding changes owned by their quests. Wire: none. ## Required - [Codecs](/quest/m1/ffi-shape/codec.md) - the binding surface being packaged -- [Generated C++ shape](/quest/m1/cpp-generated-shape.md) - the final generated names - [Client settings parity](/quest/m1/obs-client-config.md) - preserve existing OBS settings - [Session report parity](/quest/m1/obs-session-report.md) - preserve existing OBS reports diff --git a/quest/m1/ffi-shape/README.md b/quest/m1/ffi-shape/README.md index b361218d617..41801464e7f 100644 --- a/quest/m1/ffi-shape/README.md +++ b/quest/m1/ffi-shape/README.md @@ -24,10 +24,11 @@ media, and request-accept children, and the remaining children PR straight to `reanchor()`) already on `main`. Codecs ranks first below for that reason. Dart is published (`moq` 0.1.0, `moq_ffi` 0.4.x), so its renames get the same upgrade notes as the others. -- The C++ package (#4079) landed first, so #4519 ported `cpp/moq` (including - the hand-kept `moq::` aliases `just cpp check` audits), `cpp/obs`, and the - C++ interop client. C++ stays a flat `moq::` namespace with `Media*` type - names until [unprefixed names](/quest/m1/cpp-generated-shape.md) lands. +- The C++ package (#4079) landed first, so #4519 ported `cpp/moq`, `cpp/obs`, + and the C++ interop client. C++ is one flat `moq::` namespace of the + generated types, with moq-ffi's `Moq` prefix stripped (`moq::MediaTrackConsumer`): + uniffi-bindgen-cpp renders one namespace per crate, so a `media::` namespace + would need the generator to map a name prefix to a namespace. Settled shape: diff --git a/quest/m1/ffi-shape/layers-guide.md b/quest/m1/ffi-shape/layers-guide.md index 914ac114103..6e46892050f 100644 --- a/quest/m1/ffi-shape/layers-guide.md +++ b/quest/m1/ffi-shape/layers-guide.md @@ -12,9 +12,8 @@ another. Waits for [Codecs](/quest/m1/ffi-shape/codec.md), since `audio` and `video` have no namespace to map until then (decided 2026-10-09 on #4519). Keep it a table per layer, not a method reference: the API docs own the names (see -`doc/AGENTS.md`). C++ stays flat until -[One expected type and unprefixed names](/quest/m1/cpp-generated-shape.md) -lands, so its column names the `moq::Media*` types instead of a namespace. +`doc/AGENTS.md`). C++ is one flat `moq::` namespace of the generated +types, so its column names the `moq::Media*` types instead of a namespace. ## Required diff --git a/quest/m1/uniffi-fork.md b/quest/m1/uniffi-fork.md index 588bba9bfaf..168d5262de5 100644 --- a/quest/m1/uniffi-fork.md +++ b/quest/m1/uniffi-fork.md @@ -61,8 +61,7 @@ UniFFI: - **The fork's CI** builds every generator and runs its fixture suite, including the unlocked `cargo install` resolve that bit the 0.32 port. - Update the quests that name a `kixelated/uniffi-*` fork - ([Generated C++ shape](/quest/m1/cpp-generated-shape.md), - [Generated C bindings](/quest/m1/c/README.md)) to point at moq-dev/uniffi. + ([Generated C bindings](/quest/m1/c/README.md)) to point at moq-dev/uniffi. Public API: none at the move; moq-ffi's dependency names change. Wire: none. diff --git a/quest/m2/release/cpp-release.md b/quest/m2/release/cpp-release.md index 06bed522212..47a74f60d76 100644 --- a/quest/m2/release/cpp-release.md +++ b/quest/m2/release/cpp-release.md @@ -34,6 +34,5 @@ release. The nightly dry-run preparation can proceed independently. - [Codecs](/quest/m1/ffi-shape/codec.md) - settle the audio and video binding API before publishing - [Client settings parity](/quest/m1/obs-client-config.md) - the OBS Advanced settings the migration dropped come back - [Session report parity](/quest/m1/obs-session-report.md) - the dock shows the negotiated protocol and the reconnect failure again -- [Generated C++ shape](/quest/m1/cpp-generated-shape.md) - each type has one name and `moq::expected` one type before the API ships - [Nightly package proof](/quest/m1/cpp-package-check.md) - the release path is exercised before the tag diff --git a/rs/moq-ffi/build.sh b/rs/moq-ffi/build.sh index a14fdc29903..6082d259337 100755 --- a/rs/moq-ffi/build.sh +++ b/rs/moq-ffi/build.sh @@ -190,7 +190,7 @@ generate_bindings() { # C++ uses a third-party bindgen too: a fork carrying LiveKit's async support # ported to uniffi 0.32, which upstream has not released. Install it with: - # cargo install --locked uniffi-bindgen-cpp --git https://github.com/kixelated/uniffi-bindgen-cpp --tag v0.11.0-kixelated.4+v0.32.2 + # cargo install --locked uniffi-bindgen-cpp --git https://github.com/kixelated/uniffi-bindgen-cpp --rev 40c99525a125acd3ac0f2eb792c452640dbae388 if command -v uniffi-bindgen-cpp >/dev/null 2>&1; then echo " Generating cpp bindings..." uniffi-bindgen-cpp --library "$lib_path" \ diff --git a/sh/cpp/check.sh b/sh/cpp/check.sh index f75839a1cf5..106a41a48c7 100755 --- a/sh/cpp/check.sh +++ b/sh/cpp/check.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # Build and install cpp/moq, then build the probe against the installed package -# at C++17 and C++23 through CMake (C++23 also the documented in-project way) and -# run each. Outside Windows, also builds and runs it through pkg-config at C++17 +# at C++17, at C++23, and at C++23 over bindings at C++17 through CMake, and run +# each. Outside Windows, also builds and runs it through pkg-config at C++17 # and compiles the doc samples. CXX picks the compiler on Unix; Windows uses MSVC. set -euo pipefail @@ -16,16 +16,6 @@ cmake --build "$build/package" --config Release rm -rf "$prefix" cmake --install "$build/package" --config Release --prefix "$prefix" -# Every generated moq::MoqFoo needs its moq::Foo alias in the wrapper. -missing=$(comm -23 \ - <(sed -nE 's/^(struct|enum class) Moq([A-Za-z0-9]+);$/\2/p' "$prefix/include/moq/ffi/moq.hpp" | sort -u) \ - <(sed -nE 's/^using ([A-Za-z0-9]+) = Moq([A-Za-z0-9]+);$/\1 \2/p' moq/include/moq/moq.hpp | - awk '$1 == $2 { print $1 }' | sort -u)) -if [[ -n "$missing" ]]; then - echo "cpp check: cpp/moq/include/moq/moq.hpp lacks an alias for: ${missing//$'\n'/ }" >&2 - exit 1 -fi - run() { if [[ -x "$1/probe" ]]; then "$1/probe"; else "$1/Release/probe.exe"; fi } @@ -35,11 +25,11 @@ for std in 17 23; do run "$build/test-$std" done -# The setup doc/lib/cpp documents: the standard set in the project, and also required on -# the app's own target. -cmake -S moq/test -B "$build/test-target-23" -DCMAKE_BUILD_TYPE=Debug -DPROBE_CXX_STANDARD=23 -DCMAKE_PREFIX_PATH="$prefix" -cmake --build "$build/test-target-23" --config Release -run "$build/test-target-23" +# Bindings at C++17 under an app target raised to C++23: moq::expected is one type at every +# standard, so the two link. +cmake -S moq/test -B "$build/test-mixed" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_STANDARD=17 -DPROBE_CXX_STANDARD=23 -DCMAKE_PREFIX_PATH="$prefix" +cmake --build "$build/test-mixed" --config Release +run "$build/test-mixed" # The rest builds with `c++`, which on Windows is MinGW GCC and can't link the MSVC-built # package. MSVC consumers use the CMake package. From 325d66d395b2565ed538eb9dfd34e79c07e3536c Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 16 Oct 2026 19:21:26 -0700 Subject: [PATCH 3/3] build(cpp): pin uniffi-bindgen-cpp v0.11.0-kixelated.5+v0.32.2 Co-Authored-By: Claude Opus 5.5 --- .github/workflows/cpp.yml | 2 +- .github/workflows/platform.yml | 4 ++-- .github/workflows/release-cpp.yml | 2 +- cpp/moq/README.md | 2 +- flake.nix | 11 ++++------- rs/moq-ffi/build.sh | 2 +- 6 files changed, 10 insertions(+), 13 deletions(-) diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.yml index 760c5f70015..e501e057969 100644 --- a/.github/workflows/cpp.yml +++ b/.github/workflows/cpp.yml @@ -50,7 +50,7 @@ jobs: - uses: ./.github/actions/just - name: Install uniffi-bindgen-cpp - run: cargo install uniffi-bindgen-cpp --locked --git https://github.com/kixelated/uniffi-bindgen-cpp --rev 40c99525a125acd3ac0f2eb792c452640dbae388 + run: cargo install uniffi-bindgen-cpp --locked --git https://github.com/kixelated/uniffi-bindgen-cpp --tag v0.11.0-kixelated.5+v0.32.2 - name: Check run: just cpp check diff --git a/.github/workflows/platform.yml b/.github/workflows/platform.yml index 3343b7d72a6..73900bfbb6c 100644 --- a/.github/workflows/platform.yml +++ b/.github/workflows/platform.yml @@ -98,7 +98,7 @@ jobs: - name: Install uniffi-bindgen-cpp if: needs.scope.outputs.cpp == 'true' || needs.scope.outputs.obs == 'true' shell: bash - run: cargo install uniffi-bindgen-cpp --locked --git https://github.com/kixelated/uniffi-bindgen-cpp --rev 40c99525a125acd3ac0f2eb792c452640dbae388 + run: cargo install uniffi-bindgen-cpp --locked --git https://github.com/kixelated/uniffi-bindgen-cpp --tag v0.11.0-kixelated.5+v0.32.2 - name: Rust compile and tests if: needs.scope.outputs.rs == 'true' shell: bash @@ -137,7 +137,7 @@ jobs: tool: nextest@0.9.146 - name: Install uniffi-bindgen-cpp if: needs.scope.outputs.obs == 'true' - run: cargo install uniffi-bindgen-cpp --locked --git https://github.com/kixelated/uniffi-bindgen-cpp --rev 40c99525a125acd3ac0f2eb792c452640dbae388 + run: cargo install uniffi-bindgen-cpp --locked --git https://github.com/kixelated/uniffi-bindgen-cpp --tag v0.11.0-kixelated.5+v0.32.2 - name: Rust compile and tests if: needs.scope.outputs.rs == 'true' env: diff --git a/.github/workflows/release-cpp.yml b/.github/workflows/release-cpp.yml index 7f8a11b6737..fde78a21132 100644 --- a/.github/workflows/release-cpp.yml +++ b/.github/workflows/release-cpp.yml @@ -54,7 +54,7 @@ jobs: # The tag flake.nix pins; see the comment there. - name: Install uniffi-bindgen-cpp shell: bash - run: cargo install uniffi-bindgen-cpp --locked --git https://github.com/kixelated/uniffi-bindgen-cpp --rev 40c99525a125acd3ac0f2eb792c452640dbae388 + run: cargo install uniffi-bindgen-cpp --locked --git https://github.com/kixelated/uniffi-bindgen-cpp --tag v0.11.0-kixelated.5+v0.32.2 # The package version lives in cpp/moq/VERSION; a tag that disagrees is a mistake. - name: Check version diff --git a/cpp/moq/README.md b/cpp/moq/README.md index ca559d99ea7..971e1b17e9f 100644 --- a/cpp/moq/README.md +++ b/cpp/moq/README.md @@ -19,7 +19,7 @@ The generator is a fork, [kixelated/uniffi-bindgen-cpp](https://github.com/kixel ```bash cargo install uniffi-bindgen-cpp --locked \ --git https://github.com/kixelated/uniffi-bindgen-cpp \ - --rev 40c99525a125acd3ac0f2eb792c452640dbae388 + --tag v0.11.0-kixelated.5+v0.32.2 ``` `flake.nix` pins the same tag and lists every other place that names it. diff --git a/flake.nix b/flake.nix index 3ac75795e3f..b12b2d2fd72 100644 --- a/flake.nix +++ b/flake.nix @@ -378,21 +378,18 @@ # which cpp/moq/uniffi.toml turns on. Its tags add a `-kixelated.N` # pre-release so they never collide with upstream's. Move back upstream # once one tags both. - # - # TODO: pin v0.11.0-kixelated.5+v0.32.2 once kixelated/uniffi-bindgen-cpp#4 - # is released; until then this is that PR's head. uniffi-bindgen-cpp = pkgs.rustPlatform.buildRustPackage rec { pname = "uniffi-bindgen-cpp"; - version = "0.11.0-kixelated.4+v0.32.2"; + version = "0.11.0-kixelated.5+v0.32.2"; src = pkgs.fetchFromGitHub { owner = "kixelated"; repo = "uniffi-bindgen-cpp"; - rev = "40c99525a125acd3ac0f2eb792c452640dbae388"; - hash = "sha256-x39ZeM4mh96FjUKXCgPBSWVojvcPiUpSLcTFr/hNvnM="; + rev = "v${version}"; + hash = "sha256-y148irMNOsMrfjbUT/f3jlNmpxT0/z/2LVlP+t1oq8I="; }; - cargoHash = "sha256-/DRrwhJiKFCzibiJU2D3QaBM3XTmieRgUNc7tHDiGXI="; + cargoHash = "sha256-QBURLIg255O6J4A+wzZVk4cUJPdJb6JepZKofX0fLZg="; # The workspace's other member is the fixture crate, which pulls the # uniffi examples in from git; build only the generator. diff --git a/rs/moq-ffi/build.sh b/rs/moq-ffi/build.sh index 4d24c28582e..417b4ca5c9e 100755 --- a/rs/moq-ffi/build.sh +++ b/rs/moq-ffi/build.sh @@ -190,7 +190,7 @@ generate_bindings() { # C++ uses a third-party bindgen too: a fork carrying LiveKit's async support # ported to uniffi 0.32, which upstream has not released. Install it with: - # cargo install --locked uniffi-bindgen-cpp --git https://github.com/kixelated/uniffi-bindgen-cpp --rev 40c99525a125acd3ac0f2eb792c452640dbae388 + # cargo install --locked uniffi-bindgen-cpp --git https://github.com/kixelated/uniffi-bindgen-cpp --tag v0.11.0-kixelated.5+v0.32.2 if command -v uniffi-bindgen-cpp >/dev/null 2>&1; then echo " Generating cpp bindings..." uniffi-bindgen-cpp --library "$lib_path" \