fix: strip debug symbols from CLI binary to reduce distribution size#38
fix: strip debug symbols from CLI binary to reduce distribution size#38
Conversation
Add -w -s ldflags to build-cli target to match the existing Dockerfile build, removing DWARF debug info and symbol table. Reduces the distributed binary from ~50MB to ~14MB (~70% reduction). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Updates the release/build path for the CapiscIO CLI so that make build-cli produces a smaller distributable binary (aligning with the Docker build) by stripping debug info and embedding build metadata.
Changes:
- Add
-w -stogo buildlinker flags forbuild-clito strip DWARF and symbol table. - Inject
VERSIONandCOMMITinto the binary via-ldflags -X ...duringmake build-cli.
| @echo "Building CLI..." | ||
| @mkdir -p bin | ||
| go build -o bin/capiscio ./cmd/capiscio | ||
| go build -ldflags="-w -s -X main.version=$(VERSION) -X main.commit=$(COMMIT)" \ |
There was a problem hiding this comment.
-ldflags sets -X main.commit=$(COMMIT), but there is no commit string variable in the cmd/capiscio main package (only var version = "2.4.0" exists). This will cause make build-cli to fail at link time with an unknown symbol error. Either define var commit = "unknown" in the main package (and optionally include it in the --version output) or drop the -X main.commit=... flag here to keep the build working.
| go build -ldflags="-w -s -X main.version=$(VERSION) -X main.commit=$(COMMIT)" \ | |
| go build -ldflags="-w -s -X main.version=$(VERSION)" \ |
There was a problem hiding this comment.
Good catch. Added var commit = "unknown" to the main package and included it in the --version output: capiscio version v2.4.0 (commit: 807ddc4). Note that Go's linker silently ignores unknown -X targets so the build wouldn't have failed, but having the variable defined is the correct approach. See commit a8f8f24.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Define 'var commit' so -X main.commit= linker flag has a target. Include commit hash in --version output for production debugging.
Summary
-w -sldflags to thebuild-cliMakefile target, matching what the Dockerfile already does-w) and the symbol table (-s) from the distributed binaryversionandcommitbuild vars inline with the Dockerfile patternWhy
The CLI binary distributed by
capiscio-pythonandcapiscio-nodewrappers was ~50MB becausemake build-cliwas doing a barego buildwith no stripping. The Dockerfile build has had-w -sfor a long time — this just closes the gap for the Makefile path used during releases.Before: ~50MB
After: ~14MB (~70% reduction)
Further reduction to ~6-7MB is possible with UPX compression if needed, but that adds startup latency and can be a follow-up.
Test plan
make build-clicompiles without errors./bin/capiscio --versionreports correct versionls -lh bin/capiscio🤖 Generated with Claude Code