Skip to content

Commit

Permalink
use CGO with arm build (fixes go bug)
Browse files Browse the repository at this point in the history
Build all arm binaries with CGO enabled to address golang bug..

golang/go#32912

Includes arm64 to standardize the platforms supported with those
consul-template supports.

Fixes #227
  • Loading branch information
eikenb committed Dec 18, 2019
1 parent d4e8e04 commit b7299a7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
26 changes: 21 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ GOARCH ?= $(shell go env GOARCH)

# Default os-arch combination to build
XC_OS ?= darwin freebsd linux netbsd openbsd solaris windows
XC_ARCH ?= 386 amd64 arm
XC_EXCLUDE ?= darwin/arm solaris/386 solaris/arm windows/arm
XC_ARCH ?= 386 amd64 arm arm64
# XC_EXCLUDE "arm64" entries match/exclude both arm and arm64
XC_EXCLUDE ?= darwin/arm64 freebsd/arm64 netbsd/arm64 openbsd/arm64 solaris/arm64 windows/arm64 solaris/386

# GPG Signing key (blank by default, means no GPG signing)
GPG_KEY ?=
Expand All @@ -52,8 +53,15 @@ define make-xc-target
@printf "%s%20s %s\n" "-->" "${1}/${2}:" "${PROJECT} (excluded)"
else
@printf "%s%20s %s\n" "-->" "${1}/${2}:" "${PROJECT}"
case "$2" in \
arm) export CGO_ENABLED="1" ; \
export GOARM=6 \
export CC="arm-linux-gnueabihf-gcc" ;; \
arm64) export CGO_ENABLED="1" ; \
export CC="aarch64-linux-gnu-gcc" ;; \
*) export CGO_ENABLED="0" ;; \
esac ; \
env \
CGO_ENABLED="0" \
GOOS="${1}" \
GOARCH="${2}" \
go build \
Expand All @@ -74,6 +82,14 @@ $(foreach goarch,$(XC_ARCH),$(foreach goos,$(XC_OS),$(eval $(call make-xc-target

# Use docker to create pristine builds for release
pristine:
@docker build \
--rm \
--force-rm \
--no-cache \
--compress \
--file="docker/pristine/Dockerfile" \
--build-arg="GOVERSION=${GO_DOCKER_VERSION}" \
--tag="pristine-builder" .
@docker run \
--interactive \
--user $$(id -u):$$(id -g) \
Expand All @@ -82,9 +98,9 @@ pristine:
--volume="${CURRENT_DIR}:/go/src/${PROJECT}" \
--volume="${GOPATH}/pkg/mod:/go/pkg/mod" \
--workdir="/go/src/${PROJECT}" \
--env=CGO_ENABLED="0" \
--env=GO111MODULE=on \
"golang:${GO_DOCKER_VERSION}" env GOCACHE=/tmp make -j4 build
"pristine-builder" \
env GOCACHE=/tmp make -j4 build

# dev builds and installs the project locally.
dev:
Expand Down
8 changes: 8 additions & 0 deletions docker/pristine/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### Used for pristine builds
#
ARG GOVERSION=latest
FROM golang:${GOVERSION}
LABEL maintainer "John Eikenberry <jae@zhar.net>"

RUN apt-get update && \
apt-get -y install gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu

0 comments on commit b7299a7

Please sign in to comment.