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