Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add loong64 support
Browse files Browse the repository at this point in the history
Signed-off-by: yzewei <yangzewei@loongson.cn>
yzewei committed Jan 9, 2024
1 parent 8db003e commit 36962f9
Showing 16 changed files with 121 additions and 5 deletions.
4 changes: 3 additions & 1 deletion docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -135,7 +135,8 @@ target "_all-platforms" {
"linux/mips64le",
"linux/ppc64le",
"linux/s390x",
"linux/riscv64"
"linux/riscv64",
"linux/loong64"
]
}

@@ -169,6 +170,7 @@ target "sdk-extras" {
"linux/mips64le",
"linux/ppc64le",
"linux/riscv64",
"linux/loong64",
"linux/s390x",
"windows/386",
"windows/amd64",
8 changes: 8 additions & 0 deletions src/test-cargo.bats
Original file line number Diff line number Diff line change
@@ -91,6 +91,10 @@ testHelloCargoRustup() {
testHelloCargoRustup
}

@test "loong64-hellocargo-rustup" {
skip "LOONG64 not supported" # rust stdlib package not available
}

@test "386-hellocargo-rustup" {
export TARGETARCH=386
testHelloCargoRustup
@@ -143,6 +147,10 @@ testHelloCargoRustup() {
testHelloCargo
}

@test "loong64-hellocargo-rustpkg" {
skip "LOONG64 not supported" # rust stdlib package not available
}

@test "386-hellocargo-rustpkg" {
export TARGETARCH=386
testHelloCargo
14 changes: 14 additions & 0 deletions src/test-clang.bats
Original file line number Diff line number Diff line change
@@ -254,6 +254,14 @@ testBuildHello() {
expectedSuffix=
}

@test "loong64-c-ld" {
if ! supportLoongArch; then
skip "LOONGARCH not supported"
fi
export TARGETARCH=loong64
testHelloCLLD
}

@test "ppc64le-c-lld" {
export TARGETARCH=ppc64le
testHelloCLLD
@@ -300,6 +308,12 @@ testBuildHello() {
testHelloCPPLLD # actually runs with ld
}

@test "loong64-c++-ld" {
skip "LOONG64 not supported"
export TARGETARCH=loong64
testHelloCPPLLD # actually runs with ld
}

@test "386-c++-lld" {
export TARGETARCH=386
testHelloCPPLLD
17 changes: 17 additions & 0 deletions src/test-go.bats
Original file line number Diff line number Diff line change
@@ -118,6 +118,14 @@ testEnv() {
testEnv
}

@test "loong64-env" {
if ! supportLoongArch; then
skip "LoongArch GO not supported"
fi
export TARGETARCH=loong64
testEnv
}

@test "s390x-env" {
export TARGETARCH=s390x
testEnv
@@ -253,6 +261,11 @@ testHelloGO() {
testHelloGO
}

@test "loong64-hellogo" {
export TARGETARCH=loong64
testHelloGO
}

@test "386-hellogo" {
export TARGETARCH=386
testHelloGO
@@ -335,6 +348,10 @@ testHelloCGO() {
testHelloCGO
}

@test "loong64-hellocgo" {
skip "LOONG64 CGO not supported"
}

@test "386-hellocgo" {
export TARGETARCH=386
testHelloCGO
5 changes: 5 additions & 0 deletions src/test-info-alpine.bats
Original file line number Diff line number Diff line change
@@ -74,6 +74,11 @@ load 'assert'
assert_equal "riscv64" "$(TARGETPLATFORM=linux/riscv64 RISCV64_TARGET_ARCH=riscv64gc xx-info pkg-arch)" # does not change
}

@test "loong64" {
assert_equal "loong64-alpine-linux-muslabi" "$(TARGETPLATFORM=linux/loong64 xx-info triple)"
assert_equal "loongarch64" "$(TARGETPLATFORM=linux/loong64 xx-info pkg-arch)"
}

@test "custom-vendor" {
assert_equal "riscv64-unknown-linux-musl" "$(TARGETPLATFORM=linux/riscv64 XX_VENDOR=unknown xx-info triple)"
}
8 changes: 8 additions & 0 deletions src/test-info-common.bats
Original file line number Diff line number Diff line change
@@ -77,6 +77,10 @@ load 'assert'
assert_equal "riscv64" "$(TARGETPLATFORM=linux/riscv64 xx-info march)"
}

@test "loong64" {
assert_equal "loong64" "$(TARGETPLATFORM=linux/loong64 xx-info march)"
}

@test "s390x" {
assert_equal "s390x" "$(TARGETPLATFORM=linux/s390x 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)"
5 changes: 5 additions & 0 deletions src/test-info-debian.bats
Original file line number Diff line number Diff line change
@@ -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 "loong64-linux-gnuabi" "$(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)"
4 changes: 4 additions & 0 deletions src/test-info-rhel.bats
Original file line number Diff line number Diff line change
@@ -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)"
5 changes: 5 additions & 0 deletions src/test-verify.bats
Original file line number Diff line number Diff line change
@@ -222,6 +222,11 @@ load 'assert'
run xx-verify /idontexist
assert_success

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
11 changes: 11 additions & 0 deletions src/test_helper.bash
Original file line number Diff line number Diff line change
@@ -91,6 +91,17 @@ supportRiscVCGo() {
versionGTE "$(go version | awk '{print $3}' | sed 's/^go//')" "1.16"
}

supportLoongArch() {
if [ -f /etc/debian_version ]; then
if grep "sid" /etc/apt/sources.list 2>/dev/null >/dev/null; then
return 0
else
return 1
fi
fi
return 0
}

supportRC() {
command -v llvm-rc >/dev/null 2>&1
}
6 changes: 6 additions & 0 deletions src/xx-apk
Original file line number Diff line number Diff line change
@@ -51,6 +51,12 @@ setup() {
echo "https://dl-cdn.alpinelinux.org/alpine/edge/main" >"$apk_dir/repositories"
echo "https://dl-cdn.alpinelinux.org/alpine/edge/community" >>"$apk_dir/repositories"
fi
# add loongarch support
if [ "$TARGETARCH" = "loong64" ]; then
echo "http://alpine.loongnix.cn/v3.11/main" >"$apk_dir/repositories"
echo "http://alpine.loongnix.cn/v3.11/community" >>"$apk_dir/repositories"
echo "http://alpine.loongnix.cn/v3.11/testing" >>"$apk_dir/repositories"
fi
mkdir "$apk_dir/keys"
mkdir "$apk_dir/protected_paths.d"
echo "$XX_PKG_ARCH" >"$apk_dir/arch"
7 changes: 7 additions & 0 deletions src/xx-apt
Original file line number Diff line number Diff line change
@@ -140,6 +140,13 @@ if [ "$TARGETARCH" = "riscv64" ] && [ "$(xx-info vendor)" = "debian" ]; then
echo "deb [ arch=riscv64 ] http://ftp.ports.debian.org/debian-ports sid main" >>/etc/apt/sources.list.d/riscv64-sid.list
fi

if [ "$TARGETARCH" = "loong64" ] && [ "$(xx-info vendor)" = "debian" ]; then
apt-get update
apt-get install -y debian-ports-archive-keyring
echo "deb [ arch=loong64 ] http://ftp.ports.debian.org/debian-ports sid main
deb [ arch=loong64 ] http://ftp.ports.debian.org/debian-ports unreleased main" >>/etc/apt/sources.list.d/loong64-sid.list
fi

if ! dpkg --print-foreign-architectures | grep "$XX_PKG_ARCH" >/dev/null; then
if [ "$XX_OS" = "linux" ]; then
if [ "$(xx-info vendor)" = "ubuntu" ] && [ -z "$nocross" ]; then
8 changes: 4 additions & 4 deletions src/xx-cargo
Original file line number Diff line number Diff line change
@@ -79,12 +79,12 @@ if [ -n "$XX_RUSTFLAGS" ]; then
fi
export "CC_$(xx-info | tr - _)=$(xx-info)-clang"

if which "qemu-$(RISCV64_TARGET_ARCH='' ARM_TARGET_ARCH='' xx-info march)" >/dev/null 2>&1; then
export "CARGO_TARGET_$(xx-info | tr '[:lower:]' '[:upper:]' | tr - _)_RUNNER=qemu-$(RISCV64_TARGET_ARCH='' ARM_TARGET_ARCH='' xx-info march)"
if which "qemu-$(RISCV64_TARGET_ARCH='' ARM_TARGET_ARCH='' LOONG64_TARGET_ARCH='' xx-info march)" >/dev/null 2>&1; then
export "CARGO_TARGET_$(xx-info | tr '[:lower:]' '[:upper:]' | tr - _)_RUNNER=qemu-$(RISCV64_TARGET_ARCH='' ARM_TARGET_ARCH='' LOONG64_TARGET_ARCH='' xx-info march)"
if [ -f /etc/alpine-release ]; then
export "QEMU_LD_PREFIX=/$(RISCV64_TARGET_ARCH='' ARM_TARGET_ARCH='' xx-info)/"
export "QEMU_LD_PREFIX=/$(RISCV64_TARGET_ARCH='' ARM_TARGET_ARCH='' LOONG64_TARGET_ARCH='' xx-info)/"
else
export "QEMU_LD_PREFIX=/lib/$(RISCV64_TARGET_ARCH='' ARM_TARGET_ARCH='' XX_VENDOR='' xx-info)/"
export "QEMU_LD_PREFIX=/lib/$(RISCV64_TARGET_ARCH='' ARM_TARGET_ARCH='' LOONG64_TARGET_ARCH='' XX_VENDOR='' xx-info)/"
fi
fi

9 changes: 9 additions & 0 deletions src/xx-cc
Original file line number Diff line number Diff line change
@@ -175,6 +175,8 @@ detectTargetOSArch() {
targetarch="s390x"
elif [ "$arch" = "powerpc64le" ]; then
targetarch="ppc64le"
elif [ "$arch" = "loong64" ]; then
targetarch="loong64"
fi

if [ -z "$targetarch" ]; then
@@ -334,6 +336,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=
@@ -402,6 +408,9 @@ setup() {
if [ "$exp" = "riscv64" ]; then
exp="riscv"
fi
if [ "$exp" = "loong64" ]; then
exp="loongarch"
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"
11 changes: 11 additions & 0 deletions src/xx-info
Original file line number Diff line number Diff line change
@@ -189,6 +189,9 @@ if [ -z "$TARGETARCH" ]; then
"mips64le")
TARGETARCH="mips64le"
;;
"loongarch64")
TARGETARCH="loong64"
;;
esac
fi

@@ -337,6 +340,14 @@ case "$TARGETARCH" in
XX_RHEL_ARCH="mips64el"
XX_TRIPLE="mips64el${vendor}-linux-${XX_LIBC}abi64"
;;
"loong64")
XX_MARCH="loong64"
XX_DEBIAN_ARCH="loong64"
XX_ALPINE_ARCH="loongarch64"
XX_RHEL_ARCH="loong64"
XX_TRIPLE="loong64${vendor}-linux-${XX_LIBC}abi"
;;

esac

XX_PKG_ARCH=$TARGETARCH
4 changes: 4 additions & 0 deletions src/xx-verify
Original file line number Diff line number Diff line change
@@ -220,6 +220,10 @@ for f in "$@"; do
expArch="MIPS"
expArch2="64-bit LSB"
;;
"loong64")
expArch="LoongArch"
expArch2="ELF 64-bit LSB"
;;
"386")
expArch="Intel 80386"
if [ "$TARGETOS" != "windows" ]; then

0 comments on commit 36962f9

Please sign in to comment.