Skip to content

Commit 093023f

Browse files
committed
dockerfile: use osxcross toolchain on debian
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
1 parent 87b085c commit 093023f

File tree

2 files changed

+45
-12
lines changed

2 files changed

+45
-12
lines changed

Dockerfile

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ ARG XX_VERSION=1.1.1
66
ARG GOVERSIONINFO_VERSION=v1.3.0
77
ARG GOTESTSUM_VERSION=v1.7.0
88
ARG BUILDX_VERSION=0.8.2
9+
ARG OSXCROSS_VERSION=11.3-r7
910

1011
FROM --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+
1217
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-${BASE_VARIANT} AS build-base-alpine
1318
COPY --from=xx / /
1419
RUN 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

4449
FROM build-${BASE_VARIANT} AS build
50+
ARG BASE_VARIANT
4551
# GO_LINKMODE defines if static or dynamic binary should be produced
4652
ARG GO_LINKMODE=static
4753
# GO_BUILDTAGS defines additional build tags
@@ -57,15 +63,27 @@ ARG PACKAGER_NAME
5763
COPY --from=goversioninfo /out/goversioninfo /usr/bin/goversioninfo
5864
# in bullseye arm64 target does not link with lld so configure it to use ld instead
5965
RUN [ ! -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

7088
FROM build-${BASE_VARIANT} AS test
7189
COPY --from=gotestsum /out/gotestsum /usr/bin/gotestsum
@@ -79,15 +97,26 @@ FROM scratch AS test-coverage
7997
COPY --from=test /tmp/coverage.txt /coverage.txt
8098

8199
FROM build-${BASE_VARIANT} AS build-plugins
100+
ARG BASE_VARIANT
82101
ARG GO_LINKMODE=static
83102
ARG GO_BUILDTAGS
84103
ARG GO_STRIP
85104
ARG CGO_ENABLED
86105
ARG 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

92121
FROM build-base-alpine AS e2e-base-alpine
93122
RUN apk add --no-cache build-base curl docker-compose openssl openssh-client

docker-bake.hcl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ target "_common" {
2424
GO_VERSION = GO_VERSION
2525
BUILDKIT_CONTEXT_KEEP_GIT_DIR = 1
2626
}
27+
no-cache-filter = ["osxcross"]
2728
}
2829

2930
target "_platforms" {
@@ -141,16 +142,19 @@ target "update-authors" {
141142
}
142143

143144
target "test" {
145+
inherits = ["_common"]
144146
target = "test"
145147
output = ["type=cacheonly"]
146148
}
147149

148150
target "test-coverage" {
151+
inherits = ["_common"]
149152
target = "test-coverage"
150153
output = ["build/coverage"]
151154
}
152155

153156
target "e2e-image" {
157+
inherits = ["_common"]
154158
target = "e2e"
155159
output = ["type=docker"]
156160
tags = ["${IMAGE_NAME}"]

0 commit comments

Comments
 (0)