Skip to content

Commit

Permalink
feat: loongarch64 support
Browse files Browse the repository at this point in the history
  • Loading branch information
msojocs committed May 16, 2024
1 parent 47b6655 commit c7cd299
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 3 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
- { qemu_arch: x86_64, appimage_arch: x86_64 }
- { qemu_arch: armv7, appimage_arch: armhf }
- { qemu_arch: aarch64, appimage_arch: aarch64 }
- { qemu_arch: loongarch64, appimage_arch: loongarch64 }

steps:
- name: Checkout
Expand All @@ -46,12 +47,21 @@ jobs:
git rev-parse --short HEAD | xargs >> src/runtime/version
- name: Build
if: ${{ matrix.appimage_arch }} != 'loongarch64'
env:
ARCHITECTURE: ${{ matrix.appimage_arch }}
run: |
sudo apt-get -y install qemu-user-static
./chroot_build.sh
- name: Build Loongarch
if: ${{ matrix.appimage_arch }} == 'loongarch64'
env:
ARCHITECTURE: ${{ matrix.appimage_arch }}
run: |
docker run --rm --privileged loongcr.lcpu.dev/multiarch/archlinux --reset -p yes
./build_loongarch64.sh
- name: Sign
env:
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,9 @@ modules.order
Module.symvers
Mkfile.old
dkms.conf

miniroot
fuse-3.15.0
out
squa*
*.tar.*
16 changes: 13 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

set -ex

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

if ! command -v apk; then
echo "This script should be run in an Alpine container"
exit 1
Expand All @@ -12,7 +20,9 @@ apk add alpine-sdk util-linux strace file autoconf automake libtool xz

# Build static libfuse3 with patch for https://github.com/AppImage/type2-runtime/issues/10
apk add eudev-dev gettext-dev linux-headers meson # From https://git.alpinelinux.org/aports/tree/main/fuse3/APKBUILD
wget -c -q "https://github.com/libfuse/libfuse/releases/download/fuse-3.15.0/fuse-3.15.0.tar.xz"
if [ ! -f "fuse-3.15.0.tar.xz" ];then
wget -c -q "https://github.com/libfuse/libfuse/releases/download/fuse-3.15.0/fuse-3.15.0.tar.xz"
fi
echo "70589cfd5e1cff7ccd6ac91c86c01be340b227285c5e200baa284e401eea2ca0 fuse-3.15.0.tar.xz" | sha256sum -c
tar xf fuse-3.*.tar.xz
cd fuse-3.*/
Expand All @@ -28,7 +38,7 @@ cd ../../
export CFLAGS="-ffunction-sections -fdata-sections -Os"

# Build static squashfuse
apk add zstd-dev zlib-dev zlib-static # fuse3-dev fuse3-static fuse-static fuse-dev
apk add zstd-dev zlib-dev zlib-static zstd-static # fuse3-dev fuse3-static fuse-static fuse-dev
find / -name "libzstd.*" 2>/dev/null || true
wget -c -q "https://github.com/vasi/squashfuse/archive/e51978c.tar.gz"
echo "f544029ad30d8fbde4e4540c574b8cdc6d38b94df025a98d8551a9441f07d341 e51978c.tar.gz" | sha256sum -c
Expand All @@ -54,4 +64,4 @@ echo -ne 'AI\x02' | dd of=runtime-fuse3 bs=1 count=3 seek=8 conv=notrunc # magic
cd -

mkdir -p out
cp src/runtime/runtime-fuse3 "out/runtime-fuse3-${ARCHITECTURE}"
mv src/runtime/runtime-fuse3 "out/runtime-fuse3-${ARCHITECTURE}"
21 changes: 21 additions & 0 deletions build_loongarch64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

set -ex

repo_root="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")"/.)"
image="msojocs/alpine-loongarch:240514"
platform="linux/loong64"
uid="$(id -u)"
docker run \
--platform "$platform" \
--rm \
-i \
-e ARCH \
-e GITHUB_ACTIONS \
-e GITHUB_RUN_NUMBER \
-e OUT_UID="$uid" \
-v "$repo_root":/source \
-v "$PWD":/out \
-w /out \
"$image" \
sh -ex /source/build.sh
71 changes: 71 additions & 0 deletions chroot_build_loongarch64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/bin/sh

set -ex

#############################################
# Download and extract minimal Alpine system
#############################################
if [ ! -f "alpine-minirootfs-edge-240514-loongarch64.tar.gz" ]; then
wget "https://dev.alpinelinux.org/~loongarch/edge/releases/loongarch64/alpine-minirootfs-edge-240514-loongarch64.tar.gz"
fi
if [ ! -z "$(ls -A miniroot/proc)" ]; then
sudo umount miniroot/proc miniroot/sys miniroot/dev
fi
sudo rm -rf ./miniroot true # Clean up from previous runs
mkdir -p ./miniroot
cd ./miniroot
sudo tar xf ../alpine-minirootfs-*-"${ARCHITECTURE}".tar.gz
cd -

#############################################
# Prepare chroot
#############################################

sudo cp -r ./src miniroot/src
sudo cp -r ./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
#############################################

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

#############################################
# Clean up chroot
#############################################

sudo umount miniroot/proc miniroot/sys miniroot/dev

#############################################
# Copy build artefacts out
#############################################

# Use the same architecture names as https://github.com/AppImage/AppImageKit/releases/
if [ "$ARCHITECTURE" = "x86" ] ; then ARCHITECTURE=i686 ; fi

mkdir out/
sudo find miniroot/ -type f -executable -name 'runtime-fuse3' -exec cp {} "out/runtime-${ARCHITECTURE}" \;
sudo rm -rf miniroot/

0 comments on commit c7cd299

Please sign in to comment.