Fix(build): Support reproducible builds with ELECBUILD_COMMIT

Fixes runtime path resolution for reproducible AppImage builds when using ELECBUILD_COMMIT. Previously, the type2-runtime binary was built in the original project directory but the build process would look for it in the fresh clone, causing "Unable to load provided runtime file" errors.
This commit is contained in:
2025-12-08 22:34:23 +01:00
parent 9bb607bf6f
commit 7193f999e5
2 changed files with 39 additions and 5 deletions

View File

@@ -50,6 +50,15 @@ fi
# defined in the type2-runtime repo (patched with type2-runtime-reproducible-build.patch)
"$CONTRIB_APPIMAGE/make_type2_runtime.sh" || fail "Error building type2-runtime."
# if doing fresh clone, copy the runtime from original project to fresh clone
if [ ! -z "$ELECBUILD_COMMIT" ] ; then
info "Copying type2-runtime to fresh clone..."
RUNTIME_SRC="$PROJECT_ROOT/contrib/build-linux/appimage/.cache/appimage/type2-runtime"
RUNTIME_DST="$FRESH_CLONE/contrib/build-linux/appimage/.cache/appimage/type2-runtime"
mkdir -p "$(dirname "$RUNTIME_DST")"
cp -r "$RUNTIME_SRC" "$(dirname "$RUNTIME_DST")/" || fail "Failed to copy runtime to fresh clone"
fi
DOCKER_RUN_FLAGS=""
if sh -c ": >/dev/tty" >/dev/null 2>/dev/null; then
info "/dev/tty is available and usable"

View File

@@ -14,23 +14,48 @@ TYPE2_RUNTIME_REPO="https://github.com/AppImage/type2-runtime.git"
. "$CONTRIB"/build_tools_util.sh
TYPE2_RUNTIME_REPO_DIR="$PROJECT_ROOT_OR_FRESHCLONE_ROOT/contrib/build-linux/appimage/.cache/appimage/type2-runtime"
if [ -f "$TYPE2_RUNTIME_REPO_DIR/runtime-x86_64" ]; then
info "type2-runtime already built, skipping"
# Use a shared cache location that persists across fresh clones
# This is critical for reproducible builds with ELECBUILD_COMMIT
TYPE2_RUNTIME_REPO_DIR="$PROJECT_ROOT/contrib/build-linux/appimage/.cache/appimage/type2-runtime"
if [ -f "$TYPE2_RUNTIME_REPO_DIR/runtime-x86_64" ] && [ -s "$TYPE2_RUNTIME_REPO_DIR/runtime-x86_64" ]; then
info "type2-runtime already built ($(du -h "$TYPE2_RUNTIME_REPO_DIR/runtime-x86_64" | cut -f1)), skipping"
exit 0
fi
# If directory exists but runtime is missing or invalid, clean it up
if [ -d "$TYPE2_RUNTIME_REPO_DIR" ]; then
warn "type2-runtime directory exists but runtime is missing or invalid, cleaning up..."
rm -rf "$TYPE2_RUNTIME_REPO_DIR"
fi
clone_or_update_repo "$TYPE2_RUNTIME_REPO" "$TYPE2_RUNTIME_COMMIT" "$TYPE2_RUNTIME_REPO_DIR"
# Apply patch to make runtime build reproducible
info "Applying type2-runtime patch..."
cd "$TYPE2_RUNTIME_REPO_DIR"
git apply "$CONTRIB_APPIMAGE/patches/type2-runtime-reproducible-build.patch" || fail "Failed to apply runtime repo patch"
# Check if patch can be applied (it will fail if already applied or incompatible)
if git apply --check "$CONTRIB_APPIMAGE/patches/type2-runtime-reproducible-build.patch" >/dev/null 2>&1; then
git apply "$CONTRIB_APPIMAGE/patches/type2-runtime-reproducible-build.patch" || fail "Failed to apply runtime repo patch"
else
warn "Patch already applied or cannot be applied, continuing..."
fi
info "building type2-runtime in build container..."
cd "$TYPE2_RUNTIME_REPO_DIR/scripts/docker"
env ARCH=x86_64 ./build-with-docker.sh
env ARCH=x86_64 ./build-with-docker.sh || fail "Failed to build type2-runtime with docker"
# Verify the runtime was created in the expected location
if [ ! -f "./runtime-x86_64" ]; then
fail "Runtime binary was not created by docker build (expected at: $TYPE2_RUNTIME_REPO_DIR/scripts/docker/runtime-x86_64)"
fi
mv "./runtime-x86_64" "$TYPE2_RUNTIME_REPO_DIR/"
# Verify runtime is valid (not empty)
if [ ! -s "$TYPE2_RUNTIME_REPO_DIR/runtime-x86_64" ]; then
fail "Runtime binary is empty or invalid"
fi
# clean up the empty created 'out' dir to prevent permission issues
rm -rf "$TYPE2_RUNTIME_REPO_DIR/out"