Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chroot build #71

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions scripts/chroot/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#! /bin/sh

set -euxo pipefail

source arch.src

if [[ "${ARCH:-}" == "" ]]; then
echo "Usage: env ARCH=... bash $0"
exit 1
fi

build_dir="$(mktemp -d -t appimagetool-build-XXXXXX)"

cleanup () {
if [ -d "$build_dir" ]; then
rm -rf "$build_dir"
fi
}
trap cleanup EXIT


apk add bash git gcc g++ cmake make file desktop-file-utils wget \
gpgme-dev libgcrypt-dev libgcrypt-static argp-standalone zstd-dev zstd-static util-linux-static \
glib-static libassuan-static zlib-static libgpg-error-static \
curl-dev curl-static nghttp2-static libidn2-static openssl-libs-static brotli-static c-ares-static libunistring-static


# store repo root as variable
#repo_root="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")"/..)"
repo_root=/src
old_cwd="$(readlink -f "$PWD")"

#pushd "$build_dir"

/bin/bash /scripts/install-static-mksquashfs.sh 4.6.1

cmake "$repo_root" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_STATIC=ON

if [[ "${GITHUB_ACTIONS:-}" != "" ]]; then
jobs="$(nproc)"
else
jobs="$(nproc --ignore=1)"
fi

make -j"$jobs"

make install DESTDIR=AppDir

find AppDir

cp "$(which mksquashfs)" AppDir/usr/bin

cp "$repo_root"/resources/AppRun.sh AppDir/AppRun
chmod +x AppDir/AppRun

if [[ "$ARCH" == "x86" ]]; then
RELEASE_ARCH="i686"
fi

if [[ "$ARCH" == "x86_64" ]]; then
RELEASE_ARCH=${ARCH}
fi

wget https://github.com/AppImage/type2-runtime/releases/download/continuous/runtime-"$RELEASE_ARCH"

#pushd AppDir
ln -s usr/share/applications/appimagetool.desktop AppDir
ln -s usr/share/icons/hicolor/128x128/apps/appimagetool.png AppDir
ln -s usr/share/icons/hicolor/128x128/apps/appimagetool.png AppDir/.DirIcon
#popd

find AppDir
cat AppDir/appimagetool.desktop

AppDir/AppRun --runtime-file runtime-"$RELEASE_ARCH" AppDir

mv appimagetool-*.AppImage "$old_cwd"
94 changes: 94 additions & 0 deletions scripts/chroot/chroot_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#! /bin/sh

set -ex

if [ -z "${ALPINE_ARCH}" ]; then
echo "Usage: env ALPINE_ARCH=<arch> $0"
echo "Example values: x86_64 x86 armhf aarch64"
exit 2
fi

# build in a temporary directory
# this makes sure that subsequent runs do not influence each other
# also makes cleaning up easier: just dump the entire directory
tempdir="$(mktemp -d)"

# need to memorize the repository root directory's path so that we can copy files from it
repo_root_dir=$(dirname "$(readlink -f "$0")")/../../

# cleanup takes care of unmounting and removing all downloaded files
cleanup() {
for i in dev proc sys; do
sudo umount "$tempdir"/miniroot/"$i"
done
sudo rm -rf "$tempdir"
}
trap cleanup EXIT

cd "$tempdir"

#############################################
# Download and extract minimal Alpine system
#############################################

wget "http://dl-cdn.alpinelinux.org/alpine/v3.19/releases/${ALPINE_ARCH}/alpine-minirootfs-3.19.4-${ALPINE_ARCH}.tar.gz"
mkdir -p ./miniroot
cd ./miniroot
sudo tar xf ../alpine-minirootfs-*-"${ALPINE_ARCH}".tar.gz
cd -

#############################################
# Prepare chroot
#############################################
sudo mkdir miniroot/src
sudo cp -r "$repo_root_dir" miniroot/src
#sudo cp -r "$repo_root_dir"/patches miniroot/patches

sudo mount -o bind /dev miniroot/dev
sudo mount -t proc none miniroot/proc
sudo mount -t sysfs none miniroot/sys
sudo cp -p /etc/resolv.conf miniroot/etc/

#############################################
# Run build.sh in chroot
#############################################

# copy build scripts so that they are available within the chroot environment
# build.sh combines existing scripts shared by all available build environments
sudo cp -R "$repo_root_dir"/scripts miniroot/scripts

if [ "$ALPINE_ARCH" = "x86" ] || [ "$ALPINE_ARCH" = "x86_64" ]; then
echo "Architecture is x86 or x86_64, hence not using qemu-arm-static"
echo "export ARCH=${ALPINE_ARCH}" > miniroot/arch.src
sudo chroot miniroot /bin/sh -ex /scripts/chroot/build.sh
elif [ "$ALPINE_ARCH" = "aarch64" ] ; then
echo "Architecture is aarch64, hence using qemu-aarch64-static"
sudo cp "$(which qemu-aarch64-static)" miniroot/usr/bin
sudo chroot miniroot qemu-aarch64-static /bin/sh -ex /scripts/chroot/build.sh
elif [ "$ALPINE_ARCH" = "armhf" ] ; then
echo "Architecture is armhf, hence using qemu-arm-static"
sudo cp "$(which qemu-arm-static)" miniroot/usr/bin
sudo cp "$repo_root_dir"/scripts/chroot/build.sh miniroot/build.sh && sudo chroot miniroot qemu-arm-static /bin/sh -ex /scripts/chroot/build.sh
else
echo "Edit chroot_build.sh to support this architecture as well, it should be easy"
exit 1
fi

#############################################
# Copy build artifacts out
#############################################

# Use the same architecture names as https://github.com/AppImage/AppImageKit/releases/
case "$ALPINE_ARCH" in
x86)
appimage_arch=i686
;;
*)
appimage_arch="$ALPINE_ARCH"
;;
esac

cd "$repo_root_dir"
mkdir -p ./out/
sudo find "$tempdir"/miniroot/ -type f -executable -name "appimagetool-${appimage_arch}.AppImage" -exec cp {} "out/appimagetool-${appimage_arch}.AppImage" \;
# sudo find "$tempdir"/miniroot/ -type f -executable -name "runtime-${appimage_arch}.debug" -exec cp {} "out/runtime-${appimage_arch}.debug" \;
33 changes: 33 additions & 0 deletions scripts/install-static-mksquashfs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#! /bin/bash

set -euxo pipefail

if [[ "${1:-}" == "" ]]; then
echo "Usage: $0 <version>"
exit 2
fi

version="$1"

build_dir="$(mktemp -d -t mksquashfs-build-XXXXXX)"

cleanup () {
if [ -d "$build_dir" ]; then
rm -rf "$build_dir"
fi
}
trap cleanup EXIT

pushd "$build_dir"

wget https://github.com/plougher/squashfs-tools/archive/refs/tags/"$version".tar.gz -qO - | tar xvz --strip-components=1

cd squashfs-tools

if [[ "${GITHUB_ACTIONS:-}" != "" ]]; then
jobs="$(nproc)"
else
jobs="$(nproc --ignore=1)"
fi

make -j"$jobs" GZIP_SUPPORT=0 XZ_SUPPORT=0 LZO_SUPPORT=0 LZ4_SUPPORT=0 ZSTD_SUPPORT=1 COMP_DEFAULT=zstd LDFLAGS=-static USE_PREBUILT_MANPAGES=y install