From 956c52049112caf87422203b56ac04407af44fe8 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Tue, 24 Jun 2025 12:55:03 +0200 Subject: [PATCH] pkg(buildx): add -w to ldflags This disables DWARF generation, which dramatically decreases the size of the binary. Notably, this does *not* include `-s` which disables the symbol table, as doing so would *also* make it so that `govulncheck` cannot be run on the resulting binary with meaningful results. Before is ~90M and after is ~72M. If we add `-s` as well, that ~72M drops to ~63M, but we also lose `govulncheck` so again, IMO, that's not worth doing. Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- pkg/buildx/deb/rules | 2 +- pkg/buildx/rpm/docker-buildx-plugin.spec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/buildx/deb/rules b/pkg/buildx/deb/rules index b9991a72..a2320825 100644 --- a/pkg/buildx/deb/rules +++ b/pkg/buildx/deb/rules @@ -10,7 +10,7 @@ override_dh_auto_build: go build \ -mod=vendor \ -trimpath \ - -ldflags "-X github.com/docker/buildx/version.Version=$(VERSION) -X github.com/docker/buildx/version.Revision=$(REVISION) -X github.com/docker/buildx/version.Package=github.com/docker/buildx" \ + -ldflags "-w -X github.com/docker/buildx/version.Version=$(VERSION) -X github.com/docker/buildx/version.Revision=$(REVISION) -X github.com/docker/buildx/version.Package=github.com/docker/buildx" \ -o "/usr/libexec/docker/cli-plugins/docker-buildx" \ ./cmd/buildx diff --git a/pkg/buildx/rpm/docker-buildx-plugin.spec b/pkg/buildx/rpm/docker-buildx-plugin.spec index 55e4fe75..5f9ccbbb 100644 --- a/pkg/buildx/rpm/docker-buildx-plugin.spec +++ b/pkg/buildx/rpm/docker-buildx-plugin.spec @@ -27,7 +27,7 @@ pushd ${RPM_BUILD_DIR}/src/buildx go build \ -mod=vendor \ -trimpath \ - -ldflags="-X github.com/docker/buildx/version.Version=%{_origversion} -X github.com/docker/buildx/version.Revision=%{_commit} -X github.com/docker/buildx/version.Package=github.com/docker/buildx" \ + -ldflags="-w -X github.com/docker/buildx/version.Version=%{_origversion} -X github.com/docker/buildx/version.Revision=%{_commit} -X github.com/docker/buildx/version.Package=github.com/docker/buildx" \ -o "bin/docker-buildx" \ ./cmd/buildx popd