2021-03-03 02:03:02 -05:00
|
|
|
#!/usr/bin/env sh
|
2017-05-11 18:52:17 -04:00
|
|
|
set -eu
|
|
|
|
|
2021-03-03 02:03:02 -05:00
|
|
|
TARGET=${TARGET:-"build"}
|
|
|
|
|
2017-12-01 08:47:20 -05:00
|
|
|
PLATFORM=${PLATFORM:-}
|
2021-03-05 17:34:32 -05:00
|
|
|
VERSION=${VERSION:-$(git describe --match 'v[0-9]*' --dirty='.m' --always --tags | sed 's/^v//' 2>/dev/null || echo "unknown-version" )}
|
2017-05-11 18:52:17 -04:00
|
|
|
GITCOMMIT=${GITCOMMIT:-$(git rev-parse --short HEAD 2> /dev/null || true)}
|
2019-12-31 09:06:11 -05:00
|
|
|
BUILDTIME=${BUILDTIME:-$(date -u +"%Y-%m-%dT%H:%M:%SZ")}
|
2017-05-11 18:52:17 -04:00
|
|
|
|
2017-12-01 08:47:20 -05:00
|
|
|
PLATFORM_LDFLAGS=
|
|
|
|
if test -n "${PLATFORM}"; then
|
2019-01-08 10:03:51 -05:00
|
|
|
PLATFORM_LDFLAGS="-X \"github.com/docker/cli/cli/version.PlatformName=${PLATFORM}\""
|
2017-12-01 08:47:20 -05:00
|
|
|
fi
|
|
|
|
|
[20.10] use GO_LDFLAGS instead of LDFLAGS to prevent inheriting unrelated options
When building on Fedora 36, the build failed. I suspect this is because the
rpm tools also set LDFLAGS, but with options that cannot be used;
GO_LINKMODE=dynamic
+ ./scripts/build/binary
/go/src/github.com/docker/cli ~/rpmbuild/BUILD/src
Building dynamic docker-linux-arm64
+ go build -o build/docker-linux-arm64 -tags ' pkcs11' -ldflags '-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1 -Wl,-dT,/root/rpmbuild/BUILD/src/.package_note-docker-ce-cli-0.0.0.20220330082637.68cad50-0.fc36.aarch64.ld -w -X "github.com/docker/cli/cli/version.GitCommit=68cad50" -X "github.com/docker/cli/cli/version.BuildTime=2022-03-30T20:05:36Z" -X "github.com/docker/cli/cli/version.Version=0.0.0-20220330082637-68cad50" -X "github.com/docker/cli/cli/version.PlatformName=Docker Engine - Community"' -buildmode=pie github.com/docker/cli/cmd/docker
# github.com/docker/cli/cmd/docker
flag provided but not defined: -Wl,-z,relro
usage: link [options] main.o
This patch changes the variable we use to `GO_LDFLAGS`, taking a similar approach
as containerd, and various other projects using this name: https://grep.app/search?q=GO_LDFLAGS
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 391e6ad944b68720aea2c3975ec298eaaeeadd87)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-03-31 04:30:56 -04:00
|
|
|
export GO_LDFLAGS="\
|
2017-05-11 18:52:17 -04:00
|
|
|
-w \
|
2017-12-01 08:47:20 -05:00
|
|
|
${PLATFORM_LDFLAGS} \
|
2019-01-08 10:03:51 -05:00
|
|
|
-X \"github.com/docker/cli/cli/version.GitCommit=${GITCOMMIT}\" \
|
|
|
|
-X \"github.com/docker/cli/cli/version.BuildTime=${BUILDTIME}\" \
|
|
|
|
-X \"github.com/docker/cli/cli/version.Version=${VERSION}\" \
|
[20.10] use GO_LDFLAGS instead of LDFLAGS to prevent inheriting unrelated options
When building on Fedora 36, the build failed. I suspect this is because the
rpm tools also set LDFLAGS, but with options that cannot be used;
GO_LINKMODE=dynamic
+ ./scripts/build/binary
/go/src/github.com/docker/cli ~/rpmbuild/BUILD/src
Building dynamic docker-linux-arm64
+ go build -o build/docker-linux-arm64 -tags ' pkcs11' -ldflags '-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1 -Wl,-dT,/root/rpmbuild/BUILD/src/.package_note-docker-ce-cli-0.0.0.20220330082637.68cad50-0.fc36.aarch64.ld -w -X "github.com/docker/cli/cli/version.GitCommit=68cad50" -X "github.com/docker/cli/cli/version.BuildTime=2022-03-30T20:05:36Z" -X "github.com/docker/cli/cli/version.Version=0.0.0-20220330082637-68cad50" -X "github.com/docker/cli/cli/version.PlatformName=Docker Engine - Community"' -buildmode=pie github.com/docker/cli/cmd/docker
# github.com/docker/cli/cmd/docker
flag provided but not defined: -Wl,-z,relro
usage: link [options] main.o
This patch changes the variable we use to `GO_LDFLAGS`, taking a similar approach
as containerd, and various other projects using this name: https://grep.app/search?q=GO_LDFLAGS
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 391e6ad944b68720aea2c3975ec298eaaeeadd87)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-03-31 04:30:56 -04:00
|
|
|
${GO_LDFLAGS:-} \
|
2017-05-11 18:52:17 -04:00
|
|
|
"
|
|
|
|
|
2021-03-03 02:03:02 -05:00
|
|
|
GOOS="$(go env GOOS)"
|
|
|
|
GOARCH="$(go env GOARCH)"
|
2019-05-02 12:05:47 -04:00
|
|
|
if [ "${GOARCH}" = "arm" ]; then
|
2021-03-03 02:03:02 -05:00
|
|
|
GOARM="$(go env GOARM)"
|
2019-05-02 12:05:47 -04:00
|
|
|
fi
|
|
|
|
|
2021-03-03 02:03:02 -05:00
|
|
|
TARGET="$TARGET/docker-${GOOS}-${GOARCH}"
|
2019-05-02 12:05:47 -04:00
|
|
|
if [ "${GOARCH}" = "arm" ] && [ -n "${GOARM}" ]; then
|
2021-03-03 02:03:02 -05:00
|
|
|
TARGET="${TARGET}-v${GOARM}"
|
2019-05-02 12:05:47 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "${GOOS}" = "windows" ]; then
|
|
|
|
TARGET="${TARGET}.exe"
|
|
|
|
fi
|
|
|
|
export TARGET
|
|
|
|
|
2017-05-11 18:52:17 -04:00
|
|
|
export SOURCE="github.com/docker/cli/cmd/docker"
|