mirror of
https://github.com/raspberrypi/pico-sdk.git
synced 2025-08-07 17:02:52 +03:00
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
This commit is contained in:
@@ -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,
|
||||
)
|
||||
|
@@ -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_FASTBUILD_ARGS": "True"},
|
||||
)
|
||||
|
@@ -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.
|
||||
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(
|
||||
@@ -132,16 +163,23 @@ 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 = "dbg",
|
||||
args = [":debug_args"],
|
||||
overrides = "@rules_cc//cc/toolchains/features:dbg",
|
||||
)
|
||||
|
||||
cc_feature(
|
||||
name = "override_debug",
|
||||
args = [":all_opt_debug_args"],
|
||||
overrides = "@rules_cc//cc/toolchains/features:dbg",
|
||||
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 = (
|
||||
@@ -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",
|
||||
@@ -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"],
|
||||
@@ -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",
|
||||
@@ -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"],
|
||||
|
@@ -158,6 +158,10 @@ BAZEL_ONLY_ALLOWLIST = (
|
||||
"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",
|
||||
)
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user