cmd/go: build: add -static flag
This is a proposal to add `-static` flag to `go build`. Producing a static build with go already requires a non-trivial amount of flags passed to `go build`, which on Linux currently amounts to something like: `-ldflags '-extldflags "-fno-PIC -static"' -buildmode pie -tags 'osusergo netgo static_build'` [1] ...and this magic string keeps growing. It would be awesome to encapsulate this sacred knowledge internally, exposing it via a new `-static` flag for `go build` and friends. In addition to the above benefit of hiding the complexity, `-static` can also bring us more niceties, such as: * automatic `static` build tag third-party software can rely upon. Currently using `static_build` tag seems like a de-facto standard, used a lot, but it has to be explicitly defined like in [1] above. * providing `--static` flag to `pkg-config` invocations (those initiated by `// #cgo pkg-config: lib` lines in the source code). It will solve another issue (linking against a proper set of libraries for both static and dynamic link cases) for which a somewhat verbose workaround is currently required (for example, see [ploop_link_static.go](https://github.com/kolyshkin/goploop/blob/master/ploop_link_static.go) and [ploop_link_dynamic.go](https://github.com/kolyshkin/goploop/blob/master/ploop_link_dynamic.go)). ### See also * https://github.com/golang/go/issues/12058 (original proposal for adding conditional `--static` to `pkg-config`) * https://github.com/golang/go/issues/24787 (initial ver
Posted by kolyshkin on Jul 19, 2018, 11:58 PM
Tags
Related issues
- 2026 - Microsoft Office 365
- [Ubuntu] `ubuntu-latest` label will use Ubuntu 26.04 in November 2026
- Gamut mapping
- [Codex Desktop] Editing and resending a queued message triggers "App-server queued follow-up no longer exists"
- [Windows] ChatGPT 26.820.60940 fails with "invalid transport in mcp_servers.codex_app"; Beta 26.727.40816 works
- [BUG]: infinite loading of videos
Raise real-world problems, find people facing the same issue, and discuss solutions.4,000 issues0 comments
github (SaaS)
2026 - Microsoft Office 365
[Ubuntu] `ubuntu-latest` label will use Ubuntu 26.04 in November 2026
Gamut mapping
[Codex Desktop] Editing and resending a queued message triggers "App-server queued follow-up no longer exists"
[Windows] ChatGPT 26.820.60940 fails with "invalid transport in mcp_servers.codex_app"; Beta 26.727.40816 works
[BUG]: infinite loading of videos
Restore GPT-5.6 Sol’s 372k Codex context window, or provide an opt-in setting
Codex Desktop for macOS repeatedly triggers `syspolicyd` / `trustd` CPU and memory runaway
cmd/go: build: add -static flag
This is a proposal to add `-static` flag to `go build`. Producing a static build with go already requires a non-trivial amount of flags passed to `go build`, which on Linux currently amounts to something like: `-ldflags '-extldflags "-fno-PIC -static"' -buildmode pie -tags 'osusergo netgo static_build'` [1] ...and this magic string keeps growing. It would be awesome to encapsulate this sacred knowledge internally, exposing it via a new `-static` flag for `go build` and friends. In addition to the above benefit of hiding the complexity, `-static` can also bring us more niceties, such as: * automatic `static` build tag third-party software can rely upon. Currently using `static_build` tag seems like a de-facto standard, used a lot, but it has to be explicitly defined like in [1] above. * providing `--static` flag to `pkg-config` invocations (those initiated by `// #cgo pkg-config: lib` lines in the source code). It will solve another issue (linking against a proper set of libraries for both static and dynamic link cases) for which a somewhat verbose workaround is currently required (for example, see [ploop_link_static.go](https://github.com/kolyshkin/goploop/blob/master/ploop_link_static.go) and [ploop_link_dynamic.go](https://github.com/kolyshkin/goploop/blob/master/ploop_link_dynamic.go)). ### See also * https://github.com/golang/go/issues/12058 (original proposal for adding conditional `--static` to `pkg-config`) * https://github.com/golang/go/issues/24787 (initial ver
Comments (0)
No comments yet. Start the discussion.