-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix cross compile build #78
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| .DS_Store | ||
| build | ||
| ./build |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
|
|
||
| FROM golang:1.8.1 | ||
|
|
||
| # allow replacing httpredir or deb mirror | ||
| ARG APT_MIRROR=deb.debian.org | ||
| RUN sed -ri "s/(httpredir|deb).debian.org/$APT_MIRROR/g" /etc/apt/sources.list | ||
|
|
||
| RUN apt-get update -qq && apt-get install -y -q \ | ||
| libltdl-dev \ | ||
| gcc-mingw-w64 \ | ||
| parallel \ | ||
| ; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's necessary because of the It's a minor thing though, and I'm fine to change it if you prefer I drop the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤷♂️ , I'm more used to the other way around, I was just wondering if this was adding any side effect I wasn't aware off. |
||
|
|
||
| RUN go get github.com/mitchellh/gox && \ | ||
| cp /go/bin/gox /usr/bin && \ | ||
| rm -rf /go/src/* /go/pkg/* /go/bin/* | ||
|
|
||
| COPY dockerfiles/osx-cross.sh /tmp/ | ||
| RUN /tmp/osx-cross.sh | ||
| ENV PATH /osxcross/target/bin:$PATH | ||
|
|
||
| WORKDIR /go/src/github.com/docker/cli | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #!/usr/bin/env bash | ||
| # | ||
| # Install dependencies required to cross compile osx, then cleanup | ||
| # | ||
| # TODO: this should be a separate build stage when CI supports it | ||
|
|
||
|
|
||
| set -eu -o pipefail | ||
|
|
||
| PKG_DEPS="patch xz-utils clang" | ||
|
|
||
| apt-get update -qq | ||
| apt-get install -y -q $PKG_DEPS | ||
|
|
||
| OSX_SDK=MacOSX10.11.sdk | ||
| OSX_CROSS_COMMIT=a9317c18a3a457ca0a657f08cc4d0d43c6cf8953 | ||
| OSXCROSS_PATH="/osxcross" | ||
|
|
||
| echo "Cloning osxcross" | ||
| time git clone https://github.com/tpoechtrager/osxcross.git $OSXCROSS_PATH | ||
| cd $OSXCROSS_PATH | ||
| git checkout -q $OSX_CROSS_COMMIT | ||
|
|
||
| echo "Downloading OSX SDK" | ||
| time curl -sSL https://s3.dockerproject.org/darwin/v2/${OSX_SDK}.tar.xz \ | ||
| -o "${OSXCROSS_PATH}/tarballs/${OSX_SDK}.tar.xz" | ||
|
|
||
| echo "Buidling osxcross" | ||
| UNATTENDED=yes OSX_VERSION_MIN=10.6 ${OSXCROSS_PATH}/build.sh > /dev/null |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -eu | ||
|
|
||
| VERSION=${VERSION:-"unknown-version"} | ||
| GITCOMMIT=${GITCOMMIT:-$(git rev-parse --short HEAD 2> /dev/null || true)} | ||
| BUILDTIME=${BUILDTIME:-$(date --utc --rfc-3339 ns 2> /dev/null | sed -e 's/ /T/')} | ||
|
|
||
| export LDFLAGS="\ | ||
| -w \ | ||
| -X github.com/docker/cli/cli.GitCommit=${GITCOMMIT} \ | ||
| -X github.com/docker/cli/cli.BuildTime=${BUILDTIME} \ | ||
| -X github.com/docker/cli/cli.Version=${VERSION} \ | ||
| ${LDFLAGS:-} \ | ||
| " | ||
|
|
||
| export TARGET="build/docker-$(go env GOHOSTOS)-$(go env GOHOSTARCH)" | ||
| export SOURCE="github.com/docker/cli/cmd/docker" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,14 @@ | ||
| #!/usr/bin/env sh | ||
| #!/usr/bin/env bash | ||
| # | ||
| # Build a static binary for the host OS/ARCH | ||
| # | ||
|
|
||
| source ./scripts/build/ldflags | ||
| set -eu -o pipefail | ||
|
|
||
| go build -o ./build/docker --ldflags "${LDFLAGS}" github.com/docker/cli/cmd/docker | ||
| source ./scripts/build/.variables | ||
|
|
||
| echo "Building statically linked $TARGET" | ||
| export CGO_ENABLED=0 | ||
| go build -o "${TARGET}" --ldflags "${LDFLAGS}" "${SOURCE}" | ||
|
|
||
| ln -sf "$(basename ${TARGET})" build/docker |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,12 @@ | ||
| #!/usr/bin/env sh | ||
| #!/usr/bin/env bash | ||
|
|
||
| source ./scripts/build/ldflags | ||
| set -eu -o pipefail | ||
|
|
||
| gox -output build/docker-{{.OS}}-{{.Arch}} \ | ||
| -osarch="linux/arm linux/amd64 darwin/amd64 windows/amd64" \ | ||
| --ldflags "${LDFLAGS}" \ | ||
| github.com/docker/cli/cmd/docker | ||
| export BUILDDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
|
|
||
| echo "Building all binaries" | ||
| SHELL=/bin/bash parallel ::: \ | ||
| "$BUILDDIR/linux-cross" \ | ||
| "$BUILDDIR/windows" \ | ||
| "$BUILDDIR/osx" \ | ||
| ; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #!/usr/bin/env bash | ||
| # | ||
| # Build a dynamically linked binary for the host OS/ARCH | ||
| # | ||
|
|
||
| set -eu -o pipefail | ||
|
|
||
| source ./scripts/build/.variables | ||
|
|
||
| echo "Building dynamically linked $TARGET" | ||
| export CGO_ENABLED=1 | ||
| go build -o "${TARGET}" -tags pkcs11 --ldflags "${LDFLAGS}" "${SOURCE}" | ||
|
|
||
| ln -sf "$(basename ${TARGET})" build/docker |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If building with docker is the default as specified in the beginning of that section, then I would make
docker.Makefilethe defaultMakefileand the in container one the secondary one.i.e.: as an user I just want to do
make,make binaryormake crossdirectly. This is the most common behavior and doesn't force someone to have to read theREADMEif they just want the binary.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I understand that.
My concern is that
docker.Makefileis not really a good use of make. Every target is effectively.PHONY. It is not really taking advantage of any of what Make provides. It could just as easily be a bash script, or ideally a tool that is actually designed for this use case.We should be looking to remove
docker.Makefileand replace it with something else, which is why it's named this way. We could very easily drop in adobi.yamlfor this purpose and it would provide a lot of additional benefits.It should also (eventually) be merged with what is now
circle.ymlso we don't have a separate copy for CI tasks. This is not really possible with circleci, just yet.We could, for now, create a script that wraps this
make -f docker.Makefileso the instructions would be something like./task binary./task lint, etc. This would give us a shim to transition to new build tools and would probably be a lot more concise when what we have indocker.Makefileright now.Since this PR provides some necessary support for building cross, I'd like to get this merged first and address that in a separate PR.
WDTY?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is blocking quite a few things, I'm fine with merging it as it is.
But I'm afraid we'll end up breaking people relying on the cli downstream if we don't update quickly afterwards.
makeis the standard, but I agree it is ill fitted to deal with output depending on docker images (depending on theDockerfiles themselves would be an improvement though).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
I agree
makeis pretty standard for some languages, but I don't see it widely used by many golang projects. If it is a standard it's not very widely adopted. I think there are a lot more issues with make beyond just handling docker images, but Ill leave that for another thread.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be fine with having a
build.shscript instead. Not for this PR, just my 2¢.