| Tim Windelschmidt | 156248b | 2025-01-10 00:27:45 +0100 | [diff] [blame] | 1 | def _build_pure_transition_impl(settings, _attr): |
| Serge Bazanski | c3ae758 | 2020-06-08 17:15:26 +0200 | [diff] [blame] | 2 | """ |
| 3 | Transition that enables pure, static build of Go binaries. |
| 4 | """ |
| Tim Windelschmidt | 3a171d1 | 2024-12-09 23:51:23 +0100 | [diff] [blame] | 5 | race = settings["@io_bazel_rules_go//go/config:race"] |
| Serge Bazanski | 30021af | 2023-06-20 13:30:11 +0200 | [diff] [blame] | 6 | pure = not race |
| 7 | |
| Serge Bazanski | c3ae758 | 2020-06-08 17:15:26 +0200 | [diff] [blame] | 8 | return { |
| Serge Bazanski | 30021af | 2023-06-20 13:30:11 +0200 | [diff] [blame] | 9 | "@io_bazel_rules_go//go/config:pure": pure, |
| Serge Bazanski | c3ae758 | 2020-06-08 17:15:26 +0200 | [diff] [blame] | 10 | "@io_bazel_rules_go//go/config:static": True, |
| Tim Windelschmidt | 3a171d1 | 2024-12-09 23:51:23 +0100 | [diff] [blame] | 11 | "//command_line_option:platforms": "//build/platforms:linux_amd64_static", |
| Serge Bazanski | c3ae758 | 2020-06-08 17:15:26 +0200 | [diff] [blame] | 12 | } |
| 13 | |
| 14 | build_pure_transition = transition( |
| 15 | implementation = _build_pure_transition_impl, |
| Serge Bazanski | 30021af | 2023-06-20 13:30:11 +0200 | [diff] [blame] | 16 | inputs = [ |
| 17 | "@io_bazel_rules_go//go/config:race", |
| 18 | ], |
| Serge Bazanski | c3ae758 | 2020-06-08 17:15:26 +0200 | [diff] [blame] | 19 | outputs = [ |
| 20 | "@io_bazel_rules_go//go/config:pure", |
| 21 | "@io_bazel_rules_go//go/config:static", |
| Tim Windelschmidt | 3a171d1 | 2024-12-09 23:51:23 +0100 | [diff] [blame] | 22 | "//command_line_option:platforms", |
| Serge Bazanski | c3ae758 | 2020-06-08 17:15:26 +0200 | [diff] [blame] | 23 | ], |
| 24 | ) |
| 25 | |
| Tim Windelschmidt | 156248b | 2025-01-10 00:27:45 +0100 | [diff] [blame] | 26 | def _build_static_transition_impl(_settings, _attr): |
| Lorenz Brun | 5e4fc2d | 2020-09-22 18:35:15 +0200 | [diff] [blame] | 27 | """ |
| 28 | Transition that enables static builds with CGo and musl for Go binaries. |
| 29 | """ |
| 30 | return { |
| 31 | "@io_bazel_rules_go//go/config:static": True, |
| Leopold | bc93c2b | 2023-01-14 13:12:23 +0100 | [diff] [blame] | 32 | "//command_line_option:platforms": "//build/platforms:linux_amd64_static", |
| Lorenz Brun | 5e4fc2d | 2020-09-22 18:35:15 +0200 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | build_static_transition = transition( |
| 36 | implementation = _build_static_transition_impl, |
| 37 | inputs = [], |
| 38 | outputs = [ |
| 39 | "@io_bazel_rules_go//go/config:static", |
| Leopold | bc93c2b | 2023-01-14 13:12:23 +0100 | [diff] [blame] | 40 | "//command_line_option:platforms", |
| Lorenz Brun | 5e4fc2d | 2020-09-22 18:35:15 +0200 | [diff] [blame] | 41 | ], |
| 42 | ) |
| Tim Windelschmidt | 08054ca | 2025-04-04 01:11:56 +0200 | [diff] [blame] | 43 | |
| 44 | _new_settings = { |
| 45 | # This list should be expanded with any configuration options that end |
| 46 | # up reaching this rule with different values across different build |
| 47 | # graph paths, but that do not actually influence the kernel build. |
| 48 | # Force-setting them to a stable value forces the build configuration |
| 49 | # to a stable hash. |
| 50 | # See the transition's comment block for more information. |
| 51 | "@io_bazel_rules_go//go/config:pure": False, |
| 52 | "@io_bazel_rules_go//go/config:static": False, |
| 53 | |
| 54 | # Note: this toolchain is not actually used to perform the build. |
| 55 | "//command_line_option:platforms": "//build/platforms:linux_amd64_static", |
| 56 | } |
| 57 | |
| 58 | def _ignore_unused_configuration_impl(_settings, _attr): |
| 59 | return _new_settings |
| 60 | |
| 61 | # Transition to flip all known-unimportant but varying configuration options to |
| 62 | # a known, stable value. |
| 63 | # This is to prevent Bazel from creating extra configurations for possible |
| 64 | # combinations of options in case the linux_image rule is pulled through build |
| 65 | # graph fragments that have different options set. |
| 66 | # |
| 67 | # Ideally, Bazel would let us mark in a list that we only care about some set |
| 68 | # of options (or at least let us mark those that we explicitly don't care |
| 69 | # about, instead of manually setting them to some value). However, this doesn't |
| 70 | # seem to be possible, thus this transition is a bit of a hack. |
| 71 | ignore_unused_configuration = transition( |
| 72 | implementation = _ignore_unused_configuration_impl, |
| 73 | inputs = [], |
| 74 | outputs = list(_new_settings.keys()), |
| 75 | ) |