diff --git a/docker-bake.hcl b/docker-bake.hcl index 2f91c76..1614538 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -136,7 +136,8 @@ target "_all-platforms" { "linux/mips64le", "linux/ppc64le", "linux/s390x", - "linux/riscv64" + "linux/riscv64", + "linux/loong64" ] } @@ -171,6 +172,7 @@ target "sdk-extras" { "linux/ppc64le", "linux/riscv64", "linux/s390x", + "linux/loong64", "windows/386", "windows/amd64", "windows/arm", diff --git a/src/test-cargo.bats b/src/test-cargo.bats index 9244cea..99dd7d8 100755 --- a/src/test-cargo.bats +++ b/src/test-cargo.bats @@ -47,7 +47,8 @@ testHelloCargoRustup() { @test "install-rustup" { add clang lld curl ca-certificates assert_success - run sh -c "curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=1.69.0 --no-modify-path --profile=minimal" + # https://releases.rs/docs/1.81.0/ adds support for loongarch64 on musl: https://doc.rust-lang.org/rustc/platform-support/loongarch-linux.html#building-rust-programs + run sh -c "curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=1.81.0 --no-modify-path --profile=minimal" assert_success export "PATH=/root/.cargo/bin:$PATH" run rustup --version 2>/dev/null @@ -75,6 +76,14 @@ testHelloCargoRustup() { testHelloCargoRustup } +@test "loong64-hellocargo-rustup" { + if ! supportLoong64Go; then + skip "LOONGARCH64 not supported" + fi + export TARGETARCH=loong64 + testHelloCargoRustup +} + @test "ppc64le-hellocargo-rustup" { if [ -f /etc/alpine-release ]; then skip "rust stdlib not yet available for powerpc64le-unknown-linux-musl" @@ -129,6 +138,14 @@ testHelloCargoRustup() { testHelloCargo } +@test "loong64-hellocargo-rustpkg" { + if ! supportLoong64Go; then + skip "LOONGARCH64 not supported" # rust stdlib package not available + fi + export TARGETARCH=loong64 + testHelloCargo +} + @test "ppc64le-hellocargo-rustpkg" { export TARGETARCH=ppc64le testHelloCargo diff --git a/src/test-clang.bats b/src/test-clang.bats index 959385d..40a26ed 100755 --- a/src/test-clang.bats +++ b/src/test-clang.bats @@ -259,6 +259,14 @@ testBuildHello() { testHelloCLLD } +@test "loong64-c-ld" { + if ! supportLoongArch; then + skip "LOONGARCH64 not supported" + fi + export TARGETARCH=loong64 + testHelloCLLD +} + @test "386-c-lld" { export TARGETARCH=386 testHelloCPPLLD @@ -300,6 +308,24 @@ testBuildHello() { testHelloCPPLLD # actually runs with ld } +@test "loong64-c++-lld" { + if ! supportLoongArch; then + skip "LOONGARCH64 not supported" + fi + if [ -f /etc/alpine-release ]; then + # FIXME: loong64-c++-lld issue on alpine < 3.21 + # ld.lld: error: unknown emulation: elf64loongarch + # ld.lld: error: /loongarch64-alpine-linux-musl/usr/lib/gcc/loongarch64-alpine-linux-musl/14.2.0/crtbeginS.o:(.text+0x0): unknown relocation (102) against symbol + # error: unknown target triple 'loongarch64-alpine-linux-musl', please use -triple or -arch + alpineRelease=$(cat /etc/alpine-release) + if ! grep PRETTY_NAME /etc/os-release | cut -d '=' -f 2 | tr -d '"' | grep -q "edge$" || [ "$(semver compare "$alpineRelease" "3.21.0")" -lt 0 ]; then + skip + fi + fi + export TARGETARCH=loong64 + testHelloCPPLLD +} + @test "386-c++-lld" { export TARGETARCH=386 testHelloCPPLLD diff --git a/src/test-go.bats b/src/test-go.bats index 92c5c0f..56f599c 100755 --- a/src/test-go.bats +++ b/src/test-go.bats @@ -17,7 +17,7 @@ setup_file() { } teardown_file() { - for p in linux/amd64 linux/arm64 linux/ppc64le linux/s390x linux/386 linux/arm/v7 linux/arm/v6 linux/riscv64; do + for p in linux/amd64 linux/arm64 linux/ppc64le linux/s390x linux/386 linux/arm/v7 linux/arm/v6 linux/riscv64 linux/loong64; do TARGETPLATFORM=$p xxdel xx-c-essentials root=/$(TARGETPLATFORM=$p xx-info triple) if [ -d "$root" ] && [ "$root" != "/" ]; then @@ -173,6 +173,14 @@ testEnv() { testEnv } +@test "loong64-env" { + if ! supportLoong64Go; then + skip "LOONGARCH64 not supported" + fi + export TARGETARCH=loong64 + testEnv +} + @test "mips-env" { export TARGETARCH=mips expMips=hardfloat @@ -333,6 +341,14 @@ testHelloGO() { testHelloGO } +@test "loong64-hellogo" { + if ! supportLoong64Go; then + skip "LOONGARCH64 not supported" + fi + export TARGETARCH=loong64 + testHelloGO +} + @test "386-hellogo" { export TARGETARCH=386 testHelloGO @@ -452,6 +468,24 @@ testHelloCGO() { testHelloCGO } +@test "loong64-hellocgo" { + if ! supportLoong64CGo; then + skip "LOONGARCH64 not supported" + fi + if [ -f /etc/alpine-release ]; then + # FIXME: loong64-hellocgo issue on alpine < 3.21 + # ld.lld: error: unknown emulation: elf64loongarch + # ld.lld: error: /loongarch64-alpine-linux-musl/usr/lib/gcc/loongarch64-alpine-linux-musl/14.2.0/crtbeginS.o:(.text+0x0): unknown relocation (102) against symbol + # error: unknown target triple 'loongarch64-alpine-linux-musl', please use -triple or -arch + alpineRelease=$(cat /etc/alpine-release) + if ! grep PRETTY_NAME /etc/os-release | cut -d '=' -f 2 | tr -d '"' | grep -q "edge$" || [ "$(semver compare "$alpineRelease" "3.21.0")" -lt 0 ]; then + skip + fi + fi + export TARGETARCH=loong64 + testHelloCGO +} + @test "386-hellocgo" { export TARGETARCH=386 testHelloCGO diff --git a/src/test-info-alpine.bats b/src/test-info-alpine.bats index 352c38c..97812e3 100755 --- a/src/test-info-alpine.bats +++ b/src/test-info-alpine.bats @@ -92,10 +92,15 @@ load 'assert' assert_equal "riscv64" "$(TARGETPLATFORM=linux/riscv64 RISCV64_TARGET_ARCH=riscv64gc xx-info pkg-arch)" # does not change } -@test "custom-vendor" { +@test "riscv64-custom-vendor" { assert_equal "riscv64-unknown-linux-musl" "$(TARGETPLATFORM=linux/riscv64 XX_VENDOR=unknown xx-info triple)" } +@test "loong64" { + assert_equal "loongarch64-alpine-linux-musl" "$(TARGETPLATFORM=linux/loong64 xx-info triple)" + assert_equal "loongarch64" "$(TARGETPLATFORM=linux/loong64 xx-info pkg-arch)" +} + @test "mips" { assert_equal "mips-alpine-linux-musl" "$(TARGETPLATFORM=linux/mips xx-info triple)" assert_equal "mips" "$(TARGETPLATFORM=linux/mips xx-info pkg-arch)" diff --git a/src/test-info-common.bats b/src/test-info-common.bats index 80d90c8..54a5ca6 100755 --- a/src/test-info-common.bats +++ b/src/test-info-common.bats @@ -85,6 +85,10 @@ load 'assert' assert_equal "ppc64le" "$(TARGETPLATFORM=linux/ppc64le xx-info march)" } +@test "loong64" { + assert_equal "loong64" "$(TARGETPLATFORM=linux/loong64 xx-info march)" +} + @test "mips" { assert_equal "mips" "$(TARGETPLATFORM=linux/mips xx-info march)" } @@ -134,6 +138,10 @@ load 'assert' assert_success assert_output "$(TARGETPLATFORM=linux/riscv64 xx-info)" + TARGETPAIR=linux-loong64 run xx-info + assert_success + assert_output "$(TARGETPLATFORM=linux/loong64 xx-info)" + TARGETPAIR=linux-mips run xx-info assert_success assert_output "$(TARGETPLATFORM=linux/mips xx-info)" diff --git a/src/test-info-debian.bats b/src/test-info-debian.bats index 3654f1e..9c65a01 100755 --- a/src/test-info-debian.bats +++ b/src/test-info-debian.bats @@ -77,6 +77,11 @@ fi assert_equal "riscv64gc-unknown-linux-gnu" "$(TARGETPLATFORM=linux/riscv64 RISCV64_TARGET_ARCH=riscv64gc XX_VENDOR=unknown xx-info triple)" } +@test "loong64" { + assert_equal "loongarch64-linux-gnu" "$(TARGETPLATFORM=linux/loong64 xx-info triple)" + assert_equal "loong64" "$(TARGETPLATFORM=linux/loong64 xx-info pkg-arch)" +} + @test "mips" { assert_equal "mips-linux-gnu" "$(TARGETPLATFORM=linux/mips xx-info triple)" assert_equal "mips" "$(TARGETPLATFORM=linux/mips xx-info pkg-arch)" diff --git a/src/test-info-rhel.bats b/src/test-info-rhel.bats index 1dff15c..707ce1a 100755 --- a/src/test-info-rhel.bats +++ b/src/test-info-rhel.bats @@ -60,6 +60,10 @@ fi assert_equal "riscv64" "$(TARGETPLATFORM=linux/riscv64 xx-info pkg-arch)" } +@test "loong64" { + assert_equal "loong64" "$(TARGETPLATFORM=linux/loong64 xx-info pkg-arch)" +} + @test "mips" { assert_equal "mips-linux-gnu" "$(TARGETPLATFORM=linux/mips xx-info triple)" assert_equal "mips" "$(TARGETPLATFORM=linux/mips xx-info pkg-arch)" diff --git a/src/test-verify.bats b/src/test-verify.bats index a9db217..01fd478 100755 --- a/src/test-verify.bats +++ b/src/test-verify.bats @@ -250,6 +250,15 @@ load 'assert' run xx-verify /idontexist assert_failure + export XX_VERIFY_FILE_CMD_OUTPUT=": ELF 64-bit LSB executable, LoongArch, version 1 (SYSV), statically linked, BuildID[sha1]=4d126b33c220ba2efd23ed68a46ef0db96c31f76, not stripped" + export TARGETPLATFORM=linux/loong64 + run xx-verify /idontexist + assert_success + + export TARGETPLATFORM=linux/amd64 + run xx-verify /idontexist + assert_failure + unset XX_VERIFY_FILE_CMD_OUTPUT unset TARGETPLATFORM } diff --git a/src/test_helper.bash b/src/test_helper.bash index 1d78a05..a6d7036 100644 --- a/src/test_helper.bash +++ b/src/test_helper.bash @@ -45,7 +45,7 @@ xxrun() { wasclang=1 fi if [ "$p" = "golang" ]; then - p="golang-1.15" + p="golang-1.19" wasgolang=1 fi set -- "$@" "$p" @@ -63,7 +63,7 @@ xxrun() { fi fi if [ -n "$wasgolang" ] && ! command -v go 2>/dev/null >/dev/null; then - ln -s /usr/lib/go-1.15/bin/go /usr/bin/go + ln -s /usr/lib/go-1.19/bin/go /usr/bin/go fi } @@ -78,6 +78,17 @@ supportRiscV() { return 0 } +supportLoongArch() { + if [ -f /etc/debian_version ]; then + if grep "sid main" /etc/apt/sources.list 2>/dev/null >/dev/null; then + return 0 + else + return 1 + fi + fi + return 0 +} + versionGTE() { test "$(printf '%s\n' "$@" | sort -V | tail -n 1)" = "$1"; } supportRiscVGo() { @@ -105,6 +116,20 @@ supportWindowsArm64Go() { versionGTE "$(go version | awk '{print $3}' | sed 's/^go//')" "1.17" } +supportLoong64Go() { + versionGTE "$(go version | awk '{print $3}' | sed 's/^go//')" "1.19" +} + +supportLoong64CGo() { + if ! supportLoongArch; then + return 1 + fi + if ! supportLoong64Go; then + return 1 + fi + return 0 +} + supportRC() { command -v llvm-rc >/dev/null 2>&1 } diff --git a/src/xx-apk b/src/xx-apk index 766e21f..0460b22 100755 --- a/src/xx-apk +++ b/src/xx-apk @@ -59,6 +59,11 @@ setup() { echo "https://dl-cdn.alpinelinux.org/alpine/v3.20/main" >"$apk_dir/repositories" echo "https://dl-cdn.alpinelinux.org/alpine/v3.20/community" >>"$apk_dir/repositories" fi + # loong64 supported since alpine 3.21 + if [ "$TARGETARCH" = "loong64" ] && ! supportLoong64; then + echo "https://dl-cdn.alpinelinux.org/alpine/v3.21/main" >"$apk_dir/repositories" + echo "https://dl-cdn.alpinelinux.org/alpine/v3.21/community" >>"$apk_dir/repositories" + fi mkdir -p "$apk_dir/keys" mkdir -p "$apk_dir/protected_paths.d" echo "$XX_PKG_ARCH" >"$apk_dir/arch" @@ -146,6 +151,10 @@ supportRiscV() { versionGTE "$(xx-info os-version | cut -d'.' -f1-2)" "3.20" } +supportLoong64() { + versionGTE "$(xx-info os-version | cut -d'.' -f1-2)" "3.21" +} + case "$1" in "setup") setup diff --git a/src/xx-cc b/src/xx-cc index 08446d3..8a7e5df 100755 --- a/src/xx-cc +++ b/src/xx-cc @@ -175,6 +175,8 @@ detectTargetOSArch() { targetarch="s390x" elif [ "$arch" = "powerpc64le" ]; then targetarch="ppc64le" + elif [ "$arch" = "loong64" ]; then + targetarch="loong64" fi if [ -z "$targetarch" ]; then @@ -342,6 +344,10 @@ setup() { if [ "${target#riscv64}" != "${target}" ]; then prefer_lld= fi + # lld has no support for loong64 + if [ "${target#loong64}" != "${target}" ]; then + prefer_lld= + fi if [ -n "${XX_CC_PREFER_STATIC_LINKER}" ] && { [ "${target#386}" != "${target}" ] || [ "${target#powerpc64le}" != "${target}" ]; }; then prefer_lld= @@ -410,6 +416,9 @@ setup() { if [ "$exp" = "riscv64" ]; then exp="riscv" fi + if [ "$exp" = "loong64" ]; then + exp="loongarch64" + fi if ld -V 2>/dev/null | grep "$exp" >/dev/null; then ln -s "$(command -v ld)" "/usr/bin/${target}-ld" linker="/usr/bin/${target}-ld" diff --git a/src/xx-info b/src/xx-info index dfe574f..0cecfd7 100755 --- a/src/xx-info +++ b/src/xx-info @@ -190,6 +190,9 @@ if [ -z "$TARGETARCH" ]; then "s390x") TARGETARCH="s390x" ;; + "loong64") + TARGETARCH="loong64" + ;; "mips") TARGETARCH="mips" ;; @@ -221,6 +224,8 @@ if [ "$TARGETOS" = "darwin" ] && [ -z "$MACOSX_VERSION_MIN" ]; then fi fi +# debian: https://git.dpkg.org/cgit/dpkg/dpkg.git/tree/data/cputable +# alpine: https://gitlab.alpinelinux.org/alpine/apk-tools/-/blob/master/src/apk_arch.h?ref_type=heads case "$TARGETARCH" in "amd64") XX_MARCH="x86_64" @@ -309,6 +314,13 @@ case "$TARGETARCH" in XX_RHEL_ARCH="s390x" XX_TRIPLE="s390x${vendor}-linux-${XX_LIBC}" ;; + "loong64") + XX_MARCH="loong64" + XX_DEBIAN_ARCH="loong64" + XX_ALPINE_ARCH="loongarch64" + XX_RHEL_ARCH="loong64" + XX_TRIPLE="loongarch64${vendor}-linux-${XX_LIBC}" + ;; "386") XX_MARCH="i386" XX_DEBIAN_ARCH="i386" diff --git a/src/xx-verify b/src/xx-verify index 8442d53..281d620 100755 --- a/src/xx-verify +++ b/src/xx-verify @@ -214,6 +214,10 @@ for f in "$@"; do expArch="IBM S/390" expArch2="64-bit MSB" ;; + "loong64") + expArch="LoongArch" + expArch2="64-bit LSB" + ;; "mips") expArch="MIPS" expArch2="32-bit MSB" diff --git a/util/bats-assert/docker-bake.hcl b/util/bats-assert/docker-bake.hcl index 8bf3f1a..75e999b 100644 --- a/util/bats-assert/docker-bake.hcl +++ b/util/bats-assert/docker-bake.hcl @@ -19,7 +19,8 @@ target "all" { "linux/386", "linux/riscv64", "linux/s390x", - "linux/ppc64le" + "linux/ppc64le", + "linux/loong64" ] }