Fix make with LDFLAGS#162
Open
Tim Hockin (thockin) wants to merge 1 commit into
Open
Conversation
2 tasks
Davanum Srinivas (dims)
approved these changes
Jun 3, 2026
Collaborator
|
How does this behave with the install scripts, which do not use the makefile at all AFAIK? |
Collaborator
|
Do we really need ldflags? Why not just use the Go-buil- in version stamping? Kubernetes uses ldflags because this functionality didn't exist. |
Collaborator
Author
|
There's no way I can see to set a version string in Go's build info? |
Collaborator
|
Go automatically grabs the version from git |
Collaborator
Author
|
vcs.revision is the commit, we want a symbolic name for releases |
f6af754 to
c8413f4
Compare
$(KO) != $(GO)
ko does not support any way to pass build flags directly. We have to
use GOFLAGS. Go does not fully shell-parse GOFLAGS, it just does simple
whitespace splitting and whole-value quoting.
E.g. this fails for good reason:
GOFLAGS="-ldflags=-X=foo=foo -X=bar=bar"
...becomes:
[ "go", "build", "-ldflags=-X=foo=foo", "-X=bar=bar" ]
...where `-X` is passed to `go build`
We can try:
GOFLAGS="-ldflags='-X=foo=foo -X=bar=bar'"
...but that becomes
[ "go", "build", "-ldflags='-X=foo=foo", "-X=bar=bar'" ]
...which is unfortunate.
Go does some quote handling, but:
GOFLAGS='-ldflags="-X=foo=foo -X=bar=bar"'
...still becomes:
[ "go", "build", "-ldflags=\"-X=foo=foo", "-X=bar=bar\"" ]
...which is surprising.
We can try:
GOFLAGS="-ldflags=-X=foo=foo -ldflags=-X=bar=bar"
...but go just takes the last value of that flag rather than the
accumulation.
What does work is:
GOFLAGS='"-ldflags=-X=foo=foo -X=bar=bar"'
...with the WHOLE flag quoted.
c8413f4 to
68afce7
Compare
Collaborator
Author
|
Found a way to make GOFLAGS work. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ko does not support any way to pass build flags directly. We have to
use GOFLAGS. Go does not fully shell-parse GOFLAGS, it just does simple
whitespace splitting and whole-value quoting.
E.g. this fails for good reason:
GOFLAGS="-ldflags=-X=foo=foo -X=bar=bar"
...becomes:
[ "go", "build", "-ldflags=-X=foo=foo", "-X=bar=bar" ]
...where
-Xis passed togo buildWe can try:
GOFLAGS="-ldflags='-X=foo=foo -X=bar=bar'"
...but that becomes
[ "go", "build", "-ldflags='-X=foo=foo", "-X=bar=bar'" ]
...which is unfortunate.
Go does some quote handling, but:
GOFLAGS='-ldflags="-X=foo=foo -X=bar=bar"'
...still becomes:
[ "go", "build", "-ldflags="-X=foo=foo", "-X=bar=bar"" ]
...which is surprising.
We can try:
GOFLAGS="-ldflags=-X=foo=foo -ldflags=-X=bar=bar"
...but go just takes the last value of that flag rather than the accumulation.
What does work is:
GOFLAGS='"-ldflags=-X=foo=foo -X=bar=bar"'
...with the WHOLE flag quoted.