Skip to content

feat(sdk): allow per-platform strip_prefix via strip_prefixes#4622

Draft
albertocavalcante wants to merge 1 commit into
bazel-contrib:masterfrom
albertocavalcante:feat/sdk-strip-prefixes-goproxy
Draft

feat(sdk): allow per-platform strip_prefix via strip_prefixes#4622
albertocavalcante wants to merge 1 commit into
bazel-contrib:masterfrom
albertocavalcante:feat/sdk-strip-prefixes-goproxy

Conversation

@albertocavalcante
Copy link
Copy Markdown
Contributor

@albertocavalcante albertocavalcante commented Jun 2, 2026

What type of PR is this?

Feature

What does this PR do? Why is it needed?

rules_go currently can't fetch the Go SDK from a GOPROXY-style mirror because the golang.org/toolchain module layout has a different top-level directory per platform (golang.org/toolchain@v0.0.1-go1.22.5.linux-amd64, ...darwin-arm64, etc.), and a single strip_prefix can't express that.

So this adds a strip_prefixes attr (per-platform dict) on go_download_sdk and the go_sdk.download bzlmod tag. When set, it wins over strip_prefix. Otherwise nothing changes.

go_sdk.download(
    urls = ["https://<mirror>/golang.org/toolchain/@v/{}"],
    sdks = {...},
    strip_prefixes = {...},
    version = "1.22.5",
)

Which issues(s) does this PR fix?

Closes #4516

Other notes for review

There's an end-to-end test in tests/core/go_download_sdk/go_download_sdk_test.go that pulls Go 1.22.5 from the public proxy.golang.org, so the new path actually runs on CI.

Kept the scope to just the attribute. Auto-deriving urls / sdks / strip_prefixes from a goproxy = arg can be a separate PR if there's appetite for it.

The bzlmod tag was only smoke-tested locally with bazel mod deps. The automated test covers WORKSPACE-mode go_download_sdk, same rule underneath. Let me know if a BCR test for the tag would help.

The Go command (since 1.21) can fetch the toolchain as a standard Go
module named golang.org/toolchain, served by any GOPROXY-style mirror
(proxy.golang.org, Artifactory, Athens, Nexus, etc.). Unlike the
go.dev/dl layout, the per-platform archives each have a distinct
top-level directory of the form

  golang.org/toolchain@v0.0.1-go{V}.{os}-{arch}

so a single strip_prefix string is not expressive enough to cover all
platforms in one go_download_sdk (or go_sdk.download) call.

Add a strip_prefixes attribute (string_dict, keyed by "<goos>_<goarch>")
that, when non-empty, takes precedence over strip_prefix. The existing
strip_prefix attribute and its default of "go" are unchanged, so every
existing rule_go consumer is unaffected.

Refs bazel-contrib#4516. This patch covers the minimum needed to serve the SDK
from any GOPROXY-style mirror today; the convenience wrapper that
auto-derives urls/sdks/strip_prefixes from a goproxy URL prefix is
deferred to a follow-up.
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.

[feat] Support GOPROXY for Go SDK/toolchain downloads (via golang.org/toolchain module)

1 participant