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

feat: add loong64 support #53

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
7 changes: 6 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ cmake-build-*/
*.*swp*
*.bak
*.AppImage*
.cache
24 changes: 20 additions & 4 deletions ci/build-in-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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<lib> in Libs.private
Expand Down
34 changes: 34 additions & 0 deletions ci/prepare-loong64.sh
Original file line number Diff line number Diff line change
@@ -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
19 changes: 17 additions & 2 deletions src/appimagetool.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand All @@ -298,6 +299,8 @@ gchar* archToName(fARCH arch) {
return "i686";
case fARCH_x86_64:
return "x86_64";
case fARCH_loong64:
return "loong64";
}
}

Expand All @@ -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";
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
Loading