load("@rules_cc//cc:cc_library.bzl", "cc_library")
load("//bazel:defs.bzl", "compatible_with_config", "compatible_with_rp2", "incompatible_with_config")
load("//bazel/util:sdk_define.bzl", "pico_sdk_define")

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

alias(
    name = "pico_stdio_uart",
    actual = select({
        "//bazel/constraint:pico_stdio_uart_enabled": ":pico_stdio_uart_enabled",
        "//conditions:default": ":pico_stdio_uart_disabled",
    }),
)

pico_sdk_define(
    name = "LIB_PICO_STDIO_UART",
    define_name = "LIB_PICO_STDIO_UART",
    from_flag = "//bazel/config:PICO_STDIO_UART",
)

cc_library(
    name = "pico_stdio_uart_enabled",
    srcs = ["stdio_uart.c"],
    hdrs = ["include/pico/stdio_uart.h"],
    includes = ["include"],
    target_compatible_with = compatible_with_rp2() + compatible_with_config("//bazel/constraint:pico_stdio_uart_enabled"),
    deps = [
        ":LIB_PICO_STDIO_UART",
        "//src/common/pico_binary_info",
        "//src/rp2_common/hardware_gpio",
        "//src/rp2_common/hardware_uart",
        "//src/rp2_common/pico_stdio:pico_stdio_headers",
    ],
)

# Stub library that does NOT link in stdio UART support libs.
cc_library(
    name = "pico_stdio_uart_disabled",
    hdrs = ["include/pico/stdio_uart.h"],
    includes = ["include"],
    target_compatible_with = compatible_with_rp2() + incompatible_with_config("//bazel/constraint:pico_stdio_uart_enabled"),
    deps = [
        ":LIB_PICO_STDIO_UART",
        "//src/rp2_common/hardware_uart",
        "//src/rp2_common/pico_stdio:pico_stdio_headers",
    ],
)
