bazelbuild / rules_go

Go rules for Bazel
Apache License 2.0
1.36k stars 635 forks source link

Access debug.BuildInfo for Go Binaries #3904

Closed hjkatz closed 3 months ago

hjkatz commented 3 months ago

What version of rules_go are you using?

0.46.0

What version of gazelle are you using?

0.35.0

What version of Bazel are you using?

7.1.0

Does this issue reproduce with the latest releases of all the above?

Yes

What operating system and processor architecture are you using?

linux, ubuntu, nix

Any other potentially useful information about your toolchain?

What did you do?

I used bazel to install our go binary, like so:

go_binary(
    name = "nd",
    embed = [":nd_lib"],
    visibility = ["//visibility:public"],
    // gc_linkopts = ["-buildvcs=true"], [Not committed yet]
)

I tried a few options but could not figure out how to do the following:

$ go build -buildvcs=true cmd/go/nd

What did you expect to see?

I want to include vcs info at buildtime, see blog: https://shibumi.dev/posts/go-18-feature/

What did you see instead?

No build info included

malt3 commented 3 months ago

I think this is a duplicate of https://github.com/bazelbuild/rules_go/issues/3090. As mentioned in the issue, you can use stamping to achieve similar results today: https://github.com/bazelbuild/rules_go/blob/master/docs/go/core/defines_and_stamping.md#stamping-with-the-workspace-status-script

hjkatz commented 3 months ago

@malt3 Yes this is a duplicate. Thanks for pointing us in the right direction.