From abce1d427cda25245968093c41834d025e0fc7ad Mon Sep 17 00:00:00 2001 From: armandomontanez Date: Tue, 4 Jun 2024 16:50:32 -0700 Subject: [PATCH] Introduce initial Bazel build (#1705) * Build boot_stage2 with Bazel Introduces the initial foundations of a Bazel build, including a toolchain, critical generated headers, platform patterns, and enough BUILD files to build boot_stage2. * Bazel libraries to support picotool * Move SDK defines to toolchain * Switch to `archive_override` in MODULE.bazel Uses archive_override where applicable to allow transitive bzlmod deps to propagate. * Multiplatform objcopy selection in Bazel build Makes an objcopy alias that redirects to the objcopy tool for the current exec platform, which allows boot_stage2 to build on Linux, macOS, and Windows. * Generate Bazel build files Adds initial set of generated Bazel build files. Note that these do not yet build, as dependency cycles are present. * Fix dependency cycles in Bazel build Fixes many dependency cycles, some were unintentionally created by the build file generator, others are true dependency cycles that require manual workarounds. * Silence warning in pico_stdio Bazel build Silences a stray warning in the Bazel build. * Fix wildcard Bazel build This makes `bazel build //...` succeed, and also prevents the fetching of toolchains that aren't compatible with the current execution environment (i.e. Windows computers will no longer try to download macOS toolchains). * Get the SDK working Finishes out the remainder of the work required to successfully compile a working blinky example. * Fix UART stdio dependencies in Bazel build Fixes some dependencies around pico_stdlib so that pico_stdlib links properly and UART stdio works. * Add linux support to Bazel build * Get Bazel deps from registry Adds external an external registry for resolving Bazel module dependencies. * Fix host configuration for picotool Provides the appropriate defines for host builds to support the picotool build. * Remove -ffreestanding from Bazel toolchain The -ffreestanding toolchain flag is quite strict, so remove it from the Bazel toolchain. * Remove unused .bzl file * Reduce Bazel compiler flags Cuts out most of the Bazel toolchain flags and only specifies the bare-minimum set of flags. Also, adds wrapper linker flags for functions the SDK wraps. * Get USB serial working Adds initial TinyUSB support and enough integration to get USB serial working. * Remove "Generated build file" Removes comments that indicates BUILD.bazel files are generated. This was used during initial bringup to indicate hand-crafted vs automatically generated BUILD.bazel files. * Do not build USB libraries unless configured Prevents USB libraries from being built unless the build is properly configured to use them. * Switch to rules_cc toolchains Moves toolchain configuration to use the new rules in rules_cc. * Minor cleanup in parse_version.py Cleans up trailing whitespace and runs the black formatter on parse_version.py. * Simplify constraint dimensions in Bazel build Consolidates the class/chip constraint settings to be a single constraint_setting with a config_setting that represents the rp2 class. * Update pin of rules_cc in Bazel build Includes a necessary fix for the target_compatible_with expression in the cc_toolchain to work as intended. * Move toolchains from pico.bzl to BUILD.bazel Moves toolchain definitions from pico.bzl to BUILD.bazel to make them easier to find and read. * Run buildifier on Bazel build files Fix trivial formatting issues by running buildifier on all BUILD.bazel files. * Make objcopy rule Makes a simple objcopy rule to remove direct references to the ARM toolchains. * Fix link flags in Bazel build Critical flags were not being applied to link steps. This applies -mcpu and -mthumb to the link steps to make the produced binaries work again. * Mention missing host build support * Fix various Bazel library rules * pico_bit_ops was incomplete. * pico_double and pico_float were trying to link in the "none" implementation. * Extend Bazel build documentation Improves documentation and comments across the Bazel build. * Clean up auxilary tools in Bazel build Switches genrules to use skylib rules to simplify things. Reworks version header generation to use the Bazel module version rather than parsing CMake. * Update boot_stage2 Bazel build file Moves `includes` to be enumerated on the correct library. * Add WORKSPACE version fallback WORKSPACE Bazel projects don't support querying module version, so add a fallback of '0.0.1-WORKSPACE' so the build can succeed. * Fix malloc handling in Bazel build * Fix Bazel dependency cycle in pico_malloc * Prevent malloc from being linked into boot_stage2 Prevents Bazel from ever trying to link malloc into the boot_stage2 binary. * Remove custom bootloader platform A dedicated boot_stage2 platform introduces a lot of complexity that needs to be more thought-through. --- .bazelrc | 6 + .bazelversion | 1 + .gitignore | 5 + BUILD.bazel | 0 MODULE.bazel | 71 ++++++++ bazel/BUILD.bazel | 34 ++++ bazel/README.md | 137 ++++++++++++++++ bazel/config/BUILD.bazel | 52 ++++++ bazel/constraint/BUILD.bazel | 58 +++++++ bazel/generate_version_header.py | 58 +++++++ bazel/include/pico/config_autogen.h | 12 ++ bazel/platform/BUILD.bazel | 9 ++ bazel/toolchain/BUILD.bazel | 151 ++++++++++++++++++ bazel/toolchain/gcc_arm_none_eabi.BUILD | 145 +++++++++++++++++ bazel/toolchain/objcopy.bzl | 46 ++++++ bazel/util/BUILD.bazel | 1 + bazel/util/transition.bzl | 74 +++++++++ src/boards/BUILD.bazel | 105 ++++++++++++ src/common/boot_picoboot/BUILD.bazel | 8 + src/common/boot_uf2/BUILD.bazel | 7 + src/common/pico_base/BUILD.bazel | 103 ++++++++++++ src/common/pico_binary_info/BUILD.bazel | 18 +++ src/common/pico_bit_ops/BUILD.bazel | 31 ++++ src/common/pico_divider/BUILD.bazel | 13 ++ src/common/pico_stdlib/BUILD.bazel | 44 +++++ src/common/pico_sync/BUILD.bazel | 29 ++++ src/common/pico_time/BUILD.bazel | 44 +++++ .../pico_usb_reset_interface/BUILD.bazel | 7 + src/common/pico_util/BUILD.bazel | 26 +++ src/host/pico_platform/BUILD.bazel | 22 +++ src/rp2040/hardware_regs/BUILD.bazel | 53 ++++++ src/rp2040/hardware_structs/BUILD.bazel | 43 +++++ src/rp2_common/boot_stage2/BUILD.bazel | 99 ++++++++++++ src/rp2_common/cmsis/BUILD.bazel | 34 ++++ src/rp2_common/hardware_adc/BUILD.bazel | 14 ++ src/rp2_common/hardware_base/BUILD.bazel | 7 + src/rp2_common/hardware_claim/BUILD.bazel | 13 ++ src/rp2_common/hardware_clocks/BUILD.bazel | 36 +++++ src/rp2_common/hardware_divider/BUILD.bazel | 17 ++ src/rp2_common/hardware_dma/BUILD.bazel | 14 ++ src/rp2_common/hardware_exception/BUILD.bazel | 15 ++ src/rp2_common/hardware_flash/BUILD.bazel | 13 ++ src/rp2_common/hardware_gpio/BUILD.bazel | 15 ++ src/rp2_common/hardware_i2c/BUILD.bazel | 16 ++ src/rp2_common/hardware_interp/BUILD.bazel | 14 ++ src/rp2_common/hardware_irq/BUILD.bazel | 21 +++ src/rp2_common/hardware_pio/BUILD.bazel | 19 +++ src/rp2_common/hardware_pll/BUILD.bazel | 15 ++ src/rp2_common/hardware_pwm/BUILD.bazel | 12 ++ src/rp2_common/hardware_resets/BUILD.bazel | 11 ++ src/rp2_common/hardware_rtc/BUILD.bazel | 15 ++ src/rp2_common/hardware_spi/BUILD.bazel | 15 ++ src/rp2_common/hardware_sync/BUILD.bazel | 29 ++++ src/rp2_common/hardware_timer/BUILD.bazel | 29 ++++ src/rp2_common/hardware_uart/BUILD.bazel | 18 +++ src/rp2_common/hardware_vreg/BUILD.bazel | 12 ++ src/rp2_common/hardware_watchdog/BUILD.bazel | 13 ++ src/rp2_common/hardware_xosc/BUILD.bazel | 16 ++ src/rp2_common/pico_async_context/BUILD.bazel | 30 ++++ src/rp2_common/pico_bit_ops/BUILD.bazel | 25 +++ src/rp2_common/pico_bootrom/BUILD.bazel | 15 ++ .../pico_bootsel_via_double_reset/BUILD.bazel | 12 ++ src/rp2_common/pico_btstack/BUILD.bazel | 28 ++++ src/rp2_common/pico_cxx_options/BUILD.bazel | 5 + src/rp2_common/pico_cyw43_arch/BUILD.bazel | 31 ++++ src/rp2_common/pico_cyw43_driver/BUILD.bazel | 51 ++++++ src/rp2_common/pico_divider/BUILD.bazel | 20 +++ src/rp2_common/pico_double/BUILD.bazel | 85 ++++++++++ src/rp2_common/pico_fix/BUILD.bazel | 5 + .../rp2040_usb_device_enumeration/BUILD.bazel | 14 ++ src/rp2_common/pico_flash/BUILD.bazel | 20 +++ src/rp2_common/pico_float/BUILD.bazel | 85 ++++++++++ src/rp2_common/pico_i2c_slave/BUILD.bazel | 12 ++ src/rp2_common/pico_int64_ops/BUILD.bazel | 14 ++ src/rp2_common/pico_lwip/BUILD.bazel | 27 ++++ src/rp2_common/pico_malloc/BUILD.bazel | 19 +++ src/rp2_common/pico_mbedtls/BUILD.bazel | 10 ++ src/rp2_common/pico_mem_ops/BUILD.bazel | 27 ++++ src/rp2_common/pico_multicore/BUILD.bazel | 18 +++ src/rp2_common/pico_platform/BUILD.bazel | 38 +++++ src/rp2_common/pico_printf/BUILD.bazel | 23 +++ src/rp2_common/pico_rand/BUILD.bazel | 16 ++ src/rp2_common/pico_runtime/BUILD.bazel | 20 +++ src/rp2_common/pico_standard_link/BUILD.bazel | 23 +++ src/rp2_common/pico_stdio/BUILD.bazel | 47 ++++++ .../pico_stdio_semihosting/BUILD.bazel | 12 ++ src/rp2_common/pico_stdio_uart/BUILD.bazel | 14 ++ src/rp2_common/pico_stdio_usb/BUILD.bazel | 48 ++++++ src/rp2_common/pico_stdlib/BUILD.bazel | 16 ++ src/rp2_common/pico_unique_id/BUILD.bazel | 12 ++ src/rp2_common/tinyusb/BUILD.bazel | 26 +++ src/rp2_common/tinyusb/tinyusb.BUILD | 43 +++++ 92 files changed, 2836 insertions(+) create mode 100644 .bazelrc create mode 100644 .bazelversion create mode 100644 BUILD.bazel create mode 100644 MODULE.bazel create mode 100644 bazel/BUILD.bazel create mode 100644 bazel/README.md create mode 100644 bazel/config/BUILD.bazel create mode 100644 bazel/constraint/BUILD.bazel create mode 100644 bazel/generate_version_header.py create mode 100644 bazel/include/pico/config_autogen.h create mode 100644 bazel/platform/BUILD.bazel create mode 100644 bazel/toolchain/BUILD.bazel create mode 100644 bazel/toolchain/gcc_arm_none_eabi.BUILD create mode 100644 bazel/toolchain/objcopy.bzl create mode 100644 bazel/util/BUILD.bazel create mode 100644 bazel/util/transition.bzl create mode 100644 src/boards/BUILD.bazel create mode 100644 src/common/boot_picoboot/BUILD.bazel create mode 100644 src/common/boot_uf2/BUILD.bazel create mode 100644 src/common/pico_base/BUILD.bazel create mode 100644 src/common/pico_binary_info/BUILD.bazel create mode 100644 src/common/pico_bit_ops/BUILD.bazel create mode 100644 src/common/pico_divider/BUILD.bazel create mode 100644 src/common/pico_stdlib/BUILD.bazel create mode 100644 src/common/pico_sync/BUILD.bazel create mode 100644 src/common/pico_time/BUILD.bazel create mode 100644 src/common/pico_usb_reset_interface/BUILD.bazel create mode 100644 src/common/pico_util/BUILD.bazel create mode 100644 src/host/pico_platform/BUILD.bazel create mode 100644 src/rp2040/hardware_regs/BUILD.bazel create mode 100644 src/rp2040/hardware_structs/BUILD.bazel create mode 100644 src/rp2_common/boot_stage2/BUILD.bazel create mode 100644 src/rp2_common/cmsis/BUILD.bazel create mode 100644 src/rp2_common/hardware_adc/BUILD.bazel create mode 100644 src/rp2_common/hardware_base/BUILD.bazel create mode 100644 src/rp2_common/hardware_claim/BUILD.bazel create mode 100644 src/rp2_common/hardware_clocks/BUILD.bazel create mode 100644 src/rp2_common/hardware_divider/BUILD.bazel create mode 100644 src/rp2_common/hardware_dma/BUILD.bazel create mode 100644 src/rp2_common/hardware_exception/BUILD.bazel create mode 100644 src/rp2_common/hardware_flash/BUILD.bazel create mode 100644 src/rp2_common/hardware_gpio/BUILD.bazel create mode 100644 src/rp2_common/hardware_i2c/BUILD.bazel create mode 100644 src/rp2_common/hardware_interp/BUILD.bazel create mode 100644 src/rp2_common/hardware_irq/BUILD.bazel create mode 100644 src/rp2_common/hardware_pio/BUILD.bazel create mode 100644 src/rp2_common/hardware_pll/BUILD.bazel create mode 100644 src/rp2_common/hardware_pwm/BUILD.bazel create mode 100644 src/rp2_common/hardware_resets/BUILD.bazel create mode 100644 src/rp2_common/hardware_rtc/BUILD.bazel create mode 100644 src/rp2_common/hardware_spi/BUILD.bazel create mode 100644 src/rp2_common/hardware_sync/BUILD.bazel create mode 100644 src/rp2_common/hardware_timer/BUILD.bazel create mode 100644 src/rp2_common/hardware_uart/BUILD.bazel create mode 100644 src/rp2_common/hardware_vreg/BUILD.bazel create mode 100644 src/rp2_common/hardware_watchdog/BUILD.bazel create mode 100644 src/rp2_common/hardware_xosc/BUILD.bazel create mode 100644 src/rp2_common/pico_async_context/BUILD.bazel create mode 100644 src/rp2_common/pico_bit_ops/BUILD.bazel create mode 100644 src/rp2_common/pico_bootrom/BUILD.bazel create mode 100644 src/rp2_common/pico_bootsel_via_double_reset/BUILD.bazel create mode 100644 src/rp2_common/pico_btstack/BUILD.bazel create mode 100644 src/rp2_common/pico_cxx_options/BUILD.bazel create mode 100644 src/rp2_common/pico_cyw43_arch/BUILD.bazel create mode 100644 src/rp2_common/pico_cyw43_driver/BUILD.bazel create mode 100644 src/rp2_common/pico_divider/BUILD.bazel create mode 100644 src/rp2_common/pico_double/BUILD.bazel create mode 100644 src/rp2_common/pico_fix/BUILD.bazel create mode 100644 src/rp2_common/pico_fix/rp2040_usb_device_enumeration/BUILD.bazel create mode 100644 src/rp2_common/pico_flash/BUILD.bazel create mode 100644 src/rp2_common/pico_float/BUILD.bazel create mode 100644 src/rp2_common/pico_i2c_slave/BUILD.bazel create mode 100644 src/rp2_common/pico_int64_ops/BUILD.bazel create mode 100644 src/rp2_common/pico_lwip/BUILD.bazel create mode 100644 src/rp2_common/pico_malloc/BUILD.bazel create mode 100644 src/rp2_common/pico_mbedtls/BUILD.bazel create mode 100644 src/rp2_common/pico_mem_ops/BUILD.bazel create mode 100644 src/rp2_common/pico_multicore/BUILD.bazel create mode 100644 src/rp2_common/pico_platform/BUILD.bazel create mode 100644 src/rp2_common/pico_printf/BUILD.bazel create mode 100644 src/rp2_common/pico_rand/BUILD.bazel create mode 100644 src/rp2_common/pico_runtime/BUILD.bazel create mode 100644 src/rp2_common/pico_standard_link/BUILD.bazel create mode 100644 src/rp2_common/pico_stdio/BUILD.bazel create mode 100644 src/rp2_common/pico_stdio_semihosting/BUILD.bazel create mode 100644 src/rp2_common/pico_stdio_uart/BUILD.bazel create mode 100644 src/rp2_common/pico_stdio_usb/BUILD.bazel create mode 100644 src/rp2_common/pico_stdlib/BUILD.bazel create mode 100644 src/rp2_common/pico_unique_id/BUILD.bazel create mode 100644 src/rp2_common/tinyusb/BUILD.bazel create mode 100644 src/rp2_common/tinyusb/tinyusb.BUILD diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 000000000..b5ebd97a9 --- /dev/null +++ b/.bazelrc @@ -0,0 +1,6 @@ +# Required for new toolchain resolution API. +build --incompatible_enable_cc_toolchain_resolution +build --@rules_cc//cc/toolchains:experimental_enable_rule_based_toolchains + +# Produce useful output when the build fails. +common --verbose_failures diff --git a/.bazelversion b/.bazelversion new file mode 100644 index 000000000..a8907c025 --- /dev/null +++ b/.bazelversion @@ -0,0 +1 @@ +7.0.2 diff --git a/.gitignore b/.gitignore index a3b81f81d..c01419576 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,8 @@ cmake-* .DS_Store build + +bazel-* + +# Ignore until https://github.com/bazelbuild/bazel/issues/20369 is fixed. +MODULE.bazel.lock diff --git a/BUILD.bazel b/BUILD.bazel new file mode 100644 index 000000000..e69de29bb diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 000000000..394d41445 --- /dev/null +++ b/MODULE.bazel @@ -0,0 +1,71 @@ +module(name = "pico-sdk", version = "1.6.0-rc1") + +bazel_dep(name = "platforms", version = "0.0.8") + +bazel_dep(name = "bazel_skylib", version = "1.6.1") + +# Note: rules_cc is special-cased repository; a dependency on rules_cc in a +# module will not ensure that the root Bazel module has that same version of +# rules_cc. For that reason, this primarily acts as a FYI. You'll still need +# to explicitly list this dependency in your own project's MODULE.bazel file. +bazel_dep(name = "rules_cc", version = "0.0.10") + +# rules_cc v0.0.10 is not yet cut, so manually pull in the desired version. +# This does not apply to dependent projects, so it needs to be copied to your +# project's MODULE.bazel too. +archive_override( + module_name = "rules_cc", + urls = "https://github.com/bazelbuild/rules_cc/archive/1acf5213b6170f1f0133e273cb85ede0e732048f.zip", + strip_prefix = "rules_cc-1acf5213b6170f1f0133e273cb85ede0e732048f", + integrity = "sha256-NddP6xi6LzsIHT8bMSVJ2NtoURbN+l3xpjvmIgB6aSg=", +) + +http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +http_archive( + name = "arm_gcc_linux-x86_64", + url = "https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-x86_64-arm-none-eabi.tar.xz", + strip_prefix = "arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi", + build_file = "//bazel/toolchain:gcc_arm_none_eabi.BUILD", + sha256 = "6cd1bbc1d9ae57312bcd169ae283153a9572bd6a8e4eeae2fedfbc33b115fdbb", +) + +http_archive( + name = "arm_gcc_win-x86_64", + url = "https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-mingw-w64-i686-arm-none-eabi.zip", + strip_prefix = "arm-gnu-toolchain-13.2.Rel1-mingw-w64-i686-arm-none-eabi", + build_file = "//bazel/toolchain:gcc_arm_none_eabi.BUILD", + sha256 = "51d933f00578aa28016c5e3c84f94403274ea7915539f8e56c13e2196437d18f", +) + +http_archive( + name = "arm_gcc_mac-x86_64", + url = "https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-darwin-x86_64-arm-none-eabi.tar.xz", + strip_prefix = "arm-gnu-toolchain-13.2.Rel1-darwin-x86_64-arm-none-eabi", + build_file = "//bazel/toolchain:gcc_arm_none_eabi.BUILD", + sha256 = "075faa4f3e8eb45e59144858202351a28706f54a6ec17eedd88c9fb9412372cc", +) + +http_archive( + name = "arm_gcc_mac-aarch64", + url = "https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-darwin-arm64-arm-none-eabi.tar.xz", + strip_prefix = "arm-gnu-toolchain-13.2.Rel1-darwin-arm64-arm-none-eabi", + build_file = "//bazel/toolchain:gcc_arm_none_eabi.BUILD", + sha256 = "39c44f8af42695b7b871df42e346c09fee670ea8dfc11f17083e296ea2b0d279", +) + +# TODO: Provide tinyusb as a proper Bazel module. +http_archive( + name = "tinyusb", + url = "https://github.com/hathach/tinyusb/archive/86c416d4c0fb38432460b3e11b08b9de76941bf5.zip", + strip_prefix = "tinyusb-86c416d4c0fb38432460b3e11b08b9de76941bf5", + build_file = "//src/rp2_common/tinyusb:tinyusb.BUILD", + sha256 = "ac57109bba00d26ffa33312d5f334990ec9a9a4d82bf890ed8b825b4610d1da2", +) + +register_toolchains( + "//bazel/toolchain:arm_gcc_linux-x86_64", + "//bazel/toolchain:arm_gcc_win-x86_64", + "//bazel/toolchain:arm_gcc_mac-x86_64", + "//bazel/toolchain:arm_gcc_mac-aarch64", +) diff --git a/bazel/BUILD.bazel b/bazel/BUILD.bazel new file mode 100644 index 000000000..b76e1aaf7 --- /dev/null +++ b/bazel/BUILD.bazel @@ -0,0 +1,34 @@ +package(default_visibility = ["//visibility:public"]) + +py_binary( + name = "generate_version_header", + srcs = ["generate_version_header.py"], + visibility = ["//:__subpackages__"], +) + +# This isn't actually generated, it just uses the same name +# to make it show up easier in searches. +# +# Rather than generating lists of headers to match CMake, the Bazel build +# opts to have a static header that transitively include two known headers. +# By default, empty header files are included, and users/platforms are expected +# to specify an appropriate `cc_library` to replace them. +# +# You tell bazel which `cc_library` provides the respective headers by +# configuring these `label_flag`s: +# +# # Specify the library that provides "pico_config_extra_headers.h" +# --@pico-sdk//bazel/config:pico_config_extra_headers=//my_proj:my_custom_headers +# +# # Specify the library that provides "pico_config_platform_headers.h" +# --@pico-sdk//bazel/config:pico_config_platform_headers=//my_proj:my_custom_platform_headers +cc_library( + name = "generate_config_header", + hdrs = ["include/pico/config_autogen.h"], + includes = ["include"], + visibility = ["//:__subpackages__"], + deps = [ + "//bazel/config:pico_config_extra_headers", + "//bazel/config:pico_config_platform_headers", + ], +) diff --git a/bazel/README.md b/bazel/README.md new file mode 100644 index 000000000..db5078c9e --- /dev/null +++ b/bazel/README.md @@ -0,0 +1,137 @@ +# Bazel build +The Bazel build for the Pico SDK is currently community-maintained, and should +be considered an experimental work-in-progress. There are missing features, +and you may encounter significant breakages with future versions. + +You are welcome and encouraged to file issues for any problems you encounter +along the way. + +## Using the Pico SDK in a Bazel project. + +### Add pico-sdk as a dependency +First, in your `MODULE.bazel` file, add a dependency on the Pico SDK: +```python +bazel_dep( + name = "pico-sdk", + version = "1.6.0-rc1", +) +``` +Second, in the same file you'll need to add an explicit dependency on +`rules_cc`, as it's a special-cased Bazel module: +```python +# Note: rules_cc is special-cased repository; a dependency on rules_cc in a +# module will not ensure that the root Bazel module has that same version of +# rules_cc. For that reason, this primarily acts as a FYI. You'll still need +# to explicitly list this dependency in your own project's MODULE.bazel file. +bazel_dep(name = "rules_cc", version = "0.0.10") + +# rules_cc v0.0.10 is not yet cut, so manually pull in the desired version. +# This does not apply to dependent projects, so it needs to be copied to your +# project's MODULE.bazel too. +archive_override( + module_name = "rules_cc", + urls = "https://github.com/bazelbuild/rules_cc/archive/1acf5213b6170f1f0133e273cb85ede0e732048f.zip", + strip_prefix = "rules_cc-1acf5213b6170f1f0133e273cb85ede0e732048f", + integrity = "sha256-NddP6xi6LzsIHT8bMSVJ2NtoURbN+l3xpjvmIgB6aSg=", +) +``` + +### Register toolchains +These toolchains tell Bazel how to compile for ARM cores. Add the following +to the `MODULE.bazel` for your project: +```python +register_toolchains( + "@pico-sdk//bazel/toolchain:arm_gcc_linux-x86_64", + "@pico-sdk//bazel/toolchain:arm_gcc_win-x86_64", + "@pico-sdk//bazel/toolchain:arm_gcc_mac-x86_64", + "@pico-sdk//bazel/toolchain:arm_gcc_mac-aarch64", +) +``` + +### Enable required .bazelrc flags +To use the toolchains provided by the Pico SDK, you'll need to enable a few +new features. In your project's `.bazelrc`, add the following +``` +# Required for new toolchain resolution API. +build --incompatible_enable_cc_toolchain_resolution +build --@rules_cc//cc/toolchains:experimental_enable_rule_based_toolchains +``` + +### Ready to build! +You're now ready to start building Pico Projects in Bazel! When building, +don't forget to specify `--platforms` so Bazel knows you're targeting the +Raspberry Pi Pico: +```console +$ bazelisk build --platforms=@pico-sdk//bazel/platform:rp2040 //... +``` + +## SDK configuration [experimental] +These configuration options are a work in progress and may see significant +breaking changes in future versions. + +### Selecting a different board +Currently there are three configurable flags for targeting a different board: +1. `pico_config_extra_headers`: This should always point to a `cc_library `that + provides a `"pico_config_extra_headers.h"` header. You can configure this + by including a flag like the following in your build invocation: + ``` + --@pico-sdk//bazel/config:pico_config_extra_headers=//path/to:custom_extra_headers + ``` +2. `pico_config_platform_headers`: This should always point to a `cc_library` + that provides a `"pico_config_platform_headers.h"` header. + ``` + --@pico-sdk//bazel/config:pico_config_platform_headers=//path/to:custom_platform_headers + ``` +3. `pico_config_header`: This should point to a `cc_library` that sets all + necessary SDK defines. Most notably, `PICO_BOARD`, `PICO_CONFIG_HEADER`, + `PICO_ON_DEVICE`, `PICO_NO_HARDWARE`, and `PICO_BUILD`. See + `//src/boards:BUILD.bazel` for working examples. Any `defines` set on this + library will propagate to the rest of the Pico SDK. To set this configuration + option, pass a flag like the following in your Bazel build invocation: + ``` + --@pico-sdk//bazel/config:pico_config_platform_headers=//path/to:pico_board_config + ``` + +### Selecting a stdio mode +To select a different stdio mode, add it to your `platform` definition. For +example: +```python +platform( + name = "rp2040", + constraint_values = [ + "@pico-sdk//bazel/constraint:rp2040", + "@pico-sdk//bazel/constraint:stdio_usb", # Configures stdio_mode. + "@platforms//cpu:armv6-m", + ], +) +``` + +## Building the Pico SDK itself + +### First time setup +You'll need Bazel (v7.0.0 or higher) or Bazelisk (a self-updating Bazel +launcher) to build the Pico SDK. + +We strongly recommend you set up +[Bazelisk](https://bazel.build/install/bazelisk). + +### Building +To build all of the Pico SDK, run the following command: +```console +$ bazelisk build --platforms=//bazel/platform:rp2040 //... +``` + +**Note:** Since the Bazel build does not yet have any `cc_binary` rules with a +`main()` function, there won't be any binaries to flash on your board. For now, +this only builds the SDK as a collection of libraries. + +## Known issues and limitations +The Bazel build is currently experimental and incomplete. At this time, only the +stock Pi Pico board is supported, and the only configuration options are +changing the STDIO mode between UART and USB serial. + +Keep in mind the following limitations: +* Pico-W is not yet supported. +* Selecting an alternative board is not yet supported. +* Nearly all preexisting CMake configuration options are not yet supported. +* Targeting the host build of the Pico SDK is not yet supported. diff --git a/bazel/config/BUILD.bazel b/bazel/config/BUILD.bazel new file mode 100644 index 000000000..1376f229d --- /dev/null +++ b/bazel/config/BUILD.bazel @@ -0,0 +1,52 @@ +package(default_visibility = ["//visibility:public"]) + +# This should always point to a cc_library that provides +# a "pico_config_extra_headers.h". +label_flag( + name = "pico_config_extra_headers", + build_setting_default = ":no_extra_headers", +) + +# This should always point to a cc_library that provides +# a "pico_config_platform_headers.h". +label_flag( + name = "pico_config_platform_headers", + build_setting_default = ":no_platform_headers", +) + +# This should always point to a cc_library that defines PICO_CONFIG_HEADER and +# any other defines that should be applied when building the SDK. +label_flag( + name = "pico_config_header", + build_setting_default = "//src/boards:default", +) + +genrule( + name = "empty_extra_headers_file", + outs = ["generated_include/pico_config_extra_headers.h"], + cmd = "echo > $@", + cmd_bat = "copy NUL $@", + visibility = ["//visibility:private"], +) + +genrule( + name = "empty_platform_headers_file", + outs = ["generated_include/pico_config_platform_headers.h"], + cmd = "echo > $@", + cmd_bat = "copy NUL $@", + visibility = ["//visibility:private"], +) + +cc_library( + name = "no_extra_headers", + hdrs = ["generated_include/pico_config_extra_headers.h"], + includes = ["generated_include"], + visibility = ["//visibility:private"], +) + +cc_library( + name = "no_platform_headers", + hdrs = ["generated_include/pico_config_platform_headers.h"], + includes = ["generated_include"], + visibility = ["//visibility:private"], +) diff --git a/bazel/constraint/BUILD.bazel b/bazel/constraint/BUILD.bazel new file mode 100644 index 000000000..8af93fa3a --- /dev/null +++ b/bazel/constraint/BUILD.bazel @@ -0,0 +1,58 @@ +package(default_visibility = ["//visibility:public"]) + +# This constraint represents the dimension that guides the Pico SDK build. This +# constraint will only ever enumerate specific MCUs (and the host), and does NOT +# cover the differences from board-to-board. +constraint_setting( + name = "sdk_target", + default_constraint_value = "host", +) + +# This constraint value is used to guide the host build. +constraint_value( + name = "host", + constraint_setting = ":sdk_target", +) + +# This constraint value is used to guide parts of the build that are specific +# to the rp2040. +constraint_value( + name = "rp2040", + constraint_setting = ":sdk_target", +) + +# This constraint value is used to guide parts of the build that apply to all +# rp2-class chips. +config_setting( + name = "rp2", + constraint_values = [ + ":rp2040", + ], +) + +# This constraint setting guides Bazel's build file evaluation differences +# across different stdio configurations (e.g. stdio_usb needs TinyUSB). +constraint_setting( + name = "stdio_mode", + default_constraint_value = "stdio_uart", +) + +# When this constraint value is active, stdio is built against a hardware UART. +constraint_value( + name = "stdio_uart", + constraint_setting = ":stdio_mode", +) + +# When this constraint value is active, stdio is built against TinyUSB-based +# USB serial. +constraint_value( + name = "stdio_usb", + constraint_setting = ":stdio_mode", +) + +# When this constraint value is active, stdio is built against an ARM +# semihosting library. +constraint_value( + name = "stdio_semihosting", + constraint_setting = ":stdio_mode", +) diff --git a/bazel/generate_version_header.py b/bazel/generate_version_header.py new file mode 100644 index 000000000..bd47b7c4f --- /dev/null +++ b/bazel/generate_version_header.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 +"""Generate a version header for the Bazel build. + +Splits a semantic version string into major, minor, and patch and uses the +provided template to produce a working version header. +""" + +import argparse +import re +import sys + + +def _parse_args(): + parser = argparse.ArgumentParser( + description=__doc__, + ) + parser.add_argument( + "--version-string", + required=True, + help="SDK version string", + ) + parser.add_argument( + "--template", + type=argparse.FileType("r"), + required=True, + help="Path to version.h.in", + ) + parser.add_argument( + "-o", + "--output", + type=argparse.FileType("wb"), + default=sys.stdout.buffer, + help="Output file path. Defaults to stdout.", + ) + return parser.parse_args() + + +_EXPANSION_REGEX = re.compile("(?:\$\{)([a-zA-Z]\w*)(?:\})") + + +def generate_version_header(version_string, template, output): + version_parts = version_string.split('.') + defines = { + "PICO_SDK_VERSION_MAJOR": version_parts[0], + "PICO_SDK_VERSION_MINOR": version_parts[1], + "PICO_SDK_VERSION_REVISION": version_parts[2].split('-')[0], + "PICO_SDK_VERSION_STRING": version_string, + } + output.write( + _EXPANSION_REGEX.sub( + lambda val: str(defines.get(val.group(1))), + template.read(), + ).encode() + ) + + +if __name__ == "__main__": + sys.exit(generate_version_header(**vars(_parse_args()))) diff --git a/bazel/include/pico/config_autogen.h b/bazel/include/pico/config_autogen.h new file mode 100644 index 000000000..027dfe23c --- /dev/null +++ b/bazel/include/pico/config_autogen.h @@ -0,0 +1,12 @@ +// Rather than auto-generating as part of the build, this header +// is checked in directly. +// +// You can change what is included by configuring these `label_flag`s: +// --@pico-sdk//bazel/config:pico_config_extra_headers=//my_proj:my_custom_headers +// --@pico-sdk//bazel/config:pico_config_platform_headers=//my_proj:my_custom_headers + +// This header must be provided by //bazel/config:pico_config_extra_headers: +#include "pico_config_extra_headers.h" + +// This header must be provided by //bazel/config:pico_config_platform_headers: +#include "pico_config_platform_headers.h" diff --git a/bazel/platform/BUILD.bazel b/bazel/platform/BUILD.bazel new file mode 100644 index 000000000..467c0b1d6 --- /dev/null +++ b/bazel/platform/BUILD.bazel @@ -0,0 +1,9 @@ +package(default_visibility = ["//visibility:public"]) + +platform( + name = "rp2040", + constraint_values = [ + "@pico-sdk//bazel/constraint:rp2040", + "@platforms//cpu:armv6-m", # This is just FYI. + ], +) diff --git a/bazel/toolchain/BUILD.bazel b/bazel/toolchain/BUILD.bazel new file mode 100644 index 000000000..a246e0da7 --- /dev/null +++ b/bazel/toolchain/BUILD.bazel @@ -0,0 +1,151 @@ +load("@rules_cc//cc/toolchains:args.bzl", "cc_args") +load("@rules_cc//cc/toolchains:args_list.bzl", "cc_args_list") +load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") +load("@rules_cc//cc/toolchains:toolchain.bzl", "cc_toolchain") + +cc_args( + name = "cortex-m0", + actions = [ + "@rules_cc//cc/toolchains/actions:compile_actions", + "@rules_cc//cc/toolchains/actions:link_actions", + ], + args = [ + "-mcpu=cortex-m0plus", + "-mthumb", + ], +) + +cc_args( + name = "bazel_no_absolute_paths", + actions = ["@rules_cc//cc/toolchains/actions:compile_actions"], + args = [ + "-fno-canonical-system-headers", + "-no-canonical-prefixes", + ], +) + +cc_args_list( + name = "all_unconditional_args", + args = [ + ":cortex-m0", + ":bazel_no_absolute_paths", + ], +) + +cc_args( + name = "opt_debug_args", + actions = [ + "@rules_cc//cc/toolchains/actions:compile_actions", + "@rules_cc//cc/toolchains/actions:link_actions", + ], + args = [ + "-Og", # TODO: Make this configurable. + "-g3", + ], +) + +# TODO: Make this shim unnecessary. +cc_args_list( + name = "all_opt_debug_args", + args = [":opt_debug_args"], +) + +cc_feature( + name = "override_debug", + args = [":all_opt_debug_args"], + enabled = True, + overrides = "@rules_cc//cc/toolchains/features:dbg", +) + +# TODO: https://github.com/bazelbuild/rules_cc/issues/224 - This is required for +# now, but hopefully will eventually go away. +cc_feature( + name = "legacy_features", + args = [], + enabled = True, + feature_name = "force_legacy_features", + implies = [ + "@rules_cc//cc/toolchains/features/legacy:archiver_flags", + "@rules_cc//cc/toolchains/features/legacy:build_interface_libraries", + "@rules_cc//cc/toolchains/features/legacy:dynamic_library_linker_tool", + "@rules_cc//cc/toolchains/features/legacy:strip_debug_symbols", + "@rules_cc//cc/toolchains/features/legacy:linkstamps", + "@rules_cc//cc/toolchains/features/legacy:output_execpath_flags", + "@rules_cc//cc/toolchains/features/legacy:runtime_library_search_directories", + "@rules_cc//cc/toolchains/features/legacy:library_search_directories", + "@rules_cc//cc/toolchains/features/legacy:libraries_to_link", + "@rules_cc//cc/toolchains/features/legacy:force_pic_flags", + "@rules_cc//cc/toolchains/features/legacy:user_link_flags", + "@rules_cc//cc/toolchains/features/legacy:legacy_link_flags", + "@rules_cc//cc/toolchains/features/legacy:linker_param_file", + "@rules_cc//cc/toolchains/features/legacy:fission_support", + "@rules_cc//cc/toolchains/features/legacy:sysroot", + ], +) + +HOSTS = ( + ("linux", "x86_64"), + ("win", "x86_64"), + ("mac", "x86_64"), + ("mac", "aarch64"), +) + +_HOST_OS_CONSTRAINTS = { + "linux": "@platforms//os:linux", + "win": "@platforms//os:windows", + "mac": "@platforms//os:macos", +} + +_HOST_CPU_CONSTRAINTS = { + "x86_64": "@platforms//cpu:x86_64", + "aarch64": "@platforms//cpu:aarch64", +} + +[cc_toolchain( + name = "arm_gcc_{}-{}_toolchain_cortex-m".format(host_os, host_cpu), + action_type_configs = [ + "@arm_gcc_{}-{}//:arm-none-eabi-ar".format(host_os, host_cpu), + "@arm_gcc_{}-{}//:arm-none-eabi-gcc".format(host_os, host_cpu), + "@arm_gcc_{}-{}//:arm-none-eabi-g++".format(host_os, host_cpu), + "@arm_gcc_{}-{}//:arm-none-eabi-ld".format(host_os, host_cpu), + "@arm_gcc_{}-{}//:arm-none-eabi-objcopy".format(host_os, host_cpu), + "@arm_gcc_{}-{}//:arm-none-eabi-strip".format(host_os, host_cpu), + ], + args = ["@pico-sdk//bazel/toolchain:all_unconditional_args"], + compiler = "gcc", # Useful for distinguishing gcc vs clang. + cxx_builtin_include_directories = [ + "%sysroot%/arm-none-eabi/include/newlib-nano", + "%sysroot%/arm-none-eabi/include/c++/13.2.1", + "%sysroot%/arm-none-eabi/include/c++/13.2.1/arm-none-eabi", + "%sysroot%/arm-none-eabi/include/c++/13.2.1/backward", + "%sysroot%/lib/gcc/arm-none-eabi/13.2.1/include", + "%sysroot%/lib/gcc/arm-none-eabi/13.2.1/include-fixed", + "%sysroot%/arm-none-eabi/include", + ], + exec_compatible_with = [ + _HOST_CPU_CONSTRAINTS[host_cpu], + _HOST_OS_CONSTRAINTS[host_os], + ], + sysroot = "external/arm_gcc_{}-{}".format(host_os, host_cpu), + tags = ["manual"], # Don't try to build this in wildcard builds. + target_compatible_with = [ + "@pico-sdk//bazel/constraint:rp2040", + ], + toolchain_features = [ + "@pico-sdk//bazel/toolchain:legacy_features", + "@pico-sdk//bazel/toolchain:override_debug", + ], +) for host_os, host_cpu in HOSTS] + +[toolchain( + name = "arm_gcc_{}-{}".format(host_os, host_cpu), + exec_compatible_with = [ + _HOST_CPU_CONSTRAINTS[host_cpu], + _HOST_OS_CONSTRAINTS[host_os], + ], + target_compatible_with = [ + "@pico-sdk//bazel/constraint:rp2040", + ], + toolchain = ":arm_gcc_{}-{}_toolchain_cortex-m".format(host_os, host_cpu), + toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", +) for host_os, host_cpu in HOSTS] diff --git a/bazel/toolchain/gcc_arm_none_eabi.BUILD b/bazel/toolchain/gcc_arm_none_eabi.BUILD new file mode 100644 index 000000000..56bb0972f --- /dev/null +++ b/bazel/toolchain/gcc_arm_none_eabi.BUILD @@ -0,0 +1,145 @@ +load("@rules_cc//cc/toolchains:action_type_config.bzl", "cc_action_type_config") +load("@rules_cc//cc/toolchains:tool.bzl", "cc_tool") + +package(default_visibility = ["//visibility:public"]) + +cc_tool( + name = "arm-none-eabi-ar_tool", + src = select({ + "@platforms//os:windows": "//:bin/arm-none-eabi-ar.exe", + "//conditions:default": "//:bin/arm-none-eabi-ar", + }), +) + +cc_action_type_config( + name = "arm-none-eabi-ar", + action_types = ["@rules_cc//cc/toolchains/actions:ar_actions"], + tools = [":arm-none-eabi-ar_tool"], +) + +cc_tool( + name = "arm-none-eabi-g++_tool", + src = select({ + "@platforms//os:windows": "//:bin/arm-none-eabi-g++.exe", + "//conditions:default": "//:bin/arm-none-eabi-g++", + }), + data = glob([ + "**/*.spec", + "**/*.specs", + "arm-none-eabi/include/**", + "lib/gcc/arm-none-eabi/*/include/**", + "lib/gcc/arm-none-eabi/*/include-fixed/**", + "libexec/**", + ]), +) + +cc_action_type_config( + name = "arm-none-eabi-g++", + action_types = ["@rules_cc//cc/toolchains/actions:cpp_compile_actions"], + tools = [":arm-none-eabi-g++_tool"], +) + +cc_tool( + name = "arm-none-eabi-gcc_tool", + src = select({ + "@platforms//os:windows": "//:bin/arm-none-eabi-gcc.exe", + "//conditions:default": "//:bin/arm-none-eabi-gcc", + }), + data = glob([ + "**/*.spec", + "**/*.specs", + "arm-none-eabi/include/**", + "lib/gcc/arm-none-eabi/*/include/**", + "lib/gcc/arm-none-eabi/*/include-fixed/**", + "libexec/**", + ]) + + # The assembler needs to be explicitly added. Note that the path is + # intentionally different here as `as` is called from arm-none-eabi-gcc. + # `arm-none-eabi-as` will not suffice for this context. + select({ + "@platforms//os:windows": ["//:arm-none-eabi/bin/as.exe"], + "//conditions:default": ["//:arm-none-eabi/bin/as"], + }), +) + +cc_action_type_config( + name = "arm-none-eabi-gcc", + action_types = [ + "@rules_cc//cc/toolchains/actions:assembly_actions", + "@rules_cc//cc/toolchains/actions:c_compile", + ], + tools = [":arm-none-eabi-gcc_tool"], +) + +# This tool is actually just g++ under the hood, but this specifies a +# different set of data files to pull into the sandbox at runtime. +cc_tool( + name = "arm-none-eabi-ld_tool", + src = select({ + "@platforms//os:windows": "//:bin/arm-none-eabi-g++.exe", + "//conditions:default": "//:bin/arm-none-eabi-g++", + }), + data = glob([ + "**/*.a", + "**/*.ld", + "**/*.o", + "**/*.spec", + "**/*.specs", + "**/*.so", + "libexec/**", + ]), +) + +cc_action_type_config( + name = "arm-none-eabi-ld", + action_types = ["@rules_cc//cc/toolchains/actions:link_actions"], + tools = [":arm-none-eabi-ld_tool"], +) + +cc_tool( + name = "arm-none-eabi-objcopy_tool", + src = select({ + "@platforms//os:windows": "//:bin/arm-none-eabi-objcopy.exe", + "//conditions:default": "//:bin/arm-none-eabi-objcopy", + }), +) + +cc_action_type_config( + name = "arm-none-eabi-objcopy", + action_types = ["@rules_cc//cc/toolchains/actions:objcopy_embed_data"], + tools = [":arm-none-eabi-objcopy_tool"], +) + +cc_tool( + name = "arm-none-eabi-strip_tool", + src = select({ + "@platforms//os:windows": "//:bin/arm-none-eabi-strip.exe", + "//conditions:default": "//:bin/arm-none-eabi-strip", + }), +) + +cc_action_type_config( + name = "arm-none-eabi-strip", + action_types = ["@rules_cc//cc/toolchains/actions:strip"], + tools = [":arm-none-eabi-strip_tool"], +) + +cc_tool( + name = "arm-none-eabi-objdump_tool", + src = select({ + "@platforms//os:windows": "//:bin/arm-none-eabi-objdump.exe", + "//conditions:default": "//:bin/arm-none-eabi-objdump", + }), +) + +# There is not yet a well-known action type for objdump. + +cc_tool( + name = "arm-none-eabi-gcov_tool", + src = select({ + "@platforms//os:windows": "//:bin/arm-none-eabi-gcov.exe", + "//conditions:default": "//:bin/arm-none-eabi-gcov", + }), +) + +# There is not yet a well-known action type for gcov. diff --git a/bazel/toolchain/objcopy.bzl b/bazel/toolchain/objcopy.bzl new file mode 100644 index 000000000..c1ba06a34 --- /dev/null +++ b/bazel/toolchain/objcopy.bzl @@ -0,0 +1,46 @@ +load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "OBJ_COPY_ACTION_NAME") +load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cpp_toolchain", "use_cc_toolchain") + +def _objcopy_to_bin_impl(ctx): + cc_toolchain = find_cpp_toolchain(ctx) + feature_configuration = cc_common.configure_features( + ctx = ctx, + cc_toolchain = cc_toolchain, + requested_features = ctx.features, + unsupported_features = ctx.disabled_features, + ) + objcopy_tool_path = cc_common.get_tool_for_action( + feature_configuration = feature_configuration, + action_name = OBJ_COPY_ACTION_NAME, + ) + + ctx.actions.run( + inputs = depset( + direct = [ctx.file.src], + transitive = [cc_toolchain.all_files], + ), + executable = objcopy_tool_path, + outputs = [ctx.outputs.out], + arguments = [ + ctx.file.src.path, + "-Obinary", + ctx.outputs.out.path, + ], + ) + +objcopy_to_bin = rule( + implementation = _objcopy_to_bin_impl, + attrs = { + "src": attr.label( + allow_single_file = True, + mandatory = True, + doc = "File to use as input to objcopy command", + ), + "out": attr.output( + mandatory = True, + doc = "Destination file for objcopy command", + ), + }, + fragments = ["cpp"], + toolchains = use_cc_toolchain(), +) diff --git a/bazel/util/BUILD.bazel b/bazel/util/BUILD.bazel new file mode 100644 index 000000000..ffd0fb0cd --- /dev/null +++ b/bazel/util/BUILD.bazel @@ -0,0 +1 @@ +package(default_visibility = ["//visibility:public"]) diff --git a/bazel/util/transition.bzl b/bazel/util/transition.bzl new file mode 100644 index 000000000..c768c0a17 --- /dev/null +++ b/bazel/util/transition.bzl @@ -0,0 +1,74 @@ +# A transition in Bazel is a way to force changes to the way the build is +# evaluated for all dependencies of a given rule. +# +# Imagine the following simple dependency graph: +# +# ->: depends on +# a -> b -> c +# +# Normally, if you set `defines` on a, they couldn't apply to b or c because +# they are dependencies of a. There's no way for b or c to know about a's +# settings, because they don't even know a exists! +# +# We can fix this via a transition! If we put a transition in front of `a` +# that sets --copts=-DFOO=42, we're telling Bazel to build a and all of its +# dependencies under that configuration. +# +# Note: Flags must be referenced as e.g. `//command_line_option:copt` in +# transitions. +# +# `declare_transition()` eliminates the frustrating amount of boilerplate. All +# you need to do is provide a set of attrs, and then a `flag_overrides` +# dictionary that tells `declare_transition()` which attrs to pull flag values +# from. The common `src` attr tells the transition which build rule to apply +# the transition to. +def declare_transtion(attrs, flag_overrides, executable = True): + def _flag_override_impl(settings, attrs): + return { + key: str(getattr(attrs, value)) + for key, value in flag_overrides.items() + } + + _transition = transition( + implementation = _flag_override_impl, + inputs = [], + outputs = flag_overrides.keys(), + ) + + def _symlink_artifact_impl(ctx): + out = ctx.actions.declare_file(ctx.label.name) + if executable: + ctx.actions.symlink(output = out, target_file = ctx.executable.src) + return [DefaultInfo(files = depset([out]), executable = out)] + + ctx.actions.symlink( + output = out, + target_file = ctx.attr.src[0][DefaultInfo].files.to_list()[0], + ) + return [DefaultInfo(files = depset([out]))] + + return rule( + implementation = _symlink_artifact_impl, + executable = executable, + attrs = { + "src": attr.label( + cfg = _transition, + executable = executable, + mandatory = True, + ), + "_allowlist_function_transition": attr.label( + default = "@bazel_tools//tools/allowlists/function_transition_allowlist", + ), + } | attrs, + ) + +rp2040_bootloader_binary = declare_transtion( + attrs = { + "_malloc": attr.label(default = "//src/rp2_common/boot_stage2:no_malloc"), + }, + flag_overrides = { + # We don't want --custom_malloc to ever apply to the bootloader, so + # always explicitly override it here. + "//command_line_option:custom_malloc": "_malloc", + }, +) diff --git a/src/boards/BUILD.bazel b/src/boards/BUILD.bazel new file mode 100644 index 000000000..31d74b9e3 --- /dev/null +++ b/src/boards/BUILD.bazel @@ -0,0 +1,105 @@ +package(default_visibility = ["//visibility:public"]) + +# TODO: Add a macro/helper to support the rest of the boards. +cc_library( + name = "unsupported_boards", + srcs = [ + "include/boards/adafruit_feather_rp2040.h", + "include/boards/adafruit_itsybitsy_rp2040.h", + "include/boards/adafruit_kb2040.h", + "include/boards/adafruit_macropad_rp2040.h", + "include/boards/adafruit_qtpy_rp2040.h", + "include/boards/adafruit_trinkey_qt2040.h", + "include/boards/arduino_nano_rp2040_connect.h", + "include/boards/datanoisetv_rp2040_dsp.h", + "include/boards/eetree_gamekit_rp2040.h", + "include/boards/garatronic_pybstick26_rp2040.h", + "include/boards/melopero_shake_rp2040.h", + "include/boards/none.h", + "include/boards/nullbits_bit_c_pro.h", + "include/boards/pico_w.h", + "include/boards/pimoroni_badger2040.h", + "include/boards/pimoroni_interstate75.h", + "include/boards/pimoroni_keybow2040.h", + "include/boards/pimoroni_motor2040.h", + "include/boards/pimoroni_pga2040.h", + "include/boards/pimoroni_picolipo_16mb.h", + "include/boards/pimoroni_picolipo_4mb.h", + "include/boards/pimoroni_picosystem.h", + "include/boards/pimoroni_plasma2040.h", + "include/boards/pimoroni_servo2040.h", + "include/boards/pimoroni_tiny2040.h", + "include/boards/pimoroni_tiny2040_2mb.h", + "include/boards/pololu_3pi_2040_robot.h", + "include/boards/seeed_xiao_rp2040.h", + "include/boards/solderparty_rp2040_stamp.h", + "include/boards/solderparty_rp2040_stamp_carrier.h", + "include/boards/solderparty_rp2040_stamp_round_carrier.h", + "include/boards/sparkfun_micromod.h", + "include/boards/sparkfun_promicro.h", + "include/boards/sparkfun_thingplus.h", + "include/boards/vgaboard.h", + "include/boards/waveshare_rp2040_lcd_0.96.h", + "include/boards/waveshare_rp2040_lcd_1.28.h", + "include/boards/waveshare_rp2040_one.h", + "include/boards/waveshare_rp2040_plus_16mb.h", + "include/boards/waveshare_rp2040_plus_4mb.h", + "include/boards/waveshare_rp2040_zero.h", + "include/boards/wiznet_w5100s_evb_pico.h", + ], + includes = ["include"], + visibility = ["//visibility:private"], +) + +cc_library( + name = "stdio_defines", + defines = select({ + "//bazel/constraint:stdio_semihosting": ["LIB_PICO_STDIO_SEMIHOSTING=1"], + "//bazel/constraint:stdio_uart": ["LIB_PICO_STDIO_UART=1"], + "//bazel/constraint:stdio_usb": ["LIB_PICO_STDIO_USB=1"], + }), +) + +cc_library( + name = "common_board_defines", + defines = [ + "PICO_ON_DEVICE=1", + "PICO_NO_HARDWARE=0", + "PICO_BUILD=1", + ], +) + +cc_library( + name = "pico", + hdrs = ["include/boards/pico.h"], + defines = [ + 'PICO_BOARD=\\"rp2040\\"', + 'PICO_CONFIG_HEADER="boards/pico.h"', + ], + includes = ["include"], + deps = [ + ":common_board_defines", + ":stdio_defines", + ], +) + +cc_library( + name = "host", + hdrs = ["include/boards/none.h"], + defines = [ + 'PICO_BOARD=\\"none\\"', + 'PICO_CONFIG_HEADER="boards/none.h"', + "PICO_ON_DEVICE=0", + "PICO_NO_HARDWARE=1", + "PICO_BUILD=1", + ], + includes = ["include"], +) + +alias( + name = "default", + actual = select({ + "//bazel/constraint:rp2": ":pico", + "//bazel/constraint:host": ":host", + }), +) diff --git a/src/common/boot_picoboot/BUILD.bazel b/src/common/boot_picoboot/BUILD.bazel new file mode 100644 index 000000000..5007a2333 --- /dev/null +++ b/src/common/boot_picoboot/BUILD.bazel @@ -0,0 +1,8 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "boot_picoboot", + hdrs = ["include/boot/picoboot.h"], + includes = ["include"], + deps = ["//src/common/pico_base:pico_platform"], +) diff --git a/src/common/boot_uf2/BUILD.bazel b/src/common/boot_uf2/BUILD.bazel new file mode 100644 index 000000000..a170f6967 --- /dev/null +++ b/src/common/boot_uf2/BUILD.bazel @@ -0,0 +1,7 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "boot_uf2", + hdrs = ["include/boot/uf2.h"], + includes = ["include"], +) diff --git a/src/common/pico_base/BUILD.bazel b/src/common/pico_base/BUILD.bazel new file mode 100644 index 000000000..dd8cf9929 --- /dev/null +++ b/src/common/pico_base/BUILD.bazel @@ -0,0 +1,103 @@ +load("@bazel_skylib//rules:run_binary.bzl", "run_binary") + +package(default_visibility = ["//visibility:public"]) + +run_binary( + name = "version_header", + srcs = ["include/pico/version.h.in"], + outs = ["generated_include/pico/version.h"], + args = [ + "--version-string={}".format( + module_version() if module_version() != None else "0.0.1-WORKSPACE", + ), + "--template=$(location include/pico/version.h.in)", + "--output=$(location generated_include/pico/version.h)", + ], + tool = "//bazel:generate_version_header", + visibility = ["//visibility:private"], +) + +cc_library( + name = "version", + hdrs = ["generated_include/pico/version.h"], + includes = ["generated_include"], +) + +alias( + name = "platform_defs", + actual = select({ + "//bazel/constraint:host": "//src/host/pico_platform:platform_defs", + "//bazel/constraint:rp2": "//src/rp2_common/pico_platform:platform_defs", + }), +) + +alias( + name = "pico_platform", + actual = select({ + "//bazel/constraint:host": "//src/host/pico_platform:pico_platform", + "//bazel/constraint:rp2": "//src/rp2_common/pico_platform:pico_platform", + }), +) + +cc_library( + name = "pico_base_interface", + hdrs = [ + "include/pico.h", + "include/pico/assert.h", + "include/pico/config.h", + "include/pico/error.h", + "include/pico/types.h", + ], + includes = ["include"], + + # Be extra careful about who references this for now; if users depend on + # this but not `pico_base` they'll end up with undefined symbols. + # It's generally safe for anything that circularly depends on + # //src/common/pico_base:pico_base to be added to this allowlist because + # that implicitly means the transitive dependencies of pico_base will get + # linked in. + visibility = [ + "//src/common/pico_binary_info:__pkg__", + "//src/common/pico_sync:__pkg__", + "//src/common/pico_time:__pkg__", + "//src/common/pico_util:__pkg__", + "//src/host/pico_platform:__pkg__", + "//src/rp2_common/boot_stage2:__pkg__", + "//src/rp2_common/hardware_claim:__pkg__", + "//src/rp2_common/hardware_clocks:__pkg__", + "//src/rp2_common/hardware_gpio:__pkg__", + "//src/rp2_common/hardware_irq:__pkg__", + "//src/rp2_common/hardware_pll:__pkg__", + "//src/rp2_common/hardware_resets:__pkg__", + "//src/rp2_common/hardware_sync:__pkg__", + "//src/rp2_common/hardware_timer:__pkg__", + "//src/rp2_common/hardware_watchdog:__pkg__", + "//src/rp2_common/hardware_xosc:__pkg__", + "//src/rp2_common/pico_bootrom:__pkg__", + "//src/rp2_common/pico_malloc:__pkg__", + "//src/rp2_common/pico_platform:__pkg__", + "//src/rp2_common/pico_printf:__pkg__", + "//src/rp2_common/pico_runtime:__pkg__", + "//src/rp2_common/pico_standard_link:__pkg__", + ], + deps = [ + ":version", + "//bazel:generate_config_header", + "//bazel/config:pico_config_header", + ], +) + +cc_library( + name = "pico_base", + deps = [ + # :pico_platform creates circular dependencies, so break them + # via an intermediate. + ":pico_platform", + ":pico_base_interface", + "//src/rp2_common/cmsis:cmsis_core", + "//src/rp2_common/boot_stage2", + "//src/rp2_common/pico_bootrom", + "//src/rp2_common/pico_runtime", + "//src/rp2_common/pico_standard_link", + ], +) diff --git a/src/common/pico_binary_info/BUILD.bazel b/src/common/pico_binary_info/BUILD.bazel new file mode 100644 index 000000000..f3b996a4c --- /dev/null +++ b/src/common/pico_binary_info/BUILD.bazel @@ -0,0 +1,18 @@ +package(default_visibility = ["//visibility:public"]) + +# TODO: Flags to support PICO_PROGRAM_*. + +cc_library( + name = "pico_binary_info", + hdrs = [ + "include/pico/binary_info.h", + "include/pico/binary_info/code.h", + "include/pico/binary_info/defs.h", + "include/pico/binary_info/structure.h", + ], + includes = ["include"], + deps = [ + "//src/common/pico_base:pico_base_interface", + "//src/common/pico_base:pico_platform", + ], +) diff --git a/src/common/pico_bit_ops/BUILD.bazel b/src/common/pico_bit_ops/BUILD.bazel new file mode 100644 index 000000000..3a819336e --- /dev/null +++ b/src/common/pico_bit_ops/BUILD.bazel @@ -0,0 +1,31 @@ +package(default_visibility = ["//visibility:public"]) + +# This exists to break dependency cycles between +# this library and the bit ops implementations. +# Application code should always use :pico_bit_ops instead. +cc_library( + name = "pico_bit_ops_headers", + hdrs = ["include/pico/bit_ops.h"], + includes = ["include"], + visibility = [ + "//src/rp2_common/pico_bit_ops:__pkg__", + ], + deps = [ + "//src/common/pico_base", + ], +) + +cc_library( + name = "pico_bit_ops", + hdrs = ["include/pico/bit_ops.h"], + includes = ["include"], + # TODO: Add `select()` for host redirections. + target_compatible_with = select({ + "//bazel/constraint:rp2": [], + "//conditions:default": ["@platforms//:incompatible"], + }), + deps = [ + "//src/common/pico_base", + "//src/rp2_common/pico_bit_ops", + ], +) diff --git a/src/common/pico_divider/BUILD.bazel b/src/common/pico_divider/BUILD.bazel new file mode 100644 index 000000000..2349eaab5 --- /dev/null +++ b/src/common/pico_divider/BUILD.bazel @@ -0,0 +1,13 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_divider", + hdrs = ["include/pico/divider.h"], + includes = ["include"], + deps = [ + "//src/common/pico_base", + ] + select({ + "//bazel/constraint:rp2": ["//src/rp2_common/hardware_divider"], + "//bazel/constraint:host": ["//src/host/hardware_divider"], + }), +) diff --git a/src/common/pico_stdlib/BUILD.bazel b/src/common/pico_stdlib/BUILD.bazel new file mode 100644 index 000000000..0e34e6720 --- /dev/null +++ b/src/common/pico_stdlib/BUILD.bazel @@ -0,0 +1,44 @@ +package(default_visibility = ["//visibility:public"]) + +# This exists to break a header dependency cycle from rp2_common/pico_stdlib. +# Do not directly depend on this. +cc_library( + name = "pico_stdlib_interface", + hdrs = ["include/pico/stdlib.h"], + includes = ["include"], + # TODO: Add `select()` for host redirections. + target_compatible_with = select({ + "//bazel/constraint:rp2": [], + "//conditions:default": ["@platforms//:incompatible"], + }), + visibility = [ + "//src/rp2_common/pico_stdlib:__pkg__", + "//src/rp2_common/tinyusb:__pkg__", + ], + deps = [ + "//src/common/pico_base", + "//src/common/pico_time", + "//src/rp2_common/hardware_gpio", + "//src/rp2_common/hardware_uart", + "//src/rp2_common/pico_stdio", + ], +) + +cc_library( + name = "pico_stdlib", + hdrs = ["include/pico/stdlib.h"], + includes = ["include"], + # TODO: Add `select()` for host redirections. + target_compatible_with = select({ + "//bazel/constraint:rp2": [], + "//conditions:default": ["@platforms//:incompatible"], + }), + deps = [ + "//src/common/pico_base", + "//src/common/pico_time", + "//src/rp2_common/hardware_gpio", + "//src/rp2_common/hardware_uart", + "//src/rp2_common/pico_stdio", + "//src/rp2_common/pico_stdlib", + ], +) diff --git a/src/common/pico_sync/BUILD.bazel b/src/common/pico_sync/BUILD.bazel new file mode 100644 index 000000000..68042a91b --- /dev/null +++ b/src/common/pico_sync/BUILD.bazel @@ -0,0 +1,29 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_sync", + srcs = [ + "critical_section.c", + "lock_core.c", + "mutex.c", + "sem.c", + ], + hdrs = [ + "include/pico/critical_section.h", + "include/pico/lock_core.h", + "include/pico/mutex.h", + "include/pico/sem.h", + "include/pico/sync.h", + ], + includes = ["include"], + # TODO: Add `select()` for host redirections. + target_compatible_with = select({ + "//bazel/constraint:rp2": [], + "//conditions:default": ["@platforms//:incompatible"], + }), + deps = [ + "//src/common/pico_base:pico_base_interface", + "//src/common/pico_time:pico_time_headers", + "//src/rp2_common/hardware_sync", + ], +) diff --git a/src/common/pico_time/BUILD.bazel b/src/common/pico_time/BUILD.bazel new file mode 100644 index 000000000..b32dc5bec --- /dev/null +++ b/src/common/pico_time/BUILD.bazel @@ -0,0 +1,44 @@ +package(default_visibility = ["//visibility:public"]) + +# This exists to break a dependency cycle between +# this library and //src/common/pico_sync. +# Application code should always use :pico_time instead. +cc_library( + name = "pico_time_headers", + hdrs = [ + "include/pico/time.h", + "include/pico/timeout_helper.h", + ], + includes = ["include"], + visibility = [ + "//src/common/pico_sync:__pkg__", + "//src/rp2_common/tinyusb:__pkg__", + ], + deps = [ + "//src/rp2_common/hardware_timer:hardware_timer_headers", + ], +) + +cc_library( + name = "pico_time", + srcs = [ + "time.c", + "timeout_helper.c", + ], + hdrs = [ + "include/pico/time.h", + "include/pico/timeout_helper.h", + ], + includes = ["include"], + # TODO: Add `select()` for host redirections. + target_compatible_with = select({ + "//bazel/constraint:rp2": [], + "//conditions:default": ["@platforms//:incompatible"], + }), + deps = [ + "//src/common/pico_base:pico_base_interface", + "//src/common/pico_sync", + "//src/common/pico_util", + "//src/rp2_common/hardware_timer", + ], +) diff --git a/src/common/pico_usb_reset_interface/BUILD.bazel b/src/common/pico_usb_reset_interface/BUILD.bazel new file mode 100644 index 000000000..14f4a3420 --- /dev/null +++ b/src/common/pico_usb_reset_interface/BUILD.bazel @@ -0,0 +1,7 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_usb_reset_interface", + hdrs = ["include/pico/usb_reset_interface.h"], + includes = ["include"], +) diff --git a/src/common/pico_util/BUILD.bazel b/src/common/pico_util/BUILD.bazel new file mode 100644 index 000000000..00d7b239c --- /dev/null +++ b/src/common/pico_util/BUILD.bazel @@ -0,0 +1,26 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_util", + srcs = [ + "datetime.c", + "pheap.c", + "queue.c", + ], + hdrs = [ + "include/pico/util/datetime.h", + "include/pico/util/pheap.h", + "include/pico/util/queue.h", + ], + includes = ["include"], + # TODO: Add `select()` for host redirections. + target_compatible_with = select({ + "//bazel/constraint:rp2": [], + "//conditions:default": ["@platforms//:incompatible"], + }), + deps = [ + "//src/common/pico_base:pico_base_interface", + "//src/common/pico_sync", + "//src/rp2_common/hardware_sync", + ], +) diff --git a/src/host/pico_platform/BUILD.bazel b/src/host/pico_platform/BUILD.bazel new file mode 100644 index 000000000..2cad9cd4f --- /dev/null +++ b/src/host/pico_platform/BUILD.bazel @@ -0,0 +1,22 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "platform_defs", + hdrs = [ + "include/hardware/platform_defs.h", + ], + includes = ["include"], +) + +cc_library( + name = "pico_platform", + srcs = ["platform_base.c"], + hdrs = [ + "include/pico/platform.h", + ], + includes = ["include"], + deps = [ + ":platform_defs", + "//src/common/pico_base:pico_base_interface", + ], +) diff --git a/src/rp2040/hardware_regs/BUILD.bazel b/src/rp2040/hardware_regs/BUILD.bazel new file mode 100644 index 000000000..6bd00813a --- /dev/null +++ b/src/rp2040/hardware_regs/BUILD.bazel @@ -0,0 +1,53 @@ +# Always include these libraries through //src/rp2_common/pico_platform:*! +# This ensures that you'll get the right headers for the MCU you're targeting. + +package(default_visibility = ["//src/rp2_common/pico_platform:__pkg__"]) + +cc_library( + name = "platform_defs", + hdrs = [ + "include/hardware/platform_defs.h", + ], + includes = ["include"], +) + +cc_library( + name = "hardware_regs", + hdrs = [ + "include/hardware/regs/adc.h", + "include/hardware/regs/addressmap.h", + "include/hardware/regs/busctrl.h", + "include/hardware/regs/clocks.h", + "include/hardware/regs/dma.h", + "include/hardware/regs/dreq.h", + "include/hardware/regs/i2c.h", + "include/hardware/regs/intctrl.h", + "include/hardware/regs/io_bank0.h", + "include/hardware/regs/io_qspi.h", + "include/hardware/regs/m0plus.h", + "include/hardware/regs/pads_bank0.h", + "include/hardware/regs/pads_qspi.h", + "include/hardware/regs/pio.h", + "include/hardware/regs/pll.h", + "include/hardware/regs/psm.h", + "include/hardware/regs/pwm.h", + "include/hardware/regs/resets.h", + "include/hardware/regs/rosc.h", + "include/hardware/regs/rtc.h", + "include/hardware/regs/sio.h", + "include/hardware/regs/spi.h", + "include/hardware/regs/ssi.h", + "include/hardware/regs/syscfg.h", + "include/hardware/regs/sysinfo.h", + "include/hardware/regs/tbman.h", + "include/hardware/regs/timer.h", + "include/hardware/regs/uart.h", + "include/hardware/regs/usb.h", + "include/hardware/regs/usb_device_dpram.h", + "include/hardware/regs/vreg_and_chip_reset.h", + "include/hardware/regs/watchdog.h", + "include/hardware/regs/xip.h", + "include/hardware/regs/xosc.h", + ], + includes = ["include"], +) diff --git a/src/rp2040/hardware_structs/BUILD.bazel b/src/rp2040/hardware_structs/BUILD.bazel new file mode 100644 index 000000000..692334cdc --- /dev/null +++ b/src/rp2040/hardware_structs/BUILD.bazel @@ -0,0 +1,43 @@ +# Always include these libraries through //src/rp2_common/pico_platform:*! +# This ensures that you'll get the right headers for the MCU you're targeting. + +package(default_visibility = ["//src/rp2_common/pico_platform:__pkg__"]) + +cc_library( + name = "hardware_structs", + hdrs = [ + "include/hardware/structs/adc.h", + "include/hardware/structs/bus_ctrl.h", + "include/hardware/structs/clocks.h", + "include/hardware/structs/dma.h", + "include/hardware/structs/i2c.h", + "include/hardware/structs/interp.h", + "include/hardware/structs/iobank0.h", + "include/hardware/structs/ioqspi.h", + "include/hardware/structs/mpu.h", + "include/hardware/structs/nvic.h", + "include/hardware/structs/pads_qspi.h", + "include/hardware/structs/padsbank0.h", + "include/hardware/structs/pio.h", + "include/hardware/structs/pll.h", + "include/hardware/structs/psm.h", + "include/hardware/structs/pwm.h", + "include/hardware/structs/resets.h", + "include/hardware/structs/rosc.h", + "include/hardware/structs/rtc.h", + "include/hardware/structs/scb.h", + "include/hardware/structs/sio.h", + "include/hardware/structs/spi.h", + "include/hardware/structs/ssi.h", + "include/hardware/structs/syscfg.h", + "include/hardware/structs/systick.h", + "include/hardware/structs/timer.h", + "include/hardware/structs/uart.h", + "include/hardware/structs/usb.h", + "include/hardware/structs/vreg_and_chip_reset.h", + "include/hardware/structs/watchdog.h", + "include/hardware/structs/xip_ctrl.h", + "include/hardware/structs/xosc.h", + ], + includes = ["include"], +) diff --git a/src/rp2_common/boot_stage2/BUILD.bazel b/src/rp2_common/boot_stage2/BUILD.bazel new file mode 100644 index 000000000..df6a04174 --- /dev/null +++ b/src/rp2_common/boot_stage2/BUILD.bazel @@ -0,0 +1,99 @@ +load("@bazel_skylib//rules:copy_file.bzl", "copy_file") +load("@bazel_skylib//rules:run_binary.bzl", "run_binary") +load("//bazel/toolchain:objcopy.bzl", "objcopy_to_bin") +load("//bazel/util:transition.bzl", "rp2040_bootloader_binary") + +package(default_visibility = ["//visibility:private"]) + +cc_library( + name = "config", + hdrs = [ + "asminclude/boot2_helpers/exit_from_boot2.S", + "asminclude/boot2_helpers/read_flash_sreg.S", + "asminclude/boot2_helpers/wait_ssi_ready.S", + "boot2_at25sf128a.S", + "boot2_generic_03h.S", + "boot2_is25lp080.S", + "boot2_usb_blinky.S", + "boot2_w25q080.S", + "boot2_w25x10cl.S", + "include/boot_stage2/config.h", + ], + includes = [ + "asminclude", + "include", + ], + visibility = ["//src/rp2_common/pico_standard_link:__pkg__"], +) + +# Stub library to prevent custom malloc from getting linked in. boot2 will never +# need malloc, so letting it link can only cause problems. +cc_library( + name = "no_malloc", +) + +cc_binary( + name = "boot_stage2_elf_actual", + srcs = ["compile_time_choice.S"], + copts = ["-fPIC"], + linkopts = [ + "-Wl,--no-gc-sections", + "-nostartfiles", + "-T$(location boot_stage2.ld)", + ], + # this does nothing if someone passes --custom_malloc, so the + # rp2040_bootloader_binary transition forcibly clobbers --custom_malloc. + malloc = ":no_malloc", + tags = ["manual"], + deps = [ + "boot_stage2.ld", + ":config", + "//src/common/pico_base:pico_base_interface", + "//src/common/pico_base:pico_platform", + ], +) + +# Always build the bootloader with the bootloader-specific platform. +rp2040_bootloader_binary( + name = "boot_stage2_elf", + src = "boot_stage2_elf_actual", +) + +objcopy_to_bin( + name = "boot_stage2_bin", + src = ":boot_stage2_elf", + out = "boot_stage2.bin", +) + +# WORKAROUND: Python rules always require a .py extension. +copy_file( + name = "copy_tool_to_py", + src = "pad_checksum", + out = "pad_checksum_tool.py", +) + +py_binary( + name = "pad_checksum_tool", + srcs = ["pad_checksum_tool.py"], +) + +run_binary( + name = "boot_stage2_padded", + srcs = [":boot_stage2_bin"], + outs = ["boot_stage2.S"], + args = [ + "-s 0xffffffff", + "$(location boot_stage2_bin)", + "$(location boot_stage2.S)", + ], + tool = ":pad_checksum_tool", +) + +cc_library( + name = "boot_stage2", + srcs = [":boot_stage2_padded"], + visibility = ["//visibility:public"], + # This isn't referenced as a symbol, so alwayslink is required to ensure + # it doesn't get dropped before the linker script can find it. + alwayslink = True, +) diff --git a/src/rp2_common/cmsis/BUILD.bazel b/src/rp2_common/cmsis/BUILD.bazel new file mode 100644 index 000000000..24cf5dfb7 --- /dev/null +++ b/src/rp2_common/cmsis/BUILD.bazel @@ -0,0 +1,34 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "rename_exceptions", + hdrs = ["include/cmsis/rename_exceptions.h"], + includes = ["include"], +) + +cc_library( + name = "cmsis_core", + srcs = [ + "stub/CMSIS/Device/RaspberryPi/RP2040/Source/system_RP2040.c", + ], + hdrs = [ + "stub/CMSIS/Core/Include/cmsis_armcc.h", + "stub/CMSIS/Core/Include/cmsis_armclang.h", + "stub/CMSIS/Core/Include/cmsis_armclang_ltm.h", + "stub/CMSIS/Core/Include/cmsis_compiler.h", + "stub/CMSIS/Core/Include/cmsis_gcc.h", + "stub/CMSIS/Core/Include/cmsis_iccarm.h", + "stub/CMSIS/Core/Include/cmsis_version.h", + "stub/CMSIS/Core/Include/core_cm0plus.h", + "stub/CMSIS/Core/Include/mpu_armv7.h", + "stub/CMSIS/Device/RaspberryPi/RP2040/Include/RP2040.h", + "stub/CMSIS/Device/RaspberryPi/RP2040/Include/system_RP2040.h", + ], + includes = [ + "stub/CMSIS/Core/Include", + "stub/CMSIS/Device/RaspberryPi/RP2040/Include", + ], + deps = [ + "//src/rp2_common/hardware_clocks", + ], +) diff --git a/src/rp2_common/hardware_adc/BUILD.bazel b/src/rp2_common/hardware_adc/BUILD.bazel new file mode 100644 index 000000000..29dfd09cc --- /dev/null +++ b/src/rp2_common/hardware_adc/BUILD.bazel @@ -0,0 +1,14 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "hardware_adc", + srcs = ["adc.c"], + hdrs = ["include/hardware/adc.h"], + includes = ["include"], + deps = [ + "//src/common/pico_base", + "//src/rp2_common/hardware_gpio", + "//src/rp2_common/hardware_resets", + "//src/rp2_common/pico_platform:hardware_structs", + ], +) diff --git a/src/rp2_common/hardware_base/BUILD.bazel b/src/rp2_common/hardware_base/BUILD.bazel new file mode 100644 index 000000000..ebf54b9cd --- /dev/null +++ b/src/rp2_common/hardware_base/BUILD.bazel @@ -0,0 +1,7 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "hardware_base", + hdrs = ["include/hardware/address_mapped.h"], + includes = ["include"], +) diff --git a/src/rp2_common/hardware_claim/BUILD.bazel b/src/rp2_common/hardware_claim/BUILD.bazel new file mode 100644 index 000000000..b9875cac9 --- /dev/null +++ b/src/rp2_common/hardware_claim/BUILD.bazel @@ -0,0 +1,13 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "hardware_claim", + srcs = ["claim.c"], + hdrs = ["include/hardware/claim.h"], + includes = ["include"], + deps = [ + "//src/common/pico_base:pico_base_interface", + "//src/common/pico_base:pico_platform", + "//src/rp2_common/hardware_sync:hardware_sync_headers", + ], +) diff --git a/src/rp2_common/hardware_clocks/BUILD.bazel b/src/rp2_common/hardware_clocks/BUILD.bazel new file mode 100644 index 000000000..7152804c2 --- /dev/null +++ b/src/rp2_common/hardware_clocks/BUILD.bazel @@ -0,0 +1,36 @@ +package(default_visibility = ["//visibility:public"]) + +# This exists to break a dependency cycle between +# this library and //src/rp2_common/hardware_xosc. +# Application code should always use :hardware_clocks instead. +cc_library( + name = "hardware_clocks_headers", + hdrs = ["include/hardware/clocks.h"], + includes = ["include"], + visibility = [ + "//src/rp2_common/hardware_pll:__pkg__", + "//src/rp2_common/hardware_xosc:__pkg__", + ], + deps = [ + "//src/common/pico_base:pico_base_interface", + "//src/rp2_common/pico_platform:hardware_structs", + ], +) + +cc_library( + name = "hardware_clocks", + srcs = ["clocks.c"], + hdrs = ["include/hardware/clocks.h"], + includes = ["include"], + deps = [ + "//src/common/pico_base:pico_base_interface", + "//src/rp2_common/hardware_gpio", + "//src/rp2_common/hardware_irq", + "//src/rp2_common/hardware_pll", + "//src/rp2_common/hardware_watchdog", + "//src/rp2_common/hardware_xosc", + "//src/rp2_common/pico_platform:hardware_regs", + "//src/rp2_common/pico_platform:hardware_structs", + "//src/rp2_common/pico_platform:platform_defs", + ], +) diff --git a/src/rp2_common/hardware_divider/BUILD.bazel b/src/rp2_common/hardware_divider/BUILD.bazel new file mode 100644 index 000000000..0b3dc9cb2 --- /dev/null +++ b/src/rp2_common/hardware_divider/BUILD.bazel @@ -0,0 +1,17 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "hardware_divider", + srcs = ["divider.S"], + hdrs = [ + "include/hardware/divider.h", + "include/hardware/divider_helper.S", + ], + includes = ["include"], + deps = [ + "//src/common/pico_base", + "//src/rp2_common/pico_platform", + "//src/rp2_common/pico_platform:hardware_regs", + "//src/rp2_common/pico_platform:hardware_structs", + ], +) diff --git a/src/rp2_common/hardware_dma/BUILD.bazel b/src/rp2_common/hardware_dma/BUILD.bazel new file mode 100644 index 000000000..fceabfb28 --- /dev/null +++ b/src/rp2_common/hardware_dma/BUILD.bazel @@ -0,0 +1,14 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "hardware_dma", + srcs = ["dma.c"], + hdrs = ["include/hardware/dma.h"], + includes = ["include"], + deps = [ + "//src/common/pico_base", + "//src/rp2_common/hardware_claim", + "//src/rp2_common/pico_platform:hardware_regs", + "//src/rp2_common/pico_platform:hardware_structs", + ], +) diff --git a/src/rp2_common/hardware_exception/BUILD.bazel b/src/rp2_common/hardware_exception/BUILD.bazel new file mode 100644 index 000000000..72b4c410f --- /dev/null +++ b/src/rp2_common/hardware_exception/BUILD.bazel @@ -0,0 +1,15 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "hardware_exception", + srcs = ["exception.c"], + hdrs = ["include/hardware/exception.h"], + includes = ["include"], + deps = [ + "//src/common/pico_base", + "//src/rp2_common/hardware_base", + "//src/rp2_common/hardware_sync", + "//src/rp2_common/pico_platform:hardware_structs", + "//src/rp2_common/pico_platform:platform_defs", + ], +) diff --git a/src/rp2_common/hardware_flash/BUILD.bazel b/src/rp2_common/hardware_flash/BUILD.bazel new file mode 100644 index 000000000..ee79e6fdd --- /dev/null +++ b/src/rp2_common/hardware_flash/BUILD.bazel @@ -0,0 +1,13 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "hardware_flash", + srcs = ["flash.c"], + hdrs = ["include/hardware/flash.h"], + includes = ["include"], + deps = [ + "//src/common/pico_base", + "//src/rp2_common/pico_bootrom", + "//src/rp2_common/pico_platform:hardware_structs", + ], +) diff --git a/src/rp2_common/hardware_gpio/BUILD.bazel b/src/rp2_common/hardware_gpio/BUILD.bazel new file mode 100644 index 000000000..5d035eb08 --- /dev/null +++ b/src/rp2_common/hardware_gpio/BUILD.bazel @@ -0,0 +1,15 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "hardware_gpio", + srcs = ["gpio.c"], + hdrs = ["include/hardware/gpio.h"], + includes = ["include"], + deps = [ + "//src/common/pico_base:pico_base_interface", + "//src/common/pico_binary_info", + "//src/rp2_common/hardware_irq", + "//src/rp2_common/hardware_sync", + "//src/rp2_common/pico_platform:hardware_structs", + ], +) diff --git a/src/rp2_common/hardware_i2c/BUILD.bazel b/src/rp2_common/hardware_i2c/BUILD.bazel new file mode 100644 index 000000000..cd9110f8f --- /dev/null +++ b/src/rp2_common/hardware_i2c/BUILD.bazel @@ -0,0 +1,16 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "hardware_i2c", + srcs = ["i2c.c"], + hdrs = ["include/hardware/i2c.h"], + includes = ["include"], + deps = [ + "//src/common/pico_base", + "//src/common/pico_time", + "//src/rp2_common/hardware_clocks", + "//src/rp2_common/hardware_resets", + "//src/rp2_common/pico_platform:hardware_regs", + "//src/rp2_common/pico_platform:hardware_structs", + ], +) diff --git a/src/rp2_common/hardware_interp/BUILD.bazel b/src/rp2_common/hardware_interp/BUILD.bazel new file mode 100644 index 000000000..fa8106f31 --- /dev/null +++ b/src/rp2_common/hardware_interp/BUILD.bazel @@ -0,0 +1,14 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "hardware_interp", + srcs = ["interp.c"], + hdrs = ["include/hardware/interp.h"], + includes = ["include"], + deps = [ + "//src/common/pico_base", + "//src/rp2_common/hardware_claim", + "//src/rp2_common/pico_platform:hardware_regs", + "//src/rp2_common/pico_platform:hardware_structs", + ], +) diff --git a/src/rp2_common/hardware_irq/BUILD.bazel b/src/rp2_common/hardware_irq/BUILD.bazel new file mode 100644 index 000000000..0e929c9fb --- /dev/null +++ b/src/rp2_common/hardware_irq/BUILD.bazel @@ -0,0 +1,21 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "hardware_irq", + srcs = [ + "irq.c", + "irq_handler_chain.S", + ], + hdrs = ["include/hardware/irq.h"], + includes = ["include"], + deps = [ + "//src/common/pico_base:pico_base_interface", + "//src/common/pico_sync", + "//src/rp2_common/hardware_base", + "//src/rp2_common/hardware_claim", + "//src/rp2_common/pico_platform", + "//src/rp2_common/pico_platform:hardware_regs", + "//src/rp2_common/pico_platform:hardware_structs", + "//src/rp2_common/pico_platform:platform_defs", + ], +) diff --git a/src/rp2_common/hardware_pio/BUILD.bazel b/src/rp2_common/hardware_pio/BUILD.bazel new file mode 100644 index 000000000..0cf474d24 --- /dev/null +++ b/src/rp2_common/hardware_pio/BUILD.bazel @@ -0,0 +1,19 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "hardware_pio", + srcs = ["pio.c"], + hdrs = [ + "include/hardware/pio.h", + "include/hardware/pio_instructions.h", + ], + includes = ["include"], + deps = [ + "//src/common/pico_base", + "//src/rp2_common/hardware_base", + "//src/rp2_common/hardware_claim", + "//src/rp2_common/hardware_gpio", + "//src/rp2_common/pico_platform:hardware_regs", + "//src/rp2_common/pico_platform:hardware_structs", + ], +) diff --git a/src/rp2_common/hardware_pll/BUILD.bazel b/src/rp2_common/hardware_pll/BUILD.bazel new file mode 100644 index 000000000..ea0199b23 --- /dev/null +++ b/src/rp2_common/hardware_pll/BUILD.bazel @@ -0,0 +1,15 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "hardware_pll", + srcs = ["pll.c"], + hdrs = ["include/hardware/pll.h"], + includes = ["include"], + deps = [ + "//src/common/pico_base:pico_base_interface", + "//src/common/pico_base:pico_platform", + "//src/rp2_common/hardware_clocks:hardware_clocks_headers", + "//src/rp2_common/hardware_resets", + "//src/rp2_common/pico_platform:hardware_structs", + ], +) diff --git a/src/rp2_common/hardware_pwm/BUILD.bazel b/src/rp2_common/hardware_pwm/BUILD.bazel new file mode 100644 index 000000000..2b9b4d1a9 --- /dev/null +++ b/src/rp2_common/hardware_pwm/BUILD.bazel @@ -0,0 +1,12 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "hardware_pwm", + hdrs = ["include/hardware/pwm.h"], + includes = ["include"], + deps = [ + "//src/common/pico_base", + "//src/rp2_common/pico_platform:hardware_regs", + "//src/rp2_common/pico_platform:hardware_structs", + ], +) diff --git a/src/rp2_common/hardware_resets/BUILD.bazel b/src/rp2_common/hardware_resets/BUILD.bazel new file mode 100644 index 000000000..294ed23f0 --- /dev/null +++ b/src/rp2_common/hardware_resets/BUILD.bazel @@ -0,0 +1,11 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "hardware_resets", + hdrs = ["include/hardware/resets.h"], + includes = ["include"], + deps = [ + "//src/common/pico_base:pico_base_interface", + "//src/rp2_common/pico_platform:hardware_structs", + ], +) diff --git a/src/rp2_common/hardware_rtc/BUILD.bazel b/src/rp2_common/hardware_rtc/BUILD.bazel new file mode 100644 index 000000000..7992511d7 --- /dev/null +++ b/src/rp2_common/hardware_rtc/BUILD.bazel @@ -0,0 +1,15 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "hardware_rtc", + srcs = ["rtc.c"], + hdrs = ["include/hardware/rtc.h"], + includes = ["include"], + deps = [ + "//src/common/pico_base", + "//src/rp2_common/hardware_clocks", + "//src/rp2_common/hardware_irq", + "//src/rp2_common/hardware_resets", + "//src/rp2_common/pico_platform:hardware_structs", + ], +) diff --git a/src/rp2_common/hardware_spi/BUILD.bazel b/src/rp2_common/hardware_spi/BUILD.bazel new file mode 100644 index 000000000..e9bccc93e --- /dev/null +++ b/src/rp2_common/hardware_spi/BUILD.bazel @@ -0,0 +1,15 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "hardware_spi", + srcs = ["spi.c"], + hdrs = ["include/hardware/spi.h"], + includes = ["include"], + deps = [ + "//src/common/pico_base", + "//src/rp2_common/hardware_clocks", + "//src/rp2_common/hardware_resets", + "//src/rp2_common/pico_platform:hardware_regs", + "//src/rp2_common/pico_platform:hardware_structs", + ], +) diff --git a/src/rp2_common/hardware_sync/BUILD.bazel b/src/rp2_common/hardware_sync/BUILD.bazel new file mode 100644 index 000000000..380564278 --- /dev/null +++ b/src/rp2_common/hardware_sync/BUILD.bazel @@ -0,0 +1,29 @@ +package(default_visibility = ["//visibility:public"]) + +# This exists to break a dependency cycle between +# this library and //src/rp2_common/hardware_claim. +# Application code should always use :hardware_sync instead. +cc_library( + name = "hardware_sync_headers", + hdrs = ["include/hardware/sync.h"], + includes = ["include"], + visibility = ["//src/rp2_common/hardware_claim:__pkg__"], + deps = [ + "//src/common/pico_base:pico_base_interface", + "//src/rp2_common/hardware_base", + "//src/rp2_common/pico_platform:hardware_regs", + ], +) + +cc_library( + name = "hardware_sync", + srcs = ["sync.c"], + hdrs = ["include/hardware/sync.h"], + includes = ["include"], + deps = [ + "//src/common/pico_base:pico_base_interface", + "//src/rp2_common/hardware_base", + "//src/rp2_common/hardware_claim", + "//src/rp2_common/pico_platform:hardware_regs", + ], +) diff --git a/src/rp2_common/hardware_timer/BUILD.bazel b/src/rp2_common/hardware_timer/BUILD.bazel new file mode 100644 index 000000000..b97bcde6d --- /dev/null +++ b/src/rp2_common/hardware_timer/BUILD.bazel @@ -0,0 +1,29 @@ +package(default_visibility = ["//visibility:public"]) + +# This exists to break a dependency cycle between +# this library and //src/common/pico_time. +# Application code should always use :hardware_timer instead. +cc_library( + name = "hardware_timer_headers", + hdrs = ["include/hardware/timer.h"], + includes = ["include"], + visibility = ["//src/common/pico_time:__pkg__"], + deps = [ + "//src/common/pico_base:pico_base_interface", + "//src/rp2_common/pico_platform:hardware_structs", + ], +) + +cc_library( + name = "hardware_timer", + srcs = ["timer.c"], + hdrs = ["include/hardware/timer.h"], + includes = ["include"], + deps = [ + "//src/common/pico_base:pico_base_interface", + "//src/rp2_common/hardware_claim", + "//src/rp2_common/hardware_irq", + "//src/rp2_common/hardware_sync", + "//src/rp2_common/pico_platform:hardware_structs", + ], +) diff --git a/src/rp2_common/hardware_uart/BUILD.bazel b/src/rp2_common/hardware_uart/BUILD.bazel new file mode 100644 index 000000000..a329df366 --- /dev/null +++ b/src/rp2_common/hardware_uart/BUILD.bazel @@ -0,0 +1,18 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "hardware_uart", + srcs = ["uart.c"], + hdrs = ["include/hardware/uart.h"], + includes = ["include"], + deps = [ + "//src/common/pico_base", + "//src/rp2_common/hardware_base", + "//src/rp2_common/hardware_clocks", + "//src/rp2_common/hardware_resets", + "//src/rp2_common/hardware_timer", + "//src/rp2_common/pico_platform:hardware_regs", + "//src/rp2_common/pico_platform:hardware_structs", + "//src/rp2_common/pico_platform:platform_defs", + ], +) diff --git a/src/rp2_common/hardware_vreg/BUILD.bazel b/src/rp2_common/hardware_vreg/BUILD.bazel new file mode 100644 index 000000000..0a90697b2 --- /dev/null +++ b/src/rp2_common/hardware_vreg/BUILD.bazel @@ -0,0 +1,12 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "hardware_vreg", + srcs = ["vreg.c"], + hdrs = ["include/hardware/vreg.h"], + includes = ["include"], + deps = [ + "//src/common/pico_base", + "//src/rp2_common/pico_platform:hardware_structs", + ], +) diff --git a/src/rp2_common/hardware_watchdog/BUILD.bazel b/src/rp2_common/hardware_watchdog/BUILD.bazel new file mode 100644 index 000000000..fad2f97ae --- /dev/null +++ b/src/rp2_common/hardware_watchdog/BUILD.bazel @@ -0,0 +1,13 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "hardware_watchdog", + srcs = ["watchdog.c"], + hdrs = ["include/hardware/watchdog.h"], + includes = ["include"], + deps = [ + "//src/common/pico_base:pico_base_interface", + "//src/common/pico_base:pico_platform", + "//src/rp2_common/pico_platform:hardware_structs", + ], +) diff --git a/src/rp2_common/hardware_xosc/BUILD.bazel b/src/rp2_common/hardware_xosc/BUILD.bazel new file mode 100644 index 000000000..2ed2201e9 --- /dev/null +++ b/src/rp2_common/hardware_xosc/BUILD.bazel @@ -0,0 +1,16 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "hardware_xosc", + srcs = ["xosc.c"], + hdrs = ["include/hardware/xosc.h"], + includes = ["include"], + deps = [ + "//src/common/pico_base:pico_base_interface", + "//src/common/pico_base:pico_platform", + "//src/rp2_common/hardware_clocks:hardware_clocks_headers", + "//src/rp2_common/pico_platform:hardware_regs", + "//src/rp2_common/pico_platform:hardware_structs", + "//src/rp2_common/pico_platform:platform_defs", + ], +) diff --git a/src/rp2_common/pico_async_context/BUILD.bazel b/src/rp2_common/pico_async_context/BUILD.bazel new file mode 100644 index 000000000..577d1c845 --- /dev/null +++ b/src/rp2_common/pico_async_context/BUILD.bazel @@ -0,0 +1,30 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_async_context", + srcs = [ + "async_context_base.c", + "async_context_freertos.c", + "async_context_poll.c", + "async_context_threadsafe_background.c", + ], + hdrs = [ + "include/pico/async_context.h", + "include/pico/async_context_base.h", + "include/pico/async_context_freertos.h", + "include/pico/async_context_poll.h", + "include/pico/async_context_threadsafe_background.h", + ], + includes = ["include"], + # Missing deps for: + # FreeRTOS.h + # semphr.h + # timers.h + tags = ["manual"], + deps = [ + "//src/common/pico_base", + "//src/common/pico_sync", + "//src/common/pico_time", + "//src/rp2_common/hardware_irq", + ], +) diff --git a/src/rp2_common/pico_bit_ops/BUILD.bazel b/src/rp2_common/pico_bit_ops/BUILD.bazel new file mode 100644 index 000000000..35322a8af --- /dev/null +++ b/src/rp2_common/pico_bit_ops/BUILD.bazel @@ -0,0 +1,25 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_bit_ops", + srcs = ["bit_ops_aeabi.S"], + linkopts = [ + "-Wl,--wrap=__clzsi2", + "-Wl,--wrap=__clzsi2", + "-Wl,--wrap=__clzdi2", + "-Wl,--wrap=__ctzsi2", + "-Wl,--wrap=__ctzdi2", + "-Wl,--wrap=__popcountsi2", + "-Wl,--wrap=__popcountdi2", + "-Wl,--wrap=__clz", + "-Wl,--wrap=__clzl", + "-Wl,--wrap=__clzsi2", + "-Wl,--wrap=__clzll", + ], + deps = [ + "//src/common/pico_bit_ops:pico_bit_ops_headers", + "//src/rp2_common/pico_bootrom", + "//src/rp2_common/pico_platform", + ], + alwayslink = True, # Ensures the wrapped symbols are linked in. +) diff --git a/src/rp2_common/pico_bootrom/BUILD.bazel b/src/rp2_common/pico_bootrom/BUILD.bazel new file mode 100644 index 000000000..b31378cd2 --- /dev/null +++ b/src/rp2_common/pico_bootrom/BUILD.bazel @@ -0,0 +1,15 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_bootrom", + srcs = ["bootrom.c"], + hdrs = [ + "include/pico/bootrom.h", + "include/pico/bootrom/sf_table.h", + ], + includes = ["include"], + deps = [ + "//src/common/pico_base:pico_base_interface", + "//src/common/pico_base:pico_platform", + ], +) diff --git a/src/rp2_common/pico_bootsel_via_double_reset/BUILD.bazel b/src/rp2_common/pico_bootsel_via_double_reset/BUILD.bazel new file mode 100644 index 000000000..8e85b7023 --- /dev/null +++ b/src/rp2_common/pico_bootsel_via_double_reset/BUILD.bazel @@ -0,0 +1,12 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_bootsel_via_double_reset", + srcs = ["pico_bootsel_via_double_reset.c"], + deps = [ + "//src/common/pico_base", + "//src/common/pico_binary_info", + "//src/common/pico_time", + "//src/rp2_common/pico_bootrom", + ], +) diff --git a/src/rp2_common/pico_btstack/BUILD.bazel b/src/rp2_common/pico_btstack/BUILD.bazel new file mode 100644 index 000000000..c3afa3e09 --- /dev/null +++ b/src/rp2_common/pico_btstack/BUILD.bazel @@ -0,0 +1,28 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_btstack", + srcs = [ + "btstack_flash_bank.c", + "btstack_run_loop_async_context.c", + "btstack_stdin_pico.c", + ], + hdrs = [ + "include/pico/btstack_flash_bank.h", + "include/pico/btstack_run_loop_async_context.h", + ], + includes = ["include"], + # Missing deps for: + # btstack_config.h + # btstack_run_loop.h + # btstack_stdin.h + # hal_flash_bank.h + tags = ["manual"], + deps = [ + "//src/common/pico_base", + "//src/rp2_common/hardware_sync", + "//src/rp2_common/pico_async_context", + "//src/rp2_common/pico_flash", + "//src/rp2_common/pico_stdio", + ], +) diff --git a/src/rp2_common/pico_cxx_options/BUILD.bazel b/src/rp2_common/pico_cxx_options/BUILD.bazel new file mode 100644 index 000000000..6fb8268a9 --- /dev/null +++ b/src/rp2_common/pico_cxx_options/BUILD.bazel @@ -0,0 +1,5 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_cxx_options", +) diff --git a/src/rp2_common/pico_cyw43_arch/BUILD.bazel b/src/rp2_common/pico_cyw43_arch/BUILD.bazel new file mode 100644 index 000000000..9ce451613 --- /dev/null +++ b/src/rp2_common/pico_cyw43_arch/BUILD.bazel @@ -0,0 +1,31 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_cyw43_arch", + srcs = [ + "cyw43_arch.c", + "cyw43_arch_freertos.c", + "cyw43_arch_poll.c", + "cyw43_arch_threadsafe_background.c", + ], + hdrs = [ + "include/pico/cyw43_arch.h", + "include/pico/cyw43_arch/arch_freertos.h", + "include/pico/cyw43_arch/arch_poll.h", + "include/pico/cyw43_arch/arch_threadsafe_background.h", + ], + includes = ["include"], + # Missing deps for: + # cyw43.h + # cyw43_country.h + # cyw43_ll.h + # cyw43_stats.h + tags = ["manual"], + deps = [ + "//src/common/pico_base", + "//src/rp2_common/pico_async_context", + "//src/rp2_common/pico_cyw43_driver", + "//src/rp2_common/pico_lwip", + "//src/rp2_common/pico_unique_id", + ], +) diff --git a/src/rp2_common/pico_cyw43_driver/BUILD.bazel b/src/rp2_common/pico_cyw43_driver/BUILD.bazel new file mode 100644 index 000000000..1d2fa138b --- /dev/null +++ b/src/rp2_common/pico_cyw43_driver/BUILD.bazel @@ -0,0 +1,51 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_cyw43_driver", + srcs = [ + "btstack_chipset_cyw43.c", + "btstack_cyw43.c", + "btstack_hci_transport_cyw43.c", + "cyw43_bus_pio_spi.c", + "cyw43_driver.c", + ], + hdrs = [ + "include/cyw43_configport.h", + "include/pico/btstack_chipset_cyw43.h", + "include/pico/btstack_cyw43.h", + "include/pico/btstack_hci_transport_cyw43.h", + "include/pico/cyw43_driver.h", + ], + includes = ["include"], + # Missing deps for: + # ble/le_device_db_tlv.h + # btstack_chipset.h + # btstack_memory.h + # btstack_tlv.h + # btstack_tlv_flash_bank.h + # classic/btstack_link_key_db_tlv.h + # cyw43.h + # cyw43_bus_pio_spi.pio.h + # cyw43_debug_pins.h + # cyw43_internal.h + # cyw43_spi.h + # hci.h + # hci_dump.h + # hci_dump_embedded_stdout.h + # hci_dump_segger_rtt_stdout.h + # hci_transport.h + tags = ["manual"], + deps = [ + "//src/common/pico_base", + "//src/common/pico_time", + "//src/rp2_common/hardware_clocks", + "//src/rp2_common/hardware_dma", + "//src/rp2_common/hardware_gpio", + "//src/rp2_common/hardware_irq", + "//src/rp2_common/hardware_pio", + "//src/rp2_common/hardware_sync", + "//src/rp2_common/pico_async_context", + "//src/rp2_common/pico_btstack", + "//src/rp2_common/pico_unique_id", + ], +) diff --git a/src/rp2_common/pico_divider/BUILD.bazel b/src/rp2_common/pico_divider/BUILD.bazel new file mode 100644 index 000000000..f35f22508 --- /dev/null +++ b/src/rp2_common/pico_divider/BUILD.bazel @@ -0,0 +1,20 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_divider", + srcs = ["divider.S"], + linkopts = [ + "-Wl,--wrap=__aeabi_idiv", + "-Wl,--wrap=__aeabi_idivmod", + "-Wl,--wrap=__aeabi_ldivmod", + "-Wl,--wrap=__aeabi_uidiv", + "-Wl,--wrap=__aeabi_uidivmod", + "-Wl,--wrap=__aeabi_uldivmod", + ], + deps = [ + "//src/rp2_common/hardware_divider", + "//src/rp2_common/pico_platform", + "//src/rp2_common/pico_platform:hardware_regs", + ], + alwayslink = True, # Ensures the wrapped symbols are linked in. +) diff --git a/src/rp2_common/pico_double/BUILD.bazel b/src/rp2_common/pico_double/BUILD.bazel new file mode 100644 index 000000000..f52e78bdc --- /dev/null +++ b/src/rp2_common/pico_double/BUILD.bazel @@ -0,0 +1,85 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_double", + srcs = [ + "double_aeabi.S", + "double_init_rom.c", + "double_math.c", + "double_v1_rom_shim.S", + ], + hdrs = ["include/pico/double.h"], + includes = ["include"], + linkopts = [ + "-Wl,--wrap=__aeabi_dadd", + "-Wl,--wrap=__aeabi_ddiv", + "-Wl,--wrap=__aeabi_dmul", + "-Wl,--wrap=__aeabi_drsub", + "-Wl,--wrap=__aeabi_dsub", + "-Wl,--wrap=__aeabi_cdcmpeq", + "-Wl,--wrap=__aeabi_cdrcmple", + "-Wl,--wrap=__aeabi_cdcmple", + "-Wl,--wrap=__aeabi_dcmpeq", + "-Wl,--wrap=__aeabi_dcmplt", + "-Wl,--wrap=__aeabi_dcmple", + "-Wl,--wrap=__aeabi_dcmpge", + "-Wl,--wrap=__aeabi_dcmpgt", + "-Wl,--wrap=__aeabi_dcmpun", + "-Wl,--wrap=__aeabi_i2d", + "-Wl,--wrap=__aeabi_l2d", + "-Wl,--wrap=__aeabi_ui2d", + "-Wl,--wrap=__aeabi_ul2d", + "-Wl,--wrap=__aeabi_d2iz", + "-Wl,--wrap=__aeabi_d2lz", + "-Wl,--wrap=__aeabi_d2uiz", + "-Wl,--wrap=__aeabi_d2ulz", + "-Wl,--wrap=__aeabi_d2f", + "-Wl,--wrap=sqrt", + "-Wl,--wrap=cos", + "-Wl,--wrap=sin", + "-Wl,--wrap=tan", + "-Wl,--wrap=atan2", + "-Wl,--wrap=exp", + "-Wl,--wrap=log", + "-Wl,--wrap=ldexp", + "-Wl,--wrap=copysign", + "-Wl,--wrap=trunc", + "-Wl,--wrap=floor", + "-Wl,--wrap=ceil", + "-Wl,--wrap=round", + "-Wl,--wrap=sincos", + "-Wl,--wrap=asin", + "-Wl,--wrap=acos", + "-Wl,--wrap=atan", + "-Wl,--wrap=sinh", + "-Wl,--wrap=cosh", + "-Wl,--wrap=tanh", + "-Wl,--wrap=asinh", + "-Wl,--wrap=acosh", + "-Wl,--wrap=atanh", + "-Wl,--wrap=exp2", + "-Wl,--wrap=log2", + "-Wl,--wrap=exp10", + "-Wl,--wrap=log10", + "-Wl,--wrap=pow", + "-Wl,--wrap=powint", + "-Wl,--wrap=hypot", + "-Wl,--wrap=cbrt", + "-Wl,--wrap=fmod", + "-Wl,--wrap=drem", + "-Wl,--wrap=remainder", + "-Wl,--wrap=remquo", + "-Wl,--wrap=expm1", + "-Wl,--wrap=log1p", + "-Wl,--wrap=fma", + ], + deps = [ + "//src/common/pico_base", + "//src/rp2_common/hardware_divider", + "//src/rp2_common/pico_bootrom", + "//src/rp2_common/pico_platform", + ], + alwayslink = True, # Ensures the wrapped symbols are linked in. +) + +# TODO: Support double_none.S when the configuration option exists. diff --git a/src/rp2_common/pico_fix/BUILD.bazel b/src/rp2_common/pico_fix/BUILD.bazel new file mode 100644 index 000000000..a1b4b2e15 --- /dev/null +++ b/src/rp2_common/pico_fix/BUILD.bazel @@ -0,0 +1,5 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_fix", +) diff --git a/src/rp2_common/pico_fix/rp2040_usb_device_enumeration/BUILD.bazel b/src/rp2_common/pico_fix/rp2040_usb_device_enumeration/BUILD.bazel new file mode 100644 index 000000000..7b1406c1d --- /dev/null +++ b/src/rp2_common/pico_fix/rp2040_usb_device_enumeration/BUILD.bazel @@ -0,0 +1,14 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "rp2040_usb_device_enumeration", + srcs = ["rp2040_usb_device_enumeration.c"], + hdrs = ["include/pico/fix/rp2040_usb_device_enumeration.h"], + includes = ["include"], + deps = [ + "//src/common/pico_base", + "//src/common/pico_time", + "//src/rp2_common/hardware_gpio", + "//src/rp2_common/pico_platform:hardware_structs", + ], +) diff --git a/src/rp2_common/pico_flash/BUILD.bazel b/src/rp2_common/pico_flash/BUILD.bazel new file mode 100644 index 000000000..d9aac18d8 --- /dev/null +++ b/src/rp2_common/pico_flash/BUILD.bazel @@ -0,0 +1,20 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_flash", + srcs = ["flash.c"], + hdrs = ["include/pico/flash.h"], + includes = ["include"], + # Missing deps for: + # FreeRTOS.h + # task.h + tags = ["manual"], + deps = [ + "//src/common/pico_base", + "//src/common/pico_time", + "//src/rp2_common/hardware_exception", + "//src/rp2_common/hardware_flash", + "//src/rp2_common/hardware_sync", + "//src/rp2_common/pico_multicore", + ], +) diff --git a/src/rp2_common/pico_float/BUILD.bazel b/src/rp2_common/pico_float/BUILD.bazel new file mode 100644 index 000000000..c3cef5eba --- /dev/null +++ b/src/rp2_common/pico_float/BUILD.bazel @@ -0,0 +1,85 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_float", + srcs = [ + "float_aeabi.S", + "float_init_rom.c", + "float_math.c", + "float_v1_rom_shim.S", + ], + hdrs = ["include/pico/float.h"], + includes = ["include"], + linkopts = [ + "-Wl,--wrap=__aeabi_fadd", + "-Wl,--wrap=__aeabi_fdiv", + "-Wl,--wrap=__aeabi_fmul", + "-Wl,--wrap=__aeabi_frsub", + "-Wl,--wrap=__aeabi_fsub", + "-Wl,--wrap=__aeabi_cfcmpeq", + "-Wl,--wrap=__aeabi_cfrcmple", + "-Wl,--wrap=__aeabi_cfcmple", + "-Wl,--wrap=__aeabi_fcmpeq", + "-Wl,--wrap=__aeabi_fcmplt", + "-Wl,--wrap=__aeabi_fcmple", + "-Wl,--wrap=__aeabi_fcmpge", + "-Wl,--wrap=__aeabi_fcmpgt", + "-Wl,--wrap=__aeabi_fcmpun", + "-Wl,--wrap=__aeabi_i2f", + "-Wl,--wrap=__aeabi_l2f", + "-Wl,--wrap=__aeabi_ui2f", + "-Wl,--wrap=__aeabi_ul2f", + "-Wl,--wrap=__aeabi_f2iz", + "-Wl,--wrap=__aeabi_f2lz", + "-Wl,--wrap=__aeabi_f2uiz", + "-Wl,--wrap=__aeabi_f2ulz", + "-Wl,--wrap=__aeabi_f2d", + "-Wl,--wrap=sqrtf", + "-Wl,--wrap=cosf", + "-Wl,--wrap=sinf", + "-Wl,--wrap=tanf", + "-Wl,--wrap=atan2f", + "-Wl,--wrap=expf", + "-Wl,--wrap=logf", + "-Wl,--wrap=ldexpf", + "-Wl,--wrap=copysignf", + "-Wl,--wrap=truncf", + "-Wl,--wrap=floorf", + "-Wl,--wrap=ceilf", + "-Wl,--wrap=roundf", + "-Wl,--wrap=sincosf", + "-Wl,--wrap=asinf", + "-Wl,--wrap=acosf", + "-Wl,--wrap=atanf", + "-Wl,--wrap=sinhf", + "-Wl,--wrap=coshf", + "-Wl,--wrap=tanhf", + "-Wl,--wrap=asinhf", + "-Wl,--wrap=acoshf", + "-Wl,--wrap=atanhf", + "-Wl,--wrap=exp2f", + "-Wl,--wrap=log2f", + "-Wl,--wrap=exp10f", + "-Wl,--wrap=log10f", + "-Wl,--wrap=powf", + "-Wl,--wrap=powintf", + "-Wl,--wrap=hypotf", + "-Wl,--wrap=cbrtf", + "-Wl,--wrap=fmodf", + "-Wl,--wrap=dremf", + "-Wl,--wrap=remainderf", + "-Wl,--wrap=remquof", + "-Wl,--wrap=expm1f", + "-Wl,--wrap=log1pf", + "-Wl,--wrap=fmaf", + ], + deps = [ + "//src/common/pico_base", + "//src/rp2_common/hardware_divider", + "//src/rp2_common/pico_bootrom", + "//src/rp2_common/pico_platform", + ], + alwayslink = True, # Ensures the wrapped symbols are linked in. +) + +# TODO: Support float_none.S when the configuration option exists. diff --git a/src/rp2_common/pico_i2c_slave/BUILD.bazel b/src/rp2_common/pico_i2c_slave/BUILD.bazel new file mode 100644 index 000000000..36e0b9b25 --- /dev/null +++ b/src/rp2_common/pico_i2c_slave/BUILD.bazel @@ -0,0 +1,12 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_i2c_slave", + srcs = ["i2c_slave.c"], + hdrs = ["include/pico/i2c_slave.h"], + includes = ["include"], + deps = [ + "//src/rp2_common/hardware_i2c", + "//src/rp2_common/hardware_irq", + ], +) diff --git a/src/rp2_common/pico_int64_ops/BUILD.bazel b/src/rp2_common/pico_int64_ops/BUILD.bazel new file mode 100644 index 000000000..63111037b --- /dev/null +++ b/src/rp2_common/pico_int64_ops/BUILD.bazel @@ -0,0 +1,14 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_int64_ops", + srcs = ["pico_int64_ops_aeabi.S"], + hdrs = ["include/pico/int64_ops.h"], + includes = ["include"], + linkopts = ["-Wl,--wrap=__aeabi_lmul"], + deps = [ + "//src/common/pico_base", + "//src/rp2_common/pico_platform", + ], + alwayslink = True, # Ensures the wrapped symbols are linked in. +) diff --git a/src/rp2_common/pico_lwip/BUILD.bazel b/src/rp2_common/pico_lwip/BUILD.bazel new file mode 100644 index 000000000..76799a5ae --- /dev/null +++ b/src/rp2_common/pico_lwip/BUILD.bazel @@ -0,0 +1,27 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_lwip", + srcs = [ + "lwip_freertos.c", + "lwip_nosys.c", + ], + hdrs = [ + "include/arch/cc.h", + "include/pico/lwip_freertos.h", + "include/pico/lwip_nosys.h", + ], + includes = ["include"], + # Missing deps for: + # FreeRTOS.h + # lwip/tcpip.h + # lwip/timeouts.h + # semphr.h + tags = ["manual"], + deps = [ + "//src/common/pico_base", + "//src/common/pico_time", + "//src/rp2_common/pico_async_context", + "//src/rp2_common/pico_rand", + ], +) diff --git a/src/rp2_common/pico_malloc/BUILD.bazel b/src/rp2_common/pico_malloc/BUILD.bazel new file mode 100644 index 000000000..7aa6bae54 --- /dev/null +++ b/src/rp2_common/pico_malloc/BUILD.bazel @@ -0,0 +1,19 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_malloc", + srcs = ["pico_malloc.c"], + hdrs = ["include/pico/malloc.h"], + includes = ["include"], + linkopts = [ + "-Wl,--wrap=malloc", + "-Wl,--wrap=calloc", + "-Wl,--wrap=realloc", + "-Wl,--wrap=free", + ], + deps = [ + "//src/common/pico_base:pico_base_interface", + "//src/common/pico_sync", + ], + alwayslink = True, # Ensures the wrapped symbols are linked in. +) diff --git a/src/rp2_common/pico_mbedtls/BUILD.bazel b/src/rp2_common/pico_mbedtls/BUILD.bazel new file mode 100644 index 000000000..8f9a64b42 --- /dev/null +++ b/src/rp2_common/pico_mbedtls/BUILD.bazel @@ -0,0 +1,10 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_mbedtls", + srcs = ["pico_mbedtls.c"], + deps = [ + "//src/rp2_common/pico_platform", + "//src/rp2_common/pico_rand", + ], +) diff --git a/src/rp2_common/pico_mem_ops/BUILD.bazel b/src/rp2_common/pico_mem_ops/BUILD.bazel new file mode 100644 index 000000000..7d1c965a7 --- /dev/null +++ b/src/rp2_common/pico_mem_ops/BUILD.bazel @@ -0,0 +1,27 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_mem_ops", + srcs = [ + "mem_ops.c", + "mem_ops_aeabi.S", + ], + hdrs = ["include/pico/mem_ops.h"], + includes = ["include"], + linkopts = [ + "-Wl,--wrap=memcpy", + "-Wl,--wrap=memset", + "-Wl,--wrap=__aeabi_memcpy", + "-Wl,--wrap=__aeabi_memset", + "-Wl,--wrap=__aeabi_memcpy4", + "-Wl,--wrap=__aeabi_memset4", + "-Wl,--wrap=__aeabi_memcpy8", + "-Wl,--wrap=__aeabi_memset8", + ], + deps = [ + "//src/common/pico_base", + "//src/rp2_common/pico_bootrom", + "//src/rp2_common/pico_platform", + ], + alwayslink = True, # Ensures the wrapped symbols are linked in. +) diff --git a/src/rp2_common/pico_multicore/BUILD.bazel b/src/rp2_common/pico_multicore/BUILD.bazel new file mode 100644 index 000000000..220edd462 --- /dev/null +++ b/src/rp2_common/pico_multicore/BUILD.bazel @@ -0,0 +1,18 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_multicore", + srcs = ["multicore.c"], + hdrs = ["include/pico/multicore.h"], + includes = ["include"], + deps = [ + "//src/common/pico_base", + "//src/common/pico_sync", + "//src/rp2_common/hardware_claim", + "//src/rp2_common/hardware_irq", + "//src/rp2_common/hardware_sync", + "//src/rp2_common/pico_platform:hardware_regs", + "//src/rp2_common/pico_platform:hardware_structs", + "//src/rp2_common/pico_runtime", + ], +) diff --git a/src/rp2_common/pico_platform/BUILD.bazel b/src/rp2_common/pico_platform/BUILD.bazel new file mode 100644 index 000000000..0655b413e --- /dev/null +++ b/src/rp2_common/pico_platform/BUILD.bazel @@ -0,0 +1,38 @@ +package(default_visibility = ["//visibility:public"]) + +alias( + name = "platform_defs", + actual = select({ + "//bazel/constraint:rp2040": "//src/rp2040/hardware_regs:platform_defs", + }), +) + +alias( + name = "hardware_regs", + actual = select({ + "//bazel/constraint:rp2040": "//src/rp2040/hardware_regs:hardware_regs", + }), +) + +alias( + name = "hardware_structs", + actual = select({ + "//bazel/constraint:rp2040": "//src/rp2040/hardware_structs:hardware_structs", + }), +) + +cc_library( + name = "pico_platform", + srcs = ["platform.c"], + hdrs = [ + "include/pico/asm_helper.S", + "include/pico/platform.h", + ], + includes = ["include"], + deps = [ + ":hardware_regs", + ":platform_defs", + "//src/common/pico_base:pico_base_interface", + "//src/rp2_common/hardware_base", + ], +) diff --git a/src/rp2_common/pico_printf/BUILD.bazel b/src/rp2_common/pico_printf/BUILD.bazel new file mode 100644 index 000000000..d2898455d --- /dev/null +++ b/src/rp2_common/pico_printf/BUILD.bazel @@ -0,0 +1,23 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_printf", + srcs = [ + "printf.c", + ], + hdrs = ["include/pico/printf.h"], + includes = ["include"], + linkopts = [ + "-Wl,--wrap=sprintf", + "-Wl,--wrap=snprintf", + "-Wl,--wrap=vsnprintf", + ], + deps = [ + "//src/common/pico_base:pico_base_interface", + "//src/rp2_common/pico_bootrom", + "//src/rp2_common/pico_platform", + ], + alwayslink = True, # Ensures the wrapped symbols are linked in. +) + +# TODO: Support printf_none.S when the configuration option exists. diff --git a/src/rp2_common/pico_rand/BUILD.bazel b/src/rp2_common/pico_rand/BUILD.bazel new file mode 100644 index 000000000..3ef576c3d --- /dev/null +++ b/src/rp2_common/pico_rand/BUILD.bazel @@ -0,0 +1,16 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_rand", + srcs = ["rand.c"], + hdrs = ["include/pico/rand.h"], + includes = ["include"], + deps = [ + "//src/common/pico_base", + "//src/common/pico_time", + "//src/rp2_common/hardware_clocks", + "//src/rp2_common/hardware_sync", + "//src/rp2_common/pico_platform:hardware_structs", + "//src/rp2_common/pico_unique_id", + ], +) diff --git a/src/rp2_common/pico_runtime/BUILD.bazel b/src/rp2_common/pico_runtime/BUILD.bazel new file mode 100644 index 000000000..f3f9bffbe --- /dev/null +++ b/src/rp2_common/pico_runtime/BUILD.bazel @@ -0,0 +1,20 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_runtime", + srcs = ["runtime.c"], + hdrs = ["include/pico/runtime.h"], + includes = ["include"], + deps = [ + "//src/common/pico_base:pico_base_interface", + "//src/common/pico_sync", + "//src/common/pico_time", + "//src/rp2_common/hardware_clocks", + "//src/rp2_common/hardware_irq", + "//src/rp2_common/hardware_resets", + "//src/rp2_common/pico_bootrom", + "//src/rp2_common/pico_platform:hardware_regs", + "//src/rp2_common/pico_platform:hardware_structs", + "//src/rp2_common/pico_printf", + ], +) diff --git a/src/rp2_common/pico_standard_link/BUILD.bazel b/src/rp2_common/pico_standard_link/BUILD.bazel new file mode 100644 index 000000000..bfc1376ec --- /dev/null +++ b/src/rp2_common/pico_standard_link/BUILD.bazel @@ -0,0 +1,23 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_standard_link", + srcs = [ + "binary_info.c", + "crt0.S", + # "new_delete.cpp", # TODO: Doesn't build yet? + ], + # TODO: Make this configurable. + linkopts = [ + "-T$(location memmap_default.ld)", + ], + deps = [ + "memmap_default.ld", + "//src/common/pico_base:pico_base_interface", + "//src/common/pico_binary_info", + "//src/rp2_common/boot_stage2:config", + "//src/rp2_common/pico_bootrom", + "//src/rp2_common/pico_platform", + "//src/rp2_common/pico_platform:hardware_regs", + ], +) diff --git a/src/rp2_common/pico_stdio/BUILD.bazel b/src/rp2_common/pico_stdio/BUILD.bazel new file mode 100644 index 000000000..d380041a3 --- /dev/null +++ b/src/rp2_common/pico_stdio/BUILD.bazel @@ -0,0 +1,47 @@ +package(default_visibility = ["//visibility:public"]) + +# This exists to break dependency cycles between +# this library and the stdio implementations. +# Application code should always use :pico_stdio instead. +cc_library( + name = "pico_stdio_headers", + hdrs = [ + "include/pico/stdio.h", + "include/pico/stdio/driver.h", + ], + includes = ["include"], + visibility = [ + "//src/rp2_common/pico_stdio_semihosting:__pkg__", + "//src/rp2_common/pico_stdio_uart:__pkg__", + "//src/rp2_common/pico_stdio_usb:__pkg__", + "//src/rp2_common/tinyusb:__pkg__", + ], +) + +cc_library( + name = "pico_stdio", + srcs = ["stdio.c"], + hdrs = [ + "include/pico/stdio.h", + "include/pico/stdio/driver.h", + ], + includes = ["include"], + linkopts = [ + "-Wl,--wrap=printf", + "-Wl,--wrap=vprintf", + "-Wl,--wrap=puts", + "-Wl,--wrap=putchar", + "-Wl,--wrap=getchar", + ], + deps = [ + "//src/common/pico_base", + "//src/common/pico_sync", + "//src/common/pico_time", + "//src/rp2_common/pico_printf", + ] + select({ + "//bazel/constraint:stdio_semihosting": ["//src/rp2_common/pico_stdio_semihosting"], + "//bazel/constraint:stdio_uart": ["//src/rp2_common/pico_stdio_uart"], + "//bazel/constraint:stdio_usb": ["//src/rp2_common/pico_stdio_usb"], + }), + alwayslink = True, # Ensures the wrapped symbols are linked in. +) diff --git a/src/rp2_common/pico_stdio_semihosting/BUILD.bazel b/src/rp2_common/pico_stdio_semihosting/BUILD.bazel new file mode 100644 index 000000000..5ce2a69e3 --- /dev/null +++ b/src/rp2_common/pico_stdio_semihosting/BUILD.bazel @@ -0,0 +1,12 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_stdio_semihosting", + srcs = ["stdio_semihosting.c"], + hdrs = ["include/pico/stdio_semihosting.h"], + includes = ["include"], + deps = [ + "//src/common/pico_binary_info", + "//src/rp2_common/pico_stdio:pico_stdio_headers", + ], +) diff --git a/src/rp2_common/pico_stdio_uart/BUILD.bazel b/src/rp2_common/pico_stdio_uart/BUILD.bazel new file mode 100644 index 000000000..3ca99689d --- /dev/null +++ b/src/rp2_common/pico_stdio_uart/BUILD.bazel @@ -0,0 +1,14 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_stdio_uart", + srcs = ["stdio_uart.c"], + hdrs = ["include/pico/stdio_uart.h"], + includes = ["include"], + deps = [ + "//src/common/pico_binary_info", + "//src/rp2_common/hardware_gpio", + "//src/rp2_common/hardware_uart", + "//src/rp2_common/pico_stdio:pico_stdio_headers", + ], +) diff --git a/src/rp2_common/pico_stdio_usb/BUILD.bazel b/src/rp2_common/pico_stdio_usb/BUILD.bazel new file mode 100644 index 000000000..58c3cdb28 --- /dev/null +++ b/src/rp2_common/pico_stdio_usb/BUILD.bazel @@ -0,0 +1,48 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "reset_interface_headers", + hdrs = ["include/pico/stdio_usb/reset_interface.h"], + includes = ["include"], + deps = ["//src/common/pico_usb_reset_interface"], +) + +cc_library( + name = "tusb_config", + hdrs = ["include/tusb_config.h"], + includes = ["include"], +) + +cc_library( + name = "pico_stdio_usb_headers", + hdrs = ["include/pico/stdio_usb.h"], + includes = ["include"], + visibility = [ + ":__pkg__", + "//src/rp2_common/tinyusb:__pkg__", + ], +) + +cc_library( + name = "pico_stdio_usb", + srcs = [ + "reset_interface.c", + "stdio_usb.c", + "stdio_usb_descriptors.c", + ], + target_compatible_with = ["//bazel/constraint:stdio_usb"], + deps = [ + ":pico_stdio_usb_headers", + ":reset_interface_headers", + "//src/common/pico_binary_info", + "//src/common/pico_sync", + "//src/rp2_common/hardware_irq", + "//src/rp2_common/hardware_watchdog", + "//src/rp2_common/pico_bootrom", + "//src/rp2_common/pico_stdio:pico_stdio_headers", + "//src/rp2_common/pico_unique_id", + "@tinyusb", + ], + # Ensure `stdio_usb_descriptors.c` isn't affected by link order. + alwayslink = True, +) diff --git a/src/rp2_common/pico_stdlib/BUILD.bazel b/src/rp2_common/pico_stdlib/BUILD.bazel new file mode 100644 index 000000000..53b01e1c3 --- /dev/null +++ b/src/rp2_common/pico_stdlib/BUILD.bazel @@ -0,0 +1,16 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_stdlib", + srcs = ["stdlib.c"], + deps = [ + "//src/common/pico_binary_info", + "//src/common/pico_stdlib:pico_stdlib_interface", + "//src/rp2_common/hardware_clocks", + "//src/rp2_common/hardware_pll", + ] + select({ + "//bazel/constraint:stdio_semihosting": ["//src/rp2_common/pico_stdio_semihosting"], + "//bazel/constraint:stdio_uart": ["//src/rp2_common/pico_stdio_uart"], + "//bazel/constraint:stdio_usb": ["//src/rp2_common/pico_stdio_usb"], + }), +) diff --git a/src/rp2_common/pico_unique_id/BUILD.bazel b/src/rp2_common/pico_unique_id/BUILD.bazel new file mode 100644 index 000000000..7db977e3c --- /dev/null +++ b/src/rp2_common/pico_unique_id/BUILD.bazel @@ -0,0 +1,12 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "pico_unique_id", + srcs = ["unique_id.c"], + hdrs = ["include/pico/unique_id.h"], + includes = ["include"], + deps = [ + "//src/common/pico_base", + "//src/rp2_common/hardware_flash", + ], +) diff --git a/src/rp2_common/tinyusb/BUILD.bazel b/src/rp2_common/tinyusb/BUILD.bazel new file mode 100644 index 000000000..0c395a72b --- /dev/null +++ b/src/rp2_common/tinyusb/BUILD.bazel @@ -0,0 +1,26 @@ +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "tinyusb_port", + defines = [ + "CFG_TUSB_DEBUG=0", + "CFG_TUSB_MCU=OPT_MCU_RP2040", + "CFG_TUSB_OS=OPT_OS_PICO", + ], + deps = [ + "//src/common/pico_base", + "//src/common/pico_binary_info", + "//src/common/pico_stdlib:pico_stdlib_interface", + "//src/common/pico_sync", + "//src/common/pico_time:pico_time_headers", + "//src/rp2_common/hardware_gpio", + "//src/rp2_common/hardware_irq", + "//src/rp2_common/hardware_resets", + "//src/rp2_common/hardware_sync", + "//src/rp2_common/hardware_uart", + "//src/rp2_common/pico_fix/rp2040_usb_device_enumeration", + "//src/rp2_common/pico_stdio:pico_stdio_headers", + "//src/rp2_common/pico_stdio_usb:pico_stdio_usb_headers", + "//src/rp2_common/pico_stdio_usb:tusb_config", + ], +) diff --git a/src/rp2_common/tinyusb/tinyusb.BUILD b/src/rp2_common/tinyusb/tinyusb.BUILD new file mode 100644 index 000000000..dc1696b6d --- /dev/null +++ b/src/rp2_common/tinyusb/tinyusb.BUILD @@ -0,0 +1,43 @@ +package(default_visibility = ["//visibility:public"]) + +exports_files( + glob(["**/*"]), + visibility = ["//visibility:public"], +) + +cc_library( + name = "tinyusb", + srcs = [ + "hw/bsp/board.h", + "hw/bsp/rp2040/family.c", + "src/class/audio/audio_device.c", + "src/class/cdc/cdc_device.c", + "src/class/dfu/dfu_device.c", + "src/class/dfu/dfu_rt_device.c", + "src/class/hid/hid_device.c", + "src/class/midi/midi_device.c", + "src/class/msc/msc_device.c", + "src/class/net/ecm_rndis_device.c", + "src/class/net/ncm_device.c", + "src/class/usbtmc/usbtmc_device.c", + "src/class/vendor/vendor_device.c", + "src/class/video/video_device.c", + "src/common/tusb_fifo.c", + "src/device/usbd.c", + "src/device/usbd_control.c", + "src/portable/raspberrypi/rp2040/dcd_rp2040.c", + "src/portable/raspberrypi/rp2040/rp2040_usb.c", + "src/tusb.c", + ], + hdrs = glob([ + "src/**/*.h", + "hw/bsp/*.h", + "hw/bsp/rp2040/**/*.h", + ]), + includes = [ + "hw", + "hw/bsp", + "src", + ], + deps = ["@pico-sdk//src/rp2_common/tinyusb:tinyusb_port"], +)