Skip to content

Commit

Permalink
loong64 arch support
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Dec 10, 2024
1 parent 9b9d7bb commit 552c6fa
Show file tree
Hide file tree
Showing 15 changed files with 142 additions and 6 deletions.
4 changes: 3 additions & 1 deletion docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ target "_all-platforms" {
"linux/mips64le",
"linux/ppc64le",
"linux/s390x",
"linux/riscv64"
"linux/riscv64",
"linux/loong64"
]
}

Expand Down Expand Up @@ -171,6 +172,7 @@ target "sdk-extras" {
"linux/ppc64le",
"linux/riscv64",
"linux/s390x",
"linux/loong64",
"windows/386",
"windows/amd64",
"windows/arm",
Expand Down
16 changes: 16 additions & 0 deletions src/test-cargo.bats
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ testHelloCargoRustup() {
testHelloCargoRustup
}

@test "loong64-hellocargo-rustup" {
if ! supportLoongArch; 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"
Expand Down Expand Up @@ -130,6 +138,14 @@ testHelloCargoRustup() {
testHelloCargo
}

@test "loong64-hellocargo-rustpkg" {
if ! supportLoongArch; then
skip "LOONGARCH64 not supported" # rust stdlib package not available
fi
export TARGETARCH=loong64
testHelloCargo
}

@test "ppc64le-hellocargo-rustpkg" {
export TARGETARCH=ppc64le
testHelloCargo
Expand Down
13 changes: 13 additions & 0 deletions src/test-clang.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -300,6 +308,11 @@ testBuildHello() {
testHelloCPPLLD # actually runs with ld
}

@test "loong64-c++-lld" {
export TARGETARCH=loong64
testHelloCPPLLD
}

@test "386-c++-lld" {
export TARGETARCH=386
testHelloCPPLLD
Expand Down
26 changes: 25 additions & 1 deletion src/test-go.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -452,6 +468,14 @@ testHelloCGO() {
testHelloCGO
}

@test "loong64-hellocgo" {
if ! supportLoong64Go; then
skip "LOONGARCH64 not supported"
fi
export TARGETARCH=loong64
testHelloCGO
}

@test "386-hellocgo" {
export TARGETARCH=386
testHelloCGO
Expand Down
7 changes: 6 additions & 1 deletion src/test-info-alpine.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
8 changes: 8 additions & 0 deletions src/test-info-common.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
}
Expand Down Expand Up @@ -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)"
Expand Down
5 changes: 5 additions & 0 deletions src/test-info-debian.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
4 changes: 4 additions & 0 deletions src/test-info-rhel.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
9 changes: 9 additions & 0 deletions src/test-verify.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
19 changes: 17 additions & 2 deletions src/test_helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}

Expand All @@ -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() {
Expand Down Expand Up @@ -105,6 +116,10 @@ supportWindowsArm64Go() {
versionGTE "$(go version | awk '{print $3}' | sed 's/^go//')" "1.17"
}

supportLoong64Go() {
versionGTE "$(go version | awk '{print $3}' | sed 's/^go//')" "1.19"
}

supportRC() {
command -v llvm-rc >/dev/null 2>&1
}
9 changes: 9 additions & 0 deletions src/xx-apk
Original file line number Diff line number Diff line change
Expand Up @@ -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" ] && ! supportRiscV; 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 "$apk_dir/keys"
mkdir "$apk_dir/protected_paths.d"
echo "$XX_PKG_ARCH" >"$apk_dir/arch"
Expand Down Expand Up @@ -144,6 +149,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
Expand Down
9 changes: 9 additions & 0 deletions src/xx-cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ detectTargetOSArch() {
targetarch="s390x"
elif [ "$arch" = "powerpc64le" ]; then
targetarch="ppc64le"
elif [ "$arch" = "loong64" ]; then
targetarch="loong64"
fi

if [ -z "$targetarch" ]; then
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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"
Expand Down
12 changes: 12 additions & 0 deletions src/xx-info
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ if [ -z "$TARGETARCH" ]; then
"s390x")
TARGETARCH="s390x"
;;
"loong64")
TARGETARCH="loong64"
;;
"mips")
TARGETARCH="mips"
;;
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions src/xx-verify
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion util/bats-assert/docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ target "all" {
"linux/386",
"linux/riscv64",
"linux/s390x",
"linux/ppc64le"
"linux/ppc64le",
"linux/loong64"
]
}

Expand Down

0 comments on commit 552c6fa

Please sign in to comment.