Skip to content

Commit

Permalink
add loongarch support for buildkit archutil
Browse files Browse the repository at this point in the history
Signed-off-by: yzewei <[email protected]>
  • Loading branch information
yzewei committed Jan 31, 2024
1 parent 1be5cc4 commit 5ccecf5
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 4 deletions.
15 changes: 11 additions & 4 deletions util/archutil/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM debian:bullseye-slim AS base
FROM debian:trixie-slim AS base
RUN apt-get update && apt-get --no-install-recommends install -y \
gcc-x86-64-linux-gnu \
binutils-arm-linux-gnueabihf \
Expand All @@ -8,7 +8,9 @@ RUN apt-get update && apt-get --no-install-recommends install -y \
binutils-s390x-linux-gnu \
binutils-powerpc64le-linux-gnu \
binutils-mips64el-linux-gnuabi64 \
binutils-mips64-linux-gnuabi64
binutils-mips64-linux-gnuabi64 \
binutils-loongarch64-linux-gnu \

WORKDIR /src


Expand Down Expand Up @@ -52,7 +54,11 @@ FROM base AS exit-mips64
COPY fixtures/exit.mips64.s .
RUN mips64-linux-gnuabi64-as --noexecstack -o exit.o exit.mips64.s && mips64-linux-gnuabi64-ld -o exit -s exit.o

FROM golang:1.21-alpine AS generate
FROM base AS exit-loong64
COPY fixtures/exit.loongarch64.s .
RUN loongarch64-linux-gnu-as --noexecstack -o exit.o exit.loongarch64.s && loongarch64-linux-gnu-ld -o exit -s exit.o

FROM golang:1.20-alpine AS generate
WORKDIR /src
COPY --from=exit-amd64 /src/exit amd64
COPY --from=exit-386 /src/exit 386
Expand All @@ -64,9 +70,10 @@ COPY --from=exit-ppc64 /src/exit ppc64
COPY --from=exit-ppc64le /src/exit ppc64le
COPY --from=exit-mips64le /src/exit mips64le
COPY --from=exit-mips64 /src/exit mips64
COPY --from=exit-loong64 /src/exit loong64
COPY generate.go .

RUN go run generate.go amd64 386 arm64 arm riscv64 s390x ppc64 ppc64le mips64le mips64 && ls -l
RUN go run generate.go amd64 386 arm64 arm riscv64 s390x ppc64 ppc64le mips64le mips64 loong64 && ls -l


FROM scratch
Expand Down
10 changes: 10 additions & 0 deletions util/archutil/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ func SupportedPlatforms(noCache bool) []ocispecs.Platform {
arr = append(arr, linux(p))
}
}
if p := "loong64"; def.Architecture != p {
if _, err := loong64Supported(); err == nil {
arr = append(arr, linux(p))
}
}
if p := "arm"; def.Architecture != p {
if _, err := armSupported(); err == nil {
p := linux("arm")
Expand Down Expand Up @@ -144,6 +149,11 @@ func WarnIfUnsupported(pfs []ocispecs.Platform) {
printPlatformWarning(p, err)
}
}
if p.Architecture == "loong64" {
if _, err := loong64Supported(); err != nil {
printPlatformWarning(p, err)
}
}
if p.Architecture == "arm" {
if _, err := armSupported(); err != nil {
printPlatformWarning(p, err)
Expand Down
6 changes: 6 additions & 0 deletions util/archutil/fixtures/exit.loongarch64.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.global _start
.text
_start:
li.w $a0,0
li.w $a7,93
syscall 0
9 changes: 9 additions & 0 deletions util/archutil/loong64_binary.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build !loong64
// +build !loong64

package archutil

// This file is generated by running make inside the archutil package.
// Do not edit manually.

const Binaryloong64 = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x02\xff\xaa\x77\xf5\x71\x63\x62\x64\x64\x80\x01\x26\x06\x08\x6f\x03\x03\x83\x02\x88\x76\x80\x8a\x5f\x80\xd2\xcc\x60\x31\x0b\x06\x26\x06\x07\x06\x66\x06\x26\x06\x90\x1a\x56\x06\x14\xa0\xc0\x88\x44\xef\x81\x0a\xc2\x68\x98\x81\x81\x4f\x4b\x52\xd8\x18\x88\x07\x02\x50\x9a\x85\x41\x94\x81\xbb\xa4\x91\x99\x81\x41\x9b\x81\x41\xaf\x38\xa3\xb8\xa4\xa8\x24\x31\x89\x41\xaf\x24\xb5\xa2\x84\x81\x0a\x80\x9b\x81\x01\xec\x27\x98\xdb\x60\xe1\xb0\x01\xca\xe7\x41\x53\xcf\x88\x85\xcf\x8c\xc5\x5c\x98\xff\x05\x09\xe8\x07\x04\x00\x00\xff\xff\x31\xd2\xf1\xb5\x90\x01\x00\x00"
8 changes: 8 additions & 0 deletions util/archutil/loong64_check.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:build !loong64
// +build !loong64

package archutil

func loong64Supported() (string, error) {
return check("loong64", Binaryloong64)
}
7 changes: 7 additions & 0 deletions util/archutil/loong64_check_loong64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build loong64

package archutil

func loong64Supported() (string, error) {
return "", nil
}

0 comments on commit 5ccecf5

Please sign in to comment.