diff --git a/bazel/config/BUILD.bazel b/bazel/config/BUILD.bazel index ac6dc387a..b27cbdd54 100644 --- a/bazel/config/BUILD.bazel +++ b/bazel/config/BUILD.bazel @@ -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, +) diff --git a/bazel/constraint/BUILD.bazel b/bazel/constraint/BUILD.bazel index 3ce282065..acd112469 100644 --- a/bazel/constraint/BUILD.bazel +++ b/bazel/constraint/BUILD.bazel @@ -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"}, +) diff --git a/bazel/toolchain/BUILD.bazel b/bazel/toolchain/BUILD.bazel index ba8d947ca..dacd35389 100644 --- a/bazel/toolchain/BUILD.bazel +++ b/bazel/toolchain/BUILD.bazel @@ -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( @@ -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"), @@ -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"], diff --git a/tools/compare_build_systems.py b/tools/compare_build_systems.py index 86dc615a1..583e51838 100755 --- a/tools/compare_build_systems.py +++ b/tools/compare_build_systems.py @@ -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", )