Skip to content

Commit 6474854

Browse files
authored
Merge pull request #188 from crazy-max/loong64
loong64 arch support
2 parents 5b413d3 + 3f4719d commit 6474854

15 files changed

+191
-7
lines changed

docker-bake.hcl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ target "_all-platforms" {
136136
"linux/mips64le",
137137
"linux/ppc64le",
138138
"linux/s390x",
139-
"linux/riscv64"
139+
"linux/riscv64",
140+
"linux/loong64"
140141
]
141142
}
142143

@@ -171,6 +172,7 @@ target "sdk-extras" {
171172
"linux/ppc64le",
172173
"linux/riscv64",
173174
"linux/s390x",
175+
"linux/loong64",
174176
"windows/386",
175177
"windows/amd64",
176178
"windows/arm",

src/test-cargo.bats

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ testHelloCargoRustup() {
4747
@test "install-rustup" {
4848
add clang lld curl ca-certificates
4949
assert_success
50-
run sh -c "curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=1.69.0 --no-modify-path --profile=minimal"
50+
# 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
51+
run sh -c "curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=1.81.0 --no-modify-path --profile=minimal"
5152
assert_success
5253
export "PATH=/root/.cargo/bin:$PATH"
5354
run rustup --version 2>/dev/null
@@ -75,6 +76,14 @@ testHelloCargoRustup() {
7576
testHelloCargoRustup
7677
}
7778

79+
@test "loong64-hellocargo-rustup" {
80+
if ! supportLoong64Go; then
81+
skip "LOONGARCH64 not supported"
82+
fi
83+
export TARGETARCH=loong64
84+
testHelloCargoRustup
85+
}
86+
7887
@test "ppc64le-hellocargo-rustup" {
7988
if [ -f /etc/alpine-release ]; then
8089
skip "rust stdlib not yet available for powerpc64le-unknown-linux-musl"
@@ -129,6 +138,14 @@ testHelloCargoRustup() {
129138
testHelloCargo
130139
}
131140

141+
@test "loong64-hellocargo-rustpkg" {
142+
if ! supportLoong64Go; then
143+
skip "LOONGARCH64 not supported" # rust stdlib package not available
144+
fi
145+
export TARGETARCH=loong64
146+
testHelloCargo
147+
}
148+
132149
@test "ppc64le-hellocargo-rustpkg" {
133150
export TARGETARCH=ppc64le
134151
testHelloCargo

src/test-clang.bats

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,28 @@ testBuildHello() {
259259
testHelloCLLD
260260
}
261261

262+
@test "loong64-c-ld" {
263+
if ! supportLoongArch; then
264+
skip "LOONGARCH64 not supported"
265+
fi
266+
if [ -f /etc/alpine-release ]; then
267+
# FIXME: loong64-c-lld issue on alpine < 3.21
268+
# 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
269+
# ld.lld: error: /loongarch64-alpine-linux-musl/usr/lib/gcc/loongarch64-alpine-linux-musl/14.2.0/crtbeginS.o:(.text+0x3c): unknown relocation (102) against symbol
270+
# ld.lld: error: /loongarch64-alpine-linux-musl/usr/lib/gcc/loongarch64-alpine-linux-musl/14.2.0/crtbeginS.o:(.text+0x64): unknown relocation (102) against symbol
271+
# ld.lld: error: /loongarch64-alpine-linux-musl/usr/lib/gcc/loongarch64-alpine-linux-musl/14.2.0/crtbeginS.o:(.text+0xb4): unknown relocation (102) against symbol
272+
# ld.lld: error: /loongarch64-alpine-linux-musl/usr/lib/gcc/loongarch64-alpine-linux-musl/14.2.0/crtbeginS.o:(.text+0xdc): unknown relocation (102) against symbol
273+
# ld.lld: error: /loongarch64-alpine-linux-musl/usr/lib/gcc/loongarch64-alpine-linux-musl/14.2.0/crtbeginS.o:(.text+0x154): unknown relocation (102) against symbol
274+
# ld.lld: error: /loongarch64-alpine-linux-musl/usr/lib/gcc/loongarch64-alpine-linux-musl/14.2.0/crtbeginS.o:(.text+0x198): unknown relocation (102) against symbol
275+
alpineRelease=$(cat /etc/alpine-release)
276+
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
277+
skip
278+
fi
279+
fi
280+
export TARGETARCH=loong64
281+
testHelloCLLD
282+
}
283+
262284
@test "386-c-lld" {
263285
export TARGETARCH=386
264286
testHelloCPPLLD
@@ -300,6 +322,24 @@ testBuildHello() {
300322
testHelloCPPLLD # actually runs with ld
301323
}
302324

325+
@test "loong64-c++-lld" {
326+
if ! supportLoongArch; then
327+
skip "LOONGARCH64 not supported"
328+
fi
329+
if [ -f /etc/alpine-release ]; then
330+
# FIXME: loong64-c++-lld issue on alpine < 3.21
331+
# ld.lld: error: unknown emulation: elf64loongarch
332+
# 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
333+
# error: unknown target triple 'loongarch64-alpine-linux-musl', please use -triple or -arch
334+
alpineRelease=$(cat /etc/alpine-release)
335+
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
336+
skip
337+
fi
338+
fi
339+
export TARGETARCH=loong64
340+
testHelloCPPLLD
341+
}
342+
303343
@test "386-c++-lld" {
304344
export TARGETARCH=386
305345
testHelloCPPLLD

src/test-go.bats

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ setup_file() {
1717
}
1818

1919
teardown_file() {
20-
for p in linux/amd64 linux/arm64 linux/ppc64le linux/s390x linux/386 linux/arm/v7 linux/arm/v6 linux/riscv64; do
20+
for p in linux/amd64 linux/arm64 linux/ppc64le linux/s390x linux/386 linux/arm/v7 linux/arm/v6 linux/riscv64 linux/loong64; do
2121
TARGETPLATFORM=$p xxdel xx-c-essentials
2222
root=/$(TARGETPLATFORM=$p xx-info triple)
2323
if [ -d "$root" ] && [ "$root" != "/" ]; then
@@ -173,6 +173,14 @@ testEnv() {
173173
testEnv
174174
}
175175

176+
@test "loong64-env" {
177+
if ! supportLoong64Go; then
178+
skip "LOONGARCH64 not supported"
179+
fi
180+
export TARGETARCH=loong64
181+
testEnv
182+
}
183+
176184
@test "mips-env" {
177185
export TARGETARCH=mips
178186
expMips=hardfloat
@@ -333,6 +341,14 @@ testHelloGO() {
333341
testHelloGO
334342
}
335343

344+
@test "loong64-hellogo" {
345+
if ! supportLoong64Go; then
346+
skip "LOONGARCH64 not supported"
347+
fi
348+
export TARGETARCH=loong64
349+
testHelloGO
350+
}
351+
336352
@test "386-hellogo" {
337353
export TARGETARCH=386
338354
testHelloGO
@@ -452,6 +468,24 @@ testHelloCGO() {
452468
testHelloCGO
453469
}
454470

471+
@test "loong64-hellocgo" {
472+
if ! supportLoong64CGo; then
473+
skip "LOONGARCH64 not supported"
474+
fi
475+
if [ -f /etc/alpine-release ]; then
476+
# FIXME: loong64-hellocgo issue on alpine < 3.21
477+
# ld.lld: error: unknown emulation: elf64loongarch
478+
# 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
479+
# error: unknown target triple 'loongarch64-alpine-linux-musl', please use -triple or -arch
480+
alpineRelease=$(cat /etc/alpine-release)
481+
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
482+
skip
483+
fi
484+
fi
485+
export TARGETARCH=loong64
486+
testHelloCGO
487+
}
488+
455489
@test "386-hellocgo" {
456490
export TARGETARCH=386
457491
testHelloCGO

src/test-info-alpine.bats

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,15 @@ load 'assert'
9292
assert_equal "riscv64" "$(TARGETPLATFORM=linux/riscv64 RISCV64_TARGET_ARCH=riscv64gc xx-info pkg-arch)" # does not change
9393
}
9494

95-
@test "custom-vendor" {
95+
@test "riscv64-custom-vendor" {
9696
assert_equal "riscv64-unknown-linux-musl" "$(TARGETPLATFORM=linux/riscv64 XX_VENDOR=unknown xx-info triple)"
9797
}
9898

99+
@test "loong64" {
100+
assert_equal "loongarch64-alpine-linux-musl" "$(TARGETPLATFORM=linux/loong64 xx-info triple)"
101+
assert_equal "loongarch64" "$(TARGETPLATFORM=linux/loong64 xx-info pkg-arch)"
102+
}
103+
99104
@test "mips" {
100105
assert_equal "mips-alpine-linux-musl" "$(TARGETPLATFORM=linux/mips xx-info triple)"
101106
assert_equal "mips" "$(TARGETPLATFORM=linux/mips xx-info pkg-arch)"

src/test-info-common.bats

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ load 'assert'
8585
assert_equal "ppc64le" "$(TARGETPLATFORM=linux/ppc64le xx-info march)"
8686
}
8787

88+
@test "loong64" {
89+
assert_equal "loong64" "$(TARGETPLATFORM=linux/loong64 xx-info march)"
90+
}
91+
8892
@test "mips" {
8993
assert_equal "mips" "$(TARGETPLATFORM=linux/mips xx-info march)"
9094
}
@@ -134,6 +138,10 @@ load 'assert'
134138
assert_success
135139
assert_output "$(TARGETPLATFORM=linux/riscv64 xx-info)"
136140

141+
TARGETPAIR=linux-loong64 run xx-info
142+
assert_success
143+
assert_output "$(TARGETPLATFORM=linux/loong64 xx-info)"
144+
137145
TARGETPAIR=linux-mips run xx-info
138146
assert_success
139147
assert_output "$(TARGETPLATFORM=linux/mips xx-info)"

src/test-info-debian.bats

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ fi
7777
assert_equal "riscv64gc-unknown-linux-gnu" "$(TARGETPLATFORM=linux/riscv64 RISCV64_TARGET_ARCH=riscv64gc XX_VENDOR=unknown xx-info triple)"
7878
}
7979

80+
@test "loong64" {
81+
assert_equal "loongarch64-linux-gnu" "$(TARGETPLATFORM=linux/loong64 xx-info triple)"
82+
assert_equal "loong64" "$(TARGETPLATFORM=linux/loong64 xx-info pkg-arch)"
83+
}
84+
8085
@test "mips" {
8186
assert_equal "mips-linux-gnu" "$(TARGETPLATFORM=linux/mips xx-info triple)"
8287
assert_equal "mips" "$(TARGETPLATFORM=linux/mips xx-info pkg-arch)"

src/test-info-rhel.bats

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ fi
6060
assert_equal "riscv64" "$(TARGETPLATFORM=linux/riscv64 xx-info pkg-arch)"
6161
}
6262

63+
@test "loong64" {
64+
assert_equal "loong64" "$(TARGETPLATFORM=linux/loong64 xx-info pkg-arch)"
65+
}
66+
6367
@test "mips" {
6468
assert_equal "mips-linux-gnu" "$(TARGETPLATFORM=linux/mips xx-info triple)"
6569
assert_equal "mips" "$(TARGETPLATFORM=linux/mips xx-info pkg-arch)"

src/test-verify.bats

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,15 @@ load 'assert'
250250
run xx-verify /idontexist
251251
assert_failure
252252

253+
export XX_VERIFY_FILE_CMD_OUTPUT=": ELF 64-bit LSB executable, LoongArch, version 1 (SYSV), statically linked, BuildID[sha1]=4d126b33c220ba2efd23ed68a46ef0db96c31f76, not stripped"
254+
export TARGETPLATFORM=linux/loong64
255+
run xx-verify /idontexist
256+
assert_success
257+
258+
export TARGETPLATFORM=linux/amd64
259+
run xx-verify /idontexist
260+
assert_failure
261+
253262
unset XX_VERIFY_FILE_CMD_OUTPUT
254263
unset TARGETPLATFORM
255264
}

src/test_helper.bash

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ xxrun() {
4545
wasclang=1
4646
fi
4747
if [ "$p" = "golang" ]; then
48-
p="golang-1.15"
48+
p="golang-1.19"
4949
wasgolang=1
5050
fi
5151
set -- "$@" "$p"
@@ -63,7 +63,7 @@ xxrun() {
6363
fi
6464
fi
6565
if [ -n "$wasgolang" ] && ! command -v go 2>/dev/null >/dev/null; then
66-
ln -s /usr/lib/go-1.15/bin/go /usr/bin/go
66+
ln -s /usr/lib/go-1.19/bin/go /usr/bin/go
6767
fi
6868
}
6969

@@ -87,6 +87,17 @@ supportRiscV() {
8787
return 0
8888
}
8989

90+
supportLoongArch() {
91+
if [ -f /etc/debian_version ]; then
92+
if grep "sid main" /etc/apt/sources.list 2>/dev/null >/dev/null; then
93+
return 0
94+
else
95+
return 1
96+
fi
97+
fi
98+
return 0
99+
}
100+
90101
versionGTE() { test "$(printf '%s\n' "$@" | sort -V | tail -n 1)" = "$1"; }
91102

92103
supportRiscVGo() {
@@ -114,6 +125,20 @@ supportWindowsArm64Go() {
114125
versionGTE "$(go version | awk '{print $3}' | sed 's/^go//')" "1.17"
115126
}
116127

128+
supportLoong64Go() {
129+
versionGTE "$(go version | awk '{print $3}' | sed 's/^go//')" "1.19"
130+
}
131+
132+
supportLoong64CGo() {
133+
if ! supportLoongArch; then
134+
return 1
135+
fi
136+
if ! supportLoong64Go; then
137+
return 1
138+
fi
139+
return 0
140+
}
141+
117142
supportRC() {
118143
command -v llvm-rc >/dev/null 2>&1
119144
}

0 commit comments

Comments
 (0)