blob: 25b3adbc70f93b22c65e6a45aaf8b6041c6866f1 [file] [log] [blame]
Philipp Schradercc016b32021-12-30 08:59:58 -08001load("@bazel_skylib//rules:write_file.bzl", "write_file")
2load("@io_bazel_rules_go//go:def.bzl", "go_sdk", "go_toolchain")
3
Philipp Schrader37fdbb62021-12-18 00:30:37 -08004py_library(
5 name = "mirror_lib",
6 srcs = [
7 "mirror_lib.py",
8 ],
9)
10
11py_binary(
12 name = "tweak_gazelle_go_deps",
13 srcs = [
14 "tweak_gazelle_go_deps.py",
15 ],
16 visibility = ["//visibility:public"],
17 deps = [
18 ":mirror_lib",
19 ],
20)
21
22py_binary(
23 name = "mirror_go_repos",
24 srcs = [
25 "mirror_go_repos.py",
26 ],
27 data = [
Philipp Schradercc016b32021-12-30 08:59:58 -080028 "@com_github_bazelbuild_buildtools//buildifier",
Philipp Schrader37fdbb62021-12-18 00:30:37 -080029 "@go_sdk//:bin/go",
30 ],
Philipp Schradercc016b32021-12-30 08:59:58 -080031 target_compatible_with = ["@platforms//cpu:x86_64"],
Philipp Schrader37fdbb62021-12-18 00:30:37 -080032 deps = [
33 ":mirror_lib",
Philipp Schradercc016b32021-12-30 08:59:58 -080034 "@bazel_tools//tools/python/runfiles",
Philipp Schrader37fdbb62021-12-18 00:30:37 -080035 ],
36)
37
38# The remainder of this file exists to create a NOOP toolchain for Go on
39# platforms that don't support Go. We can probably get rid of this once
Philipp Schrader73e56602021-12-06 21:37:30 -080040# https://github.com/bazelbuild/bazel/issues/12897 is fixed.
41#
42# For platforms that do support Go, we use go_register_toolchain() in
43# WORKSPACE.
44
Philipp Schrader73e56602021-12-06 21:37:30 -080045write_file(
46 name = "noop_error_exit",
47 out = "noop_error_exit.sh",
48 content = [
49 "#!/bin/bash",
50 "echo 'This should never be executed. Something went wrong.' >&2",
51 "echo 'This NOOP Go toolchain should never be executed. Something went wrong.' >&2",
52 "echo 'Check that your target has `target_compatible_with` set to a platform that supports Go.' >&2",
53 "exit 1",
54 ],
55 is_executable = True,
56)
57
58go_sdk(
59 name = "noop_sdk",
60 go = ":noop_error_exit",
61 goarch = "none",
62 goos = "none",
63 root_file = "NOOP_FILE_THAT_DOES_NOT_EXIST",
64)
65
66go_toolchain(
67 name = "noop_go_toolchain_impl",
68 builder = ":noop_error_exit",
69 cgo_link_flags = None,
70 goarch = "none",
71 goos = "none",
72 link_flags = None,
73 sdk = ":noop_sdk",
74 tags = ["manual"],
75)
76
77toolchain(
78 name = "noop_go_toolchain",
79 exec_compatible_with = [
80 "@platforms//os:linux",
81 ],
82 target_compatible_with = [
83 "//tools/platforms/go:lacks_support",
84 ],
85 toolchain = ":noop_go_toolchain_impl",
86 toolchain_type = "@io_bazel_rules_go//go:toolchain",
87)