1load("//bazel:defs.bzl", "compatible_with_pico_w", "incompatible_with_config")
2
3package(default_visibility = ["//visibility:public"])
4
5alias(
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
13alias(
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
24alias(
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
35# Tuple is async_context type and whether or not lwip is enabled.
36_CONFIGURATIONS = [
37    ("freertos", False),
38    ("freertos", True),
39    ("poll", False),
40    ("poll", True),
41    ("threadsafe_background", False),
42    ("threadsafe_background", True),
43]
44
45# This produces the following labels:
46#   pico_cyw43_arch_freertos
47#   pico_cyw43_arch_lwip_freertos
48#   pico_cyw43_arch_poll
49#   pico_cyw43_arch_lwip_poll
50#   pico_cyw43_arch_threadsafe_background
51#   pico_cyw43_arch_lwip_threadsafe_background
52#
53# This is done rather than having intermediate libraries because the defines
54# for a given configuration must be applied to both .c files.
55[
56    cc_library(
57        name = "pico_cyw43_arch_" + ("lwip_" if use_lwip else "") + kind,
58        srcs = [
59            "cyw43_arch.c",
60            "cyw43_arch_{}.c".format(kind),
61        ],
62        hdrs = [
63            "include/pico/cyw43_arch.h",
64            "include/pico/cyw43_arch/arch_{}.h".format(kind),
65        ],
66        defines = [
67            "LIB_PICO_CYW43_ARCH=1",
68            "PICO_CYW43_ARCH_{}=1".format(kind.upper()),
69        ],
70        includes = ["include"],
71        target_compatible_with = compatible_with_pico_w() + (
72            incompatible_with_config("//bazel/constraint:pico_freertos_unset") if kind == "freertos" else []
73        ) + (
74            incompatible_with_config("//bazel/constraint:pico_lwip_config_unset") if use_lwip else []
75        ),
76        deps = [
77            "//src/rp2_common:pico_platform",
78            "//src/rp2_common/pico_async_context:pico_async_context_{}".format(kind),
79            "//src/rp2_common/pico_cyw43_driver",
80            "//src/rp2_common/pico_unique_id",
81        ] + (
82            ["//src/rp2_common/pico_lwip:pico_lwip_freertos"] if kind == "freertos" and use_lwip else []
83        ) + (
84            ["//src/rp2_common/pico_lwip:pico_lwip_nosys"] if kind != "freertos" and use_lwip else []
85        ) + (
86            ["//src/rp2_common/pico_lwip"] if use_lwip else []
87        ),
88    )
89    for kind, use_lwip in _CONFIGURATIONS
90]
91
92alias(
93    name = "pico_cyw43_arch_none",
94    actual = ":pico_cyw43_arch_threadsafe_background",
95)
96