blob: 2c251a06cd7da8592709a293898e65d171f4fc68 [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 ],
Philipp Schraderd96d4cb2022-02-06 15:37:29 -08009 data = [
10 "@com_github_bazelbuild_buildtools//buildifier",
11 ],
12 target_compatible_with = ["@platforms//cpu:x86_64"],
13 deps = [
14 "@bazel_tools//tools/python/runfiles",
15 ],
Philipp Schrader37fdbb62021-12-18 00:30:37 -080016)
17
18py_binary(
19 name = "tweak_gazelle_go_deps",
20 srcs = [
21 "tweak_gazelle_go_deps.py",
22 ],
23 visibility = ["//visibility:public"],
24 deps = [
25 ":mirror_lib",
26 ],
27)
28
29py_binary(
30 name = "mirror_go_repos",
31 srcs = [
32 "mirror_go_repos.py",
33 ],
34 data = [
35 "@go_sdk//:bin/go",
36 ],
Philipp Schradercc016b32021-12-30 08:59:58 -080037 target_compatible_with = ["@platforms//cpu:x86_64"],
Philipp Schraderd96d4cb2022-02-06 15:37:29 -080038 visibility = ["//visibility:public"],
Philipp Schrader37fdbb62021-12-18 00:30:37 -080039 deps = [
40 ":mirror_lib",
41 ],
42)
43
44# The remainder of this file exists to create a NOOP toolchain for Go on
45# platforms that don't support Go. We can probably get rid of this once
Philipp Schrader73e56602021-12-06 21:37:30 -080046# https://github.com/bazelbuild/bazel/issues/12897 is fixed.
47#
48# For platforms that do support Go, we use go_register_toolchain() in
49# WORKSPACE.
50
Philipp Schrader73e56602021-12-06 21:37:30 -080051write_file(
52 name = "noop_error_exit",
53 out = "noop_error_exit.sh",
54 content = [
55 "#!/bin/bash",
56 "echo 'This should never be executed. Something went wrong.' >&2",
57 "echo 'This NOOP Go toolchain should never be executed. Something went wrong.' >&2",
58 "echo 'Check that your target has `target_compatible_with` set to a platform that supports Go.' >&2",
59 "exit 1",
60 ],
61 is_executable = True,
62)
63
64go_sdk(
65 name = "noop_sdk",
66 go = ":noop_error_exit",
67 goarch = "none",
68 goos = "none",
69 root_file = "NOOP_FILE_THAT_DOES_NOT_EXIST",
70)
71
72go_toolchain(
73 name = "noop_go_toolchain_impl",
74 builder = ":noop_error_exit",
75 cgo_link_flags = None,
76 goarch = "none",
77 goos = "none",
78 link_flags = None,
79 sdk = ":noop_sdk",
80 tags = ["manual"],
81)
82
83toolchain(
84 name = "noop_go_toolchain",
85 exec_compatible_with = [
86 "@platforms//os:linux",
87 ],
88 target_compatible_with = [
89 "//tools/platforms/go:lacks_support",
90 ],
91 toolchain = ":noop_go_toolchain_impl",
92 toolchain_type = "@io_bazel_rules_go//go:toolchain",
93)