Skip to content

Commit

Permalink
update windows resources generation
Browse files Browse the repository at this point in the history
New solution is not hardcoded to amd64 but integrates
with the cross toolchain and support creating arm binaries.

Go has been updated so that ASLR works

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
  • Loading branch information
tonistiigi committed Apr 6, 2021
1 parent 6423da8 commit 8b822c9
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 77 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
Thumbs.db
.editorconfig
/build/
cli/winresources/rsrc_386.syso
cli/winresources/rsrc_amd64.syso
cli/winresources/rsrc_*.syso
/man/man1/
/man/man5/
/man/man8/
Expand Down
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-${BASE_VARIANT} AS gostable
FROM --platform=$BUILDPLATFORM golang:1.16-${BASE_VARIANT} AS golatest

FROM gostable AS go-linux
FROM gostable AS go-windows
FROM golatest AS go-windows
FROM golatest AS go-darwin

FROM --platform=$BUILDPLATFORM tonistiigi/xx@sha256:810dc54d5144f133a218e88e319184bf8b9ce01d37d46ddb37573e90decd9eef AS xx
FROM --platform=$BUILDPLATFORM tonistiigi/xx@sha256:620d36a9d7f1e3b102a5c7e8eff12081ac363828b3a44390f24fa8da2d49383d AS xx

FROM go-${TARGETOS} AS build-base-alpine
COPY --from=xx / /
RUN apk add --no-cache clang lld file
RUN apk add --no-cache clang lld llvm file git
WORKDIR /go/src/github.com/docker/cli

FROM build-base-alpine AS build-alpine
Expand Down Expand Up @@ -44,12 +44,14 @@ ARG CGO_ENABLED
ARG VERSION
RUN --mount=ro --mount=type=cache,target=/root/.cache \
--mount=from=dockercore/golang-cross:xx-sdk-extras,target=/xx-sdk,src=/xx-sdk \
--mount=type=tmpfs,target=cli/winresources \
xx-go --wrap && \
# export GOCACHE=$(go env GOCACHE)/$(xx-info)$([ -f /etc/alpine-release ] && echo "alpine") && \
TARGET=/out ./scripts/build/binary && \
xx-verify $([ "$GO_LINKMODE" = "static" ] && echo "--static") /out/docker

FROM build-base-${BASE_VARIANT} AS dev
COPY . .

FROM scratch AS binary
COPY --from=build /out .
4 changes: 1 addition & 3 deletions cli/winresources/res_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ These resources are used to provide
* An icon
* A Windows manifest declaring Windows version support
The resource object files are generated with go generate.
The resource object files are generated when building with scripts/build/binary .
The resource source files are located in scripts/winresources.
This occurs automatically when you run scripts/build/windows.
Expand All @@ -14,5 +14,3 @@ is included.
*/
package winresources

//go:generate ../../scripts/gen/windows-resources
18 changes: 17 additions & 1 deletion scripts/build/binary
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ set -eu
: "${GO_BUILDTAGS=}"
: "${GO_STRIP=}"

set -x
. ./scripts/build/.variables

if [ -z "$CGO_ENABLED" ]; then
Expand Down Expand Up @@ -55,6 +54,23 @@ if [ -n "$GO_STRIP" ]; then
LDFLAGS="$LDFLAGS -s -w"
fi

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

echo "Building $GO_LINKMODE $(basename "${TARGET}")"

export GO111MODULE=auto
Expand Down
23 changes: 0 additions & 23 deletions scripts/build/windows

This file was deleted.

45 changes: 0 additions & 45 deletions scripts/gen/windows-resources

This file was deleted.

0 comments on commit 8b822c9

Please sign in to comment.