Skip to content

cmd/go: add -static flag for simplified static builds#78659

Open
SAY-5 wants to merge 1 commit intogolang:masterfrom
SAY-5:feat/build-static-flag
Open

cmd/go: add -static flag for simplified static builds#78659
SAY-5 wants to merge 1 commit intogolang:masterfrom
SAY-5:feat/build-static-flag

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented Apr 12, 2026

When -static is passed, the build produces a statically linked binary without having to remember CGO_ENABLED=0 or the -extldflags incantation.

If CGO is explicitly enabled (CGO_ENABLED=1), it keeps cgo and passes -extldflags=-static to the linker. Otherwise it just disables cgo for a pure Go static binary.

Updates #26492

When -static is set:
- If CGO_ENABLED=1 explicitly: keeps CGO, adds -extldflags=-static
- Otherwise: disables CGO for a pure Go static binary

This simplifies the current workflow of setting CGO_ENABLED=0 or
passing -ldflags '-extldflags "-static"' manually.

Updates golang#26492
@google-cla
Copy link
Copy Markdown

google-cla bot commented Apr 12, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@SAY-5
Copy link
Copy Markdown
Author

SAY-5 commented Apr 12, 2026

I have read and agree to the Google Contributor License Agreement at https://cla.developers.google.com/. My GitHub account is SAY-5.

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.

1 participant