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

add loong64 support for src #130

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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 @@ -135,7 +135,8 @@ target "_all-platforms" {
"linux/mips64le",
"linux/ppc64le",
"linux/s390x",
"linux/riscv64"
"linux/riscv64",
"linux/loong64"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whitespace issue here and other places in HCL

]
}

Expand Down Expand Up @@ -169,6 +170,7 @@ target "sdk-extras" {
"linux/mips64le",
"linux/ppc64le",
"linux/riscv64",
"linux/loong64",
"linux/s390x",
"windows/386",
"windows/amd64",
Expand Down
8 changes: 8 additions & 0 deletions src/test-cargo.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions src/test-clang.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions src/test-go.bats
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ testEnv() {
testEnv
}

@test "loong64-env" {
export TARGETARCH=loong64
testEnv
}

@test "s390x-env" {
export TARGETARCH=s390x
testEnv
Expand Down Expand Up @@ -197,6 +202,7 @@ testEnv() {
unset TARGETOS
}


testHelloGO() {
yzewei marked this conversation as resolved.
Show resolved Hide resolved
run xx-go build -o /tmp/a.out ./fixtures/hello.go
assert_success
Expand Down Expand Up @@ -253,6 +259,14 @@ testHelloGO() {
testHelloGO
}

@test "loong64-hellogo" {
if ! supportLoongArchGo; then
skip "LOONG64 GO not supported"
fi
export TARGETARCH=loong64
testHelloGO
}

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

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

@test "386-hellocgo" {
export TARGETARCH=386
testHelloCGO
Expand Down
5 changes: 5 additions & 0 deletions src/test-info-alpine.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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-musl" "$(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)"
}
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 @@ -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)"
}
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 "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)"
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
5 changes: 5 additions & 0 deletions src/test-verify.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions src/test_helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@ 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
}

supportLoongArchGo() {
go version | grep -E "1.19|1.20|1.21" >/dev/null 2>&1
}

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
Expand Up @@ -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"
yzewei marked this conversation as resolved.
Show resolved Hide resolved
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"
Expand Down
7 changes: 7 additions & 0 deletions src/xx-apt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/xx-cargo
Original file line number Diff line number Diff line change
Expand Up @@ -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

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 @@ -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=
Expand Down Expand Up @@ -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"
Expand Down
11 changes: 11 additions & 0 deletions src/xx-info
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ if [ -z "$TARGETARCH" ]; then
"mips64le")
TARGETARCH="mips64le"
;;
"loongarch64")
TARGETARCH="loong64"
;;
esac
fi

Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/xx-verify
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion util/bats-assert/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ RUN diff test.bats.output test.bats.golden
FROM scratch AS golden
COPY --from=test-gen /work/test.bats.output test.bats.golden

FROM release
FROM release