From 61a3285864d3f1b489f48f765b61b2c7bd300372 Mon Sep 17 00:00:00 2001 From: Brian Goff Date: Fri, 5 Apr 2019 17:20:06 -0700 Subject: [PATCH] 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 Signed-off-by: Sebastiaan van Stijn --- Dockerfile | 24 +++++++++++++++++++++++- Makefile | 21 +++++++++++++++------ hack/make/.binary | 20 ++++++++++++++++++++ 3 files changed, 58 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 71dbd5ca3a..4586c03c96 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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-, 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 diff --git a/Makefile b/Makefile index 8a62a032cb..2bd3ce51e5 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/hack/make/.binary b/hack/make/.binary index ff33e18cab..357b456e09 100644 --- a/hack/make/.binary +++ b/hack/make/.binary @@ -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