diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bce7023372d..17d27c5ee97 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -204,7 +204,7 @@ jobs: ext: tar.gz content: application/gzip - name: Linux Tiles Sounds x64 (SDL3) - os: ubuntu-24.04 + os: ubuntu-22.04 android: none libbacktrace: 1 tiles: 1 @@ -362,9 +362,12 @@ jobs: if: runner.os == 'Linux' && matrix.android == 'none' && !matrix.wasm && matrix.sdl3 == 1 run: | sudo apt-get update + wget -O /tmp/llvm.sh https://apt.llvm.org/llvm.sh + chmod +x /tmp/llvm.sh + sudo /tmp/llvm.sh 18 sudo apt-get install libflac-dev libogg-dev libvorbis-dev libmpg123-dev libwavpack-dev \ libfreetype-dev libharfbuzz-dev libjpeg-dev libpng-dev libwebp-dev libtiff-dev \ - libpulse-dev libncursesw5-dev ccache gettext parallel pkg-config cmake \ + libpulse-dev libncursesw5-dev ccache gettext parallel pkg-config cmake patchelf \ libx11-dev libxext-dev libxcursor-dev libxi-dev libxfixes-dev libxrandr-dev \ libxrender-dev libxss-dev libxtst-dev libxkbcommon-dev libwayland-dev \ libdecor-0-dev libdrm-dev libgbm-dev libudev-dev libpipewire-0.3-dev \ @@ -375,25 +378,31 @@ jobs: uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4 with: path: ${{ runner.workspace }}/sdl3_prefix - key: sdl3-stack-sdl-3.4.4-image-3.4.2-ttf-3.2.2-mixer-3.2.0-${{ runner.os }}-v2 + key: sdl3-stack-sdl-3.4.10-image-3.4.4-ttf-3.2.2-mixer-3.2.4-ubuntu-22.04-v4 - name: Build SDL3 stack from source (Linux, SDL3) if: runner.os == 'Linux' && matrix.android == 'none' && !matrix.wasm && matrix.sdl3 == 1 && steps.cache-sdl3-release.outputs.cache-hit != 'true' run: | PREFIX=${{ runner.workspace }}/sdl3_prefix export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig:$PREFIX/lib/x86_64-linux-gnu/pkgconfig export CMAKE_PREFIX_PATH=$PREFIX - git clone --depth 1 --branch release-3.4.4 https://github.com/libsdl-org/SDL.git sdl3_src + git clone --depth 1 --branch release-3.4.10 https://github.com/libsdl-org/SDL.git sdl3_src cmake -S sdl3_src -B sdl3_build \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=$PREFIX \ -DBUILD_SHARED_LIBS=ON cmake --build sdl3_build -j$(nproc) cmake --install sdl3_build - git clone --depth 1 --branch release-3.4.2 https://github.com/libsdl-org/SDL_image.git sdl3_image_src + git clone --depth 1 --branch release-3.4.4 https://github.com/libsdl-org/SDL_image.git sdl3_image_src cmake -S sdl3_image_src -B sdl3_image_build \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=$PREFIX \ -DSDLIMAGE_VENDORED=OFF \ + -DSDLIMAGE_DEPS_SHARED=OFF \ + -DSDLIMAGE_STRICT=ON \ + -DSDLIMAGE_PNG=ON -DSDLIMAGE_PNG_LIBPNG=ON \ + -DSDLIMAGE_JPG=ON \ + -DSDLIMAGE_AVIF=OFF -DSDLIMAGE_JXL=OFF \ + -DSDLIMAGE_TIF=OFF -DSDLIMAGE_WEBP=OFF \ -DBUILD_SHARED_LIBS=ON cmake --build sdl3_image_build -j$(nproc) cmake --install sdl3_image_build @@ -402,29 +411,37 @@ jobs: -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=$PREFIX \ -DSDLTTF_VENDORED=OFF \ + -DSDLTTF_STRICT=ON \ + -DSDLTTF_PLUTOSVG=OFF \ -DBUILD_SHARED_LIBS=ON cmake --build sdl3_ttf_build -j$(nproc) cmake --install sdl3_ttf_build - git clone --depth 1 --branch release-3.2.0 https://github.com/libsdl-org/SDL_mixer.git sdl3_mixer_src + git clone --depth 1 --branch release-3.2.4 https://github.com/libsdl-org/SDL_mixer.git sdl3_mixer_src cmake -S sdl3_mixer_src -B sdl3_mixer_build \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=$PREFIX \ -DSDLMIXER_VENDORED=OFF \ - -DSDLMIXER_FLAC=ON -DSDLMIXER_FLAC_LIBFLAC=ON \ - -DSDLMIXER_MP3=ON -DSDLMIXER_MP3_MPG123=ON \ - -DSDLMIXER_VORBIS=VORBISFILE \ + -DSDLMIXER_DEPS_SHARED=OFF \ + -DSDLMIXER_STRICT=ON \ + -DSDLMIXER_FLAC=ON -DSDLMIXER_FLAC_LIBFLAC=ON -DSDLMIXER_FLAC_DRFLAC=OFF \ + -DSDLMIXER_MP3=ON -DSDLMIXER_MP3_MPG123=ON -DSDLMIXER_MP3_DRMP3=OFF \ + -DSDLMIXER_VORBIS_VORBISFILE=ON -DSDLMIXER_VORBIS_STB=OFF -DSDLMIXER_VORBIS_TREMOR=OFF \ -DSDLMIXER_WAVPACK=ON \ - -DSDLMIXER_OPUS=OFF -DSDLMIXER_MOD=OFF -DSDLMIXER_MIDI=OFF \ + -DSDLMIXER_OPUS=OFF -DSDLMIXER_MOD=OFF -DSDLMIXER_MIDI=OFF -DSDLMIXER_GME=OFF \ -DBUILD_SHARED_LIBS=ON cmake --build sdl3_mixer_build -j$(nproc) cmake --install sdl3_mixer_build mkdir -p $PREFIX/share cp sdl3_src/LICENSE.txt $PREFIX/share/LICENSE-SDL.txt + cp sdl3_image_src/LICENSE.txt $PREFIX/share/LICENSE-SDL3_image.txt + cp sdl3_ttf_src/LICENSE.txt $PREFIX/share/LICENSE-SDL3_ttf.txt cp sdl3_mixer_src/LICENSE.txt $PREFIX/share/LICENSE-SDL3_mixer.txt - name: Stage SDL3 license files (Linux, SDL3) if: runner.os == 'Linux' && matrix.android == 'none' && !matrix.wasm && matrix.sdl3 == 1 run: | cp ${{ runner.workspace }}/sdl3_prefix/share/LICENSE-SDL.txt ${{ github.workspace }}/LICENSE-SDL.txt + cp ${{ runner.workspace }}/sdl3_prefix/share/LICENSE-SDL3_image.txt ${{ github.workspace }}/LICENSE-SDL3_image.txt + cp ${{ runner.workspace }}/sdl3_prefix/share/LICENSE-SDL3_ttf.txt ${{ github.workspace }}/LICENSE-SDL3_ttf.txt cp ${{ runner.workspace }}/sdl3_prefix/share/LICENSE-SDL3_mixer.txt ${{ github.workspace }}/LICENSE-SDL3_mixer.txt - name: Install Emscripten (WebAssembly) if: matrix.wasm @@ -545,7 +562,7 @@ jobs: export PKG_CONFIG_PATH="$RUNNER_WORKSPACE/sdl3_prefix/lib/pkgconfig:$RUNNER_WORKSPACE/sdl3_prefix/lib/x86_64-linux-gnu/pkgconfig" export LD_LIBRARY_PATH="$RUNNER_WORKSPACE/sdl3_prefix/lib:$RUNNER_WORKSPACE/sdl3_prefix/lib/x86_64-linux-gnu" fi - make COMPILER=clang++-18 -j$((`nproc`+0)) TILES=${{ matrix.tiles }} SOUND=${{ matrix.tiles }} SDL3=${{ matrix.sdl3 == 1 && '1' || '0' }} RELEASE=1 LOCALIZE=1 LANGUAGES=all BACKTRACE=1 LIBBACKTRACE=${{ matrix.libbacktrace }} WARN_STALE_DATA=1 PCH=0 bindist + make COMPILER=clang++-18 -j$((`nproc`+0)) TILES=${{ matrix.tiles }} SOUND=${{ matrix.sound }} SDL3=${{ matrix.sdl3 == 1 && '1' || '0' }} RELEASE=1 LOCALIZE=1 LANGUAGES=all BACKTRACE=1 LIBBACKTRACE=${{ matrix.libbacktrace }} WARN_STALE_DATA=1 PCH=0 bindist mv cataclysmdda-0.J.tar.gz cdda-${{ matrix.artifact }}-${{ needs.release.outputs.timestamp }}.tar.gz - name: Build CDDA (WebAssembly) if: matrix.wasm && success() diff --git a/Makefile b/Makefile index 2809e0d3881..f897ebcc044 100644 --- a/Makefile +++ b/Makefile @@ -1026,15 +1026,25 @@ ifeq ($(TARGETSYSTEM),LINUX) CFLAGS += -mcx16 CXXFLAGS += -mcx16 BINDIST_EXTRAS += cataclysm-launcher + ifeq ($(SDL3),1) + # bundle-sdl3-linux.sh fills bindist/lib/; RUNPATH=$$ORIGIN/lib lets + # the binary resolve bundled libs without the launcher. + LDFLAGS += -Wl,-rpath,'$$ORIGIN/lib' + BUNDLE_SDL3_LINUX = 1 + endif ifneq ("$(wildcard LICENSE-SDL.txt)","") - ifeq ($(SDL3),1) - SDL_solibs = $(shell ldd $(TARGET) | awk '/libSDL3/ {print $$3}') - else + ifneq ($(SDL3),1) SDL_solibs = $(shell ldd $(TARGET) | grep libSDL2-2\.0 | cut -d ' ' -f 3) + INSTALL_EXTRAS += $(SDL_solibs) endif - INSTALL_EXTRAS += $(SDL_solibs) BINDIST_EXTRAS += LICENSE-SDL.txt ifeq ($(SDL3),1) + ifneq ("$(wildcard LICENSE-SDL3_image.txt)","") + BINDIST_EXTRAS += LICENSE-SDL3_image.txt + endif + ifneq ("$(wildcard LICENSE-SDL3_ttf.txt)","") + BINDIST_EXTRAS += LICENSE-SDL3_ttf.txt + endif ifneq ("$(wildcard LICENSE-SDL3_mixer.txt)","") BINDIST_EXTRAS += LICENSE-SDL3_mixer.txt endif @@ -1521,6 +1531,9 @@ $(BINDIST): distclean version $(TARGET) $(ZZIP_BIN) $(L10N) $(BINDIST_EXTRAS) $( $(foreach lib,$(INSTALL_EXTRAS),install --strip $(lib) $(BINDIST_DIR);) ifdef LANGUAGES cp -R --parents lang/mo $(BINDIST_DIR) +endif +ifeq ($(BUNDLE_SDL3_LINUX),1) + bash build-scripts/bundle-sdl3-linux.sh $(BINDIST_DIR) $(BINDIST_DIR)/$(notdir $(TARGET)) endif $(BINDIST_CMD) diff --git a/build-scripts/bundle-sdl3-linux.sh b/build-scripts/bundle-sdl3-linux.sh new file mode 100755 index 00000000000..5da540e86ad --- /dev/null +++ b/build-scripts/bundle-sdl3-linux.sh @@ -0,0 +1,261 @@ +#!/usr/bin/env bash +# Bundle the SDL3 ldd closure into a Linux bindist's lib/. +# Usage: bundle-sdl3-linux.sh +# Copies non-platform deps (with SONAME symlinks), RUNPATH=$ORIGIN each. + +set -euo pipefail + +BINDIST_DIR="${1:?bindist dir required}" +MAIN_BIN="${2:?main binary required}" +LIB_DIR="$BINDIST_DIR/lib" + +mkdir -p "$LIB_DIR" + +# Platform library name patterns. ldd entries matching any of these are +# treated as host-owned: not copied, walking stops. +PLATFORM_PATTERNS=( + # libc base + 'libc\.so' + 'libc\.so\.6' + 'libdl\.so' + 'libm\.so' + 'libpthread\.so' + 'libstdc\+\+\.so' + 'libgcc_s\.so' + 'librt\.so' + 'libresolv\.so' + 'ld-linux-.*\.so' + 'linux-vdso\.so' + # X11 + 'libX11\.so' + 'libxcb.*\.so' + 'libXext\.so' + 'libXcursor\.so' + 'libXi\.so' + 'libXfixes\.so' + 'libXrandr\.so' + 'libXrender\.so' + 'libXss\.so' + 'libXtst\.so' + 'libXau\.so' + 'libXdmcp\.so' + 'libICE\.so' + 'libSM\.so' + # Wayland / input + 'libwayland-.*\.so' + 'libxkbcommon.*\.so' + 'libdecor.*\.so' + 'libdbus-1\.so' + 'libibus-1\.0\.so' + # Display / DRM + 'libdrm\.so' + 'libgbm\.so' + 'libudev\.so' + 'libglapi\.so' + # GL / Vulkan + 'libGL\.so' + 'libGLX\.so' + 'libGLdispatch\.so' + 'libOpenGL\.so' + 'libEGL\.so' + 'libvulkan\.so' + # Audio + 'libasound\.so' + 'libpulse\.so' + 'libpulsecommon-.*\.so' + 'libpipewire-.*\.so' + 'libspa-.*\.so' + 'libsystemd\.so' + 'libasyncns\.so' + 'libsndfile\.so' + # Misc base + 'libffi\.so' + 'libbsd\.so' + 'libmd\.so' +) + +is_platform() { + local soname="$1" + for pat in "${PLATFORM_PATTERNS[@]}"; do + if [[ "$soname" =~ ^${pat} ]]; then + return 0 + fi + done + return 1 +} + +# Read ldd output on stdin, emit "sonamerealpath" per non-platform +# entry. Pathless entries (linux-vdso) are skipped. +collect_libs() { + awk ' + /=> not found/ { next } + / => / { + soname = $1 + path = $3 + if (path == "" || path ~ /^\(/) next + print soname "\t" path + } + ' +} + +declare -A COPIED +declare -A SEEN +declare -A ALIAS +# Map of copied real lib basename -> original resolved system path. Used for +# license attribution via dpkg -S after the walk completes. +declare -A REAL_TO_ORIGIN + +ensure_alias() { + local alias_name="$1" real_base="$2" + if [[ -z "$alias_name" || "$alias_name" == "$real_base" ]]; then return; fi + local key="$alias_name->$real_base" + if [[ -n "${ALIAS[$key]:-}" ]]; then return; fi + ALIAS[$key]=1 + ln -sf "$real_base" "$LIB_DIR/$alias_name" +} + +walk_closure() { + local target="$1" + if [[ -n "${SEEN[$target]:-}" ]]; then return; fi + SEEN[$target]=1 + + local soname realpath_resolved real base_real base_path + while IFS=$'\t' read -r soname realpath_resolved; do + [[ -z "$soname" || -z "$realpath_resolved" ]] && continue + if is_platform "$soname"; then + continue + fi + # Resolve symlinks to the real file. + real="$(readlink -f "$realpath_resolved")" + base_real="$(basename "$real")" + base_path="$(basename "$realpath_resolved")" + + # Always create the soname + resolved-path aliases (independent of + # whether the real file was copied already on a prior alias). + ensure_alias "$soname" "$base_real" + ensure_alias "$base_path" "$base_real" + + if [[ -z "${COPIED[$real]:-}" ]]; then + COPIED[$real]=1 + REAL_TO_ORIGIN[$base_real]="$real" + cp -L "$real" "$LIB_DIR/$base_real" + # Walk this library's own ldd closure. + walk_closure "$real" + fi + done < <(ldd "$target" 2>/dev/null | collect_libs) +} + +walk_closure "$MAIN_BIN" + +# RUNPATH=$ORIGIN on each bundled lib: DT_RUNPATH does not inherit to +# grandchild loads, so each .so needs its own to find sibling peers. +if ! command -v patchelf >/dev/null 2>&1; then + echo "patchelf not available; bundled libs will not resolve transitive deps" >&2 + exit 1 +fi +for so in "$LIB_DIR"/*.so*; do + if [[ -f "$so" && ! -L "$so" ]]; then + # $ORIGIN is a literal dynamic-loader token, not a shell variable. + # shellcheck disable=SC2016 + patchelf --set-rpath '$ORIGIN' "$so" + fi +done + +# The main binary is linked with an absolute RUNPATH to the build-time SDL3 +# prefix as well as $ORIGIN/lib; pin it to the bundle alone so the shipped +# libs win and the build prefix never leaks into resolution. +# shellcheck disable=SC2016 +patchelf --set-rpath '$ORIGIN/lib' "$MAIN_BIN" + +# Gate: every bundled lib resolves with LD_LIBRARY_PATH unset, and the main +# binary resolves its SDL3 deps from bindist/lib/ not the host. +echo "Verifying main binary closure with LD_LIBRARY_PATH unset" +if env -u LD_LIBRARY_PATH ldd "$MAIN_BIN" 2>&1 | grep -E 'not found|=>\s*$' >&2; then + echo "ERROR: main binary has unresolved libraries" >&2 + exit 2 +fi +echo "Verifying each bundled lib closure" +for so in "$LIB_DIR"/*.so*; do + if [[ -f "$so" && ! -L "$so" ]]; then + if env -u LD_LIBRARY_PATH ldd "$so" 2>&1 | grep -E 'not found' >&2; then + echo "ERROR: $so has unresolved libraries" >&2 + exit 3 + fi + fi +done + +# Assert each SDL3-family dep resolves under $LIB_DIR: catch a host SDL3 +# winning rpath order over the bundle. +LIB_DIR_REAL="$(readlink -f "$LIB_DIR")" +while IFS= read -r line; do + soname="$(awk '{print $1}' <<<"$line")" + target="$(awk '{print $3}' <<<"$line")" + [[ -z "$target" || "$target" == "(" ]] && continue + case "$soname" in + libSDL3*|libfreetype*|libharfbuzz*|libpng*|libjpeg*|libFLAC*|libmpg123*|libvorbis*|libogg*|libwavpack*) + target_real="$(readlink -f "$target")" + case "$target_real" in + "$LIB_DIR_REAL"/*) ;; + *) + echo "ERROR: $soname resolved to $target_real (outside $LIB_DIR_REAL)" >&2 + exit 4 + ;; + esac + ;; + esac +done < <(env -u LD_LIBRARY_PATH ldd "$MAIN_BIN" 2>/dev/null | grep ' => ') + +echo "SDL3 closure bundle complete in $LIB_DIR" + +# Per-lib license: dpkg -S the ORIGINAL resolved path (the lib/ copy is not +# in any apt db). Source-built SDL3 libs use the staged LICENSE-SDL*.txt. +LICENSE_DIR="$BINDIST_DIR/licenses" +mkdir -p "$LICENSE_DIR" +declare -A LICENSED_PKGS +{ + echo "Bundled third-party libraries (bindist/lib/):" + echo +} > "$LICENSE_DIR/README.txt" +for base_real in "${!REAL_TO_ORIGIN[@]}"; do + origin="${REAL_TO_ORIGIN[$base_real]}" + # Source-built SDL3 libs are not registered in apt; skip and rely on the + # staged LICENSE-SDL*.txt at the bindist root. + case "$base_real" in + libSDL3*) + echo "$base_real: covered by LICENSE-SDL.txt (libSDL3*_mixer also LICENSE-SDL3_mixer.txt)" >> "$LICENSE_DIR/README.txt" + continue + ;; + esac + # dpkg registers some base libs under the pre-usrmerge /lib path while + # readlink -f yields /usr/lib (or vice versa). Try both before giving up. + # dpkg -S exits non-zero on no match, so swallow it under set -e. + pkg="$(dpkg -S "$origin" 2>/dev/null | head -n1 | cut -d: -f1)" || pkg="" + if [[ -z "$pkg" ]]; then + case "$origin" in + /usr/lib/*) alt="${origin#/usr}" ;; + /lib/*) alt="/usr$origin" ;; + *) alt="" ;; + esac + if [[ -n "$alt" ]]; then + pkg="$(dpkg -S "$alt" 2>/dev/null | head -n1 | cut -d: -f1)" || pkg="" + fi + fi + if [[ -z "$pkg" ]]; then + echo "$base_real: dpkg -S returned no owner; manual attribution required" >> "$LICENSE_DIR/README.txt" + continue + fi + if [[ -n "${LICENSED_PKGS[$pkg]:-}" ]]; then + echo "$base_real: covered by licenses/${pkg}.copyright" >> "$LICENSE_DIR/README.txt" + continue + fi + LICENSED_PKGS[$pkg]=1 + src_copyright="/usr/share/doc/$pkg/copyright" + if [[ -f "$src_copyright" ]]; then + cp "$src_copyright" "$LICENSE_DIR/${pkg}.copyright" + echo "$base_real: licenses/${pkg}.copyright" >> "$LICENSE_DIR/README.txt" + else + echo "$base_real: $src_copyright not found; manual attribution required" >> "$LICENSE_DIR/README.txt" + fi +done + +echo "License staging complete in $LICENSE_DIR" diff --git a/cataclysm-launcher b/cataclysm-launcher index 5083bbdc282..21235382f5b 100755 --- a/cataclysm-launcher +++ b/cataclysm-launcher @@ -45,7 +45,7 @@ fi if [ "$BIN" ] then - env LD_LIBRARY_PATH="${DIR}:${LD_LIBRARY_PATH}" ./"${BIN}" "$@" + env LD_LIBRARY_PATH="${DIR}/lib:${DIR}:${LD_LIBRARY_PATH}" ./"${BIN}" "$@" else printerr "Couldn't find cataclysm game binary in '$DIR'/" exit 1