Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mac: build arm64 binaries #540

Merged
merged 6 commits into from
Apr 9, 2021
Merged

Conversation

tiborvass
Copy link
Contributor

@tiborvass tiborvass commented Apr 5, 2021

Signed-off-by: Tibor Vass tibor@docker.com

This PR uses golang 1.16 In order to build plugins for darwin/arm64.
However, docker app plugin does not build with go 1.16 (could not figure out how to disable go modules), and it was meant to be removed anyway.
ARM binaries had issues building with cgo, so as a workaround, this PR sets CGO_ENABLED=0 for arm (32 bit, aka armel/armhf) binaries only.

Related:

@tiborvass tiborvass force-pushed the darwin_arm64 branch 7 times, most recently from c31456e to 9e8e620 Compare April 6, 2021 09:19
@@ -10,8 +10,7 @@ override_dh_auto_build:
cd engine && TMP_GOPATH="/go" hack/dockerfile/install/install.sh proxy dynamic
cd engine && TMP_GOPATH="/go" hack/dockerfile/install/install.sh rootlesskit dynamic
# Build the CLI
cd /go/src/github.com/docker/cli && \
LDFLAGS='' DISABLE_WARN_OUTSIDE_CONTAINER=1 make VERSION=$(VERSION) GITCOMMIT=$(CLI_GITCOMMIT) dynbinary manpages
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove the LDFLAGS='' here?

(perhaps we need the same comment as in the plugins install script?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't think enough, and had too much confidence in Tonis's scripts :) I put it back.

deb/common/rules Outdated
@@ -10,8 +10,7 @@ override_dh_auto_build:
cd engine && TMP_GOPATH="/go" hack/dockerfile/install/install.sh proxy dynamic
cd engine && TMP_GOPATH="/go" hack/dockerfile/install/install.sh rootlesskit dynamic
# Build the CLI
cd /go/src/github.com/docker/cli && \
LDFLAGS='' DISABLE_WARN_OUTSIDE_CONTAINER=1 make VERSION=$(VERSION) GITCOMMIT=$(CLI_GITCOMMIT) dynbinary manpages
cd /go/src/github.com/docker/cli && VERSION=$(VERSION) GITCOMMIT=$(CLI_GITCOMMIT) LDFLAGS='' GO_LINKMODE=dynamic ./scripts/build/binary && DISABLE_WARN_OUTSIDE_CONTAINER=1 make manpages
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cd /go/src/github.com/docker/cli && VERSION=$(VERSION) GITCOMMIT=$(CLI_GITCOMMIT) LDFLAGS='' GO_LINKMODE=dynamic ./scripts/build/binary && DISABLE_WARN_OUTSIDE_CONTAINER=1 make manpages
cd /go/src/github.com/docker/cli && VERSION=$(VERSION) GITCOMMIT=$(CLI_GITCOMMIT) LDFLAGS='' GO_LINKMODE=dynamic ./scripts/build/binary && LDFLAGS='' DISABLE_WARN_OUTSIDE_CONTAINER=1 make manpages

Need to set it for both ./scripts/build/binary and for make manpages (we don't export LDFLAGS, so it's not set after && otherwise)

@tiborvass tiborvass force-pushed the darwin_arm64 branch 8 times, most recently from ab9e47a to 4d88967 Compare April 7, 2021 03:30
static/Makefile Outdated
cp $(CLI_DIR)/build/docker-darwin-amd64 build/mac/docker/docker
tar -C build/mac -c -z -f build/mac/docker-$(GEN_STATIC_VER).tgz docker
cross-mac: buildx cross-mac-plugins
cd $(CLI_DIR) && VERSION=$(GEN_STATIC_VER) docker buildx bake --set cross.platform=darwin/amd64,darwin/arm64 cross
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you building cross?

thaJeztah
thaJeztah previously approved these changes Apr 8, 2021
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after fixing the windows stage

Tibor Vass added 2 commits April 8, 2021 18:41
Signed-off-by: Tibor Vass <tibor@docker.com>
Signed-off-by: Tibor Vass <tibor@docker.com>
@tiborvass tiborvass force-pushed the darwin_arm64 branch 2 times, most recently from 6866c36 to 85c07f0 Compare April 8, 2021 19:04
Makefile Outdated
@@ -75,5 +75,5 @@ deb: checkout ## build deb packages
static: DOCKER_BUILD_PKGS:=static-linux cross-mac cross-win cross-arm
static: checkout ## build static-compiled packages
for p in $(DOCKER_BUILD_PKGS); do \
$(MAKE) -C $@ VERSION=$(VERSION) GO_VERSION=$(GO_VERSION) $${p}; \
$(MAKE) -C $@ VERSION=$(VERSION) GO_VERSION=$(GO_VERSION) GOPLATFORM=$(GOPLATFORM) $${p}; \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this called GOPLATFORM?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i can call it PLATFORM if you want but in this repo it's confusing as it can also mean the stupid "Docker CE" PLATFORM string. Happy to change the name.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not GOARCH?

Could be GO_PLATFORM to be consistent with GO_VERSION

static/Makefile Outdated
@@ -66,7 +73,7 @@ cross-arm: cross-all-cli ## create tgz with linux armhf client only

.PHONY: static-cli
static-cli:
$(MAKE) -C $(CLI_DIR) -f docker.Makefile VERSION=$(GEN_STATIC_VER) build
cd $(CLI_DIR) && VERSION=$(GEN_STATIC_VER) docker buildx bake --set binary.platform=$(GOPLATFORM) $(if $(findstring arm/,$(GOPLATFORM)),--set binary.args.CGO_ENABLED=0) binary
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you just pass in CGO_ENABLED? Afaics it is not that arm binaries can't use cgo but that arm call happens on some specific environment/jenkins node set from the caller side that causes it. If this would be arm specific we would disable cgo in docker/cli for that case(as we disable pie for some arch) but don't think but I don't think there is any proof of that atm.

@tiborvass tiborvass force-pushed the darwin_arm64 branch 2 times, most recently from 88eb12b to 6fa4429 Compare April 8, 2021 20:12
@tiborvass tiborvass marked this pull request as ready for review April 9, 2021 17:12
Signed-off-by: Tibor Vass <tibor@docker.com>
@tiborvass tiborvass force-pushed the darwin_arm64 branch 2 times, most recently from c3d6ef8 to eb9402b Compare April 9, 2021 19:15
@tiborvass
Copy link
Contributor Author

@tonistiigi fixed your concerns.

Tibor Vass added 3 commits April 9, 2021 19:44
Since we are building arm on arm64 machines we have to specify the desired platform
and not rely on the host's architecture.

Also when building arm on arm64 machines, there can be issues with cgo.
So this patch makes sure CGO_ENABLED env var gets passed on as a build arg.

Signed-off-by: Tibor Vass <tibor@docker.com>
Signed-off-by: Tibor Vass <tibor@docker.com>
In docker/cli#2993, Makefile target dynbinary
changed from a host script not depending on docker to a dockerized script.
Instead call the underlying script directly for deb/rpm.

I still think we should build deb/rpms using docker.

Signed-off-by: Tibor Vass <tibor@docker.com>
@tiborvass
Copy link
Contributor Author

@tiborvass tiborvass merged commit b392198 into docker:master Apr 9, 2021
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants