GoCommandProposalProposal-Acceptedhelp wanted
Repository metrics
- Stars
- (133,883 stars)
- PR merge metrics
- (No merged PRs in 30d)
Description
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
staticbuild tag third-party software can rely upon. Currently usingstatic_buildtag seems like a de-facto standard, used a lot, but it has to be explicitly defined like in [1] above. - providing
--staticflag topkg-configinvocations (those initiated by// #cgo pkg-config: liblines 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 and ploop_link_dynamic.go).
See also
- https://github.com/golang/go/issues/12058 (original proposal for adding conditional
--statictopkg-config) - https://github.com/golang/go/issues/24787 (initial version of this very proposal)