diff --git a/.github/workflows/cpp.yml b/.github/workflows/cpp.yml index ce2fdc0cead..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 --tag v0.11.0-kixelated.4+v0.32.2 + 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 04959631732..30752b7034a 100644 --- a/.github/workflows/platform.yml +++ b/.github/workflows/platform.yml @@ -108,7 +108,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 --tag v0.11.0-kixelated.5+v0.32.2 - name: Rust compile and tests if: needs.scope.outputs.rs == 'true' shell: bash @@ -147,7 +147,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 --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 c6bde6b28b3..abad7c6ecd0 100644 --- a/.github/workflows/release-cpp.yml +++ b/.github/workflows/release-cpp.yml @@ -74,7 +74,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 --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/.github/workflows/release-shared-ffi.yml b/.github/workflows/release-shared-ffi.yml index 27890c733df..78c4c661419 100644 --- a/.github/workflows/release-shared-ffi.yml +++ b/.github/workflows/release-shared-ffi.yml @@ -91,7 +91,7 @@ jobs: - name: Install Rust uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable - 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 --tag v0.11.0-kixelated.5+v0.32.2 - name: Download default-feature input uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 with: diff --git a/cpp/moq/CMakeLists.txt b/cpp/moq/CMakeLists.txt index 306c30007c8..24139822944 100644 --- a/cpp/moq/CMakeLists.txt +++ b/cpp/moq/CMakeLists.txt @@ -129,8 +129,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 fe357ad25d4..f411cda92da 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 + --tag v0.11.0-kixelated.5+v0.32.2 ``` `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 bd9bf99e87c..495830cace7 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 @@ -23,147 +22,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 AudioEncoder = MoqAudioEncoder; -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 VideoEncoder = MoqVideoEncoder; -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 AudioPacket = MoqAudioPacket; -using AudioEncoderFinish = MoqAudioEncoderFinish; -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 Rendition = MoqRendition; -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 VideoGop = MoqVideoGop; -using VideoPacket = MoqVideoPacket; -using VideoFrame = MoqVideoFrame; -using VideoHint = MoqVideoHint; -using VideoInit = MoqVideoInit; -using VideoProperties = MoqVideoProperties; -using WebSocketConfig = MoqWebSocketConfig; -using AnnounceEvent = MoqAnnounceEvent; -using AudioFormat = MoqAudioFormat; -using AudioPreset = MoqAudioPreset; -using AudioSampleFormat = MoqAudioSampleFormat; -using CongestionControl = MoqCongestionControl; -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 9db0eed4a20..6d951e07ae3 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 @@ -236,13 +222,14 @@ to adjust the [session limits](/bin/relay/config#session-and-peer), before reconnecting with the same workload. A session closed because its credential expired reports `ProtocolKind::kExpired`, and a request refused for an expired token is `moq::Error::kExpired`; refresh the token before retrying. -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. +[shared feature list](/lib/#what-every-binding-can-do): moq-ffi's `MoqFoo` is +`moq::Foo`, and each Rust method keeps its name. [Layers](/lib/layers) maps each wrapped Rust layer to its `moq::` types. The header is the reference; every method carries its doc comment. diff --git a/flake.nix b/flake.nix index 304eb74c450..b78cf7b1a86 100644 --- a/flake.nix +++ b/flake.nix @@ -370,26 +370,27 @@ # rs/moq-ffi/Cargo.toml. The 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, .github/workflows/platform.yml, - # .github/workflows/release-cpp.yml, and .github/workflows/release-shared-ffi.yml. + # .github/workflows/platform.yml, .github/workflows/release-cpp.yml, and + # .github/workflows/release-shared-ffi.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. 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 = "v${version}"; - hash = "sha256-pmk9M5Wt6DYlXZYPjJ2Nn0tbDi1ve3wCH0Lel9xomCY="; + 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/quest/m1/README.md b/quest/m1/README.md index ca4135f7fcd..5bfc16aa85e 100644 --- a/quest/m1/README.md +++ b/quest/m1/README.md @@ -85,7 +85,6 @@ lands before the cut. - [IETF takeover](/quest/m1/ietf-takeover.md) - carry the shared takeover contract through the negotiated IETF epoch extension - [Identity and recovery guide](/quest/m1/identity-guide.md) - explain pinned catalogs, lazy jobs, takeover, restart and version compatibility - [Dropped sources](/quest/m1/dropped-sources.md) - track consumers see the producer's real error on every end path, never `Dropped`; a dead route ends Unroutable, and the TS follower lingers on announcements instead of matching errors -- [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 - [Rust PROBE on demand](/quest/m1/probe-on-demand-rs.md) - a Rust client opens PROBE only while a `recv_bandwidth()` consumer is held, and `Stats` drops `estimated_recv_rate` - [Typed refusal reason](/quest/m1/refusal-reason.md) - an auth server's 403 names the reason (including `expired`) and the root and tier, so the relay's session outcomes count and attribute refusals 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 4b206be0940..f20ebc92dcf 100644 --- a/quest/m1/cpp-package-check.md +++ b/quest/m1/cpp-package-check.md @@ -16,6 +16,3 @@ The first publication and released-download proof stay in release execution. Public API: none beyond the binding changes owned by their quests. Wire: none. -## Required - -- [Generated C++ shape](/quest/m1/cpp-generated-shape.md) - the final generated names diff --git a/quest/m1/ffi-shape/README.md b/quest/m1/ffi-shape/README.md index 07af7612aab..72a2cdb4f88 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/m2/release/cpp-release.md b/quest/m2/release/cpp-release.md index cba4b77dd5b..ffb5f30fb83 100644 --- a/quest/m2/release/cpp-release.md +++ b/quest/m2/release/cpp-release.md @@ -31,6 +31,5 @@ release. The nightly dry-run preparation can proceed independently. - [Breaking release cut](/quest/m2/release/cut.md) - prepared code reaches release before artifact publication and installed proof -- [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/quest/m2/uniffi-fork.md b/quest/m2/uniffi-fork.md index d573aa4b80e..02c57f2ae38 100644 --- a/quest/m2/uniffi-fork.md +++ b/quest/m2/uniffi-fork.md @@ -63,8 +63,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/rs/moq-ffi/build.sh b/rs/moq-ffi/build.sh index 7a2690105ea..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 --tag v0.11.0-kixelated.4+v0.32.2 + # 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" \ diff --git a/sh/cpp/check.sh b/sh/cpp/check.sh index 201e6bfaab6..826a5f2febb 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 and benchmark runner. CXX picks the compiler on # Unix; Windows uses MSVC. set -euo pipefail @@ -27,16 +27,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 } @@ -46,11 +36,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.