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: 9 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
# would work, but that list is what scopes `just check` and `cargo semver-checks`.
[alias]
moq = ["run", "--bin", "moq", "--"]
# `cargo build-ffi` is the one definition of moq-ffi's default build, which every
# binding loads from the shared target directory: `openh264`, as releases ship
# it. Append a profile, `--target`, or `--lib`, never features. A cdylib's file
# name carries no feature hash, so a build with other features replaces
# `libmoq_ffi.so` under everyone reading it; such a build takes a target
# directory of its own (py, `sh/size/collect.sh`, `build.sh --no-default-features`)
# or a `--target` triple no default build uses (dart's `testing` build).
# Aliases resolve from the working directory, so run it inside the checkout.
build-ffi = ["build", "--locked", "--package", "moq-ffi", "--features", "openh264"]

# Browser/WASM (moq-wasm). getrandom needs its wasm_js backend, and web-sys's
# WebTransport bindings are behind the unstable cfg.
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/release-gate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ jobs:
# since a bumped dependency can change a re-exported type.
api-diff:
- "rs/**"
- ".cargo/config.toml"
- "js/**"
- "Cargo.toml"
- "Cargo.lock"
Expand All @@ -112,6 +113,7 @@ jobs:
c:
- "c/**"
- "rs/moq-ffi/**"
- ".cargo/config.toml"
- "sh/c/**"
- "rs/moq-c/native-libs/**"
- "cpp/moq/cmake/moq-ffi.cmake"
Expand All @@ -121,6 +123,7 @@ jobs:
- "cpp/moq/**"
- "cpp/justfile"
- "rs/moq-ffi/**"
- ".cargo/config.toml"
- "sh/cpp/**"
- "rs/moq-c/native-libs/**"
- "doc/lib/cpp/**"
Expand All @@ -146,6 +149,7 @@ jobs:
# The Go client builds against the modules this script stages.
- "sh/go/**"
- "cpp/moq/**"
- ".cargo/config.toml"
- ".github/workflows/interop.yml"
moq-sh:
- "infra/moq-sh/**"
Expand All @@ -155,6 +159,7 @@ jobs:
- "cpp/moq/**"
- "sh/obs/**"
- "rs/moq-ffi/**"
- ".cargo/config.toml"
- "rs/moq-c/**"
- "doc/lib/c/**"
- "doc/lib/samples.sh"
Expand Down Expand Up @@ -185,6 +190,7 @@ jobs:
- "dart/moq_ffi/**"
- "sh/dart/**"
- "rs/moq-ffi/build.sh"
- ".cargo/config.toml"
release-go-ffi:
- ".github/workflows/release-go-ffi.yml"
- ".github/workflows/release-ffi.yml"
Expand All @@ -195,6 +201,7 @@ jobs:
- "sh/go/package-ffi.sh"
- "sh/go/publish-ffi.sh"
- "rs/moq-ffi/build.sh"
- ".cargo/config.toml"
release-js:
- "js/**"
- ".github/workflows/release-js.yml"
Expand All @@ -206,6 +213,7 @@ jobs:
- ".github/workflows/release-kt-lib.yml"
- "sh/gh/release.sh"
- "rs/moq-ffi/build.sh"
- ".cargo/config.toml"
release-swift-lib:
- "swift/VERSION"
- "swift/Package.swift.template"
Expand Down
4 changes: 2 additions & 2 deletions cpp/moq/cmake/moq-ffi.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
# cargo setting (target-dir, build.target) can move them from where the packages look.

if(CMAKE_SCRIPT_MODE_FILE)
set(_args build --locked --package moq-ffi --features openh264
--message-format=json-render-diagnostics)
# The shared default build (.cargo/config.toml), which the prebuilt input matches.
set(_args build-ffi --message-format=json-render-diagnostics)
if(RELEASE)
list(APPEND _args --release)
endif()
Expand Down
18 changes: 6 additions & 12 deletions dart/moq_ffi/hook/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,11 @@ Future<_Resolved> _resolveLibrary(
/// another recipe with different features. Cargo's own timestamp check makes
/// the no-op case cheap.
Future<_Resolved> _build(Uri workspace, String target, String library) async {
final cargoArgs = [
'build',
'--locked',
'--package',
'moq-ffi',
// The software H.264 fallback is opt-in in Rust; the published library ships it.
// A checkout build is a test build, carrying the hooks leak_test.dart reads.
'--features',
'openh264,testing',
'--manifest-path',
workspace.resolve('Cargo.toml').toFilePath(),
];
// The shared default build, an alias .cargo/config.toml defines for Cargo
// runs in the workspace; it ships the software H.264 fallback. A checkout build is a test build, carrying the hooks
// leak_test.dart reads; `--target` keeps it out of the default build's
// directory, since a cdylib's file name carries no feature hash.
final cargoArgs = ['build-ffi', '--features', 'testing'];

// Android needs the NDK's linker and sysroot, which only cargo-ndk sets up.
// This mirrors rs/moq-ffi/build.sh.
Expand All @@ -112,6 +105,7 @@ Future<_Resolved> _build(Uri workspace, String target, String library) async {
final result = await Process.run(
'cargo',
args,
workingDirectory: workspace.toFilePath(),
environment: target.contains('-apple-ios')
? const {'IPHONEOS_DEPLOYMENT_TARGET': '16.0'}
: null,
Expand Down
1 change: 0 additions & 1 deletion quest/m1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ removed).
- [Next Object on a cold Rust copy](/quest/m1/next-object-cold-copy.md) - a join after an upstream group report starts at the first frame received, never skipping
- [Container consumers buffer by backpressure](/quest/m1/container-backpressure.md) - Rust and JS container consumers decode ahead only a byte budget, so a hostile publisher cannot grow them
- [An HLS viewer starts capture](/quest/m1/hls-record-demand.md) - a record-track subscriber counts as demand for its rendition's media
- [One moq-ffi build definition](/quest/m1/ffi-build-flags.md) - every binding takes moq-ffi's default features from one place
- [gofmt-clean Go wrapper](/quest/m1/go-gofmt.md) - `just go check` fails on unformatted Go
- [moqsrc max-delay](/quest/m1/gst-max-delay.md) - GStreamer's `moqsrc` takes a `max-delay` property instead of a hard-coded 1 s budget
- [JS SETUP rejection ownership](/quest/m1/js-setup-rejection.md) - reproduce an unhandled version-refusal rejection without weakening the refusal
Expand Down
18 changes: 0 additions & 18 deletions quest/m1/ffi-build-flags.md

This file was deleted.

2 changes: 1 addition & 1 deletion rs/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ x11-bench-ci:
[positional-arguments]
android *args:
bash sh/local.sh cargo ndk -t arm64-v8a --platform 26 check --locked -p moq-video --all-targets "$@"
bash sh/local.sh cargo ndk -t arm64-v8a --platform 26 -o target/android-jni build --locked -p moq-ffi --features openh264 "$@"
bash sh/local.sh cargo ndk -t arm64-v8a --platform 26 -o target/android-jni build-ffi "$@"
nm -D --undefined-only target/android-jni/arm64-v8a/libmoq_ffi.so | grep -q __android_log_

# moq-wasm's crate root is `#![cfg(target_arch = "wasm32")]`, so only a wasm32
Expand Down
6 changes: 3 additions & 3 deletions rs/moq-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ default = ["audio", "video"]
audio = ["dep:moq-audio"]
video = ["dep:moq-video", "dep:pollster"]
# The OpenH264 software H.264 fallback (vendored C++) for `video`. Off for
# development and linting; `build.sh`, maturin, and CI's tests turn it on. It is
# the only encoder on API-24 Android and the Apple simulators, so every release
# build needs it.
# development and linting; `cargo build-ffi` (.cargo/config.toml), maturin, and
# CI's tests turn it on. It is the only encoder on API-24 Android and the Apple
# simulators, so every release build needs it.
openh264 = ["moq-video?/openh264"]
# qlog trace capture (`MoqQuicConfig::qlog`). Off by default: it compiles the qlog
# machinery in and is only wanted for debugging; `moq_qlog_supported` reports it.
Expand Down
18 changes: 12 additions & 6 deletions rs/moq-ffi/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ if [[ -n "$LIBRARY" ]]; then
fi
fi

# A cdylib's file name carries no feature hash, so the minimal library gets a
# target directory of its own rather than replacing the default build's.
if [[ "$NO_DEFAULT_FEATURES" == true ]]; then
TARGET_BASE_DIR="$TARGET_BASE_DIR/minimal"
fi

# Get version from Cargo.toml if not specified
if [[ -z "$VERSION" ]]; then
VERSION=$(grep '^version' "$SCRIPT_DIR/Cargo.toml" | head -1 | sed 's/.*"\(.*\)".*/\1/')
Expand Down Expand Up @@ -113,9 +119,10 @@ can_run_on_host() {
# Build the library for a single target
build_target() {
local target="$1"
# Releases carry the OpenH264 software fallback, the only encoder on API-24
# Android and the Apple simulators; a no-op under --no-default-features.
local cargo_args=(build --locked --release --package moq-ffi --features openh264)
# The shared default build (.cargo/config.toml): releases carry the OpenH264
# software fallback, the only encoder on API-24 Android and the Apple
# simulators. It is a no-op under --no-default-features.
local cargo_args=(build-ffi --release --target-dir "$TARGET_BASE_DIR" --manifest-path "$WORKSPACE_DIR/Cargo.toml")
if [[ "$NO_DEFAULT_FEATURES" == true ]]; then
cargo_args+=(--no-default-features)
fi
Expand All @@ -131,15 +138,14 @@ build_target() {

if is_android "$target"; then
# Android targets use cargo-ndk
cargo ndk --target "$target" --platform 24 -- \
"${cargo_args[@]}" --manifest-path "$WORKSPACE_DIR/Cargo.toml"
(cd "$WORKSPACE_DIR" && cargo ndk --target "$target" --platform 24 -- "${cargo_args[@]}")
else
# Set up cross-compilation for Linux ARM64
if [[ "$target" == "aarch64-unknown-linux-gnu" ]]; then
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc
fi

cargo "${cargo_args[@]}" --target "$target" --manifest-path "$WORKSPACE_DIR/Cargo.toml"
(cd "$WORKSPACE_DIR" && cargo "${cargo_args[@]}" --target "$target")
fi
}

Expand Down
2 changes: 1 addition & 1 deletion rs/moq-ffi/examples/server_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Usage:

# Build the cdylib and generate the Python bindings.
cargo build --release --package moq-ffi
cargo build-ffi --release
cargo run --package uniffi-bindgen --features cli -- generate \
--library target/release/libmoq_ffi.so \
--language python --out-dir target/py-bindings
Expand Down
2 changes: 1 addition & 1 deletion sh/api-diff/ffi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ strip c "$c_out/include/moq.h" "$out/current/moq.h"
# uniffi-bindgen-cpp reads the metadata from a library for any target, so the
# x86_64 release library works on any host.
gh release download "$ffi_tag" --repo moq-dev/moq --pattern '*-x86_64-unknown-linux-gnu-libmoq_ffi.so' --output "$work/libmoq_ffi.so"
lib=$(cargo build --locked -p moq-ffi --lib --message-format=json |
lib=$(cargo build-ffi --lib --message-format=json |
jq -r 'select(.reason == "compiler-artifact" and .target.name == "moq_ffi") | .filenames[] | select(test("\\.(so|dylib)$"))' | tail -1)
if [[ -z "$lib" ]]; then
echo "cargo build -p moq-ffi produced no shared library" >&2
Expand Down
7 changes: 4 additions & 3 deletions sh/dart/build.test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
class BuildTest(unittest.TestCase):
def test_generator_profiles(self):
# Only the dev build carries the test hooks, which would skew a benchmark.
for profile, release, features in (("debug", False, "openh264,testing"),
("release", True, "openh264")):
for profile, release, features in (("debug", False, ["--features", "testing"]),
("release", True, [])):
with self.subTest(profile=profile), tempfile.TemporaryDirectory() as directory:
scratch = Path(directory)
calls = scratch / "calls"
Expand All @@ -35,8 +35,9 @@ def test_generator_profiles(self):
cwd=ROOT, env=env, text=True, capture_output=True)
self.assertEqual(result.returncode, 0, result.stderr)
args = calls.read_text().split()
self.assertEqual(args[0], "build-ffi")
self.assertEqual("--release" in args, release)
self.assertEqual(args[args.index("--features") + 1], features)
self.assertEqual(args[1:args.index("--target")], [*features, *(["--release"] if release else [])])

def test_failed_benchmark_restores_manifest(self):
with tempfile.TemporaryDirectory() as directory:
Expand Down
2 changes: 1 addition & 1 deletion sh/dart/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ record_cargo() {
local phase=$1 flags=$2
cat >"$generated/bin/cargo" <<EOF
#!/usr/bin/env bash
if [[ "\${1:-}" == build ]]; then
if [[ "\${1:-}" == build-ffi ]]; then
env -u PWD -u OLDPWD -u SHLVL -u _ -0 | sort -z >"$generated/$phase.env"
set -- "\$@" $flags
fi
Expand Down
19 changes: 6 additions & 13 deletions sh/dart/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,18 @@ shopt -u nocasematch
host=$(rustc -vV | sed -n 's/^host: //p')
# Checkouts use a dev build; benchmark and release staging opt into release.
profile=${MOQ_FFI_PROFILE:-debug}
# The debug features match the hook's checkout build, test hooks included; the release
# build is benchmarked, so it leaves out the counting allocator.
# The shared default build (.cargo/config.toml). The debug one adds the hook's test
# hooks, which is safe only because `--target` gives it a directory no default build
# writes; the release build is benchmarked, so it leaves out the counting allocator.
case "$profile" in
debug)
profile_args=()
features=openh264,testing
;;
release)
profile_args=(--release)
features=openh264
;;
debug) profile_args=(--features testing) ;;
release) profile_args=(--release) ;;
*)
echo "error: unsupported MOQ_FFI_PROFILE: $profile" >&2
exit 1
;;
esac
env -i "${hook_env[@]}" cargo build --locked ${profile_args[@]+"${profile_args[@]}"} --package moq-ffi --features "$features" \
--target "$host" \
--manifest-path "$WORKSPACE_DIR/Cargo.toml"
(cd "$WORKSPACE_DIR" && env -i "${hook_env[@]}" cargo build-ffi "${profile_args[@]}" --target "$host")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Update the Dart check recorder to recognize the Cargo alias

When just dart check runs, its record_cargo() wrapper in sh/dart/check.sh still intercepts only invocations whose first argument is build. Switching the generator and hook to build-ffi therefore bypasses both environment recording and the hook's --verbose injection. If the hook rebuilds the library, the drift check subsequently reads nonexistent generate.env and hook.env files and cannot report the differing variables or Cargo's rebuild reasons. Update the recorder predicate alongside these callers so the existing rebuild diagnostic remains functional.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 162466d: the recorder in sh/dart/check.sh now matches build-ffi. Both callers under it, generate.sh and the hook, use the alias, so it again records both environments and passes --verbose to the hook. just dart check passes.

(Written by Claude Opus 5.5)


case "$host" in
*-apple-*) library="$WORKSPACE_DIR/target/$host/$profile/libmoq_ffi.dylib" ;;
Expand Down
17 changes: 9 additions & 8 deletions sh/dispatch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,21 @@ declare -A scope=(
# they target. Only nightly runs the drills; this catches a stale patch.
[drill]='^(rs/|test/drill/)'
# maturin bundles rs/moq-ffi into the moq-ffi wheel, and the other
# bindings generate from it. Each check also compiles its doc samples.
# bindings generate from it, built by the `cargo build-ffi` alias in
# .cargo/config.toml. Each check also compiles its doc samples.
[py]='^(py/|sh/py/|pyproject\.toml$|uv\.lock$|rs/moq-ffi/|doc/lib/py/|doc/lib/samples\.sh$)'
[kt]='^(kt/|sh/kt/|rs/moq-ffi/|doc/lib/kt/|doc/lib/samples\.sh$)'
[swift]='^(swift/|sh/swift/|rs/moq-ffi/|doc/lib/swift/|doc/lib/samples\.sh$)'
[go]='^(go/|sh/go/|rs/moq-ffi/|doc/lib/go/|doc/lib/samples\.sh$)'
[dart]='^(dart/|sh/dart/|rs/moq-ffi/|doc/lib/dart/|doc/lib/samples\.sh$)'
[kt]='^(\.cargo/config\.toml$|kt/|sh/kt/|rs/moq-ffi/|doc/lib/kt/|doc/lib/samples\.sh$)'
[swift]='^(\.cargo/config\.toml$|swift/|sh/swift/|rs/moq-ffi/|doc/lib/swift/|doc/lib/samples\.sh$)'
[go]='^(\.cargo/config\.toml$|go/|sh/go/|rs/moq-ffi/|doc/lib/go/|doc/lib/samples\.sh$)'
[dart]='^(\.cargo/config\.toml$|dart/|sh/dart/|rs/moq-ffi/|doc/lib/dart/|doc/lib/samples\.sh$)'
# The C package links moq-c's native-libs lists, and the C++ package's FFI pin.
[c]='^(c/|sh/c/|rs/moq-ffi/|rs/moq-c/native-libs/|cpp/moq/FFI_VERSION$|cpp/moq/cmake/moq-ffi\.cmake$)'
[c]='^(\.cargo/config\.toml$|c/|sh/c/|rs/moq-ffi/|rs/moq-c/native-libs/|cpp/moq/FFI_VERSION$|cpp/moq/cmake/moq-ffi\.cmake$)'
# The package links moq-c's native-libs lists, and compiles its doc samples.
[cpp]='^(cpp/moq/|cpp/justfile$|sh/cpp/|rs/moq-ffi/|rs/moq-c/native-libs/|doc/lib/cpp/|doc/lib/samples\.sh$)'
[cpp]='^(\.cargo/config\.toml$|cpp/moq/|cpp/justfile$|sh/cpp/|rs/moq-ffi/|rs/moq-c/native-libs/|doc/lib/cpp/|doc/lib/samples\.sh$)'
# The plugin and its tests call through the bindings generated from cpp/moq
# and moq-ffi and link through moq-c's native-libs lists, and flake.nix owns
# the libobs headers it compiles against.
[obs_compile]='^(cpp/obs/|cpp/moq/|sh/obs/|rs/moq-ffi/|rs/moq-c/native-libs/|flake\.nix$)'
[obs_compile]='^(\.cargo/config\.toml$|cpp/obs/|cpp/moq/|sh/obs/|rs/moq-ffi/|rs/moq-c/native-libs/|flake\.nix$)'
# `obs check` compares the OBS pinned in buildspec.json, flake.nix, and
# nixpkgs, and the last moves on a flake.lock bump alone.
[obs]='^(cpp/obs/|sh/obs/|flake\.(nix|lock)$)'
Expand Down
8 changes: 5 additions & 3 deletions sh/go/stage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ CARGO_PROFILE=()
[[ "$PROFILE" == "release" ]] && CARGO_PROFILE=(--release)

echo "go stage: building moq-ffi for $HOST_TARGET..." >&2
# `openh264`, as release builds ship it: the software encoder the tests rely on.
cargo build --locked ${CARGO_PROFILE[@]+"${CARGO_PROFILE[@]}"} --package moq-ffi --features openh264 \
--manifest-path "$WORKSPACE_DIR/Cargo.toml" >&2
# The shared default build (.cargo/config.toml), whose `openh264` the tests rely on.
# Cargo resolves the alias, and a relative CARGO_TARGET_DIR, from the working
# directory, so the build and the metadata below both run in the workspace.
cd "$WORKSPACE_DIR"
cargo build-ffi ${CARGO_PROFILE[@]+"${CARGO_PROFILE[@]}"} >&2

TARGET_BASE=$(cargo metadata --format-version 1 --manifest-path "$WORKSPACE_DIR/Cargo.toml" --no-deps |
sed -n 's/.*"target_directory":"\([^"]*\)".*/\1/p')
Expand Down
8 changes: 5 additions & 3 deletions sh/kt/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ CARGO_PROFILE=()
[[ "$PROFILE" == "release" ]] && CARGO_PROFILE=(--release)

echo "kt generate: building moq-ffi for $HOST_TARGET..."
# `openh264`, as release builds ship it: the software encoder the tests rely on.
cargo build --locked ${CARGO_PROFILE[@]+"${CARGO_PROFILE[@]}"} --package moq-ffi --features openh264 \
--manifest-path "$WORKSPACE_DIR/Cargo.toml"
# The shared default build (.cargo/config.toml), whose `openh264` the tests rely on.
# Cargo resolves the alias, and a relative CARGO_TARGET_DIR, from the working
# directory, so the build and the metadata below both run in the workspace.
cd "$WORKSPACE_DIR"
cargo build-ffi ${CARGO_PROFILE[@]+"${CARGO_PROFILE[@]}"}

TARGET_BASE=$(cargo metadata --format-version 1 --manifest-path "$WORKSPACE_DIR/Cargo.toml" --no-deps |
sed -n 's/.*"target_directory":"\([^"]*\)".*/\1/p')
Expand Down
7 changes: 4 additions & 3 deletions sh/size/collect.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ case $(uname -s) in Linux) dylib=so ;; Darwin) dylib=dylib ;; *)
;;
esac
# Release jobs ship default features only; this shows what the feature gates save.
cargo build --locked --release -p moq-ffi --no-default-features
cp "$target/release/libmoq_ffi.$dylib" "$out/native/libmoq_ffi-minimal.$dylib"
cp "$target/release/libmoq_ffi.a" "$out/native/libmoq_ffi-minimal.a"
# Its own target directory, since the cdylib would replace the default build's.
cargo build --locked --release -p moq-ffi --no-default-features --target-dir "$target/minimal"
cp "$target/minimal/release/libmoq_ffi.$dylib" "$out/native/libmoq_ffi-minimal.$dylib"
cp "$target/minimal/release/libmoq_ffi.a" "$out/native/libmoq_ffi-minimal.a"
bun install --frozen-lockfile
just js build
bun sh/size/bundles.ts "$out/js"
Expand Down
Loading
Loading