blob: ec8aa26a36cc792e896831300bf970d986c9d719 [file] [log] [blame]
Philipp Schrader73e56602021-12-06 21:37:30 -08001# This file exists to create a NOOP toolchain for Go on platforms that don't
2# support Go. We can probably get rid of this once
3# https://github.com/bazelbuild/bazel/issues/12897 is fixed.
4#
5# For platforms that do support Go, we use go_register_toolchain() in
6# WORKSPACE.
7
8load("@bazel_skylib//rules:write_file.bzl", "write_file")
9load("@io_bazel_rules_go//go:def.bzl", "go_sdk", "go_toolchain")
10
11write_file(
12 name = "noop_error_exit",
13 out = "noop_error_exit.sh",
14 content = [
15 "#!/bin/bash",
16 "echo 'This should never be executed. Something went wrong.' >&2",
17 "echo 'This NOOP Go toolchain should never be executed. Something went wrong.' >&2",
18 "echo 'Check that your target has `target_compatible_with` set to a platform that supports Go.' >&2",
19 "exit 1",
20 ],
21 is_executable = True,
22)
23
24go_sdk(
25 name = "noop_sdk",
26 go = ":noop_error_exit",
27 goarch = "none",
28 goos = "none",
29 root_file = "NOOP_FILE_THAT_DOES_NOT_EXIST",
30)
31
32go_toolchain(
33 name = "noop_go_toolchain_impl",
34 builder = ":noop_error_exit",
35 cgo_link_flags = None,
36 goarch = "none",
37 goos = "none",
38 link_flags = None,
39 sdk = ":noop_sdk",
40 tags = ["manual"],
41)
42
43toolchain(
44 name = "noop_go_toolchain",
45 exec_compatible_with = [
46 "@platforms//os:linux",
47 ],
48 target_compatible_with = [
49 "//tools/platforms/go:lacks_support",
50 ],
51 toolchain = ":noop_go_toolchain_impl",
52 toolchain_type = "@io_bazel_rules_go//go:toolchain",
53)