From 027598672042f0e80c60efdd51a250b9d66634fd Mon Sep 17 00:00:00 2001 From: david Date: Fri, 2 Oct 2026 03:24:18 +0200 Subject: [PATCH] fix: make linux libmpv.so portable (ALSA config dir, fonts, strip) Two runtime bugs in the shipped artifact: 1. ALSA: the static libasound carried ALSA_CONFIG_DIR pointing at the build prefix (linux_prefix/share/alsa), so snd_pcm_open("default") failed on any machine without that path ("Unknown PCM default", video worked, audio did not). Build alsa-lib with --with-configdir=/usr/share/alsa so the compile-time default is the canonical system location. 2. Size: the release .so still contained ~110 MB of DWARF debug sections (whole ffmpeg tree); strip --strip-all the artifact in the collect step, matching the windows build. Also pin fontconfig's sysconfdir/localstatedir to /etc and /var so the CONFIGDIR/FONTCONFIG_PATH/FC_CACHEDIR constants compiled into libass's font stack resolve on any standard install (the runtime config search falls back to the compiled-in CONFIGDIR and a built-in default config when no FONTCONFIG_FILE/FONTCONFIG_PATH is set). The workflow now verifies the artifact: ldd shows only system libs, no debug sections remain, and no build-machine paths leaked into the binary. --- .github/workflows/build-linux.yml | 21 +++++++++++++++++++++ ci/build-libmpv-linux.sh | 20 +++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml index 634f454..dd09797 100644 --- a/.github/workflows/build-linux.yml +++ b/.github/workflows/build-linux.yml @@ -82,6 +82,27 @@ jobs: echo "=== contents ===" ls -l artifact-libmpv + # Verify the artifact is self-contained and portable: (1) it only links + # against system libs (no vendored .so), (2) it carries no debug sections + # (strip worked, artifact stays small), and (3) no build-machine paths + # leaked into the binary (the runtime config lookup must not depend on the + # runner's prefix - that is what broke ALSA before). + - name: Verify artifact (ldd, size, no build paths) + run: | + cd artifact-libmpv + echo "=== dynamic deps (system libs only) ===" + ldd libmpv.so + echo "=== debug sections (expect none) ===" + readelf -S libmpv.so | grep -c '\.debug' || true + echo "=== size ===" + du -h libmpv.so + echo "=== build-machine paths (expect no match) ===" + if strings -a libmpv.so | grep -q "linux_prefix\|/home/runner\|mpv-natives"; then + echo "ERROR: build paths found in libmpv.so" + exit 1 + fi + echo "OK: no build paths" + - name: Checksums run: | cd artifact-libmpv diff --git a/ci/build-libmpv-linux.sh b/ci/build-libmpv-linux.sh index 0d81d3a..57e6bfc 100644 --- a/ci/build-libmpv-linux.sh +++ b/ci/build-libmpv-linux.sh @@ -137,7 +137,13 @@ _alsa () { # because the static archive is linked into the shared libmpv.so, and # alsa's configure only adds -fPIC for shared builds. ( cd .. && autoreconf -fi ) - CFLAGS="$CFLAGS -fPIC" ../configure --prefix="$prefix_dir" $commonflags + # --with-configdir pins the ALSA_CONFIG_DIR compile-time default to the + # canonical system path instead of our build prefix. alsa-lib looks up its + # config at this path at runtime (env ALSA_CONFIG_DIR / ALSA_CONFIG_PATH + # override); leaving it at $prefix_dir/share/alsa makes snd_pcm_open("default") + # fail on any machine that does not carry that build path. + CFLAGS="$CFLAGS -fPIC" ../configure --prefix="$prefix_dir" \ + --with-configdir=/usr/share/alsa $commonflags makeplusinstall popd } @@ -149,7 +155,15 @@ _fontconfig () { # expat is the XML backend (our static build); no tests/tools/nls. freetype # resolves to our own static build via PKG_CONFIG_PATH (we link it into # libmpv, not fc's system one). + # sysconfdir/localstatedir are pinned to the canonical system paths so the + # config paths compiled into libfontconfig (CONFIGDIR, FONTCONFIG_PATH, + # FC_CACHEDIR) point at /etc/fonts on any machine, not at our build prefix. + # fontconfig loads its config from (in order): $FONTCONFIG_FILE, + # $FONTCONFIG_PATH, the compiled-in CONFIGDIR, then its built-in default + # config. With sysconfdir=/etc the compiled-in paths match every standard + # Linux install, so libass's font lookup works without any env vars. meson setup .. --buildtype release -Dprefix="$prefix_dir" -Dlibdir=lib \ + -Dsysconfdir=/etc -Dlocalstatedir=/var \ -Dxml-backend=expat -Dtests=disabled -Dtools=disabled -Dnls=disabled \ -Ddefault_library=static makeplusinstall @@ -309,6 +323,10 @@ LIBMPV_SO=$(find $build -maxdepth 1 -type f -name 'libmpv.so*' | sort -V | tail # jlibmpv loads libmpv.so (no version suffix), so copy the versioned object # under the versionless name. cp -pv "$LIBMPV_SO" artifact/libmpv.so +# The build releases with --buildtype release but the object still carries its +# debug sections (~110 MB here: the whole ffmpeg tree's DWARF), so strip it +# explicitly (like the windows build) to get a small distributable. +strip --strip-all artifact/libmpv.so echo "=== artifact contents ===" ls -l artifact