Skip to content

go_sdk: store SDK filenames and hashes in lockfile facts#4393

Merged
fmeum merged 1 commit intomasterfrom
facts
Jul 8, 2025
Merged

go_sdk: store SDK filenames and hashes in lockfile facts#4393
fmeum merged 1 commit intomasterfrom
facts

Conversation

@fmeum
Copy link
Member

@fmeum fmeum commented Jul 8, 2025

What type of PR is this?

Feature

What does this PR do? Why is it needed?

This moves the download of the "all versions" JSON, which can't hit the repository cache, from each individual go_download_sdk into the module extension. If the current version of Bazel supports facts, this information will also be persisted in the lockfile, allowing for truly airgapped builds assuming an up-to-date download (formerly repository) cache.

See bazelbuild/bazel#26198 for the PR that adds facts support to Bazel.

Which issues(s) does this PR fix?

Fixes #3945

Other notes for review

This moves the download of the "all versions" JSON, which can't hit the repository cache, from each individual `go_download_sdk` into the module extension. If the current version of Bazel supports facts, this information will also be persisted in the lockfile, allowing for truly airgapped builds assuming an up-to-date download (formerly repository) cache.
@fmeum fmeum changed the title go_sdk: Store SDK filenames and hashes in lockfile facts go_sdk: store SDK filenames and hashes in lockfile facts Jul 8, 2025
@fmeum fmeum requested a review from linzhp July 8, 2025 15:00
@fmeum fmeum assigned jayconrod and unassigned jayconrod Jul 8, 2025
@fmeum fmeum requested review from jayconrod and tyler-french July 8, 2025 15:00
@fmeum fmeum merged commit fab7a74 into master Jul 8, 2025
4 checks passed
@fmeum fmeum deleted the facts branch July 8, 2025 18:12
Comment on lines +373 to +379
# See _download_sdk below for details on these facts.
if hasattr(ctx, "facts"):
kwargs["facts"] = {
version: sdk_info
for version, sdk_info in sdks_by_version.items()
if version in used_versions
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this example, LGTM.

fmeum added a commit that referenced this pull request Aug 25, 2025
fmeum added a commit that referenced this pull request Aug 25, 2025
)

Reverts #4393

The facts feature didn't get merged in time for Bazel 8.4.0 and without
it this PR caused an eager fetch of the version list for the default
SDK.
avdv added a commit to avdv/replay that referenced this pull request Sep 8, 2025
Newer versions changed the way version information for go SDKs is fetched, see [4393].

It was reverted, but hasn't been released as of now.

[4393]: bazel-contrib/rules_go#4393
avdv added a commit to avdv/replay that referenced this pull request Sep 9, 2025
Newer versions changed the way version information for go SDKs is fetched, see [4393].

It was reverted, but hasn't been released as of now.

[4393]: bazel-contrib/rules_go#4393
avdv added a commit to avdv/replay that referenced this pull request Sep 9, 2025
Newer versions changed the way version information for go SDKs is fetched, see [4393].

It was reverted, but hasn't been released as of now.

[4393]: bazel-contrib/rules_go#4393
copybara-service bot pushed a commit to bazelbuild/bazel that referenced this pull request Oct 15, 2025
RELNOTES[NEW]: Module extensions can store a JSON-like Starlark object in `module_ctx.extension_metadata(facts = ...)` and retrieve it back in future evaluations of the extension via `module_ctx.facts` without any invalidation taking place.

See bazel-contrib/rules_go#4393 for a real-world application of this new feature.

Fixes #24777

Closes #26198.

PiperOrigin-RevId: 819640644
Change-Id: I281503c9d4d0e60f46b57e9a231c3d2a4658d486
fmeum added a commit to fmeum/bazel that referenced this pull request Oct 16, 2025
RELNOTES[NEW]: Module extensions can store a JSON-like Starlark object in `module_ctx.extension_metadata(facts = ...)` and retrieve it back in future evaluations of the extension via `module_ctx.facts` without any invalidation taking place.

See bazel-contrib/rules_go#4393 for a real-world application of this new feature.

Fixes bazelbuild#24777

Closes bazelbuild#26198.

PiperOrigin-RevId: 819640644
Change-Id: I281503c9d4d0e60f46b57e9a231c3d2a4658d486
(cherry picked from commit 330dc9f)
fmeum added a commit to fmeum/bazel that referenced this pull request Oct 16, 2025
RELNOTES[NEW]: Module extensions can store a JSON-like Starlark object in `module_ctx.extension_metadata(facts = ...)` and retrieve it back in future evaluations of the extension via `module_ctx.facts` without any invalidation taking place.

See bazel-contrib/rules_go#4393 for a real-world application of this new feature.

Fixes bazelbuild#24777

Closes bazelbuild#26198.

PiperOrigin-RevId: 819640644
Change-Id: I281503c9d4d0e60f46b57e9a231c3d2a4658d486
(cherry picked from commit 330dc9f)
github-merge-queue bot pushed a commit to bazelbuild/bazel that referenced this pull request Oct 16, 2025
)

RELNOTES[NEW]: Module extensions can store a JSON-like Starlark object
in `module_ctx.extension_metadata(facts = ...)` and retrieve it back in
future evaluations of the extension via `module_ctx.facts` without any
invalidation taking place.

See bazel-contrib/rules_go#4393 for a real-world
application of this new feature.

Fixes #24777

Closes #26198.

PiperOrigin-RevId: 819640644
Change-Id: I281503c9d4d0e60f46b57e9a231c3d2a4658d486 
(cherry picked from commit 330dc9f)
meteorcloudy pushed a commit to bazelbuild/bazel that referenced this pull request Oct 16, 2025
)

RELNOTES[NEW]: Module extensions can store a JSON-like Starlark object
in `module_ctx.extension_metadata(facts = ...)` and retrieve it back in
future evaluations of the extension via `module_ctx.facts` without any
invalidation taking place.

See bazel-contrib/rules_go#4393 for a real-world
application of this new feature.

Fixes #24777

Closes #26198.

PiperOrigin-RevId: 819640644
Change-Id: I281503c9d4d0e60f46b57e9a231c3d2a4658d486 
(cherry picked from commit 330dc9f)
fmeum added a commit to fmeum/bazel that referenced this pull request Oct 18, 2025
RELNOTES[NEW]: Module extensions can store a JSON-like Starlark object in `module_ctx.extension_metadata(facts = ...)` and retrieve it back in future evaluations of the extension via `module_ctx.facts` without any invalidation taking place.

See bazel-contrib/rules_go#4393 for a real-world application of this new feature.

Fixes bazelbuild#24777

Closes bazelbuild#26198.

PiperOrigin-RevId: 819640644
Change-Id: I281503c9d4d0e60f46b57e9a231c3d2a4658d486
fmeum added a commit that referenced this pull request Nov 3, 2025
)

**What type of PR is this?**

Feature

**What does this PR do? Why is it needed?**

This moves the download of the "all versions" JSON, which can't hit the
repository cache, from each individual `go_download_sdk` into the module
extension. If the current version of Bazel supports facts, this
information will also be persisted in the lockfile, allowing for truly
airgapped builds assuming an up-to-date download (formerly repository)
cache.

This is a reland of #4393 with the following improvements:
* Adapted to the more limited facts API that actually got merged.
* Prefetching of SDK hashes is now performed on a best-effort basis so
that otherwise airgapped builds that provide SDK hashes do not result in
failures.

See bazelbuild/bazel#26198 for the PR that added
facts support to Bazel.

**Which issues(s) does this PR fix?**

Fixes #3945 

**Other notes for review**

You can verify that this works by running `bazel mod show_repo
@go_default_sdk` in the BCR test repo.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants