From ca1215b436dbaef015a7e92c0f0c121871077846 Mon Sep 17 00:00:00 2001 From: yzewei Date: Fri, 22 Dec 2023 11:04:21 +0800 Subject: [PATCH] add loongarch support for buildkit archutil Signed-off-by: yzewei (cherry picked from commit 736c35ad3561f709876bfcb52e2644f71b05c805) --- hack/dockerfiles/archutil.Dockerfile | 11 +++++++++-- util/archutil/detect.go | 10 ++++++++++ util/archutil/fixtures/exit.loongarch64.s | 6 ++++++ util/archutil/loong64_binary.go | 9 +++++++++ util/archutil/loong64_check.go | 8 ++++++++ util/archutil/loong64_check_loong64.go | 7 +++++++ 6 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 util/archutil/fixtures/exit.loongarch64.s create mode 100644 util/archutil/loong64_binary.go create mode 100644 util/archutil/loong64_check.go create mode 100644 util/archutil/loong64_check_loong64.go diff --git a/hack/dockerfiles/archutil.Dockerfile b/hack/dockerfiles/archutil.Dockerfile index 20af69af3e26..3b6a875c0cea 100644 --- a/hack/dockerfiles/archutil.Dockerfile +++ b/hack/dockerfiles/archutil.Dockerfile @@ -15,7 +15,8 @@ RUN apt-get update && apt-get --no-install-recommends install -y git binutils \ 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 FROM base AS exit-amd64 @@ -58,6 +59,10 @@ FROM base AS exit-mips64 COPY util/archutil/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 && mips64-linux-gnuabi64-strip --strip-unneeded exit +FROM base AS exit-loong64 +COPY util/archutil/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 && loongarch64-linux-gnu-strip --strip-unneeded exit + FROM scratch AS exits COPY --from=exit-amd64 /src/exit amd64 COPY --from=exit-386 /src/exit 386 @@ -69,6 +74,7 @@ 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 FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS generate WORKDIR /go/src/github.com/moby/buildkit @@ -86,7 +92,8 @@ RUN --mount=type=bind,target=.,rw \ bin/archutil/ppc64 \ bin/archutil/ppc64le \ bin/archutil/mips64le \ - bin/archutil/mips64 + bin/archutil/mips64 \ + bin/archutil/loong64 tree -nh bin/archutil cp bin/archutil/*_binary.go /out EOT diff --git a/util/archutil/detect.go b/util/archutil/detect.go index 7826441271fd..5808333f91b5 100644 --- a/util/archutil/detect.go +++ b/util/archutil/detect.go @@ -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") @@ -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) diff --git a/util/archutil/fixtures/exit.loongarch64.s b/util/archutil/fixtures/exit.loongarch64.s new file mode 100644 index 000000000000..478cd622c69c --- /dev/null +++ b/util/archutil/fixtures/exit.loongarch64.s @@ -0,0 +1,6 @@ + .global _start + .text +_start: + li.w $a0,0 + li.w $a7,93 + syscall 0 diff --git a/util/archutil/loong64_binary.go b/util/archutil/loong64_binary.go new file mode 100644 index 000000000000..01d4454310df --- /dev/null +++ b/util/archutil/loong64_binary.go @@ -0,0 +1,9 @@ +//go:build !loong64 +// +build !loong64 + +package archutil + +// This file is generated by running "make archutil". +// 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\xce\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\x5f\xc5\x9b\x9d\x90\x01\x00\x00" diff --git a/util/archutil/loong64_check.go b/util/archutil/loong64_check.go new file mode 100644 index 000000000000..9bc966ce245a --- /dev/null +++ b/util/archutil/loong64_check.go @@ -0,0 +1,8 @@ +//go:build !loong64 +// +build !loong64 + +package archutil + +func loong64Supported() (string, error) { + return check("loong64", Binaryloong64) +} diff --git a/util/archutil/loong64_check_loong64.go b/util/archutil/loong64_check_loong64.go new file mode 100644 index 000000000000..20f4764ff590 --- /dev/null +++ b/util/archutil/loong64_check_loong64.go @@ -0,0 +1,7 @@ +//go:build loong64 + +package archutil + +func loong64Supported() (string, error) { + return "", nil +}