blob: f3ef7a932f9e20cd1b4e1373696964f12acd6f92 [file] [log] [blame]
Tim Windelschmidt156248b2025-01-10 00:27:45 +01001def _build_pure_transition_impl(settings, _attr):
Serge Bazanskic3ae7582020-06-08 17:15:26 +02002 """
3 Transition that enables pure, static build of Go binaries.
4 """
Tim Windelschmidt3a171d12024-12-09 23:51:23 +01005 race = settings["@io_bazel_rules_go//go/config:race"]
Serge Bazanski30021af2023-06-20 13:30:11 +02006 pure = not race
7
Serge Bazanskic3ae7582020-06-08 17:15:26 +02008 return {
Serge Bazanski30021af2023-06-20 13:30:11 +02009 "@io_bazel_rules_go//go/config:pure": pure,
Serge Bazanskic3ae7582020-06-08 17:15:26 +020010 "@io_bazel_rules_go//go/config:static": True,
Tim Windelschmidt3a171d12024-12-09 23:51:23 +010011 "//command_line_option:platforms": "//build/platforms:linux_amd64_static",
Serge Bazanskic3ae7582020-06-08 17:15:26 +020012 }
13
14build_pure_transition = transition(
15 implementation = _build_pure_transition_impl,
Serge Bazanski30021af2023-06-20 13:30:11 +020016 inputs = [
17 "@io_bazel_rules_go//go/config:race",
18 ],
Serge Bazanskic3ae7582020-06-08 17:15:26 +020019 outputs = [
20 "@io_bazel_rules_go//go/config:pure",
21 "@io_bazel_rules_go//go/config:static",
Tim Windelschmidt3a171d12024-12-09 23:51:23 +010022 "//command_line_option:platforms",
Serge Bazanskic3ae7582020-06-08 17:15:26 +020023 ],
24)
25
Tim Windelschmidt156248b2025-01-10 00:27:45 +010026def _build_static_transition_impl(_settings, _attr):
Lorenz Brun5e4fc2d2020-09-22 18:35:15 +020027 """
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,
Leopoldbc93c2b2023-01-14 13:12:23 +010032 "//command_line_option:platforms": "//build/platforms:linux_amd64_static",
Lorenz Brun5e4fc2d2020-09-22 18:35:15 +020033 }
34
35build_static_transition = transition(
36 implementation = _build_static_transition_impl,
37 inputs = [],
38 outputs = [
39 "@io_bazel_rules_go//go/config:static",
Leopoldbc93c2b2023-01-14 13:12:23 +010040 "//command_line_option:platforms",
Lorenz Brun5e4fc2d2020-09-22 18:35:15 +020041 ],
42)
Tim Windelschmidt08054ca2025-04-04 01:11:56 +020043
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
58def _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.
71ignore_unused_configuration = transition(
72 implementation = _ignore_unused_configuration_impl,
73 inputs = [],
74 outputs = list(_new_settings.keys()),
75)