add build-cross for local cross building

This commit is contained in:
kaedwen
2023-07-09 14:18:44 +02:00
parent 2d04006fa8
commit 0fc3872bdb
2 changed files with 44 additions and 1 deletions
+15 -1
View File
@@ -3,4 +3,18 @@ build:
CGO_ENABLED=1 go build -mod=vendor -o service main.go
build-static:
CGO_ENABLED=1 go build -mod=vendor -tags=embed -o service main.go
CGO_ENABLED=1 go build -mod=vendor -tags=embed -o service main.go
build-armhf:
GOARCH=arm \
ARCH=armhf \
DEPS="gcc-arm-linux-gnueabihf libc6-dev-armhf-cross" \
PREFIX=arm-linux-gnueabihf \
./build-cross.sh
build-arm64:
GOARCH=arm64 \
ARCH=arm64 \
DEPS="gcc-aarch64-linux-gnu libc6-dev-arm64-cross" \
PREFIX=aarch64-linux-gnu \
./build-cross.sh
Executable
+29
View File
@@ -0,0 +1,29 @@
#!/bin/sh
GOVERSION=${GOVERSION:-1.20.5}
CONTAINER=${PREFIX}-${ARCH}
# prepare
podman build -t ${CONTAINER} -f - <<EOF
FROM debian:stable-slim
RUN dpkg --add-architecture ${ARCH}
RUN apt-get update && apt-get install --yes --no-install-recommends make curl ca-certificates libgstreamer1.0-dev:${ARCH} libgstreamer-plugins-base1.0-dev:${ARCH} ${DEPS}
WORKDIR /go
RUN curl -L "https://go.dev/dl/go${GOVERSION}.linux-amd64.tar.gz" | tar xzf - --strip-components 1
ENV PATH "$PATH:/go/bin"
ENV CGO_ENABLED 1
ENV GOOS "linux"
ENV GOARCH "${GOARCH}"
ENV CC "${PREFIX:+$PREFIX-}gcc"
ENV PKG_CONFIG_PATH "/usr/lib/${PREFIX}/pkgconfig"
EOF
podman run \
--rm \
--volume ./:/data \
--workdir /data \
${CONTAINER} \
go build -mod=vendor -tags=embed -o service-${GOOS}-${GOARCH} main.go