Skip to content
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

promu failing to produce static binaries #60

Closed
gouthamve opened this issue Mar 2, 2017 · 7 comments · Fixed by #72
Closed

promu failing to produce static binaries #60

gouthamve opened this issue Mar 2, 2017 · 7 comments · Fixed by #72

Comments

@gouthamve
Copy link
Member

Compiling Prometheus via promu produces a dynamic build. But using CGO_ENABLED=0 env var produces a static one.

promu should natively produce a static binary.

Ref: prometheus/prometheus#2460

@mxinden
Copy link
Member

mxinden commented Mar 2, 2017

Adding CGO_ENABLED=0 to promu build would force every user to have write access to $GOROOT because go will try to rebuild all the standard lib packages and write them back to $GOROOT (See comment).

Instead we could run the standard build command in a docker container. But this would require every user to have docker installed.

If you need a static binary I suggest you run promu crossbuild (See the promu README). Make sure you comment out all architectures you don't need in the .promu.yml file under crossbuild/platforms. You will find your static binary in .build/<your-arch>/prometheus.

@gouthamve
Copy link
Member Author

Yep, while I did not know about the side-effects of using CGO_ENABLED=0, I donot want to use that.

The goal here is that promu build itself should build a static binary like the promu crossbuild command. The help also seems to suggest that promu builds static ones:

Usage:
  promu build [flags]

Flags:
      --cgo             Enable CGO
      --prefix string   Specific dir to store binaries (default is .)

Global Flags:
      --config string   Config file (default is ./.promu.yml)
  -v, --verbose         Verbose output
      --viper           Use Viper for configuration (default true)

I also ran promu build --cgo=false and even that is giving dynamic binary :(

@sdurrheimer
Copy link
Contributor

This is because when we use --cgo=false (which is the default), we don't set CGO_ENABLED=0 explicitely here.

Even he we don't specify CGO_ENABLED=1 explicitely, Golang might use some CGO.

@gouthamve
Copy link
Member Author

Umm, wait. Let me backup a little here.
So, promu by default produces binaries depending on the env_var, but we can explicitly ask it to use CGO.

Don't you think static binaries should be the default?
Or enable a way to make it build static binaries irrespective of the env_var?

@sdurrheimer
Copy link
Contributor

By default, promu build try to act like a go build command as transparent as possible. So to build a project statically, you need to specify correct goflags and the cgo config.

However in some cases, we forces some envvars or goflags to fix some issues or to help produce static binaries.

@discordianfish
Copy link
Member

@sdurrheimer I'm confused.. So what's the right way to enable static builds? It seems like there are scenarios where not setting CGO_ENABLED will make it build dynamically linked while setting CGO_ENABLED=0 explicitly gives you a statically linked binary. Even if -a -tags netgo flags are used.

@sdurrheimer
Copy link
Contributor

Unfortunately, this is the current golang behavior. It depends on the project's code. I don't know how to force golang to build statically besides setting CGO_ENABLED=0 explicitly.

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 a pull request may close this issue.

4 participants