bazel: Use platform-based flags
Somehow, we missed updating this repository!
Test: Used diff to verify the STM32 and RP2040 binaries before and after
Test: this CL are identical.
Bug: 301334234
Change-Id: I893d9ae3b723446a295706547390fc225d17768e
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/examples/+/256632
Pigweed-Auto-Submit: Ted Pudlik <tpudlik@google.com>
Reviewed-by: Erik Gilling <konkers@google.com>
Lint: Lint 🤖 <android-build-ayeaye@system.gserviceaccount.com>
Reviewed-by: Ronan Chauvin <ronanchauvin@gmail.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed-service-accounts.iam.gserviceaccount.com>
diff --git a/MODULE.bazel b/MODULE.bazel
index 9bcb2aa..c84d294 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -23,6 +23,7 @@
bazel_dep(name = "pw_toolchain")
bazel_dep(name = "rules_cc", version = "0.0.10")
bazel_dep(name = "rules_fuzzing", version = "0.5.2")
+bazel_dep(name = "rules_platform", version = "0.1.0")
bazel_dep(name = "rules_python", version = "0.36.0")
local_path_override(
diff --git a/targets/rp2040/BUILD.bazel b/targets/rp2040/BUILD.bazel
index 52430f3..7dbcc34 100644
--- a/targets/rp2040/BUILD.bazel
+++ b/targets/rp2040/BUILD.bazel
@@ -12,6 +12,9 @@
# License for the specific language governing permissions and limitations under
# the License.
+load("@pigweed//pw_build:merge_flags.bzl", "flags_from_dict")
+load("@pigweed//targets/rp2040:transition.bzl", "RP2_SYSTEM_FLAGS")
+
package(default_visibility = ["//visibility:public"])
platform(
@@ -30,6 +33,9 @@
"@platforms//cpu:armv6-m",
"@pigweed//pw_build/constraints/arm:cortex-m0",
],
+ flags = flags_from_dict(RP2_SYSTEM_FLAGS | {
+ "@pigweed//pw_system:extra_platform_libs": "//targets/rp2040:extra_platform_libs",
+ }),
)
cc_library(
diff --git a/targets/stm32f429i_disc1_stm32cube/BUILD.bazel b/targets/stm32f429i_disc1_stm32cube/BUILD.bazel
index 04946cf..be65ee2 100644
--- a/targets/stm32f429i_disc1_stm32cube/BUILD.bazel
+++ b/targets/stm32f429i_disc1_stm32cube/BUILD.bazel
@@ -12,7 +12,9 @@
# License for the specific language governing permissions and limitations under
# the License.
-load("@pigweed//pw_build:pigweed.bzl", "pw_linker_script")
+load("@pigweed//pw_build:merge_flags.bzl", "flags_from_dict")
+load("@pigweed//pw_build:pw_linker_script.bzl", "pw_linker_script")
+load("@pigweed//third_party/freertos:flags.bzl", "FREERTOS_FLAGS")
package(default_visibility = ["//visibility:public"])
@@ -31,6 +33,35 @@
"@platforms//cpu:armv7e-m",
"@pigweed//pw_build/constraints/arm:cortex-m4",
],
+ flags = flags_from_dict(FREERTOS_FLAGS | {
+ "@cmsis_core//:cc_defines": ":cmsis_cc_defines",
+ "@cmsis_device//:cmsis_core": "@cmsis_core",
+ "@freertos//:freertos_config": "@pigweed//third_party/freertos:freertos_config",
+ "@hal_driver//:cmsis_device": "@cmsis_device",
+ "@hal_driver//:cmsis_init": "@cmsis_device//:default_cmsis_init",
+ "@hal_driver//:hal_config": "@pigweed//targets/stm32f429i_disc1_stm32cube:hal_config",
+ "@pigweed//pw_assert:backend": "@pigweed//pw_assert_basic",
+ "@pigweed//pw_assert:backend_impl": "@pigweed//pw_assert_basic:impl",
+ "@pigweed//pw_assert:check_backend": "@pigweed//pw_assert_basic",
+ "@pigweed//pw_assert:check_backend_impl": "@pigweed//pw_assert_basic:impl",
+ "@pigweed//pw_boot:backend": "@pigweed//pw_boot_cortex_m",
+ "@pigweed//pw_interrupt:backend": "@pigweed//pw_interrupt_cortex_m:context",
+ "@pigweed//pw_log:backend": "@pigweed//pw_log_tokenized",
+ "@pigweed//pw_log:backend_impl": "@pigweed//pw_log_tokenized:impl",
+ "@pigweed//pw_log_tokenized:handler_backend": "@pigweed//pw_system:log_backend",
+ "@pigweed//pw_malloc:backend": "@pigweed//pw_malloc_freelist",
+ "@pigweed//pw_sys_io:backend": "@pigweed//pw_sys_io_stm32cube",
+ "@pigweed//pw_system:extra_platform_libs": "//targets/stm32f429i_disc1_stm32cube:extra_platform_libs",
+ "@pigweed//third_party/stm32cube:hal_driver": "@hal_driver",
+ }),
+)
+
+cc_library(
+ name = "cmsis_cc_defines",
+ defines = [
+ "STM32CUBE_HEADER=\\\"stm32f4xx.h\\\"",
+ "STM32F429xx",
+ ],
)
pw_linker_script(
diff --git a/targets/transition.bzl b/targets/transition.bzl
index 2d4bfa7..b2cc968 100644
--- a/targets/transition.bzl
+++ b/targets/transition.bzl
@@ -12,105 +12,12 @@
# License for the specific language governing permissions and limitations under
# the License.
-"""Bazel transitions for sample project examples.
+"""Bazel transitions for sample project examples."""
-TODO: b/301334234 - Use platform-based flags and retire these transitions.
-"""
+load("@rules_platform//platform_data:defs.bzl", "platform_data")
-load("@pigweed//pw_build:merge_flags.bzl", "merge_flags_for_transition_impl", "merge_flags_for_transition_outputs")
-load("@pigweed//targets/rp2040:transition.bzl", "RP2_SYSTEM_FLAGS")
-load("@pigweed//third_party/freertos:flags.bzl", "FREERTOS_FLAGS")
+def rp2040_binary(*, name = "", binary = "", **kwargs):
+ return platform_data(name = name, target = binary, platform = "//targets/rp2040:platform", **kwargs)
-_stm32_overrides = {
- "//command_line_option:copt": ["-DSTM32CUBE_HEADER=\"stm32f4xx.h\"", "-DSTM32F429xx"],
- "//command_line_option:platforms": "//targets/stm32f429i_disc1_stm32cube:platform",
- "@cmsis_device//:cmsis_core": "@cmsis_core",
- "@freertos//:freertos_config": "@pigweed//third_party/freertos:freertos_config",
- "@hal_driver//:cmsis_device": "@cmsis_device",
- "@hal_driver//:cmsis_init": "@cmsis_device//:default_cmsis_init",
- "@hal_driver//:hal_config": "@pigweed//targets/stm32f429i_disc1_stm32cube:hal_config",
- "@pigweed//pw_assert:backend": "@pigweed//pw_assert_basic",
- "@pigweed//pw_assert:backend_impl": "@pigweed//pw_assert_basic:impl",
- "@pigweed//pw_assert:check_backend": "@pigweed//pw_assert_basic",
- "@pigweed//pw_assert:check_backend_impl": "@pigweed//pw_assert_basic:impl",
- "@pigweed//pw_boot:backend": "@pigweed//pw_boot_cortex_m",
- "@pigweed//pw_interrupt:backend": "@pigweed//pw_interrupt_cortex_m:context",
- "@pigweed//pw_log:backend": "@pigweed//pw_log_tokenized",
- "@pigweed//pw_log:backend_impl": "@pigweed//pw_log_tokenized:impl",
- "@pigweed//pw_log_tokenized:handler_backend": "@pigweed//pw_system:log_backend",
- "@pigweed//pw_malloc:backend": "@pigweed//pw_malloc_freelist",
- "@pigweed//pw_sys_io:backend": "@pigweed//pw_sys_io_stm32cube",
- "@pigweed//pw_system:extra_platform_libs": "//targets/stm32f429i_disc1_stm32cube:extra_platform_libs",
- "@pigweed//third_party/stm32cube:hal_driver": "@hal_driver",
-}
-
-def _stm32_transition_impl(settings, attr):
- # buildifier: disable=unused-variable
- _ignore = settings, attr
-
- return merge_flags_for_transition_impl(base = FREERTOS_FLAGS, override = _stm32_overrides)
-
-_stm32_transition = transition(
- implementation = _stm32_transition_impl,
- inputs = [],
- outputs = merge_flags_for_transition_outputs(base = FREERTOS_FLAGS, override = _stm32_overrides),
-)
-
-def _stm32_binary_impl(ctx):
- out = ctx.actions.declare_file(ctx.label.name)
- ctx.actions.symlink(output = out, target_file = ctx.executable.binary)
- return [DefaultInfo(files = depset([out]), executable = out)]
-
-stm32_binary = rule(
- _stm32_binary_impl,
- attrs = {
- "binary": attr.label(
- doc = "cc_binary to build for stm32f429i_disc1_stm32cube.",
- cfg = _stm32_transition,
- executable = True,
- mandatory = True,
- ),
- "_allowlist_function_transition": attr.label(
- default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
- ),
- },
- doc = "Builds the specified binary for the stm32f429i_disc1_stm32cube platform.",
-)
-
-_rp2040_overrides = {
- "//command_line_option:platforms": "//targets/rp2040:platform",
- "@pigweed//pw_system:extra_platform_libs": "//targets/rp2040:extra_platform_libs",
-}
-
-def _rp2040_transition_impl(settings, attr):
- # buildifier: disable=unused-variable
- _ignore = settings, attr
-
- return merge_flags_for_transition_impl(base = RP2_SYSTEM_FLAGS, override = _rp2040_overrides)
-
-_rp2040_transition = transition(
- implementation = _rp2040_transition_impl,
- inputs = [],
- outputs = merge_flags_for_transition_outputs(base = RP2_SYSTEM_FLAGS, override = _rp2040_overrides),
-)
-
-def _rp2040_binary_impl(ctx):
- out = ctx.actions.declare_file(ctx.label.name)
- ctx.actions.symlink(output = out, target_file = ctx.executable.binary)
- return [DefaultInfo(files = depset([out]), executable = out)]
-
-rp2040_binary = rule(
- _rp2040_binary_impl,
- attrs = {
- "binary": attr.label(
- doc = "cc_binary to build for rp2040 using pico-sdk.",
- cfg = _rp2040_transition,
- executable = True,
- mandatory = True,
- ),
- "_allowlist_function_transition": attr.label(
- default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
- ),
- },
- doc = "Builds the specified binary for the pico-sdk rp2040 platform.",
-)
+def stm32_binary(*, name = "", binary = "", **kwargs):
+ return platform_data(name = name, target = binary, platform = "//targets/stm32f429i_disc1_stm32cube:platform", **kwargs)