Skip to content

Bazel build implementation, doesn't provide options for the compilation modes opt and debug #2395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Open
18 changes: 18 additions & 0 deletions bazel/config/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,21 @@ label_flag(
name = "PICO_MBEDTLS_CONFIG",
build_setting_default = "//bazel:empty_cc_lib",
)

# 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
bool_flag(
name = "PICO_COMPILATION_NO_OPT_ARGS",
build_setting_default = False,
)

# 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
bool_flag(
name = "PICO_COMPILATION_NO_DEBUG_ARGS",
build_setting_default = False,
)

# 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
bool_flag(
name = "PICO_COMPILATION_NO_FASTBUILD_ARGS",
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 @@ -258,3 +258,18 @@ label_flag_matches(
flag = "//bazel/config:PICO_MBEDTLS_CONFIG",
value = "//bazel:empty_cc_lib",
)

config_setting(
name = "pico_compilation_no_opt_args_set",
flag_values = {"//bazel/config:PICO_COMPILATION_NO_OPT_ARGS": "True"},
)

config_setting(
name = "pico_compilation_no_debug_args_set",
flag_values = {"//bazel/config:PICO_COMPILATION_NO_DEBUG_ARGS": "True"},
)

config_setting(
name = "pico_compilation_no_fastbuild_args_set",
flag_values = {"//bazel/config:PICO_COMPILATION_NO_FASBUILD_ARGS": "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_compilation_no_debug_args_set": [],
"//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_compilation_no_opt_args_set": [],
"//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_compilation_no_fastbuild_args_set": [],
# 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 @@ -158,6 +158,10 @@
"PICO_BT_ENABLE_BLE",
"PICO_BT_ENABLE_CLASSIC",
"PICO_BT_ENABLE_MESH",
# Compilation modes remove, These allow the user to remove the defaults, with no args. See --compilation_mode cmd line option
"PICO_COMPILATION_NO_OPT_ARGS",
"PICO_COMPILATION_NO_DEBUG_ARGS",
"PICO_COMPILATION_NO_FASTBUILD_ARGS",
)


Expand Down