1+ # This Dockerfile tests the hack/Makefile output against git2go.
12ARG BASE_VARIANT=alpine
23ARG GO_VERSION=1.17
34ARG XX_VERSION=1.1.0
45
5- ARG LIBGIT2_IMG
6- ARG LIBGIT2_TAG
6+ FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
77
8- FROM ${LIBGIT2_IMG}:${LIBGIT2_TAG} AS build-deps
8+ FROM --platform=$BUILDPLATFORM ${BASE_VARIANT} AS build-base
9+
10+ RUN apk add --no-cache \
11+ bash \
12+ curl \
13+ build-base \
14+ linux-headers \
15+ perl \
16+ cmake \
17+ pkgconfig \
18+ gcc \
19+ musl-dev \
20+ clang \
21+ lld
922
10- FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
23+ COPY --from=xx / /
24+
25+ FROM build-base AS build-cross
26+
27+ ARG TARGETPLATFORM
28+
29+ RUN xx-apk add --no-cache \
30+ build-base \
31+ pkgconfig \
32+ gcc \
33+ musl-dev \
34+ clang \
35+ lld \
36+ llvm \
37+ linux-headers
38+
39+ WORKDIR /build
40+ COPY hack/static.sh .
41+
42+ ENV CC=xx-clang
43+ ENV CXX=xx-clang++
44+
45+ RUN CHOST=$(xx-clang --print-target-triple) \
46+ ./static.sh build_libz
47+
48+ RUN CHOST=$(xx-clang --print-target-triple) \
49+ ./static.sh build_openssl
50+
51+ RUN export LIBRARY_PATH="/usr/local/$(xx-info triple)/lib:/usr/local/$(xx-info triple)/lib64:${LIBRARY_PATH}" && \
52+ export PKG_CONFIG_PATH="/usr/local/$(xx-info triple)/lib/pkgconfig:/usr/local/$(xx-info triple)/lib64/pkgconfig" && \
53+ export OPENSSL_ROOT_DIR="/usr/local/$(xx-info triple)" && \
54+ export OPENSSL_CRYPTO_LIBRARY="/usr/local/$(xx-info triple)/lib64" && \
55+ export OPENSSL_INCLUDE_DIR="/usr/local/$(xx-info triple)/include/openssl"
56+
57+ RUN ./static.sh build_libssh2
58+ RUN ./static.sh build_libgit2
59+
60+
61+ # trimmed removes all non necessary files (i.e. openssl binary).
62+ FROM build-cross AS trimmed
63+
64+ ARG TARGETPLATFORM
65+ RUN mkdir -p /trimmed/usr/local/$(xx-info triple)/ && \
66+ mkdir -p /trimmed/usr/local/$(xx-info triple)/share
67+
68+ RUN cp -r /usr/local/$(xx-info triple)/lib/ /trimmed/usr/local/$(xx-info triple)/ && \
69+ cp -r /usr/local/$(xx-info triple)/lib64/ /trimmed/usr/local/$(xx-info triple)/ | true && \
70+ cp -r /usr/local/$(xx-info triple)/include/ /trimmed/usr/local/$(xx-info triple)/ && \
71+ cp -r /usr/local/$(xx-info triple)/share/doc/ /trimmed/usr/local/$(xx-info triple)/share/
72+
73+ FROM scratch as libs-arm64
74+ COPY --from=trimmed /trimmed/ /
75+
76+ FROM scratch as libs-amd64
77+ COPY --from=trimmed /trimmed/ /
78+
79+ FROM scratch as libs-armv7
80+ COPY --from=trimmed /trimmed/ /
81+
82+ FROM libs-$TARGETARCH$TARGETVARIANT as libs
83+
84+ # Everything above this line is a copy from Dockefile.
1185
1286FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-${BASE_VARIANT} as gostable
1387
1488FROM gostable AS go-linux
1589
1690# Build-base consists of build platform dependencies and xx.
1791# These will be used at current arch to yield execute the cross compilations.
18- FROM go-${TARGETOS} AS build -base
92+ FROM go-${TARGETOS} AS go -base
1993
2094RUN apk add clang lld pkgconfig
2195
2296COPY --from=xx / /
2397
2498# build-go-mod can still be cached at build platform architecture.
25- FROM build -base as build-go-mod
99+ FROM go -base as build-go-mod
26100
27101WORKDIR /root/smoketest
28102COPY tests/smoketest/go.mod .
@@ -42,7 +116,7 @@ RUN xx-apk add musl-dev gcc clang lld
42116WORKDIR /root/smoketest
43117
44118COPY tests/smoketest/main.go .
45- COPY --from=build-deps /usr/local/ /usr/local/
119+ COPY --from=libs /usr/local/ /usr/local/
46120
47121ENV CGO_ENABLED=1
48122RUN export LIBRARY_PATH="/usr/local/$(xx-info triple):/usr/local/$(xx-info triple)/lib64" && \
0 commit comments