Size of binares for arm builds is 180MB

I am trying to get a small arm7 package of telegraf, to run on embedded device.

Everythings works fine with command like below:

BUILDTAGS=“custom,inputs.cpu,inputs.disk,inputs.exec,outputs.influxdb,parsers.influx” make package include_packages=“linux_armhf.tar.gz”

The size of the binary is 180MB though, when for x86/amd it is ~25MB. Actually official download of telegraf for arm7 (as well asm arm64) also is very heavy.

Building command seems to include strip option:

CGO_ENABLED=0 go build -o build/linux-arm6/ -ldflags “-w -s -X (cut here)” ./cmd/telegraf

Inspecting binary it says it is statically build and stripped, so looks like it must include some very large libraries and makes it useless for small targets.

Any idea why telegraf is so large? Is it possible to make it significantly smaller?

Build tags don’t appear to be passed to the package build, only a normal build:

diff --git a/Makefile b/Makefile
index 7479404e2..c4f6be591 100644
--- a/Makefile
+++ b/Makefile
@@ -274,7 +274,7 @@ install: $(buildbin)
 $(buildbin):
        echo $(GOOS)
        @mkdir -pv $(dir $@)
-       CGO_ENABLED=0 go build -o $(dir $@) -ldflags "$(LDFLAGS)" ./cmd/telegraf
+       CGO_ENABLED=0 go build -o $(dir $@) -tags "$(BUILDTAGS)" -ldflags "$(LDFLAGS)" ./cmd/telegraf
 
 # Define packages Telegraf supports, organized by architecture with a rule to echo the list to limit include_packages
 # e.g. make package include_packages="$(make amd64)"

Once that change is made I see a much smaller build:

❯ ls -lah ./build/linux-arm6/
total 16M
drwxr-xr-x 1 powersj powersj  16 Oct  2 08:18 ./
drwxr-xr-x 1 powersj powersj  56 Oct  2 08:18 ../
-rwxr-xr-x 1 powersj powersj 16M Oct  2 08:18 telegraf*
❯ ls -lah ./build/dist/
total 5.7M
drwxr-xr-x 1 powersj powersj   86 Oct  2 08:18 ./
drwxr-xr-x 1 powersj powersj   56 Oct  2 08:18 ../
-rw-r--r-- 1 powersj powersj 5.7M Oct  2 08:18 telegraf-1.29.0~6b01384c_linux_armhf.tar.gz

I am not entirely sure why we did not do this in the past, but I have put up chore: Add build tags to buildbin Makefile target by powersj · Pull Request #14034 · influxdata/telegraf · GitHub to add it. I’ll see if CI is happy with it still. Locally building with the build tags set or unset seem to produce what I expected.

Works great, thanks!