mirror of
https://fuchsia.googlesource.com/third_party/pigweed.googlesource.com/pigweed/pigweed
synced 2024-07-12 01:23:34 +00:00
bazel: Provide backend collections as dicts
Implements the pattern suggested in https://pigweed.dev/bazel_compatibility.html#provide-default-backend-collections-as-dicts. See http://pwrev.dev/219871 for an example of how this is intended to be used. We'll probably remove the merge_flags_for_transition_impl and merge_flags_for_transition_outputs helpers once we've migrated to platform-based flags. Bug: 344654805 Change-Id: Id93bfee331e37b261a5d4d788093d4f927ed2ba1 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/219911 Lint: Ted Pudlik <tpudlik@google.com> Reviewed-by: Taylor Cramer <cramertj@google.com> Commit-Queue: Ted Pudlik <tpudlik@google.com>
This commit is contained in:
parent
4a79fe82a3
commit
db3b2adb2d
51
pw_build/merge_flags.bzl
Normal file
51
pw_build/merge_flags.bzl
Normal file
|
@ -0,0 +1,51 @@
|
|||
# Copyright 2024 The Pigweed Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
# use this file except in compliance with the License. You may obtain a copy of
|
||||
# the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations under
|
||||
# the License.
|
||||
"""Functions for merging flags for platforms and transitions."""
|
||||
|
||||
def merge_flags(base, override):
|
||||
"""Merge flags for platforms.
|
||||
|
||||
See https://pigweed.dev/bazel_compatibility.html#provide-default-backend-collections-as-dicts
|
||||
for a usage example.
|
||||
|
||||
Args:
|
||||
base: Dict of flags to use as the starting point. Typically one of
|
||||
the dictionaries provided in @pigweed//pw_build:backends.bzl.
|
||||
override: Dict of overrides or additions to the base dict.
|
||||
|
||||
Returns:
|
||||
A list of flags in a format accepted by the `flags` attribute of `platform`.
|
||||
"""
|
||||
flags = base | override
|
||||
return ["--{}={}".format(k, v) for k, v in flags.items()]
|
||||
|
||||
def merge_flags_for_transition_impl(base, override):
|
||||
"""Merge flags for a transition's impl function.
|
||||
|
||||
Args:
|
||||
base: Dict of flags to use as the starting point. Typically one of
|
||||
the dictionaries provided in @pigweed//pw_build:backends.bzl.
|
||||
override: Dict of overrides or additions to the base dict.
|
||||
"""
|
||||
return base | override
|
||||
|
||||
def merge_flags_for_transition_outputs(base, override):
|
||||
"""Merge flags for a transition's output function.
|
||||
|
||||
Args:
|
||||
base: Dict of flags to use as the starting point. Typically one of
|
||||
the dictionaries provided in @pigweed//pw_build:backends.bzl.
|
||||
override: Dict of overrides or additions to the base dict.
|
||||
"""
|
||||
return (base | override).keys()
|
|
@ -14,68 +14,43 @@
|
|||
|
||||
"""Bazel transitions for the rp2040."""
|
||||
|
||||
load("//pw_build:merge_flags.bzl", "merge_flags_for_transition_impl", "merge_flags_for_transition_outputs")
|
||||
load("//third_party/freertos:flags.bzl", "FREERTOS_FLAGS")
|
||||
|
||||
# LINT.IfChange
|
||||
# Typical RP2040 pw_system backends and other platform configuration flags.
|
||||
RP2040_SYSTEM_FLAGS = FREERTOS_FLAGS | {
|
||||
"@freertos//:freertos_config": "@pigweed//targets/rp2040:freertos_config",
|
||||
"@pico-sdk//bazel/config:PICO_STDIO_UART": True,
|
||||
"@pico-sdk//bazel/config:PICO_STDIO_USB": True,
|
||||
"@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_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_sys_io:backend": "@pigweed//pw_sys_io_rp2040",
|
||||
"@pigweed//pw_system:extra_platform_libs": "@pigweed//targets/rp2040:extra_platform_libs",
|
||||
"@pigweed//pw_unit_test:main": "@pigweed//targets/rp2040:unit_test_app",
|
||||
}
|
||||
|
||||
# Additional flags specific to the upstream Pigweed RP2040 platform.
|
||||
_rp2040_flags = {
|
||||
"//command_line_option:platforms": "@pigweed//targets/rp2040",
|
||||
}
|
||||
# LINT.ThenChange(//.bazelrc)
|
||||
|
||||
def _rp2040_transition_impl(settings, attr):
|
||||
# buildifier: disable=unused-variable
|
||||
_ignore = settings, attr
|
||||
return {
|
||||
"//command_line_option:platforms": "@pigweed//targets/rp2040",
|
||||
"@freertos//:freertos_config": "@pigweed//targets/rp2040:freertos_config",
|
||||
"@pico-sdk//bazel/config:PICO_STDIO_UART": True,
|
||||
"@pico-sdk//bazel/config:PICO_STDIO_USB": True,
|
||||
"@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_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_sync:binary_semaphore_backend": "@pigweed//pw_sync_freertos:binary_semaphore",
|
||||
"@pigweed//pw_sync:interrupt_spin_lock_backend": "@pigweed//pw_sync_freertos:interrupt_spin_lock",
|
||||
"@pigweed//pw_sync:mutex_backend": "@pigweed//pw_sync_freertos:mutex",
|
||||
"@pigweed//pw_sync:thread_notification_backend": "@pigweed//pw_sync_freertos:thread_notification",
|
||||
"@pigweed//pw_sync:timed_thread_notification_backend": "@pigweed//pw_sync_freertos:timed_thread_notification",
|
||||
"@pigweed//pw_sys_io:backend": "@pigweed//pw_sys_io_rp2040",
|
||||
"@pigweed//pw_system:extra_platform_libs": "@pigweed//targets/rp2040:extra_platform_libs",
|
||||
"@pigweed//pw_thread:id_backend": "@pigweed//pw_thread_freertos:id",
|
||||
"@pigweed//pw_thread:iteration_backend": "@pigweed//pw_thread_freertos:thread_iteration",
|
||||
"@pigweed//pw_thread:sleep_backend": "@pigweed//pw_thread_freertos:sleep",
|
||||
"@pigweed//pw_thread:thread_backend": "@pigweed//pw_thread_freertos:thread",
|
||||
"@pigweed//pw_unit_test:main": "@pigweed//targets/rp2040:unit_test_app",
|
||||
}
|
||||
|
||||
# LINT.ThenChange(//.bazelrc)
|
||||
return merge_flags_for_transition_impl(base = RP2040_SYSTEM_FLAGS, override = _rp2040_flags)
|
||||
|
||||
_rp2040_transition = transition(
|
||||
implementation = _rp2040_transition_impl,
|
||||
inputs = [],
|
||||
outputs = [
|
||||
"//command_line_option:platforms",
|
||||
"@freertos//:freertos_config",
|
||||
"@pico-sdk//bazel/config:PICO_STDIO_USB",
|
||||
"@pico-sdk//bazel/config:PICO_STDIO_UART",
|
||||
"@pigweed//pw_assert:backend",
|
||||
"@pigweed//pw_assert:backend_impl",
|
||||
"@pigweed//pw_assert:check_backend",
|
||||
"@pigweed//pw_assert:check_backend_impl",
|
||||
"@pigweed//pw_interrupt:backend",
|
||||
"@pigweed//pw_log:backend",
|
||||
"@pigweed//pw_log:backend_impl",
|
||||
"@pigweed//pw_log_tokenized:handler_backend",
|
||||
"@pigweed//pw_sync:binary_semaphore_backend",
|
||||
"@pigweed//pw_sync:interrupt_spin_lock_backend",
|
||||
"@pigweed//pw_sync:mutex_backend",
|
||||
"@pigweed//pw_sync:thread_notification_backend",
|
||||
"@pigweed//pw_sync:timed_thread_notification_backend",
|
||||
"@pigweed//pw_sys_io:backend",
|
||||
"@pigweed//pw_system:extra_platform_libs",
|
||||
"@pigweed//pw_thread:id_backend",
|
||||
"@pigweed//pw_thread:sleep_backend",
|
||||
"@pigweed//pw_thread:thread_backend",
|
||||
"@pigweed//pw_thread:iteration_backend",
|
||||
"@pigweed//pw_unit_test:main",
|
||||
],
|
||||
outputs = merge_flags_for_transition_outputs(base = RP2040_SYSTEM_FLAGS, override = _rp2040_flags),
|
||||
)
|
||||
|
||||
def _rp2040_binary_impl(ctx):
|
||||
|
|
30
third_party/freertos/flags.bzl
vendored
Normal file
30
third_party/freertos/flags.bzl
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
# Copyright 2024 The Pigweed Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
# use this file except in compliance with the License. You may obtain a copy of
|
||||
# the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations under
|
||||
# the License.
|
||||
"""Typical FreeRTOS backends and other platform configuration flags."""
|
||||
|
||||
# LINT.IfChange
|
||||
FREERTOS_FLAGS = {
|
||||
"@pigweed//pw_chrono:system_clock_backend": "@pigweed//pw_chrono_freertos:system_clock",
|
||||
"@pigweed//pw_chrono:system_timer_backend": "@pigweed//pw_chrono_freertos:system_timer",
|
||||
"@pigweed//pw_sync:binary_semaphore_backend": "@pigweed//pw_sync_freertos:binary_semaphore",
|
||||
"@pigweed//pw_sync:interrupt_spin_lock_backend": "@pigweed//pw_sync_freertos:interrupt_spin_lock",
|
||||
"@pigweed//pw_sync:mutex_backend": "@pigweed//pw_sync_freertos:mutex",
|
||||
"@pigweed//pw_sync:thread_notification_backend": "@pigweed//pw_sync_freertos:thread_notification",
|
||||
"@pigweed//pw_sync:timed_thread_notification_backend": "@pigweed//pw_sync_freertos:timed_thread_notification",
|
||||
"@pigweed//pw_thread:id_backend": "@pigweed//pw_thread_freertos:id",
|
||||
"@pigweed//pw_thread:iteration_backend": "@pigweed//pw_thread_freertos:thread_iteration",
|
||||
"@pigweed//pw_thread:sleep_backend": "@pigweed//pw_thread_freertos:sleep",
|
||||
"@pigweed//pw_thread:thread_backend": "@pigweed//pw_thread_freertos:thread",
|
||||
}
|
||||
# LINT.ThenChange(//.bazelrc)
|
Loading…
Reference in New Issue
Block a user