Skip to content

Commit

Permalink
Copy private go_bin_for_host rule from rules_go to /bazel/ci
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Weiße <[email protected]>
  • Loading branch information
daniel-weisse committed Dec 10, 2024
1 parent 92e5c17 commit 3168e78
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bazel/ci/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
load("@buildifier_prebuilt//:rules.bzl", "buildifier", "buildifier_test")
load("@com_github_ash2k_bazel_tools//multirun:def.bzl", "multirun")
load("@gazelle//:def.bzl", "gazelle")
load("@io_bazel_rules_go//go/private/rules:go_bin_for_host.bzl", "go_bin_for_host")
load("//bazel/ci:go_bin_for_host.bzl", "go_bin_for_host")
load("//bazel/ci:proto_targets.bzl", "proto_targets")
load("//bazel/sh:def.bzl", "noop_warn", "repo_command", "sh_template")

Expand Down
26 changes: 26 additions & 0 deletions bazel/ci/go_bin_for_host.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Go toolchain for the host platform
# Inspired by https://github.com/bazel-contrib/rules_go/blob/6e4fdcfeb1a333b54ab39ae3413d4ded46d8958d/go/private/rules/go_bin_for_host.bzl
load("@local_config_platform//:constraints.bzl", "HOST_CONSTRAINTS")

GO_TOOLCHAIN = "@io_bazel_rules_go//go:toolchain"

def _ensure_target_cfg(ctx):
if "-exec" in ctx.bin_dir.path or "/host/" in ctx.bin_dir.path:
fail("exec not found")

def _go_bin_for_host_impl(ctx):
_ensure_target_cfg(ctx)
sdk = ctx.toolchains[GO_TOOLCHAIN].sdk
sdk_files = ctx.runfiles([sdk.go] + sdk.headers + sdk.libs + sdk.srcs + sdk.tools)
return [
DefaultInfo(
files = depset([sdk.go]),
runfiles = sdk_files,
),
]

go_bin_for_host = rule(
implementation = _go_bin_for_host_impl,
toolchains = [GO_TOOLCHAIN],
exec_compatible_with = HOST_CONSTRAINTS,
)

0 comments on commit 3168e78

Please sign in to comment.