Skip to content

Commit

Permalink
Add exec_compatible_with to @go_sdk//:builder
Browse files Browse the repository at this point in the history
go_tool_binary() is completely oblivious of toolchains. The reason being
that Go toolchains actually depend on their output. Adding a toolchain
dependency would thus add a cyclic dependency. This is problematic,
because it means that the actions with mnemonic GoToolchainBinaryBuild
end up getting scheduled on arbitrary workers.

Address this by adding exec_compatible_with to the locations where
go_tool_binary() is instantiated, namely the auto-generated BUILD files
that are part of Go SDKs.

Fixes: bazelbuild#3942
  • Loading branch information
EdSchouten committed May 15, 2024
1 parent a54fd56 commit 0722bce
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions go/private/BUILD.sdk.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ go_tool_binary(
srcs = ["@io_bazel_rules_go//go/tools/builders:builder_srcs"],
ldflags = "-X main.rulesGoStdlibPrefix={}".format(RULES_GO_STDLIB_PREFIX),
sdk = ":go_sdk",
exec_compatible_with = {exec_compatible_with},
)

non_go_reset_target(
Expand Down
5 changes: 5 additions & 0 deletions go/private/sdk.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "patch", "read_user_netrc", "use_netrc")
load("//go/private:common.bzl", "executable_path")
load("//go/private:nogo.bzl", "go_register_nogo")
load("//go/private:platforms.bzl", "GOARCH_CONSTRAINTS", "GOOS_CONSTRAINTS")
load("//go/private/skylib/lib:versions.bzl", "versions")

MIN_SUPPORTED_VERSION = (1, 14, 0)
Expand Down Expand Up @@ -515,6 +516,10 @@ def _sdk_build_file(ctx, platform, version, experiments):
"{exe}": ".exe" if goos == "windows" else "",
"{version}": version,
"{experiments}": repr(experiments),
"{exec_compatible_with}": repr([
GOARCH_CONSTRAINTS[goarch],
GOOS_CONSTRAINTS[goos],
]),
},
)

Expand Down

0 comments on commit 0722bce

Please sign in to comment.