fixing bundled libraries

This commit is contained in:
Logan Rawlins committed 2026-11-07 10:53:52 -07:00
1 parent 394df3109b
commit f22f2eb0a2
8 files changed
+246 -34

No files matched your search

+4 -4
View File
@@ -56,7 +56,7 @@ jobs:
- name: Install Linux build deps
run: |
sudo apt-get update
sudo apt-get install -y clang cmake ninja-build pkg-config jq libgtk-3-dev librsvg2-dev libgirepository1.0-dev libgtk-3-bin libgdk-pixbuf2.0-bin libgdk-pixbuf-2.0-dev dpkg-dev patchelf file desktop-file-utils xdg-user-dirs shellcheck libssl-dev libunwind-dev libvulkan-dev libgl1-mesa-dev libasound2-dev libsecret-1-dev
sudo apt-get install -y clang cmake ninja-build pkg-config jq libgtk-3-dev librsvg2-dev libgirepository1.0-dev libgtk-3-bin libgdk-pixbuf2.0-bin libgdk-pixbuf-2.0-dev dpkg-dev patchelf file desktop-file-utils xdg-user-dirs shellcheck libssl-dev libunwind-dev libvulkan-dev libgl1-mesa-dev libasound2-dev libsecret-1-dev libgpg-error0
- uses: actions/cache@v4
with:
path: ~/.cache/meshcore-open/appimage
@@ -87,7 +87,7 @@ jobs:
- name: Test AppImage in clean Ubuntu
run: |
mkdir -p build/appimage-runtime
docker run --rm --stop-timeout 15 --user "$(id -u):$(id -g)" --mount "type=bind,source=$PWD/build/linux/x64/release/meshcore-open-x86_64.AppImage,target=/artifact.AppImage,readonly" --mount "type=bind,source=$PWD/scripts/appimage/test_runtime.sh,target=/test_runtime.sh,readonly" --mount "type=bind,source=$PWD/build/appimage-runtime,target=/results" meshcore-appimage-runtime:ci timeout --verbose --signal=TERM --kill-after=15s 300s xvfb-run -a bash /test_runtime.sh /artifact.AppImage /results
docker run --rm --stop-timeout 15 --user "$(id -u):$(id -g)" --mount "type=bind,source=$PWD/build/linux/x64/release/meshcore-open-x86_64.AppImage,target=/artifact.AppImage,readonly" --mount "type=bind,source=$PWD/scripts/appimage/test_runtime.sh,target=/test_runtime.sh,readonly" --mount "type=bind,source=$PWD/scripts/appimage/dependencies.sh,target=/dependencies.sh,readonly" --mount "type=bind,source=$PWD/build/appimage-runtime,target=/results" meshcore-appimage-runtime:ci env MESHCORE_APPIMAGE_DEPENDENCIES=/dependencies.sh timeout --verbose --signal=TERM --kill-after=15s 300s xvfb-run -a bash /test_runtime.sh /artifact.AppImage /results
- uses: actions/upload-artifact@v4
if: always()
with:
@@ -126,7 +126,7 @@ jobs:
- name: Install Linux build deps
run: |
sudo apt-get update
sudo apt-get install -y clang cmake ninja-build pkg-config jq libgtk-3-dev librsvg2-dev libgirepository1.0-dev libgtk-3-bin libgdk-pixbuf2.0-bin libgdk-pixbuf-2.0-dev dpkg-dev patchelf file desktop-file-utils xdg-user-dirs shellcheck libssl-dev libunwind-dev libvulkan-dev libgl1-mesa-dev libasound2-dev libsecret-1-dev
sudo apt-get install -y clang cmake ninja-build pkg-config jq libgtk-3-dev librsvg2-dev libgirepository1.0-dev libgtk-3-bin libgdk-pixbuf2.0-bin libgdk-pixbuf-2.0-dev dpkg-dev patchelf file desktop-file-utils xdg-user-dirs shellcheck libssl-dev libunwind-dev libvulkan-dev libgl1-mesa-dev libasound2-dev libsecret-1-dev libgpg-error0
- uses: actions/cache@v4
with:
path: ~/.cache/meshcore-open/appimage
@@ -163,7 +163,7 @@ jobs:
- name: Test ARM64 AppImage in clean Ubuntu
run: |
mkdir -p build/appimage-runtime
docker run --rm --stop-timeout 15 --platform linux/arm64 --user "$(id -u):$(id -g)" --mount "type=bind,source=$PWD/build/linux/arm64/release/meshcore-open-aarch64.AppImage,target=/artifact.AppImage,readonly" --mount "type=bind,source=$PWD/scripts/appimage/test_runtime.sh,target=/test_runtime.sh,readonly" --mount "type=bind,source=$PWD/build/appimage-runtime,target=/results" meshcore-appimage-runtime-arm64:ci timeout --verbose --signal=TERM --kill-after=15s 300s xvfb-run -a bash /test_runtime.sh /artifact.AppImage /results
docker run --rm --stop-timeout 15 --platform linux/arm64 --user "$(id -u):$(id -g)" --mount "type=bind,source=$PWD/build/linux/arm64/release/meshcore-open-aarch64.AppImage,target=/artifact.AppImage,readonly" --mount "type=bind,source=$PWD/scripts/appimage/test_runtime.sh,target=/test_runtime.sh,readonly" --mount "type=bind,source=$PWD/scripts/appimage/dependencies.sh,target=/dependencies.sh,readonly" --mount "type=bind,source=$PWD/build/appimage-runtime,target=/results" meshcore-appimage-runtime-arm64:ci env MESHCORE_APPIMAGE_DEPENDENCIES=/dependencies.sh timeout --verbose --signal=TERM --kill-after=15s 300s xvfb-run -a bash /test_runtime.sh /artifact.AppImage /results
- uses: actions/upload-artifact@v4
if: always()
with:
+10 -7
View File
@@ -173,7 +173,7 @@ dependencies:
```bash
sudo apt-get install clang cmake ninja-build pkg-config libgtk-3-dev \
librsvg2-dev libgirepository1.0-dev libgtk-3-bin libgdk-pixbuf2.0-bin \
libgdk-pixbuf-2.0-dev dpkg-dev patchelf binutils curl jq file desktop-file-utils xdg-user-dirs
libgdk-pixbuf-2.0-dev dpkg-dev patchelf binutils curl jq file desktop-file-utils xdg-user-dirs libgpg-error0
```
The build automatically downloads checksum-verified architecture-matched
@@ -199,12 +199,15 @@ container can write the host-owned output and cache directories. The original
native bundle is retained. Custom targets, obfuscation and split-debug-info
require a bundle-only build when container rebuilding is needed.
The image includes Flutter assets, native plugins, ONNX Runtime and
redistributable GTK dependencies. It does not include graphics drivers, BlueZ
services, USB permissions, downloaded inference models or user data. The GTK
packaging plugin uses X11, so Wayland sessions need XWayland. The host still
needs compatible glibc and graphics libraries (`libgl1`, `libegl1`, and
`libgles2` on Ubuntu). Launch normally, or without
The image includes Flutter assets, native plugins, ONNX Runtime and the
transitive redistributable runtime libraries, including GTK and X11/Wayland
client libraries. Packaging audits every bundled ELF and fails if a portable
dependency resolves from the build host instead of the AppDir. It does not
include glibc/the ELF loader, graphics drivers, BlueZ services, USB permissions,
downloaded inference models or user data. The GTK packaging plugin uses X11, so
Wayland sessions need XWayland. The host still needs compatible glibc and
graphics libraries (`libgl1`, `libegl1`, and `libgles2` on Ubuntu). Launch
normally, or without
FUSE by extracting:
```bash
+2 -2
View File
@@ -7,7 +7,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
librsvg2-dev libgirepository1.0-dev libgdk-pixbuf-2.0-dev libgtk-3-bin \
libgdk-pixbuf2.0-bin binutils patchelf curl jq \
file desktop-file-utils xdg-user-dirs git rsync unzip xz-utils make g++ dpkg-dev \
libssl-dev libunwind-dev libvulkan-dev libgl1-mesa-dev libglu1-mesa-dev \
libssl-dev libunwind-dev libvulkan-dev libgl1-mesa-dev libglu1-mesa-dev libgpg-error0 \
libasound2-dev libsecret-1-dev \
&& rm -rf /var/lib/apt/lists/*
@@ -23,5 +23,5 @@ FROM ${BASE_IMAGE} AS runtime-test
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
xvfb xauth x11-utils x11-apps xdotool imagemagick dbus-x11 binutils libgl1 libegl1 libgles2 \
libgl1-mesa-dri fonts-dejavu-core \
libgl1-mesa-dri libgpg-error0 fonts-dejavu-core \
&& rm -rf /var/lib/apt/lists/*
+168
View File
@@ -0,0 +1,168 @@
#!/usr/bin/env bash
set -euo pipefail
fail() {
printf 'AppImage dependencies: %s\n' "$*" >&2
return 1
}
is_host_interface() {
case "$1" in
linux-vdso.so.*|ld-linux*.so.*|ld64.so.*|libc.so.*|libm.so.*|libpthread.so.*|\
libdl.so.*|librt.so.*|libresolv.so.*|libutil.so.*|libanl.so.*|\
libBrokenLocale.so.*|libnss_*.so.*|libGL.so.*|libGLX.so.*|libEGL.so.*|\
libGLES*.so.*|libOpenGL.so.*|libglapi.so.*|libvulkan.so.*|libdrm*.so.*|libgbm.so.*)
return 0
;;
*) return 1 ;;
esac
}
is_inside_appdir() {
[[ "$1" == "$2/"* ]]
}
copy_dependency() {
local appdir="$1" soname="$2" source="$3" source_real real_name library_dir target existing_real
source_real="$(realpath -e -- "$source")" || {
fail "Cannot resolve dependency $soname from $source"
return 1
}
[[ -f "$source_real" ]] || { fail "Dependency is not a regular file: $source_real"; return 1; }
real_name="${source_real##*/}"
library_dir="$appdir/usr/lib"
target="$library_dir/$real_name"
mkdir -p "$library_dir"
if [[ -e "$target" || -L "$target" ]]; then
existing_real="$(realpath -e -- "$target")" || {
fail "Broken bundled library path: $target"
return 1
}
if [[ "$existing_real" != "$source_real" ]] && ! cmp -s -- "$existing_real" "$source_real"; then
fail "Conflicting libraries map to $target"
return 1
fi
else
cp -p -- "$source_real" "$target"
fi
if [[ "$soname" != "$real_name" ]]; then
if [[ -e "$library_dir/$soname" || -L "$library_dir/$soname" ]]; then
existing_real="$(realpath -e -- "$library_dir/$soname")" || {
fail "Broken bundled SONAME link: $library_dir/$soname"
return 1
}
if [[ "$existing_real" != "$source_real" ]] && ! cmp -s -- "$existing_real" "$source_real"; then
fail "Conflicting libraries provide SONAME $soname"
return 1
fi
else
ln -s "$real_name" "$library_dir/$soname"
fi
fi
}
scan_appdir() {
local appdir="$1" report="$2" mode="$3" changed_name="$4"
local appdir_real search_path elf output status line soname resolution resolved resolved_real
local failed=0 copied_any=0
local -a elf_files=()
appdir_real="$(realpath -e -- "$appdir")"
search_path="$appdir/usr/lib:$appdir/usr/bin/lib"
: > "$report"
mapfile -d '' -t elf_files < <(find "$appdir/usr/bin" "$appdir/usr/lib" \
\( -type f -o -type l \) -print0 2>/dev/null || true)
for elf in "${elf_files[@]}"; do
readelf -h "$elf" >/dev/null 2>&1 || continue
printf '%s\n' "${elf#"$appdir/"}" >> "$report"
if output="$(LD_LIBRARY_PATH="$search_path" ldd "$elf" 2>&1)"; then
status=0
else
status=$?
fi
while IFS= read -r line; do
soname=''
resolution=''
if [[ "$line" =~ ^[[:space:]]*([^[:space:]]+)[[:space:]]*=\>[[:space:]]*(.*)$ ]]; then
soname="${BASH_REMATCH[1]}"
resolution="${BASH_REMATCH[2]}"
elif [[ "$line" =~ ^[[:space:]]*(/[^[:space:]]+) ]]; then
resolution="${BASH_REMATCH[1]}"
soname="${resolution##*/}"
else
continue
fi
soname="${soname##*/}"
if [[ "$resolution" == 'not found'* ]]; then
printf ' %s => NOT FOUND\n' "$soname" >> "$report"
printf 'AppImage dependencies: %s needs missing %s\n' "$elf" "$soname" >&2
failed=1
continue
fi
resolved="${resolution%%[[:space:]]*}"
[[ "$resolved" == /* ]] || continue
if ! resolved_real="$(realpath -e -- "$resolved" 2>/dev/null)"; then
printf ' %s => UNRESOLVED (%s)\n' "$soname" "$resolved" >> "$report"
printf 'AppImage dependencies: %s resolves %s to missing path %s\n' \
"$elf" "$soname" "$resolved" >&2
failed=1
continue
fi
if is_inside_appdir "$resolved_real" "$appdir_real"; then
printf ' %s => %s [bundled]\n' "$soname" "$resolved_real" >> "$report"
elif is_host_interface "$soname"; then
printf ' %s => %s [host interface]\n' "$soname" "$resolved_real" >> "$report"
elif [[ "$mode" == bundle ]]; then
printf ' %s => %s [bundling]\n' "$soname" "$resolved_real" >> "$report"
copy_dependency "$appdir" "$soname" "$resolved_real"
copied_any=1
else
printf ' %s => %s [unexpected host dependency]\n' "$soname" "$resolved_real" >> "$report"
printf 'AppImage dependencies: %s resolves non-allowlisted %s from %s\n' \
"$elf" "$soname" "$resolved_real" >&2
failed=1
fi
done <<< "$output"
if ((status != 0)) && [[ "$output" != *'not found'* ]]; then
printf 'AppImage dependencies: ldd failed for %s (exit %s): %s\n' \
"$elf" "$status" "$output" >&2
failed=1
fi
done
printf -v "$changed_name" '%s' "$copied_any"
((failed == 0))
}
bundle_appdir_dependencies() {
local appdir="$1" report="$2" pass changed
for ((pass = 1; pass <= 32; pass++)); do
scan_appdir "$appdir" "$report" bundle changed || return 1
((changed == 1)) || break
done
((pass <= 32)) || { fail 'Dependency closure did not converge after 32 passes'; return 1; }
audit_appdir_dependencies "$appdir" "$report"
}
audit_appdir_dependencies() {
local appdir="$1" report="$2" changed=0
scan_appdir "$appdir" "$report" audit changed
}
main() {
[[ $# == 3 ]] || { fail 'Usage: dependencies.sh bundle|audit APPDIR REPORT'; return 1; }
local mode="$1" appdir="$2" report="$3"
[[ -d "$appdir/usr/bin" && -d "$appdir/usr/lib" ]] || {
fail "Invalid AppDir: $appdir"
return 1
}
command -v readelf >/dev/null || { fail 'Missing readelf'; return 1; }
command -v ldd >/dev/null || { fail 'Missing ldd'; return 1; }
case "$mode" in
bundle) bundle_appdir_dependencies "$appdir" "$report" ;;
audit) audit_appdir_dependencies "$appdir" "$report" ;;
*) fail "Unknown mode: $mode"; return 1 ;;
esac
}
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
main "$@"
fi
+32
View File
@@ -147,4 +147,36 @@ mock_glibc=2.39
requires_container_rebuild "$temporary/bundle/meshcore_open" 2.39
unset -f readelf getconf
mkdir -p "$temporary/audit-appdir/usr/bin" "$temporary/audit-appdir/usr/lib" \
"$temporary/host" "$temporary/fakebin"
cp "$(type -P true)" "$temporary/audit-appdir/usr/bin/fixture"
printf 'test library\n' > "$temporary/host/libgpg-error.so.0.37.0"
ln -s libgpg-error.so.0.37.0 "$temporary/host/libgpg-error.so.0"
cat > "$temporary/fakebin/ldd" <<'EOF'
#!/usr/bin/env bash
if [[ -e "$MESHCORE_TEST_APPDIR/usr/lib/libgpg-error.so.0" ]]; then
printf 'libgpg-error.so.0 => %s/usr/lib/libgpg-error.so.0 (0x0)\n' "$MESHCORE_TEST_APPDIR"
else
printf 'libgpg-error.so.0 => %s (0x0)\n' "$MESHCORE_TEST_HOST_LIBRARY"
fi
EOF
chmod +x "$temporary/fakebin/ldd"
MESHCORE_TEST_APPDIR="$temporary/audit-appdir" \
MESHCORE_TEST_HOST_LIBRARY="$temporary/host/libgpg-error.so.0" \
PATH="$temporary/fakebin:$PATH" \
bash "$project/scripts/appimage/dependencies.sh" bundle \
"$temporary/audit-appdir" "$temporary/dependency-audit.log"
[[ -L "$temporary/audit-appdir/usr/lib/libgpg-error.so.0" ]]
[[ -f "$temporary/audit-appdir/usr/lib/libgpg-error.so.0.37.0" ]]
grep -Fq 'libgpg-error.so.0 =>' "$temporary/dependency-audit.log"
mkdir -p "$temporary/audit-missing/usr/bin" "$temporary/audit-missing/usr/lib"
cp "$temporary/audit-appdir/usr/bin/fixture" "$temporary/audit-missing/usr/bin/fixture"
MESHCORE_TEST_APPDIR="$temporary/audit-missing" \
MESHCORE_TEST_HOST_LIBRARY="$temporary/host/libgpg-error.so.0" \
PATH="$temporary/fakebin:$PATH" \
assert_fails bash "$project/scripts/appimage/dependencies.sh" audit \
"$temporary/audit-missing" "$temporary/dependency-rejected.log"
grep -Fq 'unexpected host dependency' "$temporary/dependency-rejected.log"
printf 'AppImage packaging contract tests passed\n'
+6 -21
View File
@@ -86,27 +86,12 @@ log "ELF architecture audit passed ($elf_count files)"
dependencies="$output/dependencies.log"
: > "$dependencies"
run_timed 'check application dependencies' 20s "$workspace/ldd.log" \
ldd "$appdir/usr/bin/meshcore_open"
cat "$workspace/ldd.log" >> "$dependencies"
while IFS= read -r -d '' library; do
relative="${library#"$appdir/"}"
if run_timed "check dependencies: $relative" 20s "$workspace/ldd.log" ldd "$library"; then
cat "$workspace/ldd.log" >> "$dependencies"
else
status=$?
cat "$workspace/ldd.log" >> "$dependencies"
if [[ "$status" == 124 || "$status" == 137 ]]; then
exit "$status"
fi
log "ldd returned $status for $relative; continuing unresolved-dependency scan"
fi
done < <(find "$appdir/usr/bin/lib" "$appdir/usr/lib" -type f -name '*.so*' -print0)
if grep 'not found' "$dependencies"; then
log 'Unresolved AppImage dependencies'
exit 1
fi
log 'Dependency audit passed'
dependency_checker="${MESHCORE_APPIMAGE_DEPENDENCIES:-$(dirname "${BASH_SOURCE[0]}")/dependencies.sh}"
[[ -f "$dependency_checker" ]] || { log "Missing dependency checker: $dependency_checker"; exit 1; }
run_timed 'audit dependency origins' 120s "$workspace/dependency-audit.log" \
bash "$dependency_checker" audit "$appdir" "$dependencies"
cat "$workspace/dependency-audit.log" >> "$dependencies"
log 'Dependency origin audit passed'
mkdir -p "$workspace/home/Documents" "$workspace/home/config"
printf 'XDG_DOCUMENTS_DIR="%s/Documents"\n' "$workspace/home" > "$workspace/home/config/user-dirs.dirs"
+22
View File
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -euo pipefail
if [[ $# != 2 ]]; then
printf 'Usage: verify_image.sh APPIMAGE REPORT\n' >&2
exit 2
fi
image="$(realpath -e -- "$1")"
report="$2"
dependency_checker="$(dirname "${BASH_SOURCE[0]}")/dependencies.sh"
workspace="$(mktemp -d)"
trap 'rm -rf "$workspace"' EXIT
mkdir -p "$(dirname "$report")"
cp -p -- "$image" "$workspace/extractor"
printf '\0\0\0' | dd of="$workspace/extractor" bs=1 seek=8 count=3 conv=notrunc status=none
(
cd "$workspace"
./extractor --appimage-extract >/dev/null
)
bash "$dependency_checker" audit "$workspace/squashfs-root" "$report"
printf 'AppImage dependency audit passed: %s\n' "$report"
+2
View File
@@ -156,6 +156,7 @@ package_direct() {
dependencies+=(--deploy-deps-only "$library")
done < <(find "$appdir/usr/bin/lib" -type f -print0)
"$linuxdeploy" --appdir "$appdir" "${dependencies[@]}"
bash "$project/scripts/appimage/dependencies.sh" bundle "$appdir" "$work/dependency-audit.txt"
while IFS= read -r -d '' library; do
readelf -h "$library" >/dev/null 2>&1 || continue
relative="$(realpath --relative-to="$(dirname "$library")" "$appdir/usr/lib")"
@@ -187,6 +188,7 @@ package_direct() {
cp "$MESHCORE_APPIMAGE_FLUTTER_ROOT/LICENSE" "$appdir/usr/share/doc/meshcore-open/Flutter-LICENSE"
fi
audit_appdir "$appdir" "$work/audit.txt"
cat "$work/dependency-audit.txt" >> "$work/audit.txt"
ARCH="$appimage_arch" "$appimagetool" --runtime-file "$cache/runtime" --no-appstream \
"$appdir" "$work/$appimage_name"
chmod +x "$work/$appimage_name"