link: add external deps to Go build info#4595
Open
sluongng wants to merge 2 commits into
Open
Conversation
428b15a to
f611d80
Compare
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.
69a4604 to
564d659
Compare
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
564d659 to
01e1e77
Compare
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.
The new dep-only modinfo path under-reported external dependencies in
debug.ReadBuildInfo().Deps. Commit-pinned and local override repos can exposePackageInfo.package_namewithout a version, and with the existing Gazelle pin realgo_depsrepos 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.0in the main workspace and the BCR test module and refreshMODULE.bazel.locksogo_depsrepos emit the package metadata this build-info path relies on. This keeps the dependency metadata fix while avoiding thego.workminimum introduced in Gazelle0.48.0+, which requires Go1.24.12whenGOTOOLCHAIN=local.Thread external module metadata from analysis into the archive and link actions and emit dep-only modinfo for supported build modes. Keep
PackageInfoentries that have apackage_namebut an emptypackage_version, normalize that case to(devel), and continue adding a leadingvfor tagged versions. Read metadata from bothpackage_metadataandapplicable_licenses, wire inrules_licenseforPackageInfolookup, 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 passingmodinfoto SDKs whose linkers understand that directive.This matches the Go toolchain's build-info behavior. In
cmd/go/internal/load/pkg.go,debugModFromModinforecords missing versions as(devel)instead of dropping the module. Inruntime/debug/mod.go,ParseBuildInfoaccepts module records with either two or three columns, so dep-only records do not require a non-empty version.