From ad42b982ca80285c2cdfa00209cf110fa5db1238 Mon Sep 17 00:00:00 2001 From: msojocs Date: Tue, 21 May 2024 14:08:35 +0800 Subject: [PATCH] feat: add loong64 support --- .github/workflows/build.yml | 7 ++++++- .gitignore | 1 + ci/build-in-docker.sh | 24 ++++++++++++++++++++---- ci/prepare-loong64.sh | 34 ++++++++++++++++++++++++++++++++++ src/appimagetool.c | 19 +++++++++++++++++-- 5 files changed, 78 insertions(+), 7 deletions(-) create mode 100755 ci/prepare-loong64.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 44c5c16..668b45b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: false matrix: - ARCH: ['x86_64', 'i686', 'armhf', 'aarch64'] + ARCH: ['x86_64', 'i686', 'armhf', 'aarch64', 'loong64'] env: ARCH: ${{ matrix.ARCH }} @@ -23,8 +23,13 @@ jobs: submodules: 'recursive' - name: Set up QEMU integration for Docker + if: matrix.ARCH != 'loong64' run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes + - name: Set up QEMU integration for Loong64 + if: matrix.ARCH == 'loong64' + run: ./ci/prepare-loong64.sh + - name: Build in Docker container run: | bash -ex ci/build-in-docker.sh diff --git a/.gitignore b/.gitignore index 15fb151..511ce75 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ cmake-build-*/ *.*swp* *.bak *.AppImage* +.cache \ No newline at end of file diff --git a/ci/build-in-docker.sh b/ci/build-in-docker.sh index 42e4283..a83ed5e 100755 --- a/ci/build-in-docker.sh +++ b/ci/build-in-docker.sh @@ -24,6 +24,19 @@ case "$ARCH" in image_prefix=arm64v8 platform=linux/arm64/v8 ;; + loong64) + # create docker image + mkdir -p tmp + cd tmp + # edge-9c13e7 v3.18 Neither of them is able to be used. + wget -c https://dev.alpinelinux.org/~loongarch/edge/releases/loongarch64/alpine-minirootfs-edge-240514-loongarch64.tar.gz + # Actually: Alpine Linux 3.20.0_alpha20240329 (edge) + docker import alpine-minirootfs-*.tar.gz "loong64/alpine:3.19" --platform "linux/loong64" + cd .. + # create docker image end + image_prefix=loong64 # official unsatble + platform=linux/loong64 + ;; *) echo "unknown architecture: $ARCH" exit 2 @@ -40,8 +53,10 @@ repo_root="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")"/..)" # b) allow the build scripts to "mv" the binaries into the /out directory uid="$(id -u)" -# make sure Docker image is up to date -docker pull "$image" +if [ "$ARCH" != "loong64" ];then # loong64 is created locally, so it cannot be pulled. + # make sure Docker image is up to date + docker pull "$image" +fi # mount workspace read-only, trying to make sure the build doesn't ever touch the source code files # of course, this only works reliably if you don't run this script from that directory @@ -62,10 +77,11 @@ docker run \ set -euxo pipefail -apk add bash git gcc g++ cmake make file desktop-file-utils wget \ +apk add --no-cache 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 + curl-dev curl-static nghttp2-static libidn2-static openssl-libs-static brotli-static c-ares-static libunistring-static \ + libunistring-dev libpsl-static # libcurl's pkg-config scripts are broken. everywhere, everytime. # these additional flags have been collected from all the .pc files whose libs are mentioned as -l in Libs.private diff --git a/ci/prepare-loong64.sh b/ci/prepare-loong64.sh new file mode 100755 index 0000000..88d226c --- /dev/null +++ b/ci/prepare-loong64.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +set -ex + +cleanup () { + echo "clean" +} +trap cleanup EXIT + +mkdir -p tmp +cd tmp +mkdir -p qemu-user-static +cd qemu-user-static +wget -c https://archlinux.org/packages/extra/x86_64/qemu-user-static/download/ -O qemu-user-static.pkg.tar.zst +unzstd qemu-user-static.pkg.tar.zst +tar -xf qemu-user-static.pkg.tar +sudo mv ./usr/bin/* /usr/bin +ls -l /usr/bin/qemu-* +cd .. + +mkdir -p qemu-user-static-binfmt +cd qemu-user-static-binfmt +wget -c https://archlinux.org/packages/extra/x86_64/qemu-user-static-binfmt/download/ -O qemu-user-static-binfmt.pkg.tar.zst +unzstd qemu-user-static-binfmt.pkg.tar.zst +tar -xf qemu-user-static-binfmt.pkg.tar +sudo mv ./usr/lib/binfmt.d/* /usr/lib/binfmt.d +ls -l /usr/lib/binfmt.d/qemu-* +cd .. + +sudo systemctl restart systemd-binfmt.service + +# from https://packages.ubuntu.com/noble/amd64/qemu-user-static/download +# wget -c http://kr.archive.ubuntu.com/ubuntu/pool/universe/q/qemu/qemu-user-static_8.2.2+ds-0ubuntu1_amd64.deb +# sudo dpkg -i qemu-user-static_8.2.2+ds-0ubuntu1_amd64.deb diff --git a/src/appimagetool.c b/src/appimagetool.c index d3a10fe..53cff52 100644 --- a/src/appimagetool.c +++ b/src/appimagetool.c @@ -63,7 +63,8 @@ typedef enum { fARCH_i686, fARCH_x86_64, fARCH_armhf, - fARCH_aarch64 + fARCH_aarch64, + fARCH_loong64 } fARCH; static gchar const APPIMAGEIGNORE[] = ".appimageignore"; @@ -282,7 +283,7 @@ static void replacestr(char *line, const char *search, const char *replace) int count_archs(bool* archs) { int countArchs = 0; int i; - for (i = 0; i < 4; i++) { + for (i = 0; i < 5; i++) { countArchs += archs[i]; } return countArchs; @@ -298,6 +299,8 @@ gchar* archToName(fARCH arch) { return "i686"; case fARCH_x86_64: return "x86_64"; + case fARCH_loong64: + return "loong64"; } } @@ -310,6 +313,8 @@ gchar* getArchName(bool* archs) { return archToName(fARCH_armhf); else if (archs[fARCH_aarch64]) return archToName(fARCH_aarch64); + else if (archs[fARCH_loong64]) + return archToName(fARCH_loong64); else return "all"; } @@ -338,6 +343,12 @@ void extract_arch_from_e_machine_field(int16_t e_machine, const gchar* sourcenam if(verbose) fprintf(stderr, "%s used for determining architecture %s\n", sourcename, archToName(fARCH_aarch64)); } + // https://areweloongyet.com/docs/world-compat-details/#elf-%E6%96%87%E4%BB%B6%E6%A0%BC%E5%BC%8F + if (e_machine == 258) { + archs[fARCH_loong64] = 1; + if(verbose) + fprintf(stderr, "%s used for determining architecture %s\n", sourcename, archToName(fARCH_loong64)); + } } void extract_arch_from_text(gchar *archname, const gchar* sourcename, bool* archs) { @@ -370,6 +381,10 @@ void extract_arch_from_text(gchar *archname, const gchar* sourcename, bool* arch archs[fARCH_aarch64] = 1; if (verbose) fprintf(stderr, "%s used for determining architecture ARM aarch64\n", sourcename); + } else if (g_ascii_strncasecmp("loong64", archname, 20) == 0) { + archs[fARCH_loong64] = 1; + if (verbose) + fprintf(stderr, "%s used for determining architecture loong64\n", sourcename); } } }