mirror of https://github.com/docker/cli.git
[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 391e6ad944
)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
16169434a4
commit
6f7a931a2d
|
@ -13,13 +13,13 @@ if test -n "${PLATFORM}"; then
|
||||||
PLATFORM_LDFLAGS="-X \"github.com/docker/cli/cli/version.PlatformName=${PLATFORM}\""
|
PLATFORM_LDFLAGS="-X \"github.com/docker/cli/cli/version.PlatformName=${PLATFORM}\""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
export LDFLAGS="\
|
export GO_LDFLAGS="\
|
||||||
-w \
|
-w \
|
||||||
${PLATFORM_LDFLAGS} \
|
${PLATFORM_LDFLAGS} \
|
||||||
-X \"github.com/docker/cli/cli/version.GitCommit=${GITCOMMIT}\" \
|
-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.BuildTime=${BUILDTIME}\" \
|
||||||
-X \"github.com/docker/cli/cli/version.Version=${VERSION}\" \
|
-X \"github.com/docker/cli/cli/version.Version=${VERSION}\" \
|
||||||
${LDFLAGS:-} \
|
${GO_LDFLAGS:-} \
|
||||||
"
|
"
|
||||||
|
|
||||||
GOOS="$(go env GOOS)"
|
GOOS="$(go env GOOS)"
|
||||||
|
|
|
@ -47,11 +47,11 @@ if [ "$CGO_ENABLED" = "1" ] && [ "$(go env GOOS)" != "windows" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$CGO_ENABLED" = "1" ] && [ "$GO_LINKMODE" = "static" ] && [ "$(go env GOOS)" = "linux" ]; then
|
if [ "$CGO_ENABLED" = "1" ] && [ "$GO_LINKMODE" = "static" ] && [ "$(go env GOOS)" = "linux" ]; then
|
||||||
LDFLAGS="$LDFLAGS -extldflags -static"
|
GO_LDFLAGS="$GO_LDFLAGS -extldflags -static"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$GO_STRIP" ]; then
|
if [ -n "$GO_STRIP" ]; then
|
||||||
LDFLAGS="$LDFLAGS -s -w"
|
GO_LDFLAGS="$GO_LDFLAGS -s -w"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$(go env GOOS)" = "windows" ]; then
|
if [ "$(go env GOOS)" = "windows" ]; then
|
||||||
|
@ -75,6 +75,6 @@ echo "Building $GO_LINKMODE $(basename "${TARGET}")"
|
||||||
|
|
||||||
export GO111MODULE=auto
|
export GO111MODULE=auto
|
||||||
|
|
||||||
go build -o "${TARGET}" -tags "${GO_BUILDTAGS}" --ldflags "${LDFLAGS}" ${GO_BUILDMODE} "${SOURCE}"
|
go build -o "${TARGET}" -tags "${GO_BUILDTAGS}" --ldflags "${GO_LDFLAGS}" ${GO_BUILDMODE} "${SOURCE}"
|
||||||
|
|
||||||
ln -sf "$(basename "${TARGET}")" "$(dirname "${TARGET}")/docker"
|
ln -sf "$(basename "${TARGET}")" "$(dirname "${TARGET}")/docker"
|
||||||
|
|
|
@ -17,5 +17,5 @@ for p in cli-plugins/examples/* "$@" ; do
|
||||||
|
|
||||||
echo "Building statically linked $TARGET"
|
echo "Building statically linked $TARGET"
|
||||||
export CGO_ENABLED=0
|
export CGO_ENABLED=0
|
||||||
GO111MODULE=auto go build -o "${TARGET}" --ldflags "${LDFLAGS}" "github.com/docker/cli/${p}"
|
GO111MODULE=auto go build -o "${TARGET}" --ldflags "${GO_LDFLAGS}" "github.com/docker/cli/${p}"
|
||||||
done
|
done
|
||||||
|
|
|
@ -12,7 +12,7 @@ export GOOS=darwin
|
||||||
export GOARCH=amd64
|
export GOARCH=amd64
|
||||||
export CC=o64-clang
|
export CC=o64-clang
|
||||||
export CXX=o64-clang++
|
export CXX=o64-clang++
|
||||||
export LDFLAGS="$LDFLAGS -linkmode external -s"
|
export GO_LDFLAGS="$GO_LDFLAGS -linkmode external -s"
|
||||||
export LDFLAGS_STATIC_DOCKER='-extld='${CC}
|
export LDFLAGS_STATIC_DOCKER='-extld='${CC}
|
||||||
|
|
||||||
source ./scripts/build/plugins
|
source ./scripts/build/plugins
|
||||||
|
|
|
@ -109,12 +109,12 @@ Function Execute-Build($additionalBuildTags, $directory) {
|
||||||
Write-Host "INFO: Building..."
|
Write-Host "INFO: Building..."
|
||||||
|
|
||||||
$buildTime=$(Get-Date).ToUniversalTime()
|
$buildTime=$(Get-Date).ToUniversalTime()
|
||||||
$env:LDFLAGS="-linkmode=internal `
|
$env:GO_LDFLAGS="-linkmode=internal `
|
||||||
-X \""github.com/docker/cli/cli/version.Version=$dockerVersion\"" `
|
-X \""github.com/docker/cli/cli/version.Version=$dockerVersion\"" `
|
||||||
-X \""github.com/docker/cli/cli/version.GitCommit=$gitCommit\"" `
|
-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.BuildTime=$buildTime\"""
|
||||||
if ($env:PLATFORM) {
|
if ($env:PLATFORM) {
|
||||||
$env:LDFLAGS="$env:LDFLAGS -X \""github.com/docker/cli/cli/version.PlatformName=$env:PLATFORM\"""
|
$env:GO_LDFLAGS="$env:GO_LDFLAGS -X \""github.com/docker/cli/cli/version.PlatformName=$env:PLATFORM\"""
|
||||||
}
|
}
|
||||||
|
|
||||||
# Generate a version in the form major,minor,patch,build
|
# Generate a version in the form major,minor,patch,build
|
||||||
|
@ -138,7 +138,7 @@ Function Execute-Build($additionalBuildTags, $directory) {
|
||||||
# By using --% we can use \"key=%foo%\" and have a environment variable foo that contains spaces
|
# By using --% we can use \"key=%foo%\" and have a environment variable foo that contains spaces
|
||||||
go build $raceParm $verboseParm $allParm $optParm -tags "$buildTags" `
|
go build $raceParm $verboseParm $allParm $optParm -tags "$buildTags" `
|
||||||
-o "$root\build\$directory.exe" `
|
-o "$root\build\$directory.exe" `
|
||||||
-ldflags --% "%LDFLAGS%"
|
-ldflags --% "%GO_LDFLAGS%"
|
||||||
|
|
||||||
if ($LASTEXITCODE -ne 0) { Throw "Failed to compile" }
|
if ($LASTEXITCODE -ne 0) { Throw "Failed to compile" }
|
||||||
Pop-Location; $global:pushed=$False
|
Pop-Location; $global:pushed=$False
|
||||||
|
|
Loading…
Reference in New Issue