Skip to content

Commit 34db795

Browse files
keithnglevin
andauthored
Create an enable_wip_features Starlark build config. (#2806)
To be used for features still undergoing testing, or which will only be used for testing for the foreseeable future. (cherry picked from commit 795fdb4) Co-authored-by: Nicholas Levin <nglevin@google.com>
1 parent 972e4dc commit 34db795

File tree

2 files changed

+58
-14
lines changed

2 files changed

+58
-14
lines changed

apple/build_settings/BUILD

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,36 @@
11
# Build settings used throughout rules_apple build rules.
22

33
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
4-
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "string_flag")
4+
load(
5+
"@bazel_skylib//rules:common_settings.bzl",
6+
"bool_flag",
7+
"bool_setting",
8+
"string_flag",
9+
)
510
load(
611
"//apple/build_settings:build_settings.bzl",
12+
"build_flags",
713
"build_settings",
814
)
915

1016
package(default_visibility = ["//visibility:public"])
1117

1218
licenses(["notice"])
1319

20+
# Flags are configurable from the command line; pure "*_setting"s are not. Rely on this distinction
21+
# to keep Starlark custom build settings de-facto "private" vs public while keeping them accessible
22+
# to the toolchains.
1423
[
1524
bool_flag(
25+
name = build_flag_name,
26+
build_setting_default = build_flag_info.default,
27+
)
28+
for build_flag_name, build_flag_info in build_flags.items()
29+
if type(build_flag_info.default) == "bool"
30+
]
31+
32+
[
33+
bool_setting(
1634
name = build_setting_name,
1735
build_setting_default = build_setting_info.default,
1836
)
@@ -22,11 +40,11 @@ licenses(["notice"])
2240

2341
[
2442
string_flag(
25-
name = build_setting_name,
26-
build_setting_default = build_setting_info.default,
43+
name = build_flag_name,
44+
build_setting_default = build_flag_info.default,
2745
)
28-
for build_setting_name, build_setting_info in build_settings.items()
29-
if type(build_setting_info.default) == "string"
46+
for build_flag_name, build_flag_info in build_flags.items()
47+
if type(build_flag_info.default) == "string"
3048
]
3149

3250
bzl_library(
@@ -35,6 +53,9 @@ bzl_library(
3553
visibility = [
3654
"//:__subpackages__",
3755
],
56+
deps = [
57+
"@bazel_skylib//lib:dicts",
58+
],
3859
)
3960

4061
# Consumed by bazel tests.

apple/build_settings/build_settings.bzl

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@
1414

1515
"""List of Bazel's rules_apple build settings."""
1616

17-
# List of all registered build settings at `rules_apple/apple/build_settings/BUILD`.
18-
build_settings = {
17+
load("@bazel_skylib//lib:dicts.bzl", "dicts")
18+
19+
# List of all registered build settings with command line flags at
20+
# `rules_apple/apple/build_settings/BUILD`.
21+
build_flags = {
1922
"parse_xcframework_info_plist": struct(
2023
doc = """
2124
Configuration for enabling XCFramework import rules use the xcframework_processor_tool to
@@ -50,14 +53,34 @@ physical devices) or `xcrun simctl list devices` (for simulators).
5053
),
5154
}
5255

53-
_BUILD_SETTING_LABELS = {
54-
build_setting_name: str(Label("//apple/build_settings:{target_name}".format(
55-
target_name = build_setting_name,
56-
)))
57-
for build_setting_name in build_settings
56+
# List of all registered build settings without command line flags at
57+
# `rules_apple/apple/build_settings/BUILD`.
58+
build_settings = {
59+
"enable_wip_features": struct(
60+
doc = """
61+
Enables functionality that is still a work in progress, with interfaces and output that can change
62+
at any time, that is only ready for automated testing now.
63+
64+
This could indicate functionality intended for a future release of the Apple BUILD rules, or
65+
functionality that is never intended to be production-ready but is required of automated testing.
66+
""",
67+
default = False,
68+
),
5869
}
5970

71+
_all_build_settings = dicts.add(build_settings, build_flags)
72+
6073
build_settings_labels = struct(
61-
all_labels = _BUILD_SETTING_LABELS.values(),
62-
**_BUILD_SETTING_LABELS
74+
all_labels = [
75+
str(Label("//apple/build_settings:{target_name}".format(
76+
target_name = build_setting_name,
77+
)))
78+
for build_setting_name in _all_build_settings
79+
],
80+
**{
81+
build_setting_name: str(Label("//apple/build_settings:{target_name}".format(
82+
target_name = build_setting_name,
83+
)))
84+
for build_setting_name in _all_build_settings
85+
}
6386
)

0 commit comments

Comments
 (0)