Fix make with LDFLAGS#162
Conversation
|
How does this behave with the install scripts, which do not use the makefile at all AFAIK? |
|
Do we really need ldflags? Why not just use the Go-buil- in version stamping? Kubernetes uses ldflags because this functionality didn't exist. |
|
There's no way I can see to set a version string in Go's build info? |
|
Go automatically grabs the version from git |
|
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
|
Found a way to make GOFLAGS work. |
True, but that's in ~ |
Where does that value come from? There are no docs I can find on it? |
It's the module version, for the main module in the binary, which indirectly comes from vcs. I want to avoid having a complex bash build system again, and go gives us reasonable metadata built in. |
I tried adding a tag and got nothing. Go's docs here are awful. |
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.