Skip to content

Commit 902ca8a

Browse files
committed
feat: make bootstrap=script default for linux
1 parent 9fb13ec commit 902ca8a

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

python/config_settings/BUILD.bazel

+15-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ load(
1111
"PrecompileSourceRetentionFlag",
1212
"VenvsSitePackages",
1313
"VenvsUseDeclareSymlinkFlag",
14+
rp_string_flag = "string_flag",
1415
)
1516
load(
1617
"//python/private/pypi:flags.bzl",
@@ -87,14 +88,26 @@ string_flag(
8788
visibility = ["//visibility:public"],
8889
)
8990

90-
string_flag(
91+
rp_string_flag(
9192
name = "bootstrap_impl",
92-
build_setting_default = BootstrapImplFlag.SYSTEM_PYTHON,
93+
build_setting_default = BootstrapImplFlag.SCRIPT,
94+
override = select({
95+
":_is_windows": BootstrapImplFlag.SYSTEM_PYTHON,
96+
"//conditions:default": "",
97+
}),
9398
values = sorted(BootstrapImplFlag.__members__.values()),
9499
# NOTE: Only public because it's an implicit dependency
95100
visibility = ["//visibility:public"],
96101
)
97102

103+
# For some reason, @platforms//os:windows can't be directly used
104+
# in the select() for the flag. But it can be used when put behind
105+
# a config_setting().
106+
config_setting(
107+
name = "_is_windows",
108+
constraint_values = ["@platforms//os:windows"],
109+
)
110+
98111
# This is used for pip and hermetic toolchain resolution.
99112
string_flag(
100113
name = "py_linux_libc",

python/private/flags.bzl

+31-1
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,38 @@ AddSrcsToRunfilesFlag = FlagEnum(
3535
is_enabled = _AddSrcsToRunfilesFlag_is_enabled,
3636
)
3737

38+
def _string_flag_impl(ctx):
39+
if ctx.attr.override:
40+
value = ctx.attr.override
41+
else:
42+
value = ctx.build_setting_value
43+
44+
if value not in ctx.attr.values:
45+
fail((
46+
"Invalid value for {name}: got {value}, must " +
47+
"be one of {allowed}"
48+
).format(
49+
name = ctx.label,
50+
value = value,
51+
allowed = ctx.attr.values,
52+
))
53+
54+
return [
55+
BuildSettingInfo(value = value),
56+
config_common.FeatureFlagInfo(value = value),
57+
]
58+
59+
string_flag = rule(
60+
implementation = _string_flag_impl,
61+
build_setting = config.string(flag = True),
62+
attrs = {
63+
"override": attr.string(),
64+
"values": attr.string_list(),
65+
},
66+
)
67+
3868
def _bootstrap_impl_flag_get_value(ctx):
39-
return ctx.attr._bootstrap_impl_flag[BuildSettingInfo].value
69+
return ctx.attr._bootstrap_impl_flag[config_common.FeatureFlagInfo].value
4070

4171
# buildifier: disable=name-conventions
4272
BootstrapImplFlag = enum(

0 commit comments

Comments
 (0)