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

loong64 arch support #188

Draft
wants to merge 2 commits into
base: master
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
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
19 changes: 18 additions & 1 deletion src/test-cargo.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
26 changes: 26 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,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
Expand Down
36 changes: 35 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,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
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
29 changes: 27 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,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
}
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" ] && ! 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"
Expand Down Expand Up @@ -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
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
Loading
Loading