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>
86 lines
2.5 KiB
Bash
Executable File
86 lines
2.5 KiB
Bash
Executable File
#!/usr/bin/env sh
|
|
set -eu
|
|
|
|
: "${CGO_ENABLED=}"
|
|
: "${GO_LINKMODE=static}"
|
|
: "${GO_BUILDMODE=}"
|
|
: "${GO_BUILDTAGS=}"
|
|
: "${GO_STRIP=}"
|
|
|
|
TARGET=${TARGET:-"build"}
|
|
|
|
PLATFORM=${PLATFORM:-}
|
|
VERSION=${VERSION:-$(git describe --match 'v[0-9]*' --dirty='.m' --always --tags | sed 's/^v//' 2>/dev/null || echo "unknown-version" )}
|
|
GITCOMMIT=${GITCOMMIT:-$(git rev-parse --short HEAD 2> /dev/null || true)}
|
|
BUILDTIME=${BUILDTIME:-$(date -u --date="@${SOURCE_DATE_EPOCH:-$(date +%s)}" +"%Y-%m-%dT%H:%M:%SZ")}
|
|
|
|
GOOS="$(go env GOOS)"
|
|
GOARCH="$(go env GOARCH)"
|
|
if [ "${GOARCH}" = "arm" ]; then
|
|
GOARM="$(go env GOARM)"
|
|
fi
|
|
|
|
TARGET="$TARGET/docker-${GOOS}-${GOARCH}"
|
|
if [ "${GOARCH}" = "arm" ] && [ -n "${GOARM}" ]; then
|
|
TARGET="${TARGET}-v${GOARM}"
|
|
fi
|
|
if [ "${GOOS}" = "windows" ]; then
|
|
TARGET="${TARGET}.exe"
|
|
fi
|
|
export TARGET
|
|
|
|
if [ -z "$CGO_ENABLED" ]; then
|
|
case "$(go env GOOS)" in
|
|
linux)
|
|
case "$(go env GOARCH)" in
|
|
amd64|arm64|arm|s390x)
|
|
CGO_ENABLED=1
|
|
;;
|
|
*)
|
|
CGO_ENABLED=0
|
|
;;
|
|
esac
|
|
;;
|
|
darwin|windows)
|
|
CGO_ENABLED=1
|
|
;;
|
|
*)
|
|
CGO_ENABLED=0
|
|
;;
|
|
esac
|
|
fi
|
|
export CGO_ENABLED
|
|
|
|
if [ "$CGO_ENABLED" = "1" ] && [ "$(go env GOOS)" != "windows" ]; then
|
|
case "$(go env GOARCH)" in
|
|
mips*|ppc64)
|
|
# pie build mode is not supported on mips architectures
|
|
;;
|
|
*)
|
|
GO_BUILDMODE="-buildmode=pie"
|
|
;;
|
|
esac
|
|
fi
|
|
export GO_BUILDMODE
|
|
|
|
GO_LDFLAGS="${GO_LDFLAGS:-} -w"
|
|
GO_LDFLAGS="$GO_LDFLAGS -X \"github.com/docker/cli/cli/version.GitCommit=${GITCOMMIT}\""
|
|
GO_LDFLAGS="$GO_LDFLAGS -X \"github.com/docker/cli/cli/version.BuildTime=${BUILDTIME}\""
|
|
GO_LDFLAGS="$GO_LDFLAGS -X \"github.com/docker/cli/cli/version.Version=${VERSION}\""
|
|
if test -n "${PLATFORM}"; then
|
|
GO_LDFLAGS="$GO_LDFLAGS -X \"github.com/docker/cli/cli/version.PlatformName=${PLATFORM}\""
|
|
fi
|
|
if [ "$CGO_ENABLED" = "1" ] && [ "$GO_LINKMODE" = "static" ] && [ "$(go env GOOS)" = "linux" ]; then
|
|
GO_LDFLAGS="$GO_LDFLAGS -extldflags -static"
|
|
fi
|
|
if [ "$CGO_ENABLED" = "1" ] && [ "$GO_LINKMODE" = "static" ]; then
|
|
# compiling statically with CGO enabled requires osusergo to be set.
|
|
GO_BUILDTAGS="$GO_BUILDTAGS osusergo"
|
|
fi
|
|
if [ -n "$GO_STRIP" ]; then
|
|
GO_LDFLAGS="$GO_LDFLAGS -s"
|
|
fi
|
|
export GO_LDFLAGS="$GO_LDFLAGS" # https://github.com/koalaman/shellcheck/issues/2064
|
|
|
|
export SOURCE="github.com/docker/cli/cmd/docker"
|