2021-03-03 02:03:02 -05:00
|
|
|
#!/usr/bin/env sh
|
2017-05-11 18:52:17 -04:00
|
|
|
#
|
|
|
|
# Build a static binary for the host OS/ARCH
|
|
|
|
#
|
2017-05-09 12:38:23 -04:00
|
|
|
|
2021-03-03 02:03:02 -05:00
|
|
|
set -eu
|
2017-05-09 12:38:23 -04:00
|
|
|
|
2021-03-03 02:03:02 -05:00
|
|
|
: "${CGO_ENABLED=}"
|
|
|
|
: "${GO_LINKMODE=static}"
|
|
|
|
: "${GO_BUILDMODE=}"
|
|
|
|
: "${GO_BUILDTAGS=}"
|
|
|
|
: "${GO_STRIP=}"
|
2017-05-11 18:52:17 -04:00
|
|
|
|
2021-03-03 02:03:02 -05:00
|
|
|
. ./scripts/build/.variables
|
2017-05-11 18:52:17 -04:00
|
|
|
|
2021-03-03 02:03:02 -05:00
|
|
|
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
|
|
|
|
GO_BUILDTAGS="$GO_BUILDTAGS pkcs11"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$CGO_ENABLED" = "1" ] && [ "$GO_LINKMODE" = "static" ] && [ "$(go env GOOS)" = "linux" ]; then
|
[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="$GO_LDFLAGS -extldflags -static"
|
2021-03-03 02:03:02 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$GO_STRIP" ]; then
|
[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="$GO_LDFLAGS -s -w"
|
2021-03-03 02:03:02 -05:00
|
|
|
fi
|
|
|
|
|
2021-03-05 03:56:55 -05:00
|
|
|
if [ "$(go env GOOS)" = "windows" ]; then
|
|
|
|
# Generate a Windows file version of the form major,minor,patch,build
|
|
|
|
VERSION_QUAD=$(printf "%s" "$VERSION" | sed -re 's/^([0-9.]*).*$/\1/' | tr . , | sed -re 's/^[0-9]+$/\0,0/' | sed -re 's/^[0-9]+,[0-9]+$/\0,0/' | sed -re 's/^[0-9]+,[0-9]+,[0-9]+$/\0,0/')
|
|
|
|
|
|
|
|
set --
|
|
|
|
[ -n "$VERSION" ] && set -- "$@" -D "DOCKER_VERSION=\"$VERSION\""
|
|
|
|
[ -n "$VERSION_QUAD" ] && set -- "$@" -D "DOCKER_VERSION_QUAD=$VERSION_QUAD"
|
|
|
|
[ -n "$GITCOMMIT" ] && set -- "$@" -D "DOCKER_COMMIT=\"$GITCOMMIT\""
|
|
|
|
|
|
|
|
windres=$($(go env CC) --print-prog-name=windres)
|
|
|
|
|
|
|
|
target="$(dirname "$0")/../../cli/winresources/rsrc_$(go env GOARCH).syso"
|
|
|
|
mkdir -p "$(dirname "${target}")"
|
|
|
|
"$windres" -i "$(dirname "$0")/../winresources/docker.rc" -o "$target" "$@"
|
|
|
|
echo "package winresources" > "$(dirname "${target}")/stub_windows.go"
|
|
|
|
fi
|
|
|
|
|
2021-03-03 02:03:02 -05:00
|
|
|
echo "Building $GO_LINKMODE $(basename "${TARGET}")"
|
|
|
|
|
|
|
|
export GO111MODULE=auto
|
|
|
|
|
[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 build -o "${TARGET}" -tags "${GO_BUILDTAGS}" --ldflags "${GO_LDFLAGS}" ${GO_BUILDMODE} "${SOURCE}"
|
2021-03-03 02:03:02 -05:00
|
|
|
|
|
|
|
ln -sf "$(basename "${TARGET}")" "$(dirname "${TARGET}")/docker"
|