Skip to content

Commit be54918

Browse files
authored
Bazel build implementation, doesn't provide options for the compilation modes opt and debug (#2395)
* Bazel add default compliation args for opt and debug. Can be overriden * Add docstrings for new compilation mode override flags * Remove cc_args_list shims, which arent needed anymore for cc_feature * Add Compilation mode overrides to the BAZEL_ONLY_ALLOWLIST, these dont exist in Cmake * For completness add the fastbuild default options, and override flag * Remove the default options for fastbuiild, as the bazel doc defaults didnt make much sense, nor work. Leaving these for completness and future addition * Rename the config and constraint labels from OVERRIDE to REMOVE_DEFS * Change naming of flags from PICO_COMPILATION_XXX_REMOVE_DEFS to PICO_COMPILATION_NO_XXX_ARGS for OPT, FASTBUILD & DEBUG variants * Fixup spellling mistakes, and comments * Fix typo PICO_COMPILATION_NO_FASBUILD_ARGS to FASTBUILD
1 parent e6d1892 commit be54918

File tree

4 files changed

+92
-15
lines changed

4 files changed

+92
-15
lines changed

bazel/config/BUILD.bazel

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,21 @@ label_flag(
300300
name = "PICO_MBEDTLS_CONFIG",
301301
build_setting_default = "//bazel:empty_cc_lib",
302302
)
303+
304+
# PICO_BAZEL_CONFIG: PICO_COMPILATION_NO_OPT_ARGS, Makes the opt compilation mode a no-op so custom optimization arguments can be injected via the --copt flag instead, type=bool, default=0, group=build
305+
bool_flag(
306+
name = "PICO_COMPILATION_NO_OPT_ARGS",
307+
build_setting_default = False,
308+
)
309+
310+
# PICO_BAZEL_CONFIG: PICO_COMPILATION_NO_DEBUG_ARGS, Makes the debug compilation mode a no-op so custom debug arguments can be injected via the --copt flag instead, type=bool, default=0, group=build
311+
bool_flag(
312+
name = "PICO_COMPILATION_NO_DEBUG_ARGS",
313+
build_setting_default = False,
314+
)
315+
316+
# PICO_BAZEL_CONFIG: PICO_COMPILATION_NO_FASTBUILD_ARGS, Makes the fastbuild compilation mode a no-op so custom fastbuild arguments can be injected via the --copt flag instead, type=bool, default=0, group=build
317+
bool_flag(
318+
name = "PICO_COMPILATION_NO_FASTBUILD_ARGS",
319+
build_setting_default = False,
320+
)

bazel/constraint/BUILD.bazel

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,3 +258,18 @@ label_flag_matches(
258258
flag = "//bazel/config:PICO_MBEDTLS_CONFIG",
259259
value = "//bazel:empty_cc_lib",
260260
)
261+
262+
config_setting(
263+
name = "pico_compilation_no_opt_args_set",
264+
flag_values = {"//bazel/config:PICO_COMPILATION_NO_OPT_ARGS": "True"},
265+
)
266+
267+
config_setting(
268+
name = "pico_compilation_no_debug_args_set",
269+
flag_values = {"//bazel/config:PICO_COMPILATION_NO_DEBUG_ARGS": "True"},
270+
)
271+
272+
config_setting(
273+
name = "pico_compilation_no_fastbuild_args_set",
274+
flag_values = {"//bazel/config:PICO_COMPILATION_NO_FASTBUILD_ARGS": "True"},
275+
)

bazel/toolchain/BUILD.bazel

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,46 @@ cc_args(
8989
)
9090

9191
cc_args(
92-
name = "opt_debug_args",
92+
name = "debug_args",
9393
actions = [
9494
"@rules_cc//cc/toolchains/actions:compile_actions",
9595
"@rules_cc//cc/toolchains/actions:link_actions",
9696
],
97-
args = [
98-
"-Og", # TODO: Make this configurable.
99-
"-g3",
97+
args = select({
98+
"//bazel/constraint:pico_compilation_no_debug_args_set": [],
99+
"//conditions:default": [
100+
"-Og",
101+
"-g3",
102+
],
103+
})
104+
)
105+
106+
cc_args(
107+
name = "opt_args",
108+
actions = [
109+
"@rules_cc//cc/toolchains/actions:compile_actions",
110+
"@rules_cc//cc/toolchains/actions:link_actions",
111+
],
112+
args = select({
113+
"//bazel/constraint:pico_compilation_no_opt_args_set": [],
114+
"//conditions:default": [
115+
"-O2",
116+
"-DNDEBUG",
117+
],
118+
})
119+
)
120+
121+
cc_args(
122+
name = "fastbuild_args",
123+
actions = [
124+
"@rules_cc//cc/toolchains/actions:compile_actions",
125+
"@rules_cc//cc/toolchains/actions:link_actions",
100126
],
127+
args = select({
128+
"//bazel/constraint:pico_compilation_no_fastbuild_args_set": [],
129+
# The conditions default are kept as nothing here, The bazel docs default are -gmlt -Wl,-S.
130+
"//conditions:default": [],
131+
})
101132
)
102133

103134
configurable_toolchain_feature(
@@ -132,18 +163,25 @@ configurable_toolchain_feature(
132163
linkopts = ["-Wl,-z,max-page-size=4096"],
133164
)
134165

135-
# TODO: Make this shim unnecessary.
136-
cc_args_list(
137-
name = "all_opt_debug_args",
138-
args = [":opt_debug_args"],
139-
)
140166

141167
cc_feature(
142-
name = "override_debug",
143-
args = [":all_opt_debug_args"],
168+
name = "dbg",
169+
args = [":debug_args"],
144170
overrides = "@rules_cc//cc/toolchains/features:dbg",
145171
)
146172

173+
cc_feature(
174+
name = "opt",
175+
args = [":opt_args"],
176+
overrides = "@rules_cc//cc/toolchains/features:opt",
177+
)
178+
179+
cc_feature(
180+
name = "fastbuild",
181+
args = [":fastbuild_args"],
182+
overrides = "@rules_cc//cc/toolchains/features:fastbuild",
183+
)
184+
147185
HOSTS = (
148186
("linux", "x86_64"),
149187
("linux", "aarch64"),
@@ -180,7 +218,9 @@ _HOST_CPU_CONSTRAINTS = {
180218
tags = ["manual"], # Don't try to build this in wildcard builds.
181219
known_features = [
182220
"@rules_cc//cc/toolchains/args:experimental_replace_legacy_action_config_features",
183-
"@pico-sdk//bazel/toolchain:override_debug",
221+
"@pico-sdk//bazel/toolchain:dbg",
222+
"@pico-sdk//bazel/toolchain:opt",
223+
"@pico-sdk//bazel/toolchain:fastbuild",
184224
"@pico-sdk//bazel/toolchain:gc_sections",
185225
"@pico-sdk//bazel/toolchain:cxx_no_exceptions",
186226
"@pico-sdk//bazel/toolchain:cxx_no_rtti",
@@ -189,7 +229,6 @@ _HOST_CPU_CONSTRAINTS = {
189229
],
190230
enabled_features = [
191231
"@rules_cc//cc/toolchains/args:experimental_replace_legacy_action_config_features",
192-
"@pico-sdk//bazel/toolchain:override_debug",
193232
] + select({
194233
"//bazel/constraint:pico_no_gc_sections_enabled": [],
195234
"//conditions:default": [":gc_sections"],
@@ -232,7 +271,9 @@ _HOST_CPU_CONSTRAINTS = {
232271
tags = ["manual"], # Don't try to build this in wildcard builds.
233272
known_features = [
234273
"@rules_cc//cc/toolchains/args:experimental_replace_legacy_action_config_features",
235-
"@pico-sdk//bazel/toolchain:override_debug",
274+
"@pico-sdk//bazel/toolchain:dbg",
275+
"@pico-sdk//bazel/toolchain:opt",
276+
"@pico-sdk//bazel/toolchain:fastbuild",
236277
"@pico-sdk//bazel/toolchain:gc_sections",
237278
"@pico-sdk//bazel/toolchain:cxx_no_exceptions",
238279
"@pico-sdk//bazel/toolchain:cxx_no_rtti",
@@ -241,7 +282,6 @@ _HOST_CPU_CONSTRAINTS = {
241282
],
242283
enabled_features = [
243284
"@rules_cc//cc/toolchains/args:experimental_replace_legacy_action_config_features",
244-
"@pico-sdk//bazel/toolchain:override_debug",
245285
] + select({
246286
"//bazel/constraint:pico_no_gc_sections_enabled": [],
247287
"//conditions:default": [":gc_sections"],

tools/compare_build_systems.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@
158158
"PICO_BT_ENABLE_BLE",
159159
"PICO_BT_ENABLE_CLASSIC",
160160
"PICO_BT_ENABLE_MESH",
161+
# Compilation modes remove, These allow the user to remove the defaults, with no args. See --compilation_mode cmd line option
162+
"PICO_COMPILATION_NO_OPT_ARGS",
163+
"PICO_COMPILATION_NO_DEBUG_ARGS",
164+
"PICO_COMPILATION_NO_FASTBUILD_ARGS",
161165
)
162166

163167

0 commit comments

Comments
 (0)