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

how to get the dependencies and their versions for go executables built with bazel #4159

Open
blumamir opened this issue Oct 27, 2024 · 0 comments

Comments

@blumamir
Copy link

blumamir commented Oct 27, 2024

Hi,

Me and https://github.com/RonFed are working on OpenTelemetry auto instrumentation module. This issue is regarding the one here

In order to correctly instrument a go binary, we need to extract the dependencies and their versions from the executable file.

We use the debug/buildinfo from the standard library, doing something similar to this:

import  (
  "debug/buildinfo"
)

	f, err := os.Open("/path/to/go/executable")
	if err != nil {
		fmt.Println("Error:", err)
		return
	}
	defer f.Close()

	bi, err := buildinfo.Read(f)
	if err != nil {
		fmt.Println("Error:", err)
		return
	}

	fmt.Println("deps:")
	fmt.Println(bi.Deps)

When running this inspection on a binary built with go build and go.mod, we are able to see the deps in the executable. However, when inspecting an executable built with bazel, the deps are not there.

Example sections from our build configuration:

BUILD.bazel

go_library(
    name = "rolldice_lib",
    srcs = [
        "main.go",
        "rolldice.go",
    ],
    importpath = "github.com/tendermint/tendermint/rolldice",
    visibility = ["//visibility:private"],
    deps = [
        "@com_github_gin_gonic_gin//:go_default_library"
    ],
)

deps.bzl

...
    go_repository(
        name = "com_github_gin_gonic_gin",
        build_file_proto_mode = "disable_global",
        importpath = "github.com/gin-gonic/gin",
        sum = "h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=",
        version = "v1.10.0",
    )
...

How can we get this info from a binary built with bazel? Any help will be appreciated

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

No branches or pull requests

1 participant