-
-
Notifications
You must be signed in to change notification settings - Fork 684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support fully static binaries #161
Comments
The current binaries presumably have a shared dependency on libpthread and libc? I get the same result on linux if I say 'go install github.com/bazelbuild/rules_go/go/tools/gazelle/gazelle as when I What is the magic flag to 'go build' to make it fully static? |
Should produce a static binary. |
I was just looking for how to set this particular variable, and see it's been discussed here already. Has there been any progress made on passing along values of environment variables that Go builds can depend on? I see there is limited support, specifically for |
Any update about this? If no, are there any workarounds? |
@jayconrod may look into this |
I'm definitely planning to improve this. Cross compilation is a slightly higher priority in the short term though. |
Also related: #217 Specifically, this would partially solve (although I believe this uses libc rather than the go libc implementation): go_binary(
name = "foo",
srcs = ["foo.go"],
gc_linkopts = [
"-linkmode external",
"-extldflags -static",
],
) |
@mikedanese The gc_linkopts attribute seems to has not been implemented. |
@GinFungYJF It is not implemented in the opensource rules but it does exist in the google internal rules (which are completely different). #217 proposes we implement similar feature in opensource. |
go_binary(
name = "main",
srcs = ["main.go"],
go_linkopts = [
"-extldflags",
"-static",
],
library = ":cgo_lib",
)
cgo_library(
name = "cgo_lib",
srcs = ["cgo_lib.go"],
cdeps = [":foo"],
)
cc_library(
name = "foo",
srcs = ["foo.c"],
) Couple things to note:
@mikedanese, is anything missing? Should anything work differently? |
I'm closing this because |
@jayconrod I can't think of anything (other than mac support :) ). Thanks! |
The correct attribute is |
Yes, |
Are there more flags that need to be passed in to statically link pthread? My rule looks like this go_binary(
name = "bin",
library = ":go_default_library",
gc_linkopts = [
"-extldflags",
"-static",
],
) when I compile it
Following the dependencies, pthread is coming in from a dependency on sqlite |
Woo! That fixed it. Thanks for the help! |
Users should be able to produce fully static binaries from go source, especially exclusively go source.
The text was updated successfully, but these errors were encountered: