IssueRaiser

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

Raise real-world problems, find people facing the same issue, and discuss solutions.4,000 issues0 comments

github (SaaS)

cmd/go: build: add -static flag

kolyshkinJul 19, 2018, 11:58 PM

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.

Comment on this issue