Skip to content

link: add external deps to Go build info#4595

Open
sluongng wants to merge 2 commits into
bazel-contrib:masterfrom
sluongng:sluongng/buildinfo-deps
Open

link: add external deps to Go build info#4595
sluongng wants to merge 2 commits into
bazel-contrib:masterfrom
sluongng:sluongng/buildinfo-deps

Conversation

@sluongng
Copy link
Copy Markdown
Contributor

@sluongng sluongng commented Apr 20, 2026

The new dep-only modinfo path under-reported external dependencies in debug.ReadBuildInfo().Deps. Commit-pinned and local override repos can expose PackageInfo.package_name without a version, and with the existing Gazelle pin real go_deps repos still did not emit the metadata this path needs. That left rules_go binaries missing dependency entries even when external packages were linked in.

Upgrade Gazelle to 0.47.0 in the main workspace and the BCR test module and refresh MODULE.bazel.lock so go_deps repos emit the package metadata this build-info path relies on. This keeps the dependency metadata fix while avoiding the go.work minimum introduced in Gazelle 0.48.0+, which requires Go 1.24.12 when GOTOOLCHAIN=local.

Thread external module metadata from analysis into the archive and link actions and emit dep-only modinfo for supported build modes. Keep PackageInfo entries that have a package_name but an empty package_version, normalize that case to (devel), and continue adding a leading v for tagged versions. Read metadata from both package_metadata and applicable_licenses, wire in rules_license for PackageInfo lookup, and extend the builder, starlark, go_bazel_test, reproducibility coverage, and stardoc wiring, including a versionless dependency case and explicit doc-generation deps for the core and extras docs targets. Keep the builder/linker path compatible with Go 1.17.x by emitting dep-only modinfo directly and only passing modinfo to SDKs whose linkers understand that directive.

This matches the Go toolchain's build-info behavior. In cmd/go/internal/load/pkg.go, debugModFromModinfo records missing versions as (devel) instead of dropping the module. In runtime/debug/mod.go, ParseBuildInfo accepts module records with either two or three columns, so dep-only records do not require a non-empty version.

@sluongng sluongng force-pushed the sluongng/buildinfo-deps branch 2 times, most recently from 428b15a to f611d80 Compare April 20, 2026 08:59
The dep-only buildinfo work depends on go_deps repos exposing
Gazelle-generated package metadata. With the existing 0.36.0 pin,
real go_deps workspaces still produced binaries with empty
runtime/debug.ReadBuildInfo().Deps because that metadata was never
emitted.

Upgrade the main workspace and the BCR test module to Gazelle 0.47.0
and refresh MODULE.bazel.lock so the metadata is available in the
supported Bzlmod + go.mod flow. Stay below Gazelle 0.48.0 because its
go.work file requires Go 1.24.12, while rules_go CI still runs Go
1.24.0 with GOTOOLCHAIN=local on Linux.
@sluongng sluongng force-pushed the sluongng/buildinfo-deps branch 3 times, most recently from 69a4604 to 564d659 Compare April 20, 2026 09:46
The new dep-only modinfo path under-reported external dependencies in
debug.ReadBuildInfo().Deps because commit-pinned and local override
repos had PackageInfo.package_name but an empty package_version, so
rules_go dropped them before link time even though their packages
contributed to the binary.

Populate runtime/debug.ReadBuildInfo().Deps for rules_go binaries by
threading external module metadata from analysis into archive and link
actions and emitting dep-only modinfo for supported build modes.

Match cmd/go's build-info behavior here. In go1.26.2, (1) shows
debugModFromModinfo recording missing versions as "(devel)" instead of
omitting them, and (2) shows the modinfo parser accepting module
records without requiring a non-empty version.

Keep PackageInfo entries that have a package_name but an empty
package_version, normalize that case to "(devel)", and keep adding a
leading "v" for tagged versions.

Bazel can surface repo metadata through either package_metadata or
applicable_licenses depending on the rule surface, so read both
spellings and wire in rules_license for PackageInfo lookup. Extend the
builder, starlark, go_bazel_test, and reproducibility coverage,
including a versionless dependency case.

The new rules_license load also changes the Starlark dependency graph
seen by stardoc, so patch rules_license to export the loaded .bzl
files to the docs extractor and add explicit doc-generation deps for
the core and extras docs targets. That keeps CI doc extraction working
after the new metadata lookup is wired in.

(1) https://go.dev/src/cmd/go/internal/load/pkg.go#L2335-L2348
(2) https://go.dev/src/runtime/debug/mod.go#L177-L190
@sluongng sluongng force-pushed the sluongng/buildinfo-deps branch from 564d659 to 01e1e77 Compare April 20, 2026 14:24
@sluongng sluongng marked this pull request as ready for review April 20, 2026 14:30
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 this pull request may close these issues.

1 participant