From 2b3562af1c10a434d956c34ed2df1c1f1b69a2b8 Mon Sep 17 00:00:00 2001 From: wangling12 Date: Mon, 29 Nov 2021 18:08:06 +0800 Subject: [PATCH] add support for loongarch64 --- ci/build-appdir.sh | 2 ++ ci/build-binaries-and-appimage.sh | 22 +++++++++++++++++----- src/appimagetool.c | 20 +++++++++++++++++--- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/ci/build-appdir.sh b/ci/build-appdir.sh index 4be7c977a..5d55cb020 100755 --- a/ci/build-appdir.sh +++ b/ci/build-appdir.sh @@ -66,6 +66,8 @@ if [ -d /deps/ ]; then cp "$(ldconfig -p | grep libffi.so.6 | grep arm | grep hf | cut -d'>' -f2 | tr -d ' ')" "$appimagetool_appdir"/usr/lib/ elif [ "$ARCH" == "aarch64" ]; then cp "$(ldconfig -p | grep libffi.so.6 | grep aarch64 | cut -d'>' -f2 | tr -d ' ')" "$appimagetool_appdir"/usr/lib/ + elif [ "$ARCH" == "loongarch64" ]; then + cp "$(ldconfig -p | grep libffi.so.6 | grep loongarch64 | cut -d'>' -f2 | tr -d ' ')" "$appimagetool_appdir"/usr/lib/ else echo "WARNING: unknown architecture, not bundling libffi" fi diff --git a/ci/build-binaries-and-appimage.sh b/ci/build-binaries-and-appimage.sh index cfca7ded9..6213d868c 100755 --- a/ci/build-binaries-and-appimage.sh +++ b/ci/build-binaries-and-appimage.sh @@ -40,11 +40,23 @@ OLD_CWD="$(readlink -f .)" pushd "$BUILD_DIR" # configure build and generate build files -cmake "$REPO_ROOT" \ - -DCMAKE_INSTALL_PREFIX=/usr \ - -DCMAKE_BUILD_TYPE=RelWithDebInfo \ - -DBUILD_TESTING=ON \ - -DAPPIMAGEKIT_PACKAGE_DEBS=ON + +CMAKE_ARGS=( + "-DCMAKE_INSTALL_PREFIX=/usr" + "-DCMAKE_BUILD_TYPE=RelWithDebInfo" + "-DBUILD_TESTING=ON" + "-DAPPIMAGEKIT_PACKAGE_DEBS=ON" +) + +if [[ "$ARCH" =~ loongarch ]]; then + CMAKE_ARGS=( + "${CMAKE_ARGS[@]}" + "-DBUILD_TESTING=ON" + "-DUSE_SYSTEM_LIBARCHIVE=ON" + ) +fi + +cmake "$REPO_ROOT" "${CMAKE_ARGS[@]}" # run build if [[ "$CI" != "" ]]; then diff --git a/src/appimagetool.c b/src/appimagetool.c index b9939253e..d74a49295 100644 --- a/src/appimagetool.c +++ b/src/appimagetool.c @@ -65,7 +65,9 @@ enum fARCH { fARCH_i386, fARCH_x86_64, fARCH_arm, - fARCH_aarch64 + fARCH_aarch64, + fARCH_loongarch64, + fARCH_SIZE // To get the number of architectures. }; static gchar const APPIMAGEIGNORE[] = ".appimageignore"; @@ -288,7 +290,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 < fARCH_SIZE; i++) { countArchs += archs[i]; } return countArchs; @@ -303,11 +305,18 @@ gchar* getArchName(bool* archs) { return "armhf"; else if (archs[fARCH_aarch64]) return "aarch64"; + else if (archs[fARCH_loongarch64]) + return "loongarch64"; else return "all"; } void extract_arch_from_e_machine_field(int16_t e_machine, const gchar* sourcename, bool* archs) { + if (e_machine == 2) { + archs[fARCH_loongarch64] = 1; + if(verbose) + fprintf(stderr, "%s used for determining architecture loongarch64\n", sourcename); + } if (e_machine == 3) { archs[fARCH_i386] = 1; if(verbose) @@ -363,6 +372,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("loongarch64", archname, 20) == 0) { + archs[fARCH_loongarch64] = 1; + if (verbose) + fprintf(stderr, "%s used for determining architecture loongarch64\n", sourcename); } } } @@ -720,7 +733,8 @@ main (int argc, char *argv[]) } /* Determine the architecture */ - bool archs[4] = {0, 0, 0, 0}; + bool archs[fARCH_SIZE]; + memset(archs,0,sizeof(bool)*fARCH_SIZE); extract_arch_from_text(getenv("ARCH"), "Environmental variable ARCH", archs); if (count_archs(archs) != 1) { /* If no $ARCH variable is set check a file */