Skip to content

Commit 4cb5c1c

Browse files
authored
bazel build: Fix compilation bugs for Pico-W support (#1797)
* Add @pico-sdk prefix to bazel/config in lwip.BUILD Without this, we're trying to refer to a subpackage of the lwip directory called bazel/config, which doesn't exist. See similar references in this file. * bazelbuild: Fix compilation errors with pico_lwip and freertos This fixes two general problems. * pico_lwip_contrib_freertos misspelled several things (omitted contrib/ dir prefix, didn't have @pico-sdk in front of out references to pico-sdk targets) This is fixed simply by fixing the spellings. * Circular dependency between pico_lwip_core and pico_lwip_contrib_freertos. In NO_SYS=0 mode, lwip wants to include sys_arch.h. But sys_arch.h is defined in pico_lwip_contrib_freertos. sys_arch.c in turn wants to include lwip's opt.h and arch.h, among other things. So it needs to depend on pico_lwip_core. This is fixed by extracting all the headers into a common rule which can be depended on by both targets, then depending on it in the relevant targets. Additionally, for the LWIP+FreeRTOS build to work correctly, we need to actually depend on the pico_lwip_contrib_freertos rule from pico_lwip_core. This the purpose of the select in the deps of pico_lwip_core. * bazel+cyw43: Fix compilation errors. This fixes issues with the cyw43 driver build rules in Bazel: * Before this, the btstack would always be included even if it could not be used. If the user did not specify a btstack config, this would cause a compilation error. Now, we condition the linking and building of the btstack on whether there is a config for it. * Before, the btbus was not properly linked. * Implements code review feedback
1 parent 4a27277 commit 4cb5c1c

File tree

3 files changed

+63
-18
lines changed

3 files changed

+63
-18
lines changed

src/rp2_common/pico_cyw43_driver/BUILD.bazel

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,55 @@ cc_library(
1616
cc_library(
1717
name = "pico_cyw43_driver",
1818
srcs = [
19-
"btstack_chipset_cyw43.c",
20-
"btstack_cyw43.c",
21-
"btstack_hci_transport_cyw43.c",
2219
"cyw43_bus_pio_spi.c",
2320
"cyw43_driver.c",
2421
],
2522
hdrs = [
26-
"include/pico/btstack_chipset_cyw43.h",
27-
"include/pico/btstack_cyw43.h",
28-
"include/pico/btstack_hci_transport_cyw43.h",
2923
"include/pico/cyw43_driver.h",
3024
],
3125
includes = ["include"],
3226
target_compatible_with = compatible_with_pico_w(),
3327
deps = [
3428
":cyw43_bus_pio",
3529
":cyw43_configport",
36-
"//bazel/config:PICO_BTSTACK_CONFIG",
3730
"//src/rp2_common:pico_platform",
3831
"//src/rp2_common/hardware_clocks",
3932
"//src/rp2_common/hardware_dma",
4033
"//src/rp2_common/hardware_irq",
4134
"//src/rp2_common/hardware_pio",
4235
"//src/rp2_common/hardware_sync",
4336
"//src/rp2_common/pico_async_context",
37+
"//src/rp2_common/pico_unique_id",
38+
"@cyw43-driver//:cyw43_driver",
39+
] +
40+
# Only depend on the btstack if its configuration is set up.
41+
select({
42+
"//bazel/constraint:pico_btstack_config_unset": [],
43+
"//conditions:default": [":pico_cyw43_btstack"],
44+
}),
45+
)
46+
47+
cc_library(
48+
name = "pico_cyw43_btstack",
49+
srcs = [
50+
"btstack_chipset_cyw43.c",
51+
"btstack_cyw43.c",
52+
"btstack_hci_transport_cyw43.c",
53+
],
54+
hdrs = [
55+
"include/pico/btstack_chipset_cyw43.h",
56+
"include/pico/btstack_cyw43.h",
57+
"include/pico/btstack_hci_transport_cyw43.h",
58+
],
59+
includes = ["include"],
60+
deps = [
61+
":cyw43_bus_pio",
62+
":cyw43_configport",
63+
"//bazel/config:PICO_BTSTACK_CONFIG",
4464
"//src/rp2_common/pico_btstack:btstack_run_loop_async_context",
4565
"//src/rp2_common/pico_btstack:pico_btstack_base",
4666
"//src/rp2_common/pico_btstack:pico_btstack_flash_bank",
47-
"//src/rp2_common/pico_unique_id",
67+
"//src/rp2_common/pico_cyw43_driver/cybt_shared_bus:cybt_shared_bus_driver",
4868
"@cyw43-driver//:cyw43_driver",
4969
],
5070
)

src/rp2_common/pico_cyw43_driver/cyw43-driver.BUILD

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ cc_library(
1111
"src/cyw43_stats.c",
1212
],
1313
hdrs = glob(["**/*.h"]),
14-
defines = ["CYW43_ENABLE_BLUETOOTH=1"],
14+
defines = select({
15+
"@pico-sdk//bazel/constraint:pico_btstack_config_unset": [
16+
"CYW43_ENABLE_BLUETOOTH=0",
17+
],
18+
"//conditions:default": [
19+
"CYW43_ENABLE_BLUETOOTH=1",
20+
],
21+
}),
1522
includes = [
1623
"firmware",
1724
"src",

src/rp2_common/pico_lwip/lwip.BUILD

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,36 @@ load("@pico-sdk//bazel:defs.bzl", "incompatible_with_config")
22

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

5+
# Some of the LWIP sys_arch.h and the lwip headers depend circularly on one
6+
# another. Include them all in the same target.
7+
cc_library(
8+
name = "pico_lwip_headers",
9+
hdrs = glob(["**/*.h"]),
10+
includes = [
11+
"contrib/ports/freertos/include/arch",
12+
"src/include",
13+
],
14+
deps = [
15+
"@pico-sdk//bazel/config:PICO_LWIP_CONFIG",
16+
"@pico-sdk//src/rp2_common/pico_lwip:pico_lwip_config",
17+
],
18+
visibility = ["//visibility:private"],
19+
)
20+
521
cc_library(
622
name = "pico_lwip_core",
723
srcs = glob(["src/core/*.c"]),
8-
hdrs = glob(["**/*.h"]),
9-
includes = ["src/include"],
1024
target_compatible_with = incompatible_with_config(
1125
"@pico-sdk//bazel/constraint:pico_lwip_config_unset",
1226
),
1327
deps = [
14-
"@pico-sdk//bazel/config:PICO_LWIP_CONFIG",
15-
"@pico-sdk//src/rp2_common/pico_lwip:pico_lwip_config",
16-
],
28+
":pico_lwip_headers",
29+
] + select({
30+
"@pico-sdk//bazel/constraint:pico_freertos_unset": [],
31+
"//conditions:default": [
32+
":pico_lwip_contrib_freertos",
33+
],
34+
}),
1735
)
1836

1937
cc_library(
@@ -151,13 +169,13 @@ cc_library(
151169

152170
cc_library(
153171
name = "pico_lwip_contrib_freertos",
154-
srcs = ["ports/freertos/sys_arch.c"],
155-
includes = ["ports/freertos/include"],
172+
srcs = ["contrib/ports/freertos/sys_arch.c"],
173+
includes = ["contrib/ports/freertos/include"],
156174
target_compatible_with = incompatible_with_config(
157175
"@pico-sdk//bazel/constraint:pico_freertos_unset",
158176
),
159177
deps = [
160-
":pico_lwip_core",
161-
"//bazel/config:PICO_FREERTOS_LIB",
178+
":pico_lwip_headers",
179+
"@pico-sdk//bazel/config:PICO_FREERTOS_LIB",
162180
],
163181
)

0 commit comments

Comments
 (0)