@@ -6,9 +6,14 @@ ARG XX_VERSION=1.1.1
66ARG GOVERSIONINFO_VERSION=v1.3.0
77ARG GOTESTSUM_VERSION=v1.7.0
88ARG BUILDX_VERSION=0.8.2
9+ ARG OSXCROSS_VERSION=11.3-r7
910
1011FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
1112
13+ FROM crazymax/osxcross:${OSXCROSS_VERSION}-alpine AS osxcross-alpine
14+ FROM --platform=$BUILDPLATFORM crazymax/osxcross:${OSXCROSS_VERSION}-debian AS osxcross-bullseye
15+ FROM osxcross-${BASE_VARIANT} AS osxcross
16+
1217FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-${BASE_VARIANT} AS build-base-alpine
1318COPY --from=xx / /
1419RUN apk add --no-cache bash clang lld llvm file git
@@ -42,6 +47,7 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
4247 && /out/gotestsum --version
4348
4449FROM build-${BASE_VARIANT} AS build
50+ ARG BASE_VARIANT
4551# GO_LINKMODE defines if static or dynamic binary should be produced
4652ARG GO_LINKMODE=static
4753# GO_BUILDTAGS defines additional build tags
@@ -57,15 +63,27 @@ ARG PACKAGER_NAME
5763COPY --from=goversioninfo /out/goversioninfo /usr/bin/goversioninfo
5864# in bullseye arm64 target does not link with lld so configure it to use ld instead
5965RUN [ ! -f /etc/alpine-release ] && xx-info is-cross && [ "$(xx-info arch)" = "arm64" ] && XX_CC_PREFER_LINKER=ld xx-clang --setup-target-triple || true
60- RUN --mount=type=bind,target=.,ro \
66+ RUN --mount=type=bind,target=. \
6167 --mount=type=cache,target=/root/.cache \
62- --mount=from=dockercore/golang-cross:xx-sdk-extras,target=/xx-sdk,src=/xx-sdk \
63- --mount=type=tmpfs,target=cli/winresources \
64- # override the default behavior of go with xx-go
65- xx-go --wrap && \
66- # export GOCACHE=$(go env GOCACHE)/$(xx-info)$([ -f /etc/alpine-release ] && echo "alpine") && \
67- TARGET=/out ./scripts/build/binary && \
68- xx-verify $([ "$GO_LINKMODE" = "static" ] && echo "--static" ) /out/docker
68+ --mount=from=osxcross,src=/osxcross,target=/osxcross \
69+ --mount=from=osxcross,src=/osxsdk,target=/xx-sdk \
70+ --mount=type=tmpfs,target=cli/winresources <<EOT
71+ set -e
72+ if [ "$BASE_VARIANT" != "alpine" ] && [ "$(xx-info os)" = "darwin" ]; then
73+ # on debian, use osxcross toolchain that includes the llvm-dsymutil tool
74+ # and right minimal llvm version required
75+ # more info: https://github.com/docker/cli/pull/3717
76+ export PATH="/osxcross/bin:$PATH"
77+ export LD_LIBRARY_PATH="/osxcross/lib:$LD_LIBRARY_PATH"
78+ export CC="o64-clang"
79+ export CXX="o64-clang++"
80+ fi
81+ # override the default behavior of go with xx-go
82+ xx-go --wrap
83+ # export GOCACHE=$(go env GOCACHE)/$(xx-info)$([ -f /etc/alpine-release ] && echo "alpine")
84+ TARGET=/out ./scripts/build/binary
85+ xx-verify $([ "$GO_LINKMODE" = "static" ] && echo "--static" ) /out/docker
86+ EOT
6987
7088FROM build-${BASE_VARIANT} AS test
7189COPY --from=gotestsum /out/gotestsum /usr/bin/gotestsum
@@ -79,15 +97,26 @@ FROM scratch AS test-coverage
7997COPY --from=test /tmp/coverage.txt /coverage.txt
8098
8199FROM build-${BASE_VARIANT} AS build-plugins
100+ ARG BASE_VARIANT
82101ARG GO_LINKMODE=static
83102ARG GO_BUILDTAGS
84103ARG GO_STRIP
85104ARG CGO_ENABLED
86105ARG VERSION
87- RUN --mount=ro --mount=type=cache,target=/root/.cache \
88- --mount=from=dockercore/golang-cross:xx-sdk-extras,target=/xx-sdk,src=/xx-sdk \
89- xx-go --wrap && \
90- TARGET=/out ./scripts/build/plugins e2e/cli-plugins/plugins/*
106+ RUN --mount=type=bind,target=. \
107+ --mount=type=cache,target=/root/.cache \
108+ --mount=from=osxcross,src=/osxcross,target=/osxcross \
109+ --mount=from=osxcross,src=/osxsdk,target=/xx-sdk <<EOT
110+ set -e
111+ if [ "$BASE_VARIANT" != "alpine" ] && [ "$(xx-info os)" = "darwin" ]; then
112+ export PATH="/osxcross/bin:$PATH"
113+ export LD_LIBRARY_PATH="/osxcross/lib:$LD_LIBRARY_PATH"
114+ export CC="o64-clang"
115+ export CXX="o64-clang++"
116+ fi
117+ xx-go --wrap
118+ TARGET=/out ./scripts/build/plugins e2e/cli-plugins/plugins/*
119+ EOT
91120
92121FROM build-base-alpine AS e2e-base-alpine
93122RUN apk add --no-cache build-base curl docker-compose openssl openssh-client
0 commit comments