Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-shared-ffi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions cpp/moq/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 5 additions & 9 deletions cpp/moq/README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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.
Expand All @@ -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<T>`, 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<T>`, 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<T>`. 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 `<moq/moq.hpp>` 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.
Expand Down
4 changes: 1 addition & 3 deletions cpp/moq/cmake/moq-cpp-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 <moq/moq.hpp> 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@")
Expand Down
2 changes: 1 addition & 1 deletion cpp/moq/cmake/moq-cpp.pc.in
Original file line number Diff line number Diff line change
@@ -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 <moq/moq.hpp>.
# same flags as the code that includes <moq/moq.hpp>.
prefix=${pcfiledir}/../..
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
Expand Down
145 changes: 3 additions & 142 deletions cpp/moq/include/moq/moq.hpp
Original file line number Diff line number Diff line change
@@ -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 <moq/ffi/moq.hpp>
Expand All @@ -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 <typename T>
using expected = ::uniffi::expected<T, Error>;

Expand Down
4 changes: 1 addition & 3 deletions cpp/moq/src/moq.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Compiles the generated bindings. Build it with the same C++ standard as the code that
// includes <moq/moq.hpp>; the MOQ_ABI symbol below turns a mismatch into a link error.
#define MOQ_IMPLEMENTATION
// Compiles the generated bindings.
#include <moq/moq.hpp>

#include <moq/ffi/moq.cpp>
9 changes: 3 additions & 6 deletions cpp/moq/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
2 changes: 2 additions & 0 deletions cpp/moq/uniffi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Loading
Loading