wireplumber: migrate to upstream git + external patches (Rule 2 policy fix, v6.0 2026)

Per local/AGENTS.md Rule 2 (NO OVERLAY-STYLE PATCHES — AMENDED 2026), big
external projects must NOT have source forks in local/sources/. WirePlumber's
Red Bear edits now live as external patches in local/patches/wireplumber/,
matching the established mesa and libdrm migration pattern.

The patch contains the redox_compat/ shim headers that bridge relibc gaps
for the meson subprojects, and any build script adjustments for cross-
compilation under the Redox toolchain.

The local/sources/wireplumber/ fork is preserved as a historical reference
but no longer used by the build system. A follow-up commit will remove
it after we verify a clean rebuild from upstream git + patch.
This commit is contained in:
Red Bear Maintainer
2026-06-09 22:57:43 +03:00
parent 326df9ca66
commit 722f0c4523
2 changed files with 292 additions and 20 deletions
@@ -0,0 +1,232 @@
From 851ab7d96d6a10c5c67f50988db75810bc61ebbc Mon Sep 17 00:00:00 2001
From: Red Bear Maintainer <maintainer@redbearos.org>
Date: Вт, 09 июн 2026 19:50:57 +0000
Subject: [PATCH] wireplumber: redox_compat shim headers and Red Bear README
Red Bear OS external patch for wireplumber, applied on top of the
upstream freedesktop wireplumber 0.4.14
(https://gitlab.freedesktop.org/pipewire/wireplumber) by the
cookbook's git apply mechanism in local/recipes/libs/wireplumber/recipe.toml.
Per local/AGENTS.md Rule 2 (NO OVERLAY-STYLE PATCHES — AMENDED 2026),
wireplumber is a big external project. Red Bear does NOT maintain a
source fork of wireplumber. All Red Bear edits to upstream wireplumber
live as external patches under local/patches/wireplumber/.
Changes (vs upstream 0.4.14):
* README-redbear.md: Red Bear port status and intentionally-disabled
plugins (systemd, elogind, GObject introspection) — same role as
the pipewire fork README; documents the build gap analysis.
* redox_compat/byteswap.h: glibc <byteswap.h> API (bswap_16/32/64)
on top of relibc <endian.h>. Reached via CFLAGS -I in the recipe.
* redox_compat/sys/mman.h: Linux mmap() extension flags
(MAP_LOCKED, MAP_HUGETLB, MAP_NORESERVE, MAP_POPULATE,
MAP_NONBLOCK, MAP_DENYWRITE, MAP_EXECUTABLE, MAP_GROWSDOWN) that
relibc does not yet provide. Values match the Linux kernel UABI.
Reached via CFLAGS -I in the recipe.
These shims are the same ones used by the pipewire recipe and address
the same relibc gaps. They will be removed once relibc gains the
upstream equivalents.
---
diff --git a/README-redbear.md b/README-redbear.md
new file mode 100644
index 0000000..a155dee
--- /dev/null
+++ b/README-redbear.md
@@ -0,0 +1,70 @@
+# WirePlumber — Red Bear OS source fork
+
+This is the Red Bear OS fork of upstream WirePlumber, baseline at tag
+`0.4.14` of `https://gitlab.freedesktop.org/pipewire/wireplumber`.
+
+It is consumed by `local/recipes/libs/wireplumber/`, which builds the
+session manager, the C client library, and the `wpctl` control utility
+on the Redox toolchain.
+
+## What works on Redox
+
+| Component | Status | Notes |
+|-----------|--------|-------|
+| `libwireplumber-0.4.so` | builds | the C client library; depends on `libpipewire-0.3.so` and `glib-2.0` (both available via the Red Bear OS build) |
+| `wireplumber` daemon | builds | the session and policy manager itself; talks D-Bus to the desktop session |
+| `wpctl` | builds | command-line control utility for inspecting and mutating the PipeWire graph |
+| SPA policy modules | builds | the Lua-loaded modules that implement the per-stream policy rules |
+
+## What is intentionally disabled on Redox
+
+| Component | Reason | Where the gap is |
+|-----------|--------|------------------|
+| `systemd` activation | Redox uses init.d, not systemd | meson `-Dsystemd=disabled` |
+| `elogind` integration | Redox does not ship elogind | meson `-Delogind=disabled` |
+| `systemd-system-service` install | not relevant on Redox | meson `-Dsystemd-system-service=false` |
+| `systemd-user-service` install | not relevant on Redox | meson `-Dsystemd-user-service=false` |
+| GObject introspection (g-ir) | GIR toolchain is not yet wired into the Red Bear OS build | meson `-Dintrospection=disabled` |
+| D-Bus system bus tests | need a running dbus-daemon; the cooked build is offline-only | meson `-Ddbus-tests=false` |
+| System Lua | Red Bear does not yet ship a Lua interpreter; the bundled Lua subproject is used | meson `-Dsystem-lua=false` |
+
+## TODO before this can be runtime-validated
+
+* **audiod + pipewire + wireplumber integration** — wireplumber and
+ pipewire both need a working audiod backend in pipewire to actually
+ produce audio. See `local/sources/pipewire/README-redbear.md` for
+ the same gap documented on the pipewire side.
+* **Lua vendor** — wireplumber needs a Lua interpreter. The current
+ build relies on the bundled Lua subproject (meson wrap), which
+ fetches the Lua source on first configure. For a fully offline build
+ we need to vendor the Lua wrap into `local/sources/wireplumber/`
+ and commit it to git, then switch the build to `-Dsystem-lua=true`
+ with the wrapped Lua.
+* **`wireplumber.options` config file** — once the runtime is
+ validated, a default `wireplumber.options` Lua config should be
+ installed by the recipe's `[[files]]` entry in
+ `config/redbear-full.toml` (similar to the existing
+ `/etc/dbus-1/system.d/` policy files).
+* **KDE Plasma audio integration** — once audiod + pipewire +
+ wireplumber are validated end-to-end, confirm that KWin, Plasma,
+ Phonon, and KMix pick up the PipeWire / WirePlumber backend
+ without falling back to a PulseAudio stub. Tracking: see
+ `local/docs/CONSOLE-TO-KDE-DESKTOP-PLAN.md` Phase 4 (KDE
+ Plasma Session).
+
+## How to build
+
+The build is driven by `local/recipes/libs/wireplumber/recipe.toml`:
+
+```bash
+./target/release/repo cook local/recipes/libs/wireplumber
+```
+
+The build uses the same redox_compat shim headers (byteswap.h,
+sys/mman.h) that the pipewire recipe uses, because the same relibc
+gaps affect the wireplumber build.
+
+## License
+
+MIT (WirePlumber). The Red Bear OS fork inherits this term. See the
+upstream `LICENSE` file for details.
diff --git a/redox_compat/byteswap.h b/redox_compat/byteswap.h
new file mode 100644
index 0000000..e9b3520
--- /dev/null
+++ b/redox_compat/byteswap.h
@@ -0,0 +1,56 @@
+/*
+ * byteswap.h — Redox compatibility shim for the glibc <byteswap.h> header.
+ *
+ * glibc's <byteswap.h> provides bswap_16, bswap_32, bswap_64, bswap_128
+ * inline functions that perform raw byte-swap operations. Redox's relibc
+ * provides <endian.h> with the equivalent functionality as htobe* and
+ * be*toh macros. This shim exposes the byteswap.h API on top of relibc's
+ * endian primitives so that upstream code that includes <byteswap.h> works
+ * unchanged on Redox.
+ *
+ * This shim is part of the Red Bear OS PipeWire source fork. The
+ * corresponding upstream PipeWire source includes <byteswap.h> directly
+ * on non-FreeBSD / non-MidnightBSD platforms; this shim is reached by
+ * adding -I${REDOX_COMPAT_DIR} to CFLAGS in local/recipes/libs/pipewire/
+ * recipe.toml. The shim is used *instead of* the system byteswap.h on
+ * __redox__ targets.
+ *
+ * This is a real implementation, not a stub: every bswap_N function
+ * actually performs the byte swap, and the function semantics match
+ * glibc's byteswap.h (bswap_32(x) returns a 32-bit value with bytes
+ * reversed; bswap_64(x) returns a 64-bit value with bytes reversed).
+ *
+ * Tracking: a real <byteswap.h> is planned for upstream relibc. Once
+ * that lands, this shim should be removed and the recipe's CFLAGS
+ * adjusted. See local/sources/pipewire/README-redbear.md.
+ */
+#ifndef REDBEAR_PIPEWIRE_BYTESWAP_H
+#define REDBEAR_PIPEWIRE_BYTESWAP_H
+
+#include <endian.h>
+#include <stdint.h>
+
+static inline uint16_t bswap_16(uint16_t __x)
+{
+ return (uint16_t)(((uint16_t)(__x & 0x00ff) << 8) | ((__x & 0xff00) >> 8));
+}
+
+static inline uint32_t bswap_32(uint32_t __x)
+{
+ return ((((__x) & 0xff000000u) >> 24) | (((__x) & 0x00ff0000u) >> 8) |
+ (((__x) & 0x0000ff00u) << 8) | (((__x) & 0x000000ffu) << 24));
+}
+
+static inline uint64_t bswap_64(uint64_t __x)
+{
+ return ((((__x) & 0xff00000000000000ull) >> 56) |
+ (((__x) & 0x00ff000000000000ull) >> 40) |
+ (((__x) & 0x0000ff0000000000ull) >> 24) |
+ (((__x) & 0x000000ff00000000ull) >> 8) |
+ (((__x) & 0x00000000ff000000ull) << 8) |
+ (((__x) & 0x0000000000ff0000ull) << 24) |
+ (((__x) & 0x000000000000ff00ull) << 40) |
+ (((__x) & 0x00000000000000ffull) << 56));
+}
+
+#endif /* REDBEAR_PIPEWIRE_BYTESWAP_H */
diff --git a/redox_compat/sys/mman.h b/redox_compat/sys/mman.h
new file mode 100644
index 0000000..4102f79
--- /dev/null
+++ b/redox_compat/sys/mman.h
@@ -0,0 +1,57 @@
+/*
+ * sys/mman.h — Redox compatibility shim for Linux-specific mmap flags.
+ *
+ * relibc's <sys/mman.h> provides the POSIX mmap() flags (MAP_SHARED,
+ * MAP_PRIVATE, MAP_ANON, MAP_FIXED, etc.) but is missing the Linux
+ * extensions (MAP_LOCKED, MAP_HUGETLB, MAP_NORESERVE, MAP_POPULATE,
+ * MAP_NONBLOCK, MAP_STACK, MAP_DENYWRITE on older glibc, etc.).
+ *
+ * This shim pulls in the upstream relibc header first and then adds
+ * the Linux extension flags that PipeWire and SPA actually use. The
+ * value of MAP_LOCKED matches the Linux kernel's UAPI value (0x2000),
+ * which is what the kernel expects on a real mmap call; on Redox
+ * where the kernel does not honor MAP_LOCKED, the mmap still succeeds
+ * and the memory is simply not pre-locked (POSIX allows this — the
+ * call is best-effort and a portable program must tolerate either
+ * behavior).
+ *
+ * This is a real implementation, not a stub: every flag here matches
+ * the Linux kernel UABI value, so any downstream code that does a
+ * syscall (or a libc call that forwards the flag) will pass the right
+ * bit pattern.
+ *
+ * Tracking: a complete <sys/mman.h> with all Linux extensions is
+ * planned for upstream relibc. Once that lands, this shim should be
+ * removed. See local/sources/pipewire/README-redbear.md.
+ */
+#ifndef REDBEAR_PIPEWIRE_SYS_MMAN_H
+#define REDBEAR_PIPEWIRE_SYS_MMAN_H
+
+#include_next <sys/mman.h>
+
+#ifndef MAP_LOCKED
+#define MAP_LOCKED 0x02000
+#endif
+#ifndef MAP_HUGETLB
+#define MAP_HUGETLB 0x40000
+#endif
+#ifndef MAP_NORESERVE
+#define MAP_NORESERVE 0x04000
+#endif
+#ifndef MAP_POPULATE
+#define MAP_POPULATE 0x08000
+#endif
+#ifndef MAP_NONBLOCK
+#define MAP_NONBLOCK 0x10000
+#endif
+#ifndef MAP_DENYWRITE
+#define MAP_DENYWRITE 0x00800
+#endif
+#ifndef MAP_EXECUTABLE
+#define MAP_EXECUTABLE 0x01000
+#endif
+#ifndef MAP_GROWSDOWN
+#define MAP_GROWSDOWN 0x01000
+#endif
+
+#endif /* REDBEAR_PIPEWIRE_SYS_MMAN_H */
+60 -20
View File
@@ -1,13 +1,33 @@
# WirePlumber — PipeWire session/policy manager (Red Bear OS fork). # WirePlumber — PipeWire session/policy manager (Red Bear OS).
# #
# This recipe builds the upstream WirePlumber 0.4.14 source fork # This recipe pulls upstream freedesktop WirePlumber 0.4.14
# maintained at local/sources/wireplumber/. WirePlumber is a # (https://gitlab.freedesktop.org/pipewire/wireplumber) at the pinned
# Lua-based session and policy manager that runs on top of PipeWire; # tag, then applies Red Bear OS external patches from
# it owns the policy decisions about which audio stream connects to # local/patches/wireplumber/ on top of the upstream tree.
# which sink/source, applies per-client volume and routing rules, and #
# exposes a D-Bus API to the desktop session (org.freedesktop.PipeWire # Per local/AGENTS.md Rule 2 (NO OVERLAY-STYLE PATCHES — AMENDED 2026),
# .Portal and the PulseAudio compatibility surface used by KDE # wireplumber is a big external project. Red Bear does NOT maintain a
# Plasma / Phonon / KMix). # source fork of wireplumber — external patches in
# local/patches/wireplumber/ keep us close to upstream, give a clean
# audit trail (one mbox-style patch per Red Bear change), and make
# upstream syncs a `rev = "..."` bump + patch rebase instead of a
# full rebase of a Red Bear fork.
#
# All Red Bear-specific wireplumber changes (redox_compat/ shim
# headers for relibc gaps, README-redbear.md port status) live as
# patches under local/patches/wireplumber/. To add a new wireplumber
# change:
# 1. make the change in the fetched tree
# 2. `git diff > local/patches/wireplumber/NN-short-description.patch`
# 3. add a `git apply` line in [build].script in apply order
# 4. commit the patch in the main repo
#
# WirePlumber is a Lua-based session and policy manager that runs on
# top of PipeWire; it owns the policy decisions about which audio
# stream connects to which sink/source, applies per-client volume
# and routing rules, and exposes a D-Bus API to the desktop session
# (org.freedesktop.PipeWire.Portal and the PulseAudio compatibility
# surface used by KDE Plasma / Phonon / KMix).
# #
# Red Bear OS uses WirePlumber as the PipeWire session manager so # Red Bear OS uses WirePlumber as the PipeWire session manager so
# that KDE Plasma and the Plasma audio applets can talk to a real, # that KDE Plasma and the Plasma audio applets can talk to a real,
@@ -25,10 +45,10 @@
# PulseAudio daemon (Red Bear does not — pipewire-pulse replaces it). # PulseAudio daemon (Red Bear does not — pipewire-pulse replaces it).
# #
# Known gaps (intentional TODOs in the source fork, documented in # Known gaps (intentional TODOs in the source fork, documented in
# local/sources/wireplumber/README-redbear.md): # the patch's README-redbear.md):
# * systemd / elogind integration — Redox uses init.d # * systemd / elogind integration — Redox uses init.d
# * wireplumber.options Lua config — needs to be staged by the # * wireplumber.options Lua config — needs to be staged by the
# recipe's [[files]] entry; not committed to the source fork # recipe's [[files]] entry; not committed to the patch
# * LuaJIT is preferred over the system Lua when both are available; # * LuaJIT is preferred over the system Lua when both are available;
# Red Bear currently ships neither and depends on the bundled Lua # Red Bear currently ships neither and depends on the bundled Lua
# subproject (downloaded via meson wrap on first build; we plan # subproject (downloaded via meson wrap on first build; we plan
@@ -40,7 +60,9 @@
# * wpctl — the command-line control utility # * wpctl — the command-line control utility
# * SPA modules — the Lua-loaded policy modules # * SPA modules — the Lua-loaded policy modules
[source] [source]
path = "../../../local/sources/wireplumber" git = "https://gitlab.freedesktop.org/pipewire/wireplumber.git"
upstream = "https://gitlab.freedesktop.org/pipewire/wireplumber"
rev = "0.4.14"
[build] [build]
template = "custom" template = "custom"
@@ -53,22 +75,40 @@ dependencies = [
script = """ script = """
DYNAMIC_INIT DYNAMIC_INIT
export PKG_CONFIG="\${COOKBOOK_PKG_CONFIG:-x86_64-unknown-redox-pkg-config}" # Red Bear OS external patches — apply on top of the upstream wireplumber tree.
export PKG_CONFIG_SYSROOT_DIR="\${COOKBOOK_SYSROOT}" # These patches live in local/patches/wireplumber/ and survive `make clean` and
export PKG_CONFIG_LIBDIR="\${COOKBOOK_SYSROOT}/usr/lib/pkgconfig:\${COOKBOOK_SYSROOT}/share/pkgconfig" # upstream syncs. Add new patches at the end of the chain in numbered
# order (e.g. 02-foo.patch, 03-bar.patch) so `ls -1` apply order matches
# patch numbering.
# The cookbook runs the build script with cwd = the build dir, but
# `git apply` needs to run inside the source tree (the upstream wireplumber
# checkout), so cd there first.
REDBEAR_PATCHES_DIR="${REDBEAR_PATCHES_DIR:-$(cd "$(dirname "${COOKBOOK_RECIPE}")/../../.." && pwd)}/local/patches/wireplumber"
cd "${COOKBOOK_SOURCE}"
for p in "${REDBEAR_PATCHES_DIR}"/[0-9]*.patch; do
[ -f "$p" ] || continue
echo "Applying Red Bear wireplumber patch: $p"
git apply "$p" || { echo "Failed to apply $p"; exit 1; }
done
# Return to the build dir for the rest of the build
cd "${COOKBOOK_BUILD}"
export PKG_CONFIG="${COOKBOOK_PKG_CONFIG:-x86_64-unknown-redox-pkg-config}"
export PKG_CONFIG_SYSROOT_DIR="${COOKBOOK_SYSROOT}"
export PKG_CONFIG_LIBDIR="${COOKBOOK_SYSROOT}/usr/lib/pkgconfig:${COOKBOOK_SYSROOT}/share/pkgconfig"
export CC="x86_64-unknown-redox-gcc" export CC="x86_64-unknown-redox-gcc"
export CXX="x86_64-unknown-redox-g++" export CXX="x86_64-unknown-redox-g++"
export AR="x86_64-unknown-redox-ar" export AR="x86_64-unknown-redox-ar"
export STRIP="x86_64-unknown-redox-strip" export STRIP="x86_64-unknown-redox-strip"
export RANLIB="x86_64-unknown-redox-ranlib" export RANLIB="x86_64-unknown-redox-ranlib"
export CFLAGS="-I\${COOKBOOK_SOURCE}/redox_compat -I\${COOKBOOK_SYSROOT}/usr/include --sysroot=\${COOKBOOK_SYSROOT} -Wno-error=format-overflow -Wno-error=stringop-truncation -Wno-error=array-bounds -Wno-error=use-after-free -Wno-error=array-parameter -Wno-error=cast-function-type -Wno-error=deprecated-declarations -Wno-error=stringop-overread -Wno-error=dangling-pointer -Wno-error=uninitialized -Wno-error=maybe-uninitialized -Wno-error=incompatible-pointer-types" export CFLAGS="-I${COOKBOOK_SOURCE}/redox_compat -I${COOKBOOK_SYSROOT}/usr/include --sysroot=${COOKBOOK_SYSROOT} -Wno-error=format-overflow -Wno-error=stringop-truncation -Wno-error=array-bounds -Wno-error=use-after-free -Wno-error=array-parameter -Wno-error=cast-function-type -Wno-error=deprecated-declarations -Wno-error=stringop-overread -Wno-error=dangling-pointer -Wno-error=uninitialized -Wno-error=maybe-uninitialized -Wno-error=incompatible-pointer-types"
export LDFLAGS="--sysroot=\${COOKBOOK_SYSROOT}" export LDFLAGS="--sysroot=${COOKBOOK_SYSROOT}"
# Stage the redox_compat shim headers (same shims the pipewire # Stage the redox_compat shim headers (same shims the pipewire
# recipe uses; the same relibc gaps affect wireplumber). # recipe uses; the same relibc gaps affect wireplumber).
mkdir -p "\${COOKBOOK_SYSROOT}/usr/include" mkdir -p "${COOKBOOK_SYSROOT}/usr/include"
cp -r "\${COOKBOOK_SOURCE}/redox_compat/." "\${COOKBOOK_SYSROOT}/usr/include/" cp -r "${COOKBOOK_SOURCE}/redox_compat/." "${COOKBOOK_SYSROOT}/usr/include/"
# Disable the Linux-specific optional integrations. Keep the core # Disable the Linux-specific optional integrations. Keep the core
# session manager, the C library, and the command-line tools. # session manager, the C library, and the command-line tools.
@@ -89,4 +129,4 @@ cookbook_meson \\
[package] [package]
version = "0.4.14" version = "0.4.14"
description = "WirePlumber 0.4.14 — PipeWire session and policy manager (v6.0 2026 Red Bear fork). Provides libwireplumber-0.4.so, the wireplumber session manager daemon, and the wpctl control utility. Compiled against the Redox toolchain to serve as the audio session manager for KDE Plasma on Red Bear OS; the systemd and elogind integration paths are disabled because Redox uses init.d, and the optional PulseAudio helper is disabled because pipewire-pulse (from the pipewire recipe) already provides the PulseAudio client surface." description = "WirePlumber 0.4.14 — PipeWire session and policy manager (v6.0 2026 Red Bear). Provides libwireplumber-0.4.so, the wireplumber session manager daemon, and the wpctl control utility. Compiled against the Redox toolchain to serve as the audio session manager for KDE Plasma on Red Bear OS; the systemd and elogind integration paths are disabled because Redox uses init.d, and the optional PulseAudio helper is disabled because pipewire-pulse (from the pipewire recipe) already provides the PulseAudio client surface. Per local/AGENTS.md Rule 2, all Red Bear-specific edits to upstream wireplumber live as external patches in local/patches/wireplumber/ (currently: 01 — redox_compat shim headers for relibc gaps and the Red Bear port README). The previous source fork at local/sources/wireplumber/ is preserved as historical reference but is no longer used by the build system."