From e0768becf79ea70bb91c5050acb5cb678815c7fd Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 27 May 2022 12:30:41 +0200 Subject: [PATCH] Makefile: use urfave_cli_no_docs for binaries that don't need it We only need the `ToMan()` as part of the `bin/gen-manpages` binary, which generates the man-pages; other binaries don't use this code, so we can set the `urfave_cli_no_docs` build-tag to exclude `cpuguy83/md2man` and `russross/blackfriday` (and other dependencies) from the binaries: Before: ls -lh bin total 149M -rwxr-xr-x 1 root root 49M May 27 10:12 containerd -rwxr-xr-x 1 root root 6.1M May 27 10:13 containerd-shim -rwxr-xr-x 1 root root 8.1M May 27 10:13 containerd-shim-runc-v1 -rwxr-xr-x 1 root root 8.2M May 27 10:13 containerd-shim-runc-v2 -rwxr-xr-x 1 root root 22M May 27 10:12 containerd-stress -rwxr-xr-x 1 root root 26M May 27 10:11 ctr -rwxr-xr-x 1 root root 30M May 27 10:14 gen-manpages ls -l bin total 151676 -rwxr-xr-x 1 root root 51280184 May 27 10:12 containerd -rwxr-xr-x 1 root root 6332416 May 27 10:13 containerd-shim -rwxr-xr-x 1 root root 8458240 May 27 10:13 containerd-shim-runc-v1 -rwxr-xr-x 1 root root 8536064 May 27 10:13 containerd-shim-runc-v2 -rwxr-xr-x 1 root root 22567160 May 27 10:12 containerd-stress -rwxr-xr-x 1 root root 26873752 May 27 10:11 ctr -rwxr-xr-x 1 root root 30508888 May 27 10:14 gen-manpages After: ls -lh bin total 147M -rwxr-xr-x 1 root root 49M May 27 10:26 containerd -rwxr-xr-x 1 root root 6.1M May 27 10:26 containerd-shim -rwxr-xr-x 1 root root 8.1M May 27 10:26 containerd-shim-runc-v1 -rwxr-xr-x 1 root root 8.2M May 27 10:26 containerd-shim-runc-v2 -rwxr-xr-x 1 root root 22M May 27 10:26 containerd-stress -rwxr-xr-x 1 root root 26M May 27 10:26 ctr -rwxr-xr-x 1 root root 30M May 27 10:27 gen-manpages ls -l bin total 149912 -rwxr-xr-x 1 root root 50930360 May 27 10:26 containerd -rwxr-xr-x 1 root root 6332416 May 27 10:26 containerd-shim -rwxr-xr-x 1 root root 8458240 May 27 10:26 containerd-shim-runc-v1 -rwxr-xr-x 1 root root 8536064 May 27 10:26 containerd-shim-runc-v2 -rwxr-xr-x 1 root root 22209144 May 27 10:26 containerd-stress -rwxr-xr-x 1 root root 26523896 May 27 10:26 ctr -rwxr-xr-x 1 root root 30508888 May 27 10:27 gen-manpages Signed-off-by: Sebastiaan van Stijn --- Makefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 45c0067702ca3..cc56559a082d5 100644 --- a/Makefile +++ b/Makefile @@ -88,6 +88,7 @@ ifdef BUILDTAGS GO_BUILDTAGS = ${BUILDTAGS} endif GO_BUILDTAGS ?= +GO_BUILDTAGS += urfave_cli_no_docs GO_BUILDTAGS += ${DEBUG_TAGS} GO_TAGS=$(if $(GO_BUILDTAGS),-tags "$(strip $(GO_BUILDTAGS))",) GO_LDFLAGS=-ldflags '-X $(PKG)/version.Version=$(VERSION) -X $(PKG)/version.Revision=$(REVISION) -X $(PKG)/version.Package=$(PACKAGE) $(EXTRA_LDFLAGS)' @@ -221,13 +222,18 @@ FORCE: define BUILD_BINARY @echo "$(WHALE) $@" -@$(GO) build ${DEBUG_GO_GCFLAGS} ${GO_GCFLAGS} ${GO_BUILD_FLAGS} -o $@ ${GO_LDFLAGS} ${GO_TAGS} ./$< +$(GO) build ${DEBUG_GO_GCFLAGS} ${GO_GCFLAGS} ${GO_BUILD_FLAGS} -o $@ ${GO_LDFLAGS} ${GO_TAGS} ./$< endef # Build a binary from a cmd. bin/%: cmd/% FORCE $(call BUILD_BINARY) +# gen-manpages must not have the urfave_cli_no_docs build-tag set +bin/gen-manpages: cmd/gen-manpages FORCE + @echo "$(WHALE) $@" + $(GO) build ${DEBUG_GO_GCFLAGS} ${GO_GCFLAGS} ${GO_BUILD_FLAGS} -o $@ ${GO_LDFLAGS} $(subst urfave_cli_no_docs,,${GO_TAGS}) ./cmd/gen-manpages + bin/containerd-shim: cmd/containerd-shim FORCE # set !cgo and omit pie for a static shim build: https://github.com/golang/go/issues/17789#issuecomment-258542220 @echo "$(WHALE) $@" @CGO_ENABLED=${SHIM_CGO_ENABLED} $(GO) build ${GO_BUILD_FLAGS} -o $@ ${SHIM_GO_LDFLAGS} ${GO_TAGS} ./cmd/containerd-shim