mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-16 10:33:11 -06:00
Maybe make cross-compiling work?
This commit is contained in:
parent
61aaad087e
commit
0e4c0035b6
|
|
@ -4,7 +4,7 @@
|
|||
# base installs required dependencies and runs go mod download to cache dependencies
|
||||
#
|
||||
FROM --platform=${BUILDPLATFORM} docker.io/golang:1.19-alpine AS base
|
||||
RUN apk --update --no-cache add bash build-base
|
||||
RUN apk --update --no-cache add bash build-base curl
|
||||
|
||||
#
|
||||
# build creates all needed binaries
|
||||
|
|
@ -14,9 +14,11 @@ WORKDIR /src
|
|||
ARG TARGETOS
|
||||
ARG TARGETARCH
|
||||
ARG FLAGS
|
||||
ENV GOOS $TARGETOS
|
||||
ENV GOARCH $TARGETARCH
|
||||
RUN --mount=target=. \
|
||||
--mount=type=cache,target=/root/.cache/go-build \
|
||||
GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="${FLAGS}" -trimpath -o /out/ ./cmd/...
|
||||
sh ./build/docker/crossbuild.sh
|
||||
|
||||
#
|
||||
# The dendrite base image; mainly creates a user and switches to it
|
||||
|
|
|
|||
32
build/docker/crossbuild.sh
Normal file
32
build/docker/crossbuild.sh
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#!/bin/sh
|
||||
set -ex
|
||||
|
||||
case $GOARCH in
|
||||
arm64)
|
||||
curl -s https://musl.cc/aarch64-linux-musl-cross.tgz | tar xz --strip-components=1 -C /usr
|
||||
export CC=aarch64-linux-musl-gcc
|
||||
;;
|
||||
|
||||
amd64)
|
||||
curl -s https://musl.cc/x86_64-linux-musl-cross.tgz | tar xz --strip-components=1 -C /usr
|
||||
export CC=x86_64-linux-musl-gcc
|
||||
;;
|
||||
|
||||
i386)
|
||||
curl -s https://musl.cc/i686-linux-musl-cross.tgz | tar xz --strip-components=1 -C /usr
|
||||
export CC=i686-linux-musl-gcc
|
||||
;;
|
||||
|
||||
arm)
|
||||
curl -s https://musl.cc/armv7l-linux-musleabihf-cross.tgz | tar xz --strip-components=1 -C /usr
|
||||
export CC=armv7l-linux-musleabihf-gcc
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "Unknown GOARCH=${GOARCH}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
go env
|
||||
CGO_ENABLED=1 go build -v -ldflags="-linkmode external -extldflags -static ${FLAGS}" -trimpath -o /out/ ./cmd/...
|
||||
Loading…
Reference in a new issue