1load("@rules_cc//cc:defs.bzl", "cc_library")
2
3# PICO_BUILD_DEFINE: PICO_PROGRAM_NAME, Provided by PICO_DEFAULT_BINARY_INFO or a manually linked custom_pico_binary_info target, type=string, group=pico_binary_info
4# PICO_BUILD_DEFINE: PICO_PROGRAM_DESCRIPTION, Provided by PICO_DEFAULT_BINARY_INFO or a manually linked custom_pico_binary_info target, type=string, group=pico_binary_info
5# PICO_BUILD_DEFINE: PICO_PROGRAM_URL, Provided by PICO_DEFAULT_BINARY_INFO or a manually linked custom_pico_binary_info target, type=string, group=pico_binary_info
6# PICO_BUILD_DEFINE: PICO_PROGRAM_VERSION_STRING, Provided by PICO_DEFAULT_BINARY_INFO or a manually linked custom_pico_binary_info target, type=string, group=pico_binary_info
7# PICO_BUILD_DEFINE: PICO_TARGET_NAME, The name of the build target being compiled, type=string, default=target name, group=build
8def custom_pico_binary_info(name = None, program_name = None, program_description = None, program_url = None, program_version_string = None, build_target_name = None):
9    _all_defines = []
10    if program_name != None:
11        _all_defines.append('PICO_PROGRAM_NAME=\\"{}\\"'.format(program_name))
12    if program_description != None:
13        _all_defines.append('PICO_PROGRAM_DESCRIPTION=\\"{}\\"'.format(program_description))
14    if program_url != None:
15        _all_defines.append('PICO_PROGRAM_URL=\\"{}\\"'.format(program_url))
16    if program_version_string != None:
17        _all_defines.append('PICO_PROGRAM_VERSION_STRING=\\"{}\\"'.format(program_version_string))
18
19    # TODO: There's no practical way to support this correctly without a
20    # `pico_cc_binary` wrapper. Either way, this would be the right place to put
21    # it.
22    _build_target_name_defines = []
23    if build_target_name != None:
24        _build_target_name_defines.append('PICO_TARGET_NAME=\\"{}\\"'.format(build_target_name))
25    cc_library(
26        name = name,
27        defines = _all_defines + select({
28            "@pico-sdk//bazel/constraint:pico_no_target_name_enabled": [],
29            "//conditions:default": _build_target_name_defines,
30        }),
31        srcs = ["@pico-sdk//src/rp2_common/pico_standard_binary_info:binary_info_srcs"],
32        deps = [
33            "@pico-sdk//src/rp2_common/pico_standard_binary_info:PICO_BAZEL_BUILD_TYPE",
34            "@pico-sdk//src/common/pico_base_headers:version",
35            "@pico-sdk//src/common/pico_binary_info",
36            "@pico-sdk//src/rp2_common:boot_stage2_config",
37        ],
38        alwayslink = True,
39    )
40