Philipp Schrader | cc016b3 | 2021-12-30 08:59:58 -0800 | [diff] [blame] | 1 | load("@bazel_skylib//rules:write_file.bzl", "write_file") |
| 2 | load("@io_bazel_rules_go//go:def.bzl", "go_sdk", "go_toolchain") |
| 3 | |
Philipp Schrader | 37fdbb6 | 2021-12-18 00:30:37 -0800 | [diff] [blame] | 4 | py_library( |
| 5 | name = "mirror_lib", |
| 6 | srcs = [ |
| 7 | "mirror_lib.py", |
| 8 | ], |
Philipp Schrader | d96d4cb | 2022-02-06 15:37:29 -0800 | [diff] [blame] | 9 | 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 Schrader | 37fdbb6 | 2021-12-18 00:30:37 -0800 | [diff] [blame] | 16 | ) |
| 17 | |
| 18 | py_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 | |
| 29 | py_binary( |
| 30 | name = "mirror_go_repos", |
| 31 | srcs = [ |
| 32 | "mirror_go_repos.py", |
| 33 | ], |
| 34 | data = [ |
| 35 | "@go_sdk//:bin/go", |
| 36 | ], |
Philipp Schrader | cc016b3 | 2021-12-30 08:59:58 -0800 | [diff] [blame] | 37 | target_compatible_with = ["@platforms//cpu:x86_64"], |
Philipp Schrader | d96d4cb | 2022-02-06 15:37:29 -0800 | [diff] [blame] | 38 | visibility = ["//visibility:public"], |
Philipp Schrader | 37fdbb6 | 2021-12-18 00:30:37 -0800 | [diff] [blame] | 39 | 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 Schrader | 73e5660 | 2021-12-06 21:37:30 -0800 | [diff] [blame] | 46 | # 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 Schrader | 73e5660 | 2021-12-06 21:37:30 -0800 | [diff] [blame] | 51 | write_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 | |
| 64 | go_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 | |
| 72 | go_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 | |
| 83 | toolchain( |
| 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 | ) |