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
9 changes: 8 additions & 1 deletion cpp/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ default:
# on Unix; Windows uses MSVC.

# Build and install cpp/moq, then build the probe against the installed package at C++17 and
# C++23 through CMake, and at C++17 through pkg-config, and run each. Also compiles the doc samples.
# C++23 through CMake (C++23 also the documented in-project way), and at C++17 through
# pkg-config, and run each. Also compiles the doc samples.
check $FILES="":
#!/usr/bin/env bash
set -euo pipefail
Expand Down Expand Up @@ -54,6 +55,12 @@ check $FILES="":
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"

# The samples in doc/lib/cpp compile against the installed headers.
bash ../doc/lib/samples.sh cpp ../doc/lib/cpp/index.md >"$build/doc-samples.cpp"
if [[ "$(uname -s)" != MINGW* && "$(uname -s)" != MSYS* ]]; then
Expand Down
4 changes: 3 additions & 1 deletion cpp/moq/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ foreach(_line IN LISTS _lines)
endif()
endforeach()

# The bindings compile here with the including project's standard and flags; see src/moq.cpp.
# 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.
# Named moq-cpp so an in-tree build can sit beside libmoq's `moq` target.
add_library(moq-cpp STATIC src/moq.cpp)
add_library(moq::cpp ALIAS moq-cpp)
Expand Down
4 changes: 4 additions & 0 deletions cpp/moq/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ Every generated type lives in `namespace moq`. Objects are `std::shared_ptr`; re
- `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 or a misused future aborts with a message on stderr.
- Futures are polled and continuations run on one process-wide executor thread unless the application installs its own with `moq::set_executor` before the first async call. `moq::shutdown()` stops the moq-ffi runtime thread (`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. Native moq-ffi runs each async call as a spawned task that holds an `AbortOnDrop` on it (`rs/moq-ffi/src/ffi.rs`), so dropping the future aborts the work at its next await point instead of letting it finish unobserved. The continuation of a cancelled future never runs, and `get()` on it aborts.
Expand Down
6 changes: 4 additions & 2 deletions cpp/moq/cmake/moq-cpp-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ if(NOT TARGET moq::cpp)
INTERFACE_LINK_LIBRARIES "@MOQ_NATIVE_LIBS@;Threads::Threads"
)

# The generated bindings compile here, in the consumer's project, so they see the same
# standard and flags as the code that includes <moq/moq.hpp>.
# 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.
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
10 changes: 9 additions & 1 deletion cpp/moq/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# 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.
# 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.
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 All @@ -22,3 +27,6 @@ find_package(moq-cpp REQUIRED)

add_executable(probe probe.cpp)
target_link_libraries(probe PRIVATE moq::cpp)
if(PROBE_CXX_STANDARD)
target_compile_features(probe PRIVATE cxx_std_${PROBE_CXX_STANDARD})
endif()
19 changes: 15 additions & 4 deletions doc/lib/cpp/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ 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)
```
Expand All @@ -36,10 +37,20 @@ c++ -std=c++17 app.cpp $(pkg-config --variable=sources moq-cpp) $(pkg-config --c

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. Compile it with the same standard
as the code that includes `<moq/moq.hpp>`; `find_package` does this for you,
and a mismatch fails to link rather than corrupting memory. On MSVC, link the
release runtime (`/MD`), which the Rust library uses in every configuration.
`tl::expected` depending on the standard. 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 `<moq/moq.hpp>`. 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
Expand Down
1 change: 0 additions & 1 deletion quest/m1/cpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ Confirmed in [#4100](https://github.com/moq-dev/moq/pull/4100):
- [Client settings parity](/quest/m1/cpp/client-config.md) - moq-ffi offers libmoq's client knobs, and the OBS advanced settings get back the ones the migration dropped
- [Session report parity](/quest/m1/cpp/session-report.md) - a session reports its negotiated draft and reconnect failures, so the OBS dock shows them again
- [Cancel](/quest/m1/cpp/cancel.md) - a cancelled or consumed future reports `valid() == false`, like `std::future`, and a read of it aborts with a message naming the misuse
- [C++ standard](/quest/m1/cpp/cxx-standard.md) - a consumer that sets C++23 only on its own target links the package

## Related

Expand Down
29 changes: 0 additions & 29 deletions quest/m1/cpp/cxx-standard.md

This file was deleted.

Loading