Skip to content

Commit

Permalink
Use same Go SDK as Gazelle for go_bazel_test
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Jan 15, 2025
1 parent 141d912 commit a0a37ce
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ go_sdk.download(
)
use_repo(
go_sdk,
"go_host_compatible_sdk_label",
"go_toolchains",
# This name is ugly on purpose to avoid a conflict with a user-named SDK.
"io_bazel_rules_nogo",
go_sdk = "go_default_sdk",
)

register_toolchains("@go_toolchains//:all")
Expand Down
11 changes: 11 additions & 0 deletions go/private/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,11 @@ def go_rules_dependencies(force = False):
name = "io_bazel_rules_go_bazel_features",
)

_maybe(
_go_host_compatible_sdk_label,
name = "go_host_compatible_sdk_label",
)

wrapper(
http_archive,
name = "rules_shell",
Expand All @@ -327,6 +332,12 @@ def go_rules_dependencies(force = False):
url = "https://github.com/bazelbuild/rules_shell/releases/download/v0.3.0/rules_shell-v0.3.0.tar.gz",
)

def _go_host_compatible_sdk_label_impl(ctx):
ctx.file("BUILD.bazel")
ctx.file("defs.bzl", """HOST_COMPATIBLE_SDK = Label("@go_sdk//:ROOT")""")

_go_host_compatible_sdk_label = repository_rule(_go_host_compatible_sdk_label_impl)

def _maybe(repo_rule, name, **kwargs):
if name not in native.existing_rules():
repo_rule(name = name, **kwargs)
Expand Down
11 changes: 8 additions & 3 deletions go/tools/bazel_testing/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@go_host_compatible_sdk_label//:defs.bzl", "HOST_COMPATIBLE_SDK")
load("//go:def.bzl", "go_library")

_HOST_COMPATIBLE_SDK_ROOT = HOST_COMPATIBLE_SDK.same_package_label("ROOT")

_HOST_COMPATIBLE_SDK_FILES = HOST_COMPATIBLE_SDK.same_package_label("files")

go_library(
name = "bazel_testing",
srcs = ["bazel_testing.go"],
data = [
"@go_sdk//:ROOT",
"@go_sdk//:files",
_HOST_COMPATIBLE_SDK_FILES,
_HOST_COMPATIBLE_SDK_ROOT,
],
importpath = "github.com/bazelbuild/rules_go/go/tools/bazel_testing",
visibility = ["//visibility:public"],
x_defs = {
"goRootFile": "$(rlocationpath @go_sdk//:ROOT)",
"goRootFile": "$(rlocationpath {})".format(_HOST_COMPATIBLE_SDK_ROOT),
},
deps = [
"//go/runfiles",
Expand Down

0 comments on commit a0a37ce

Please sign in to comment.