Disclaimer: Generated most of the body content using LLM / GenAI. Hope it's clear, open to feedback.
TLDR; I would like rules_go to support downloading the Toolchain/SDK from GOPROXY as well. (and ideally even recognize the toolchain directive in the go.mod file.
If this makes sense, I will plan to send a patch.
Problem Statement
Currently, go_register_toolchains fetches Go SDKs from a hardcoded URL template that defaults to go.dev/dl (e.g., https://go.dev/dl/go1.25.0.linux-amd64.tar.gz).
Many organizations prefer to source all build artifacts from an internal, trusted repository (like Artifactory, Nexus, Athens, etc.) that implements the GOPROXY protocol. While rules_go correctly uses GOPROXY for module dependencies, the SDK download mechanism is separate.
This forces users to implement and maintain separate workarounds for the Go SDK itself, such as:
- Mirroring: Hosting all SDK
.tar.gz variants on an internal HTTP server and passing a custom urls list.
- Downloader Configuration: Maintaining a
bazel_downloader.cfg file to intercept and rewrite the hardcoded go.dev/dl URLs.
Both solutions add maintenance overhead and are redundant when a fully capable GOPROXY is already in use for all other Go modules.
Proposed Solution
The native Go command (since 1.21) can now fetch the toolchain as a standard Go module: golang.org/toolchain.
When go get toolchain@go1.25.0 is run, the Go command resolves this to a platform-specific module version (e.g., v0.0.1-go1.25.0.linux-amd64) and fetches it as a .zip file from the configured GOPROXY.
rules_go could adopt this same "toolchain-as-a-module" fetching mechanism. This would allow the SDK to be downloaded using the same GOPROXY logic as all other module dependencies.
Key Benefits
- Reduces Maintenance: Eliminates the need for a
bazel_downloader.cfg or a separate HTTP mirror for Go SDKs.
- Unifies Artifact Source: Allows all Go-related artifacts (modules and the SDK) to be sourced from a single, trusted
GOPROXY.
- Aligns with Go Toolchain: Leverages the modern, standard Go method for toolchain distribution, including proxy and checksum mechanisms.
Potential Implementation
This could be exposed as a new attribute on go_register_toolchains, such as download_method = "goproxy" | "http".
When download_method = "goproxy" is set, the rule would:
- Resolve the
version to the correct golang.org/toolchain module version for the host/target platform.
- Use the existing
GOPROXY logic (respecting GOPROXY, GOSUMDB, etc.) to fetch and unzip this module.
- Use the contents as the Go SDK.
Disclaimer: Generated most of the body content using LLM / GenAI. Hope it's clear, open to feedback.
TLDR; I would like
rules_goto support downloading the Toolchain/SDK fromGOPROXYas well. (and ideally even recognize thetoolchaindirective in thego.modfile.If this makes sense, I will plan to send a patch.
Problem Statement
Currently,
go_register_toolchainsfetches Go SDKs from a hardcoded URL template that defaults togo.dev/dl(e.g.,https://go.dev/dl/go1.25.0.linux-amd64.tar.gz).Many organizations prefer to source all build artifacts from an internal, trusted repository (like Artifactory, Nexus, Athens, etc.) that implements the
GOPROXYprotocol. Whilerules_gocorrectly usesGOPROXYfor module dependencies, the SDK download mechanism is separate.This forces users to implement and maintain separate workarounds for the Go SDK itself, such as:
.tar.gzvariants on an internal HTTP server and passing a customurlslist.bazel_downloader.cfgfile to intercept and rewrite the hardcodedgo.dev/dlURLs.Both solutions add maintenance overhead and are redundant when a fully capable
GOPROXYis already in use for all other Go modules.Proposed Solution
The native Go command (since 1.21) can now fetch the toolchain as a standard Go module:
golang.org/toolchain.When
go get toolchain@go1.25.0is run, the Go command resolves this to a platform-specific module version (e.g.,v0.0.1-go1.25.0.linux-amd64) and fetches it as a.zipfile from the configuredGOPROXY.rules_gocould adopt this same "toolchain-as-a-module" fetching mechanism. This would allow the SDK to be downloaded using the sameGOPROXYlogic as all other module dependencies.Key Benefits
bazel_downloader.cfgor a separate HTTP mirror for Go SDKs.GOPROXY.Potential Implementation
This could be exposed as a new attribute on
go_register_toolchains, such asdownload_method = "goproxy" | "http".When
download_method = "goproxy"is set, the rule would:versionto the correctgolang.org/toolchainmodule version for the host/target platform.GOPROXYlogic (respectingGOPROXY,GOSUMDB, etc.) to fetch and unzip this module.