Skip to content

fix: strip debug symbols from CLI binary to reduce distribution size#38

Merged
beonde merged 2 commits intomainfrom
fix/cli-binary-strip-ldflags
Mar 5, 2026
Merged

fix: strip debug symbols from CLI binary to reduce distribution size#38
beonde merged 2 commits intomainfrom
fix/cli-binary-strip-ldflags

Conversation

@beonde
Copy link
Member

@beonde beonde commented Mar 3, 2026

Summary

  • Adds -w -s ldflags to the build-cli Makefile target, matching what the Dockerfile already does
  • Removes DWARF debug info (-w) and the symbol table (-s) from the distributed binary
  • Also injects version and commit build vars inline with the Dockerfile pattern

Why

The CLI binary distributed by capiscio-python and capiscio-node wrappers was ~50MB because make build-cli was doing a bare go build with no stripping. The Dockerfile build has had -w -s for 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-cli compiles without errors
  • ./bin/capiscio --version reports correct version
  • Binary is functional (badge issue/verify, gateway start)
  • Confirm binary size reduction: ls -lh bin/capiscio

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings March 3, 2026 21:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 -s to go build linker flags for build-cli to strip DWARF and symbol table.
  • Inject VERSION and COMMIT into the binary via -ldflags -X ... during make 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)" \
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-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.

Suggested change
go build -ldflags="-w -s -X main.version=$(VERSION) -X main.commit=$(COMMIT)" \
go build -ldflags="-w -s -X main.version=$(VERSION)" \

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link

codecov bot commented Mar 3, 2026

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.
@beonde beonde merged commit 1c0e601 into main Mar 5, 2026
4 checks passed
@beonde beonde deleted the fix/cli-binary-strip-ldflags branch March 5, 2026 03:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants