Skip to content

Commit fd64ca3

Browse files
Initial Pico 2 W Bazel support
Improves compatibility with Pico W and Pico 2 W by fixing issues that prevented correct linking of wireless libraries.
1 parent 1b64cac commit fd64ca3

File tree

15 files changed

+255
-71
lines changed

15 files changed

+255
-71
lines changed

bazel/config/BUILD.bazel

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,31 @@ string_flag(
245245
# PICO_BAZEL_CONFIG: PICO_BTSTACK_CONFIG, [Bazel only] The cc_library that provides btstack_config.h, default=//bazel:empty_cc_lib, group=wireless
246246
label_flag(
247247
name = "PICO_BTSTACK_CONFIG",
248-
build_setting_default = "//bazel:empty_cc_lib",
248+
build_setting_default = "//bazel:incompatible_cc_lib",
249+
)
250+
251+
# PICO_BAZEL_CONFIG: PICO_BT_ENABLE_BLE, [Bazel only] Whether or not to link in BLE portions of the btstack as part of //src/rp2_common/pico_btstack. Also defines ENABLE_BLE=1, type=bool, default=False, group=wireless
252+
bool_flag(
253+
name = "PICO_BT_ENABLE_BLE",
254+
build_setting_default = False,
255+
)
256+
257+
# PICO_BAZEL_CONFIG: PICO_BT_ENABLE_CLASSIC, [Bazel only] Whether or not to link in classic BT portions of the btstack as part of //src/rp2_common/pico_btstack. Also defines ENABLE_CLASSIC=1, type=bool, default=False, group=wireless
258+
bool_flag(
259+
name = "PICO_BT_ENABLE_CLASSIC",
260+
build_setting_default = False,
261+
)
262+
263+
# PICO_BAZEL_CONFIG: PICO_BT_ENABLE_MESH, [Bazel only] Whether or not to link in mesh BT portions of the btstack as part of //src/rp2_common/pico_btstack. Also defines ENABLE_MESH=1, type=bool, default=False, group=wireless
264+
bool_flag(
265+
name = "PICO_BT_ENABLE_MESH",
266+
build_setting_default = False,
249267
)
250268

251269
# PICO_BAZEL_CONFIG: PICO_LWIP_CONFIG, [Bazel only] The cc_library that provides lwipopts.h, default=//bazel:empty_cc_lib, group=wireless
252270
label_flag(
253271
name = "PICO_LWIP_CONFIG",
254-
build_setting_default = "//bazel:empty_cc_lib",
272+
build_setting_default = "//bazel:incompatible_cc_lib",
255273
)
256274

257275
# PICO_BAZEL_CONFIG: PICO_FREERTOS_LIB, [Bazel only] The cc_library that provides FreeRTOS, default=//bazel:empty_cc_lib, group=wireless

bazel/constraint/BUILD.bazel

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ config_setting(
4848
flag_values = {"//bazel/config:PICO_BOARD": "pico_w"},
4949
)
5050

51+
config_setting(
52+
name = "is_pico2_w",
53+
flag_values = {"//bazel/config:PICO_BOARD": "pico2_w"},
54+
)
55+
5156
config_setting(
5257
name = "pico_toolchain_clang_enabled",
5358
flag_values = {"//bazel/config:PICO_TOOLCHAIN": "clang"},
@@ -199,13 +204,18 @@ config_setting(
199204
)
200205

201206
config_setting(
202-
name = "pico_btstack_config_unset",
203-
flag_values = {"//bazel/config:PICO_BTSTACK_CONFIG": "//bazel:empty_cc_lib"},
207+
name = "pico_bt_enable_ble_enabled",
208+
flag_values = {"//bazel/config:PICO_BT_ENABLE_BLE": "True"},
209+
)
210+
211+
config_setting(
212+
name = "pico_bt_enable_classic_enabled",
213+
flag_values = {"//bazel/config:PICO_BT_ENABLE_CLASSIC": "True"},
204214
)
205215

206216
config_setting(
207-
name = "pico_lwip_config_unset",
208-
flag_values = {"//bazel/config:PICO_LWIP_CONFIG": "//bazel:empty_cc_lib"},
217+
name = "pico_bt_enable_mesh_enabled",
218+
flag_values = {"//bazel/config:PICO_BT_ENABLE_MESH": "True"},
209219
)
210220

211221
config_setting(

bazel/defs.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def compatible_with_pico_w():
8888
return select({
8989
"@pico-sdk//bazel/constraint:cyw43_wireless": [],
9090
"@pico-sdk//bazel/constraint:is_pico_w": [],
91+
"@pico-sdk//bazel/constraint:is_pico2_w": [],
9192
"//conditions:default": ["@platforms//:incompatible"],
9293
})
9394

bazel/util/transition.bzl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
def _normalize_flag_value(val):
2+
"""Converts flag values to transition-safe primitives."""
3+
if type(val) == "label":
4+
return str(val)
5+
return val
6+
17
def declare_transtion(attrs, flag_overrides = None, append_to_flags = None, executable = True):
28
"""A helper that drastically simplifies declaration of a transition.
39
@@ -31,7 +37,7 @@ def declare_transtion(attrs, flag_overrides = None, append_to_flags = None, exec
3137
final_overrides = {}
3238
if flag_overrides != None:
3339
final_overrides = {
34-
key: str(getattr(attrs, value))
40+
key: _normalize_flag_value(getattr(attrs, value))
3541
for key, value in flag_overrides.items()
3642
}
3743
if append_to_flags != None:
@@ -108,6 +114,8 @@ kitchen_sink_test_binary = declare_transtion(
108114
attrs = {
109115
"bt_stack_config": attr.label(mandatory = True),
110116
"lwip_config": attr.label(mandatory = True),
117+
"enable_ble": attr.bool(default = False),
118+
"enable_bt_classic": attr.bool(default = False),
111119
# This could be shared, but we don't in order to make it clearer that
112120
# a transition is in use.
113121
"_allowlist_function_transition": attr.label(
@@ -117,6 +125,8 @@ kitchen_sink_test_binary = declare_transtion(
117125
flag_overrides = {
118126
"@pico-sdk//bazel/config:PICO_BTSTACK_CONFIG": "bt_stack_config",
119127
"@pico-sdk//bazel/config:PICO_LWIP_CONFIG": "lwip_config",
128+
"@pico-sdk//bazel/config:PICO_BT_ENABLE_BLE": "enable_ble",
129+
"@pico-sdk//bazel/config:PICO_BT_ENABLE_CLASSIC": "enable_bt_classic",
120130
},
121131
)
122132

src/rp2_common/pico_btstack/BUILD.bazel

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,27 @@ load("//bazel:defs.bzl", "compatible_with_pico_w", "incompatible_with_config")
22

33
package(default_visibility = ["//visibility:public"])
44

5+
# Prefer using this target to link in all the enabled bt modules, as it will
6+
# link the appropriate libraries and set the appropraite defines based on the
7+
# following flags:
8+
#
9+
# --@pico-sdk//bazel/constraint:PICO_BT_ENABLE_BLE
10+
# --@pico-sdk//bazel/constraint:PICO_BT_ENABLE_CLASSIC
11+
# --@pico-sdk//bazel/constraint:PICO_BT_ENABLE_MESH
12+
cc_library(
13+
name = "pico_btstack",
14+
deps = ["pico_btstack_base"] + select({
15+
"//bazel/constraint:pico_bt_enable_ble_enabled": [":pico_btstack_ble"],
16+
"//conditions:default": [],
17+
}) + select({
18+
"//bazel/constraint:pico_bt_enable_classic_enabled": [":pico_btstack_classic"],
19+
"//conditions:default": [],
20+
}) + select({
21+
"//bazel/constraint:pico_bt_enable_mesh_enabled": [":pico_btstack_mesh"],
22+
"//conditions:default": [],
23+
}),
24+
)
25+
526
# Prefer these aliases to directly referencing @btstack, as it's possible that
627
# name may change.
728
alias(
@@ -19,6 +40,11 @@ alias(
1940
actual = "@btstack//:pico_btstack_classic",
2041
)
2142

43+
alias(
44+
name = "pico_btstack_mesh",
45+
actual = "@btstack//:pico_btstack_classic",
46+
)
47+
2248
alias(
2349
name = "pico_btstack_sbc_encoder",
2450
actual = "@btstack//:pico_btstack_classic",
@@ -63,10 +89,9 @@ cc_library(
6389
cc_library(
6490
name = "pico_btstack_stdin",
6591
srcs = ["btstack_stdin_pico.c"],
66-
target_compatible_with = incompatible_with_config(
67-
"//bazel/constraint:pico_btstack_config_unset",
68-
) + compatible_with_pico_w(),
92+
target_compatible_with = compatible_with_pico_w(),
6993
deps = [
94+
"//bazel/config:PICO_BTSTACK_CONFIG",
7095
"//src/rp2_common:pico_platform",
7196
"//src/rp2_common/pico_stdio",
7297
],

0 commit comments

Comments
 (0)