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 | ], |
| 9 | ) |
| 10 | |
| 11 | py_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 | |
| 22 | py_binary( |
| 23 | name = "mirror_go_repos", |
| 24 | srcs = [ |
| 25 | "mirror_go_repos.py", |
| 26 | ], |
| 27 | data = [ |
Philipp Schrader | cc016b3 | 2021-12-30 08:59:58 -0800 | [diff] [blame^] | 28 | "@com_github_bazelbuild_buildtools//buildifier", |
Philipp Schrader | 37fdbb6 | 2021-12-18 00:30:37 -0800 | [diff] [blame] | 29 | "@go_sdk//:bin/go", |
| 30 | ], |
Philipp Schrader | cc016b3 | 2021-12-30 08:59:58 -0800 | [diff] [blame^] | 31 | target_compatible_with = ["@platforms//cpu:x86_64"], |
Philipp Schrader | 37fdbb6 | 2021-12-18 00:30:37 -0800 | [diff] [blame] | 32 | deps = [ |
| 33 | ":mirror_lib", |
Philipp Schrader | cc016b3 | 2021-12-30 08:59:58 -0800 | [diff] [blame^] | 34 | "@bazel_tools//tools/python/runfiles", |
Philipp Schrader | 37fdbb6 | 2021-12-18 00:30:37 -0800 | [diff] [blame] | 35 | ], |
| 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 Schrader | 73e5660 | 2021-12-06 21:37:30 -0800 | [diff] [blame] | 40 | # 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 Schrader | 73e5660 | 2021-12-06 21:37:30 -0800 | [diff] [blame] | 45 | write_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 | |
| 58 | go_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 | |
| 66 | go_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 | |
| 77 | toolchain( |
| 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 | ) |