Skip to content

Commit b8b48f7

Browse files
Improve Bazel btstack build correctness
1 parent 5ef902b commit b8b48f7

File tree

7 files changed

+104
-8
lines changed

7 files changed

+104
-8
lines changed

bazel/config/BUILD.bazel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,17 @@ string_flag(
151151
],
152152
)
153153

154+
# PICO_BAZEL_CONFIG: PICO_ASYNC_CONTEXT_IMPL, The default implementation for pico_async_context to link, type=string, default=threadsafe_background, group=build
155+
string_flag(
156+
name = "PICO_ASYNC_CONTEXT_IMPL",
157+
build_setting_default = "threadsafe_background",
158+
values = [
159+
"poll",
160+
"threadsafe_background",
161+
"freertos",
162+
],
163+
)
164+
154165
# PICO_BAZEL_CONFIG: PICO_BINARY_INFO_ENABLED, Whether to include binary info in final firmware, type=bool, default=1, group=pico_stdlib
155166
bool_flag(
156167
name = "PICO_BINARY_INFO_ENABLED",

bazel/constraint/BUILD.bazel

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,21 @@ config_setting(
180180
flag_values = {"//bazel/config:PICO_DEFAULT_PRINTF_IMPL": "compiler"},
181181
)
182182

183+
config_setting(
184+
name = "pico_async_context_poll_enabled",
185+
flag_values = {"//bazel/config:PICO_ASYNC_CONTEXT_IMPL": "poll"},
186+
)
187+
188+
config_setting(
189+
name = "pico_async_context_threadsafe_background_enabled",
190+
flag_values = {"//bazel/config:PICO_ASYNC_CONTEXT_IMPL": "threadsafe_background"},
191+
)
192+
193+
config_setting(
194+
name = "pico_async_context_freertos_enabled",
195+
flag_values = {"//bazel/config:PICO_ASYNC_CONTEXT_IMPL": "freertos"},
196+
)
197+
183198
config_setting(
184199
name = "pico_use_default_max_page_size_enabled",
185200
flag_values = {"//bazel/config:PICO_USE_DEFAULT_MAX_PAGE_SIZE": "True"},

src/rp2_common/pico_async_context/BUILD.bazel

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,18 @@ load("//bazel:defs.bzl", "compatible_with_rp2", "incompatible_with_config")
22

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

5-
cc_library(
5+
alias(
66
name = "pico_async_context",
7+
actual = select({
8+
"//bazel/constraint:pico_async_context_poll_enabled": ":pico_async_context_poll",
9+
"//bazel/constraint:pico_async_context_threadsafe_background_enabled": ":pico_async_context_threadsafe_background",
10+
"//bazel/constraint:pico_async_context_freertos_enabled": ":pico_async_context_freertos",
11+
"//conditions:default": "//bazel:incompatible_cc_lib",
12+
}),
13+
)
14+
15+
cc_library(
16+
name = "pico_async_context_base",
717
srcs = ["async_context_base.c"],
818
hdrs = [
919
"include/pico/async_context.h",
@@ -26,7 +36,7 @@ cc_library(
2636
"//bazel/constraint:pico_freertos_unset",
2737
),
2838
deps = [
29-
":pico_async_context",
39+
":pico_async_context_base",
3040
"//bazel/config:PICO_FREERTOS_LIB",
3141
"//src/common/pico_sync",
3242
"//src/common/pico_time",
@@ -42,7 +52,7 @@ cc_library(
4252
includes = ["include"],
4353
target_compatible_with = compatible_with_rp2(),
4454
deps = [
45-
":pico_async_context",
55+
":pico_async_context_base",
4656
"//src/common/pico_sync",
4757
"//src/common/pico_time",
4858
"//src/rp2_common:pico_platform",
@@ -56,7 +66,7 @@ cc_library(
5666
includes = ["include"],
5767
target_compatible_with = compatible_with_rp2(),
5868
deps = [
59-
":pico_async_context",
69+
":pico_async_context_base",
6070
"//src/common/pico_sync",
6171
"//src/common/pico_time",
6272
"//src/rp2_common:pico_platform",

src/rp2_common/pico_btstack/BUILD.bazel

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,17 @@ alias(
4343

4444
alias(
4545
name = "pico_btstack_mesh",
46-
actual = "@btstack//:pico_btstack_classic",
46+
actual = "@btstack//:pico_btstack_mesh",
4747
)
4848

4949
alias(
5050
name = "pico_btstack_sbc_encoder",
51-
actual = "@btstack//:pico_btstack_classic",
51+
actual = "@btstack//:pico_btstack_sbc_encoder",
52+
)
53+
54+
alias(
55+
name = "pico_btstack_sbc_decoder",
56+
actual = "@btstack//:pico_btstack_sbc_decoder",
5257
)
5358

5459
alias(
@@ -92,8 +97,10 @@ cc_library(
9297
srcs = ["btstack_stdin_pico.c"],
9398
target_compatible_with = compatible_with_pico_w() + incompatible_with_config("//bazel/constraint:pico_btstack_config_unset"),
9499
deps = [
100+
":pico_btstack_base",
95101
"//bazel/config:PICO_BTSTACK_CONFIG",
96102
"//src/rp2_common:pico_platform",
97103
"//src/rp2_common/pico_stdio",
98104
],
105+
alwayslink = True,
99106
)

src/rp2_common/pico_btstack/btstack.BUILD

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ cc_library(
3737
}),
3838
includes = [
3939
".",
40+
"3rd-party/bluedroid/decoder/include",
41+
"3rd-party/bluedroid/encoder/include",
4042
"3rd-party/md5",
4143
"3rd-party/micro-ecc",
4244
"3rd-party/rijndael",
@@ -89,6 +91,7 @@ cc_library(
8991
copts = _DISABLE_WARNINGS,
9092
target_compatible_with = incompatible_with_config("@pico-sdk//bazel/constraint:pico_btstack_config_unset"),
9193
deps = [":pico_btstack_base_headers"],
94+
alwayslink = True,
9295
)
9396

9497
cc_library(
@@ -118,6 +121,7 @@ cc_library(
118121
copts = _DISABLE_WARNINGS,
119122
target_compatible_with = compatible_with_config("@pico-sdk//bazel/constraint:pico_bt_enable_ble_enabled"),
120123
deps = [":pico_btstack_base_headers"],
124+
alwayslink = True,
121125
)
122126

123127
cc_library(
@@ -174,6 +178,7 @@ cc_library(
174178
":pico_btstack_base",
175179
":pico_btstack_base_headers",
176180
],
181+
alwayslink = True,
177182
)
178183

179184
cc_library(
@@ -218,6 +223,14 @@ cc_library(
218223
":pico_btstack_base_headers",
219224
":pico_btstack_ble",
220225
],
226+
alwayslink = True,
227+
)
228+
229+
cc_library(
230+
name = "pico_btstack_sbc_common",
231+
srcs = ["src/classic/btstack_sbc_bluedroid.c"],
232+
deps = [":pico_btstack_base_headers"],
233+
target_compatible_with = incompatible_with_config("@pico-sdk//bazel/constraint:pico_btstack_config_unset"),
221234
)
222235

223236
cc_library(
@@ -235,13 +248,18 @@ cc_library(
235248
],
236249
copts = _DISABLE_WARNINGS,
237250
includes = ["3rd-party/bluedroid/decoder/include"],
238-
deps = [":pico_btstack_base_headers"],
251+
deps = [
252+
":pico_btstack_base_headers",
253+
":pico_btstack_sbc_common",
254+
],
255+
alwayslink = True,
239256
)
240257

241258
cc_library(
242259
name = "pico_btstack_sbc_decoder",
243260
srcs = [
244261
"src/classic/btstack_sbc_decoder_bluedroid.c",
262+
"3rd-party/bluedroid/decoder/srce/readsamplesjoint.inc",
245263
"3rd-party/bluedroid/decoder/srce/alloc.c",
246264
"3rd-party/bluedroid/decoder/srce/bitalloc.c",
247265
"3rd-party/bluedroid/decoder/srce/bitalloc-sbc.c",
@@ -259,7 +277,11 @@ cc_library(
259277
],
260278
copts = _DISABLE_WARNINGS,
261279
includes = ["3rd-party/bluedroid/decoder/include"],
262-
deps = [":pico_btstack_base_headers"],
280+
deps = [
281+
":pico_btstack_base_headers",
282+
":pico_btstack_sbc_common",
283+
],
284+
alwayslink = True,
263285
)
264286

265287
cc_library(

src/rp2_common/pico_cyw43_arch/BUILD.bazel

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

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

5+
alias(
6+
name = "pico_cyw43_arch",
7+
actual = select({
8+
"//bazel/constraint:pico_lwip_config_unset": ":select_no_lwip",
9+
"//conditions:default": ":select_lwip",
10+
})
11+
)
12+
13+
alias(
14+
name = "select_lwip",
15+
actual = select({
16+
"//bazel/constraint:pico_async_context_poll_enabled": ":pico_cyw43_arch_lwip_poll",
17+
"//bazel/constraint:pico_async_context_threadsafe_background_enabled": ":pico_cyw43_arch_lwip_threadsafe_background",
18+
"//bazel/constraint:pico_async_context_freertos_enabled": ":pico_cyw43_arch_lwip_freertos",
19+
"//conditions:default": "//bazel:incompatible_cc_lib",
20+
}),
21+
visibility = ["//visibility:private"],
22+
)
23+
24+
alias(
25+
name = "select_no_lwip",
26+
actual = select({
27+
"//bazel/constraint:pico_async_context_poll_enabled": ":pico_cyw43_arch_poll",
28+
"//bazel/constraint:pico_async_context_threadsafe_background_enabled": ":pico_cyw43_arch_threadsafe_background",
29+
"//bazel/constraint:pico_async_context_freertos_enabled": ":pico_cyw43_arch_freertos",
30+
"//conditions:default": "//bazel:incompatible_cc_lib",
31+
}),
32+
visibility = ["//visibility:private"],
33+
)
34+
535
# Tuple is async_context type and whether or not lwip is enabled.
636
_CONFIGURATIONS = [
737
("freertos", False),

tools/compare_build_systems.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
"PICO_DEFAULT_PRINTF_IMPL",
148148
"PICO_DEFAULT_RAND_IMPL",
149149
"PICO_BINARY_INFO_ENABLED",
150+
"PICO_ASYNC_CONTEXT_IMPL",
150151
# Allows selection of clang/gcc when using the dynamically fetched
151152
# toolchains.
152153
"PICO_TOOLCHAIN",

0 commit comments

Comments
 (0)