diff --git a/.bazelrc b/.bazelrc index bae68e8b49..d0f0f8f322 100644 --- a/.bazelrc +++ b/.bazelrc @@ -142,108 +142,30 @@ common --//pw_env_setup/py:pigweed_json=//:pigweed.json build --//pw_function:config_override=//pw_function:upstream_default_config # Config for all RP2xxx platforms. -# -# TODO: b/301334234 - Make the platform set the flags below. -# LINT.IfChange build:rp2040 --platforms=@pigweed//targets/rp2040 -build:rp2040 --//pw_assert:assert_backend=@pigweed//pw_assert_trap -build:rp2040 --//pw_assert:assert_backend_impl=@pigweed//pw_assert_trap:impl -build:rp2040 --//pw_assert:check_backend=@pigweed//pw_assert_trap -build:rp2040 --//pw_assert:check_backend_impl=@pigweed//pw_assert_trap:impl -build:rp2040 --//pw_cpu_exception:entry_backend=@pigweed//pw_cpu_exception_cortex_m:cpu_exception -build:rp2040 --//pw_cpu_exception:entry_backend_impl=@pigweed//pw_cpu_exception_cortex_m:cpu_exception_impl -build:rp2040 --//pw_cpu_exception:handler_backend=@pigweed//pw_cpu_exception:basic_handler -build:rp2040 --//pw_cpu_exception:support_backend=@pigweed//pw_cpu_exception_cortex_m:support -build:rp2040 --//pw_interrupt:backend=@pigweed//pw_interrupt_cortex_m:context -build:rp2040 --//pw_log:backend=@pigweed//pw_log_tokenized -build:rp2040 --//pw_log:backend_impl=@pigweed//pw_log_tokenized:impl -build:rp2040 --//pw_log_tokenized:handler_backend=@pigweed//pw_system:log_backend -build:rp2040 --//pw_sync:binary_semaphore_backend=//pw_sync_freertos:binary_semaphore -build:rp2040 --//pw_sync:counting_semaphore_backend=@pigweed//pw_sync_freertos:counting_semaphore -build:rp2040 --//pw_sync:interrupt_spin_lock_backend=//pw_sync_freertos:interrupt_spin_lock -build:rp2040 --//pw_sync:mutex_backend=//pw_sync_freertos:mutex -build:rp2040 --//pw_sync:thread_notification_backend=//pw_sync_freertos:thread_notification -build:rp2040 --//pw_sync:timed_thread_notification_backend=//pw_sync_freertos:timed_thread_notification -build:rp2040 --//pw_sys_io:backend=//pw_sys_io_rp2040 -build:rp2040 --//pw_system:extra_platform_libs=@pigweed//targets/rp2040:extra_platform_libs -build:rp2040 --//pw_system:device_handler_backend=@pigweed//targets/rp2040:device_handler -build:rp2040 --//pw_thread:id_backend=@pigweed//pw_thread_freertos:id -build:rp2040 --//pw_thread:iteration_backend=@pigweed//pw_thread_freertos:thread_iteration -build:rp2040 --//pw_thread:sleep_backend=@pigweed//pw_thread_freertos:sleep -build:rp2040 --//pw_thread:test_thread_context_backend=@pigweed//pw_thread_freertos:test_thread_context -build:rp2040 --//pw_thread:thread_backend=@pigweed//pw_thread_freertos:thread -build:rp2040 --//pw_thread:yield_backend=@pigweed//pw_thread_freertos:yield -build:rp2040 --//pw_toolchain:cortex-m_toolchain_kind=clang -build:rp2040 --//pw_trace:backend=@pigweed//pw_trace_tokenized:pw_trace_tokenized -build:rp2040 --//pw_unit_test:backend=//pw_unit_test:light -build:rp2040 --//pw_unit_test:main=//targets/rp2040:unit_test_app -build:rp2040 --//pw_build:default_module_config=//targets/rp2040:pigweed_module_config -build:rp2040 --@freertos//:freertos_config=@pigweed//targets/rp2040:freertos_config -build:rp2040 --@pico-sdk//bazel/config:PICO_STDIO_USB=True -build:rp2040 --@pico-sdk//bazel/config:PICO_STDIO_UART=True -build:rp2040 --@pico-sdk//bazel/config:PICO_CLIB=llvm_libc -build:rp2040 --@pico-sdk//bazel/config:PICO_TOOLCHAIN="clang" test:rp2040 --run_under=//targets/rp2040/py:unit_test_client -# LINT.ThenChange(//targets/rp2040/transition.bzl) -# RP2350 is the same but with a different --platforms setting. -build:rp2350 --config=rp2040 build:rp2350 --platforms=@pigweed//targets/rp2040:rp2350 +test:rp2350 --run_under=//targets/rp2040/py:unit_test_client # Config for the stm32f429i_disc1 baremetal platform. -# -# TODO: b/301334234 - Make the platform set the flags below. build:stm32f429i_baremetal --platforms=//targets/stm32f429i_disc1:platform -build:stm32f429i_baremetal --//pw_assert:check_backend=@pigweed//pw_assert_basic -build:stm32f429i_baremetal --//pw_assert:check_backend_impl=@pigweed//pw_assert_basic:impl -build:stm32f429i_baremetal --//pw_boot:backend=@pigweed//pw_boot_cortex_m -build:stm32f429i_baremetal --//pw_log:backend=@pigweed//pw_log_basic -build:stm32f429i_baremetal --//pw_log:backend_impl=@pigweed//pw_log_basic:impl -build:stm32f429i_baremetal --//pw_malloc:backend=@pigweed//pw_malloc:bucket_block_allocator -build:stm32f429i_baremetal --//pw_system:extra_platform_libs=@pigweed//targets/stm32f429i_disc1:extra_platform_libs -build:stm32f429i_baremetal --//pw_sys_io:backend=//pw_sys_io_baremetal_stm32f429 - # Config for the stm32f429i_disc1_stm32cube freertos platform. # -# TODO: b/301334234 - Make the platform set the flags below. build:stm32f429i_freertos --platforms=//targets/stm32f429i_disc1_stm32cube:platform +# This should be moved to platform-based flags once +# https://github.com/bazelbuild/bazel/issues/22453 +# is fixed. build:stm32f429i_freertos --copt="-DSTM32CUBE_HEADER=\"stm32f4xx.h\"" build:stm32f429i_freertos --copt="-DSTM32F429xx" -build:stm32f429i_freertos --@stm32f4xx_hal_driver//:hal_config=//targets/stm32f429i_disc1_stm32cube:hal_config -build:stm32f429i_freertos --//pw_assert:check_backend=@pigweed//pw_assert_basic -build:stm32f429i_freertos --//pw_assert:check_backend_impl=@pigweed//pw_assert_basic:impl -build:stm32f429i_freertos --//pw_boot:backend=@pigweed//pw_boot_cortex_m -build:stm32f429i_freertos --//pw_log:backend=@pigweed//pw_log_tokenized -build:stm32f429i_freertos --//pw_log:backend_impl=@pigweed//pw_log_tokenized:impl -build:stm32f429i_freertos --//pw_log_tokenized:handler_backend=@pigweed//pw_system:log_backend -build:stm32f429i_freertos --//pw_malloc:backend=@pigweed//pw_malloc:bucket_block_allocator -build:stm32f429i_freertos --//pw_sync:binary_semaphore_backend=//pw_sync_freertos:binary_semaphore -build:stm32f429i_freertos --//pw_sync:interrupt_spin_lock_backend=//pw_sync_freertos:interrupt_spin_lock -build:stm32f429i_freertos --//pw_sync:mutex_backend=//pw_sync_freertos:mutex -build:stm32f429i_freertos --//pw_sync:thread_notification_backend=//pw_sync_freertos:thread_notification -build:stm32f429i_freertos --//pw_sync:timed_thread_notification_backend=//pw_sync_freertos:timed_thread_notification -build:stm32f429i_freertos --//pw_thread:id_backend=@pigweed//pw_thread_freertos:id -build:stm32f429i_freertos --//pw_thread:iteration_backend=@pigweed//pw_thread_freertos:thread_iteration -build:stm32f429i_freertos --//pw_thread:sleep_backend=@pigweed//pw_thread_freertos:sleep -build:stm32f429i_freertos --//pw_thread:thread_backend=@pigweed//pw_thread_freertos:thread -build:stm32f429i_freertos --//pw_unit_test:main=//targets/stm32f429i_disc1_stm32cube:unit_test_app -build:stm32f429i_freertos --//pw_system:extra_platform_libs=@pigweed//targets/stm32f429i_disc1_stm32cube:extra_platform_libs -build:stm32f429i_freertos --//pw_sys_io:backend=//pw_sys_io_stm32cube + # Config for the lm3s6965evb platform, used to build pw_rust/examples. -# -# TODO: b/301334234 - Make the platform set the flags below. build:lm3s6965evb --platforms=//pw_build/platforms:lm3s6965evb -build:lm3s6965evb --//pw_log/rust:pw_log_backend=//pw_rust/examples/tokenized_logging:pw_log_backend -build:lm3s6965evb --//pw_sys_io:backend=//pw_sys_io_baremetal_lm3s6965evb # Config for the microbit platform, used to build pw_rust/examples. -# -# TODO: b/301334234 - Make the platform set the flags below. build:microbit --platforms=//pw_build/platforms:lm3s6965evb -build:microbit --//pw_log/rust:pw_log_backend=//pw_rust/examples/tokenized_logging:pw_log_backend -build:microbit --//pw_sys_io:backend=//pw_sys_io_baremetal_lm3s6965evb # For some platforms i.e. google/oss-fuzz we need to use the system provided # rather than the hermetic toolchains. This allows oss-fuzz to override the diff --git a/pw_allocator/examples/spin_lock.cc b/pw_allocator/examples/spin_lock.cc index c17d4a057d..2ef0edb792 100644 --- a/pw_allocator/examples/spin_lock.cc +++ b/pw_allocator/examples/spin_lock.cc @@ -22,6 +22,10 @@ #include "pw_thread/thread_core.h" #include "pw_unit_test/framework.h" +// TODO: https://pwbug.dev/365161669 - Express joinability as a build-system +// constraint. +#if PW_THREAD_JOINING_ENABLED + namespace examples { /// Threaded task that performs several allocations. @@ -90,3 +94,5 @@ TEST(SpinLockExample, RunTasks) { } } // namespace + +#endif // PW_THREAD_JOINING_ENABLED diff --git a/pw_allocator/synchronized_allocator_test.cc b/pw_allocator/synchronized_allocator_test.cc index 7982e3c3af..4fa4648028 100644 --- a/pw_allocator/synchronized_allocator_test.cc +++ b/pw_allocator/synchronized_allocator_test.cc @@ -32,6 +32,10 @@ #include "pw_thread/yield.h" #include "pw_unit_test/framework.h" +// TODO: https://pwbug.dev/365161669 - Express joinability as a build-system +// constraint. +#if PW_THREAD_JOINING_ENABLED + namespace { // Test fixtures. @@ -305,3 +309,5 @@ TEST(SynchronizedAllocatorTest, GenerateRequestsMutex) { } } // namespace + +#endif // PW_THREAD_JOINING_ENABLED diff --git a/pw_build/platforms/BUILD.bazel b/pw_build/platforms/BUILD.bazel index 7cb60dd6af..e9540928f0 100644 --- a/pw_build/platforms/BUILD.bazel +++ b/pw_build/platforms/BUILD.bazel @@ -11,6 +11,9 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations under # the License. + +load("//pw_build:merge_flags.bzl", "flags_from_dict") + package(default_visibility = ["//visibility:public"]) # -------------------- @@ -53,6 +56,10 @@ platform( "@platforms//os:none", "@rust_crates//:no_std", ], + flags = flags_from_dict({ + "@pigweed//pw_log/rust:pw_log_backend": "//pw_rust/examples/tokenized_logging:pw_log_backend", + "@pigweed//pw_sys_io:backend": "//pw_sys_io_baremetal_lm3s6965evb", + }), ) platform( diff --git a/pw_stream/mpsc_stream_test.cc b/pw_stream/mpsc_stream_test.cc index 2e7c76b5f4..30d834f938 100644 --- a/pw_stream/mpsc_stream_test.cc +++ b/pw_stream/mpsc_stream_test.cc @@ -21,6 +21,10 @@ #include "pw_thread/thread.h" #include "pw_unit_test/framework.h" +// TODO: https://pwbug.dev/365161669 - Express joinability as a build-system +// constraint. +#if PW_THREAD_JOINING_ENABLED + namespace pw::stream { namespace { @@ -593,3 +597,5 @@ TEST(MpscStreamTest, BufferedMpscReader) { } // namespace } // namespace pw::stream + +#endif // PW_THREAD_JOINING_ENABLED diff --git a/targets/rp2040/BUILD.bazel b/targets/rp2040/BUILD.bazel index 22520bb0d7..00af6a3ab3 100644 --- a/targets/rp2040/BUILD.bazel +++ b/targets/rp2040/BUILD.bazel @@ -12,9 +12,10 @@ # License for the specific language governing permissions and limitations under # the License. +load("//pw_build:merge_flags.bzl", "flags_from_dict") load("//pw_build:pigweed.bzl", "pw_cc_binary") load("//targets/rp2040:flash.bzl", "flash_rp2040") -load("//targets/rp2040:transition.bzl", "rp2040_binary") +load("//targets/rp2040:transition.bzl", "RP2_SYSTEM_FLAGS", "rp2040_binary") package(default_visibility = ["//visibility:public"]) @@ -44,6 +45,7 @@ platform( "@rust_crates//:no_std", "@platforms//os:none", ], + flags = flags_from_dict(RP2_SYSTEM_FLAGS), visibility = ["//visibility:private"], ) diff --git a/targets/rp2040/transition.bzl b/targets/rp2040/transition.bzl index f7e95a2682..af84698c8f 100644 --- a/targets/rp2040/transition.bzl +++ b/targets/rp2040/transition.bzl @@ -14,10 +14,9 @@ """Bazel transitions for the rp2xxx series.""" -load("//pw_build:merge_flags.bzl", "merge_flags_for_transition_impl", "merge_flags_for_transition_outputs") +load("@rules_platform//platform_data:defs.bzl", "platform_data") load("//third_party/freertos:flags.bzl", "FREERTOS_FLAGS") -# LINT.IfChange # Typical RP2040 pw_system backends and other platform configuration flags. RP2_SYSTEM_FLAGS = FREERTOS_FLAGS | { "@freertos//:freertos_config": str(Label("//targets/rp2040:freertos_config")), @@ -46,72 +45,9 @@ RP2_SYSTEM_FLAGS = FREERTOS_FLAGS | { "@pigweed//pw_unit_test:backend": str(Label("//pw_unit_test:light")), "@pigweed//pw_unit_test:main": str(Label("//targets/rp2040:unit_test_app")), } -# LINT.ThenChange(//.bazelrc) -# Additional flags specific to the upstream Pigweed RP2040 platform. -_rp2040_flags = { - "//command_line_option:platforms": str(Label("//targets/rp2040:rp2040")), -} - -_rp2350_flags = { - "//command_line_option:platforms": str(Label("//targets/rp2040:rp2350")), -} - -def _rp2_transition(device_specific_flags): - def _rp2_transition_impl(settings, attr): - # buildifier: disable=unused-variable - _ignore = settings, attr - return merge_flags_for_transition_impl( - base = RP2_SYSTEM_FLAGS, - override = device_specific_flags, - ) - - return transition( - implementation = _rp2_transition_impl, - inputs = [], - outputs = merge_flags_for_transition_outputs( - base = RP2_SYSTEM_FLAGS, - override = device_specific_flags, - ), - ) - -def _rp2_binary_impl(ctx): - out = ctx.actions.declare_file(ctx.label.name) - ctx.actions.symlink(output = out, is_executable = True, target_file = ctx.executable.binary) - return [DefaultInfo(files = depset([out]), executable = out)] - -rp2040_binary = rule( - _rp2_binary_impl, - attrs = { - "binary": attr.label( - doc = "cc_binary to build for the rp2040", - cfg = _rp2_transition(_rp2040_flags), - executable = True, - mandatory = True, - ), - "_allowlist_function_transition": attr.label( - default = "@bazel_tools//tools/allowlists/function_transition_allowlist", - ), - }, - doc = "Builds the specified binary for the rp2040 platform", - # This target is for rp2040 and can't be run on host. - executable = False, -) +def rp2040_binary(name = "", binary = "", testonly = False): + return platform_data(name = name, target = binary, testonly = testonly, platform = "//targets/rp2040:rp2040") -rp2350_binary = rule( - _rp2_binary_impl, - attrs = { - "binary": attr.label( - doc = "cc_binary to build for the rp2040", - cfg = _rp2_transition(_rp2350_flags), - executable = True, - mandatory = True, - ), - "_allowlist_function_transition": attr.label( - default = "@bazel_tools//tools/allowlists/function_transition_allowlist", - ), - }, - doc = "Builds the specified binary for the rp2350 platform", - # This target is for rp2350 and can't be run on host. - executable = False, -) +def rp2350_binary(name = "", binary = "", testonly = False): + return platform_data(name = name, target = binary, testonly = testonly, platform = "//targets/rp2040:rp2350") diff --git a/targets/stm32f429i_disc1/BUILD.bazel b/targets/stm32f429i_disc1/BUILD.bazel index 6070ba22dd..8c65d7c406 100644 --- a/targets/stm32f429i_disc1/BUILD.bazel +++ b/targets/stm32f429i_disc1/BUILD.bazel @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations under # the License. +load("//pw_build:merge_flags.bzl", "flags_from_dict") load( "//pw_build:pigweed.bzl", "pw_linker_script", @@ -32,6 +33,16 @@ platform( "@pw_toolchain//constraints/arm_mcpu:cortex-m4", "@rust_crates//:no_std", ], + flags = flags_from_dict({ + "@pigweed//pw_assert:check_backend": "//pw_assert_basic", + "@pigweed//pw_assert:check_backend_impl": "//pw_assert_basic:impl", + "@pigweed//pw_boot:backend": "//pw_boot_cortex_m", + "@pigweed//pw_log:backend": "//pw_log_basic", + "@pigweed//pw_log:backend_impl": "//pw_log_basic:impl", + "@pigweed//pw_malloc:backend": "//pw_malloc:bucket_block_allocator", + "@pigweed//pw_sys_io:backend": "//pw_sys_io_baremetal_stm32f429", + "@pigweed//pw_system:extra_platform_libs": "//targets/stm32f429i_disc1:extra_platform_libs", + }), ) cc_library( diff --git a/targets/stm32f429i_disc1_stm32cube/BUILD.bazel b/targets/stm32f429i_disc1_stm32cube/BUILD.bazel index e02a75de65..d03ef1f7ef 100644 --- a/targets/stm32f429i_disc1_stm32cube/BUILD.bazel +++ b/targets/stm32f429i_disc1_stm32cube/BUILD.bazel @@ -12,10 +12,12 @@ # License for the specific language governing permissions and limitations under # the License. +load("//pw_build:merge_flags.bzl", "flags_from_dict") load( "//pw_build:pigweed.bzl", "pw_linker_script", ) +load("//third_party/freertos:flags.bzl", "FREERTOS_FLAGS") package(default_visibility = ["//visibility:public"]) @@ -43,8 +45,6 @@ constraint_value( constraint_setting = "@freertos//:freertos_config_setting", ) -# TODO: b/301334234 - Set the flags currently in the stm32f429i config in -# .bazelrc using this platform, once that's supported. platform( name = "platform", constraint_values = [ @@ -59,6 +59,27 @@ platform( "@pw_toolchain//constraints/arm_mcpu:cortex-m4", "@rust_crates//:no_std", ], + flags = flags_from_dict(FREERTOS_FLAGS | { + "@pigweed//pw_assert:check_backend": "//pw_assert_basic", + "@pigweed//pw_assert:check_backend_impl": "//pw_assert_basic:impl", + "@pigweed//pw_boot:backend": "//pw_boot_cortex_m", + "@pigweed//pw_log:backend": "//pw_log_tokenized", + "@pigweed//pw_log:backend_impl": "//pw_log_tokenized:impl", + "@pigweed//pw_log_tokenized:handler_backend": "//pw_system:log_backend", + "@pigweed//pw_malloc:backend": "//pw_malloc:bucket_block_allocator", + "@pigweed//pw_sys_io:backend": "//pw_sys_io_stm32cube", + "@pigweed//pw_system:extra_platform_libs": "//targets/stm32f429i_disc1_stm32cube:extra_platform_libs", + "@pigweed//pw_unit_test:main": "//targets/stm32f429i_disc1_stm32cube:unit_test_app", + "@stm32f4xx_hal_driver//:hal_config": "//targets/stm32f429i_disc1_stm32cube:hal_config", + }), + # These flags should be added once + # https://github.com/bazelbuild/bazel/issues/22453 + # is fixed. + # + # + [ + # "--copt=\"-DSTM32CUBE_HEADER=\\\"stm32f4xx.h\\\"\"", + # "--copt=\"-DSTM32F429xx\"", + # ], ) cc_library(