Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions bazel/config/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,21 @@ label_flag(
name = "PICO_FREERTOS_LIB",
build_setting_default = "//bazel:empty_cc_lib",
)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add docstrings above these and add them to the exclusion list in BAZEL_ONLY_ALLOWLIST here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, Thanks. These have been added.

# PICO_BAZEL_CONFIG: PICO_COMPILATION_OPT_OVERRIDE, Override the default opt compilation mode arguments to none, type=bool, default=0, group=build
bool_flag(
name = "PICO_COMPILATION_OPT_OVERRIDE",
build_setting_default = False,
)

# PICO_BAZEL_CONFIG: PICO_COMPILATION_DEBUG_OVERRIDE, Override the default dbg compilation mode arguments to none, type=bool, default=0, group=build
bool_flag(
name = "PICO_COMPILATION_DEBUG_OVERRIDE",
build_setting_default = False,
)

# PICO_BAZEL_CONFIG: PICO_COMPILATION_FASTBUILD_OVERRIDE, Override the default fastbuild compilation mode arguments to none, type=bool, default=0, group=build
bool_flag(
name = "PICO_COMPILATION_FASTBUILD_OVERRIDE",
build_setting_default = False,
)
15 changes: 15 additions & 0 deletions bazel/constraint/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,18 @@ label_flag_matches(
flag = "//bazel/config:PICO_FREERTOS_LIB",
value = "//bazel:empty_cc_lib",
)

config_setting(
name = "pico_compiliation_opt_override",
flag_values = {"//bazel/config:PICO_COMPILATION_OPT_OVERRIDE": "True"},
)

config_setting(
name = "pico_compiliation_debug_override",
flag_values = {"//bazel/config:PICO_COMPILATION_DEBUG_OVERRIDE": "True"},
)

config_setting(
name = "pico_compiliation_fastbuild_override",
flag_values = {"//bazel/config:PICO_COMPILATION_FASTBUILD_OVERRIDE": "True"},
)
70 changes: 55 additions & 15 deletions bazel/toolchain/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,46 @@ cc_args(
)

cc_args(
name = "opt_debug_args",
name = "debug_args",
actions = [
"@rules_cc//cc/toolchains/actions:compile_actions",
"@rules_cc//cc/toolchains/actions:link_actions",
],
args = [
"-Og", # TODO: Make this configurable.
"-g3",
args = select({
"//bazel/constraint:pico_compiliation_debug_override": [],
"//conditions:default": [
"-Og",
"-g3",
],
})
)

cc_args(
name = "opt_args",
actions = [
"@rules_cc//cc/toolchains/actions:compile_actions",
"@rules_cc//cc/toolchains/actions:link_actions",
],
args = select({
"//bazel/constraint:pico_compiliation_opt_override": [],
"//conditions:default": [
"-O2",
"-DNDEBUG",
],
})
)

cc_args(
name = "fastbuild_args",
actions = [
"@rules_cc//cc/toolchains/actions:compile_actions",
"@rules_cc//cc/toolchains/actions:link_actions",
],
args = select({
"//bazel/constraint:pico_compiliation_fastbuild_override": [],
# The conditions default are kept as nothing here, The bazel docs default are -gmlt -Wl,-S.
"//conditions:default": [],
})
)

configurable_toolchain_feature(
Expand Down Expand Up @@ -132,18 +163,25 @@ configurable_toolchain_feature(
linkopts = ["-Wl,-z,max-page-size=4096"],
)

# TODO: Make this shim unnecessary.
cc_args_list(
name = "all_opt_debug_args",
args = [":opt_debug_args"],
)

cc_feature(
name = "override_debug",
args = [":all_opt_debug_args"],
name = "dbg",
args = [":debug_args"],
overrides = "@rules_cc//cc/toolchains/features:dbg",
)

cc_feature(
name = "opt",
args = [":opt_args"],
overrides = "@rules_cc//cc/toolchains/features:opt",
)

cc_feature(
name = "fastbuild",
args = [":fastbuild_args"],
overrides = "@rules_cc//cc/toolchains/features:fastbuild",
)

HOSTS = (
("linux", "x86_64"),
("linux", "aarch64"),
Expand Down Expand Up @@ -180,7 +218,9 @@ _HOST_CPU_CONSTRAINTS = {
tags = ["manual"], # Don't try to build this in wildcard builds.
known_features = [
"@rules_cc//cc/toolchains/args:experimental_replace_legacy_action_config_features",
"@pico-sdk//bazel/toolchain:override_debug",
"@pico-sdk//bazel/toolchain:dbg",
"@pico-sdk//bazel/toolchain:opt",
"@pico-sdk//bazel/toolchain:fastbuild",
"@pico-sdk//bazel/toolchain:gc_sections",
"@pico-sdk//bazel/toolchain:cxx_no_exceptions",
"@pico-sdk//bazel/toolchain:cxx_no_rtti",
Expand All @@ -189,7 +229,6 @@ _HOST_CPU_CONSTRAINTS = {
],
enabled_features = [
"@rules_cc//cc/toolchains/args:experimental_replace_legacy_action_config_features",
"@pico-sdk//bazel/toolchain:override_debug",
] + select({
"//bazel/constraint:pico_no_gc_sections_enabled": [],
"//conditions:default": [":gc_sections"],
Expand Down Expand Up @@ -232,7 +271,9 @@ _HOST_CPU_CONSTRAINTS = {
tags = ["manual"], # Don't try to build this in wildcard builds.
known_features = [
"@rules_cc//cc/toolchains/args:experimental_replace_legacy_action_config_features",
"@pico-sdk//bazel/toolchain:override_debug",
"@pico-sdk//bazel/toolchain:dbg",
"@pico-sdk//bazel/toolchain:opt",
"@pico-sdk//bazel/toolchain:fastbuild",
"@pico-sdk//bazel/toolchain:gc_sections",
"@pico-sdk//bazel/toolchain:cxx_no_exceptions",
"@pico-sdk//bazel/toolchain:cxx_no_rtti",
Expand All @@ -241,7 +282,6 @@ _HOST_CPU_CONSTRAINTS = {
],
enabled_features = [
"@rules_cc//cc/toolchains/args:experimental_replace_legacy_action_config_features",
"@pico-sdk//bazel/toolchain:override_debug",
] + select({
"//bazel/constraint:pico_no_gc_sections_enabled": [],
"//conditions:default": [":gc_sections"],
Expand Down
4 changes: 4 additions & 0 deletions tools/compare_build_systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@
"PICO_BT_ENABLE_BLE",
"PICO_BT_ENABLE_CLASSIC",
"PICO_BT_ENABLE_MESH",
# Compilation modes overrides, These allow the user to override the defaults, with no args. See --compilation_mode cmd line option
"PICO_COMPILATION_FASTBUILD_OVERRIDE",
"PICO_COMPILATION_DEBUG_OVERRIDE",
"PICO_COMPILATION_OPT_OVERRIDE",
)


Expand Down