From f81025a0dab8a87dfc2769abbb79c8ec2aee172a Mon Sep 17 00:00:00 2001 From: Nils Schlemminger Date: Wed, 11 Nov 2026 16:55:26 +0100 Subject: [PATCH] Bundle the X11 window libraries in the AppImage The AppImage catalog test (Ubuntu 22.04) quit at start with "Library libxkbcommon-x11.so could not be loaded": winit loads its window libraries at run time and the AppImage carried none. - build.sh: copy libxkbcommon, libxkbcommon-x11, libxcb-xkb, libXcursor, libXi and their dependencies to usr/lib, point the editor and the parts manager there with patchelf, ship the packages' copyright files - build.sh: refuse a library that is neither bundled nor on every system, and bundled libraries needing a newer glibc than the programs - build.sh: ship the AppStream data as appdata.xml in the AppImage - ci.yml: install patchelf and the libraries in the Debian 12 container - installation.md, CHANGELOG.md Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 3 ++- CHANGELOG.md | 4 +++ docs/installation.md | 5 +++- installer/linux/build.sh | 56 ++++++++++++++++++++++++++++++++++++++-- 4 files changed, 64 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b57f6afb..6fc964ca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -85,7 +85,8 @@ jobs: run: | apt-get update apt-get install -y --no-install-recommends ca-certificates curl git build-essential pkg-config file dpkg-dev rpm \ - libxkbcommon-dev libgtk-3-dev libwayland-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev + libxkbcommon-dev libgtk-3-dev libwayland-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev \ + patchelf libxkbcommon-x11-0 libxcursor1 libxi6 - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@1.97.0 - uses: taiki-e/install-action@v2 diff --git a/CHANGELOG.md b/CHANGELOG.md index 1dde3556..d6c7f1b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ its GitHub release ([docs/releasing.md](docs/releasing.md)). ## [0.1.2] - unreleased +- **AppImage on more systems:** the AppImage carries the keyboard and cursor libraries + of X11 (xkbcommon, Xcursor, Xi), so the editor and the parts manager start on systems + without them instead of quitting with *Library libxkbcommon-x11.so could not be + loaded*. - **Invisible grid lines:** connection points and wire ends off the drawing grid, as in imported drawings or on device boxes of any size, add invisible grid lines through them. The pointer snaps to them where they are nearer than the grid, so wires can be diff --git a/docs/installation.md b/docs/installation.md index da87e06f..bb25d5be 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -69,7 +69,7 @@ bash installer/linux/build.sh flatpak snap # sandboxed packages | --- | --- | --- | --- | | Debian, Ubuntu | `openecraft__amd64.deb` | `sudo apt install ./openecraft_*.deb` | `dpkg-dev` | | Fedora, RHEL, openSUSE | `openecraft--1.x86_64.rpm` | `sudo dnf install ./openecraft-*.rpm` | `rpmbuild` | -| Any distribution | `OpenECraft--x86_64.AppImage` | `chmod +x`, start it | `appimagetool` and its runtime (downloaded, checksums verified) | +| Any distribution | `OpenECraft--x86_64.AppImage` | `chmod +x`, start it | Debian or Ubuntu, `patchelf`, `appimagetool` and its runtime (downloaded, checksums verified) | | Any distribution | `OpenECraft--x86_64.flatpak` | `flatpak install --user OpenECraft-*.flatpak` | `flatpak-builder` | | Any distribution | `openecraft__amd64.snap` | `sudo snap install --dangerous openecraft_*.snap` | `snapcraft` | | Any distribution | `OpenECraft--linux-x86_64.tar.gz` | `./install.sh` (to `~/.local`) | `tar` | @@ -81,6 +81,9 @@ the Flatpak with `flatpak run --command=openecraft-cli io.github.nilres.OpenECra and in the snap as `openecraft.cli`, `openecraft.parts-manager`, … CI builds them on every push (artifacts `openecraft-linux-packages`, `openecraft-flatpak`, `openecraft-snap`); deb, rpm, AppImage and tar.gz are built on Debian 12 and run with glibc 2.36 or newer. +The AppImage carries the window libraries that are not on every system (xkbcommon, +Xcursor, Xi: `appimage_libs` in `installer/linux/build.sh`); the build refuses one that +needs another library or a newer glibc than the programs. The desktop entries, MIME types and AppStream data (`io.github.nilres.OpenECraft`) are in `installer/linux/`; a new version needs a `` in the metainfo file. diff --git a/installer/linux/build.sh b/installer/linux/build.sh index fc789c2c..177e7acf 100755 --- a/installer/linux/build.sh +++ b/installer/linux/build.sh @@ -9,8 +9,9 @@ # # deb dpkg-deb, dpkg-shlibdeps (apt install dpkg-dev) # rpm rpmbuild (dnf install rpm-build, apt install rpm) -# appimage appimagetool (APPIMAGETOOL=, otherwise release 1.9.1 is downloaded) and -# the AppImage runtime (release 20251108, downloaded; both checksums verified) +# appimage Debian or Ubuntu (dpkg-query), patchelf, appimagetool (APPIMAGETOOL=, +# otherwise release 1.9.1 is downloaded) and the AppImage runtime (release +# 20251108, downloaded; both checksums verified) # flatpak flatpak, flatpak-builder (the runtime is installed from Flathub) # snap snapcraft (SNAPCRAFT="sudo snapcraft" SNAPCRAFT_ARGS=--destructive-mode in CI) # @@ -168,10 +169,61 @@ download() { fi } +# The window libraries winit loads at run time that are not on every system, with what +# they need. The AppImage carries them; the libraries of the AppImage excludelist +# (libX11, libxcb, libwayland-client, libGL, libEGL, …) and the Wayland libraries tied to +# libwayland-client come from the system. +appimage_libs=(libxkbcommon.so.0 libxkbcommon-x11.so.0 libxcb-xkb.so.1 libXcursor.so.1 libXrender.so.1 + libXfixes.so.3 libXi.so.6 libXext.so.6) +appimage_system_libs=(libc.so.6 libm.so.6 libdl.so.2 libpthread.so.0 librt.so.1 libutil.so.1 libgcc_s.so.1 + ld-linux-x86-64.so.2 ld-linux-aarch64.so.1 libX11.so.6 libX11-xcb.so.1 libxcb.so.1 libz.so.1) + +# bundle_libs : copies appimage_libs to usr/lib and their packages' copyright +# files to usr/share/doc, makes the editor and the parts manager look there first and refuses a library the AppImage neither has nor may expect. +# $ORIGIN is for patchelf, not the shell. +# shellcheck disable=SC2016 +bundle_libs() { + local dir="$1" lib path pkg file need + need patchelf appimage + need readelf appimage + need ldconfig appimage + need dpkg-query "the licenses of the libraries in the AppImage (build it on Debian or Ubuntu)" + install -d "$dir/usr/lib" + for lib in "${appimage_libs[@]}"; do + path="$(ldconfig -p | awk -v lib="$lib" '$1 == lib && !found { print $NF; found = 1 }')" + [ -n "$path" ] || die "$lib not found, needed for appimage" + path="$(readlink -f "$path")" + install -m 644 "$path" "$dir/usr/lib/$lib" + patchelf --set-rpath '$ORIGIN' "$dir/usr/lib/$lib" + pkg="$(dpkg-query -S "*/${path##*/}" | awk -F : 'NR == 1 { print $1 }')" || die "no package contains $path" + install -D -m 644 "/usr/share/doc/$pkg/copyright" "$dir/usr/share/doc/$pkg/copyright" + done + patchelf --set-rpath '$ORIGIN/../lib' "$dir/usr/bin/openecraft" "$dir/usr/bin/openecraft-parts-manager" + for file in "$dir"/usr/bin/* "$dir"/usr/lib/*; do + for need in $(readelf -d "$file" | sed -n 's/.*(NEEDED).*\[\(.*\)\]$/\1/p'); do + [ -e "$dir/usr/lib/$need" ] || [[ " ${appimage_system_libs[*]} " == *" $need "* ]] \ + || die "$need, needed by ${file##*/}, is neither in the AppImage nor on every system" + done + done + local bins_glibc libs_glibc + bins_glibc="$(glibc_needed "$dir"/usr/bin/*)" + libs_glibc="$(glibc_needed "$dir"/usr/lib/*)" + [ "$(printf '%s\n' "$bins_glibc" "$libs_glibc" | sort -V | tail -n 1)" = "$bins_glibc" ] \ + || die "the libraries for the AppImage need $libs_glibc, the programs only $bins_glibc: build on an older system" +} + +# glibc_needed ...: the newest glibc version the files need, e.g. GLIBC_2.35. +glibc_needed() { + readelf -V "$@" | grep -o 'GLIBC_[0-9.]*' | sort -uV | tail -n 1 +} + build_appimage() { local dir="$work/OpenECraft.AppDir" tool="${APPIMAGETOOL:-}" runtime [ -n "${runtime_sha256[$arch]:-}" ] || die "no AppImage runtime for $arch" stage "$dir/usr" + bundle_libs "$dir" + # The AppImage catalog and appimagetool look for AppStream data by its older name. + mv "$dir/usr/share/metainfo/$id.metainfo.xml" "$dir/usr/share/metainfo/$id.appdata.xml" install -m 644 "$here/appimage/RUNTIME-LICENSES.txt" "$dir/usr/share/doc/openecraft/APPIMAGE-RUNTIME-LICENSES.txt" install -m 755 "$here/appimage/AppRun" "$dir/AppRun" cp "$here/$id.desktop" "$dir/$id.desktop"