Support cross-compile for arm

Pretty much cross-compile doesn't work because  of this:

> profiles/seccomp/seccomp.go:13:2: build constraints exclude all Go files in /go/src/github.com/docker/docker/vendor/github.com/seccomp/libseccomp-golang

This changes adds a new Dockerfile target for cross compilation with the
neccesary arch specific libseccomp packages and CC toolchains.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Brian Goff 2019-04-05 17:20:06 -07:00 committed by Sebastiaan van Stijn
parent c2cb72e085
commit 61a3285864
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
3 changed files with 58 additions and 7 deletions

View file

@ -24,6 +24,8 @@
# the case. Therefore, you don't have to disable it anymore.
#
ARG CROSS="false"
FROM golang:1.12.3 AS base
# allow replacing httpredir or deb mirror
ARG APT_MIRROR=deb.debian.org
@ -93,11 +95,31 @@ RUN /download-frozen-image-v2.sh /build \
# See also ensureFrozenImagesLinux() in "integration-cli/fixtures_linux_daemon_test.go" (which needs to be updated when adding images to this list)
# Just a little hack so we don't have to install these deps twice, once for runc and once for dockerd
FROM base AS runtime-dev
FROM base AS runtime-dev-cross-false
RUN apt-get update && apt-get install -y \
libapparmor-dev \
libseccomp-dev
FROM runtime-dev-cross-false AS runtime-dev-cross-true
RUN dpkg --add-architecture armhf
RUN dpkg --add-architecture arm64
RUN dpkg --add-architecture armel
# These crossbuild packages rely on gcc-<arch>, but this doesn't want to install
# on non-amd64 systems.
# Additionally, the crossbuild-amd64 is currently only on debian:buster, so
# other architectures cannnot crossbuild amd64.
RUN if [ "$(go env GOHOSTARCH)" = "amd64" ]; then \
apt-get update \
&& apt-get install -y \
crossbuild-essential-armhf \
crossbuild-essential-arm64 \
crossbuild-essential-armel \
libseccomp-dev:armhf \
libseccomp-dev:arm64 \
libseccomp-dev:armel; \
fi
FROM runtime-dev-cross-${CROSS} AS runtime-dev
FROM base AS tomlv
ENV INSTALL_BINARY_NAME=tomlv

View file

@ -117,9 +117,6 @@ INTERACTIVE := $(shell [ -t 0 ] && echo 1 || echo 0)
ifeq ($(INTERACTIVE), 1)
DOCKER_FLAGS += -t
endif
ifeq ($(BIND_DIR), .)
DOCKER_BUILD_OPTS += --target=dev
endif
DOCKER_RUN_DOCKER := $(DOCKER_FLAGS) "$(DOCKER_IMAGE)"
@ -134,6 +131,21 @@ binary: build ## build the linux binaries
dynbinary: build ## build the linux dynbinaries
$(DOCKER_RUN_DOCKER) hack/make.sh dynbinary
cross: DOCKER_CROSS := true
cross: build ## cross build the binaries for darwin, freebsd and\nwindows
$(DOCKER_RUN_DOCKER) hack/make.sh dynbinary binary cross
ifdef DOCKER_CROSSPLATFORMS
build: DOCKER_CROSS := true
else
build: DOCKER_CROSS ?= false
endif
ifeq ($(BIND_DIR), .)
build: DOCKER_BUILD_OPTS += --target=dev
endif
build: DOCKER_BUILD_ARGS += --build-arg=CROSS=$(DOCKER_CROSS)
build: DOCKER_BUILDKIT ?= 1
build: bundles
$(warning The docker client CLI has moved to github.com/docker/cli. For a dev-test cycle involving the CLI, run:${\n} DOCKER_CLI_PATH=/host/path/to/cli/binary make shell ${\n} then change the cli and compile into a binary at the same location.${\n})
@ -149,9 +161,6 @@ clean: clean-cache
clean-cache:
docker volume rm -f docker-dev-cache
cross: build ## cross build the binaries for darwin, freebsd and\nwindows
$(DOCKER_RUN_DOCKER) hack/make.sh dynbinary binary cross
help: ## this help
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9_-]+:.*?## / {gsub("\\\\n",sprintf("\n%22c",""), $$2);printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

View file

@ -47,6 +47,26 @@ if [ "$(go env GOOS)/$(go env GOARCH)" != "$(go env GOHOSTOS)/$(go env GOHOSTARC
export CC=x86_64-w64-mingw32-gcc
export CGO_ENABLED=1
;;
linux/arm)
case "${GOARM}" in
5|"")
export CC=arm-linux-gnueabi-gcc
export CGO_ENABLED=1
;;
7)
export CC=arm-linux-gnueabihf-gcc
export CGO_ENABLED=1
;;
esac
;;
linux/arm64)
export CC=aarch64-linux-gnu-gcc
export CGO_ENABLED=1
;;
linux/amd64)
export CC=x86_64-linux-gnu-gcc
export CGO_ENABLED=1
;;
esac
fi