Skip to content

Commit 336a672

Browse files
authored
Merge branch 'develop' into rtt-stdio-support
2 parents 801a16c + c93c3f4 commit 336a672

File tree

277 files changed

+25033
-16889
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

277 files changed

+25033
-16889
lines changed

.bazelrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Required for new toolchain resolution API.
2+
build --incompatible_enable_cc_toolchain_resolution
3+
build --@rules_cc//cc/toolchains:experimental_enable_rule_based_toolchains
4+
5+
# Produce useful output when the build fails.
6+
common --verbose_failures

.bazelversion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.0.2

.github/workflows/macOS.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ jobs:
2323
- name: Install dependencies
2424
run: |
2525
brew install cmake
26-
brew tap ArmMbed/homebrew-formulae
27-
brew install arm-none-eabi-gcc
26+
brew install --cask gcc-arm-embedded
2827
2928
- name: Build Project
3029
# bash required otherwise this mysteriously (no error) fails at "Generating cyw43_bus_pio_spi.pio.h"

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@
33
cmake-*
44
.DS_Store
55
build
6+
7+
bazel-*
8+
9+
# Ignore until https://github.com/bazelbuild/bazel/issues/20369 is fixed.
10+
MODULE.bazel.lock

BUILD.bazel

Whitespace-only changes.

CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.13)
1+
cmake_minimum_required(VERSION 3.13...3.27)
22

33
# Note: this CMakeLists.txt can be used as a top-level CMakeLists.txt for the SDK itself. For all other uses
44
# it is included as a subdirectory via the pico_sdk_init() method provided by pico_sdk_init.cmake
@@ -61,4 +61,3 @@ if (NOT TARGET _pico_sdk_inclusion_marker)
6161
pico_promote_common_scope_vars()
6262
endif()
6363
endif()
64-

MODULE.bazel

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
module(name = "pico-sdk", version = "1.6.0-rc1")
2+
3+
bazel_dep(name = "platforms", version = "0.0.8")
4+
5+
bazel_dep(name = "bazel_skylib", version = "1.6.1")
6+
7+
# Note: rules_cc is special-cased repository; a dependency on rules_cc in a
8+
# module will not ensure that the root Bazel module has that same version of
9+
# rules_cc. For that reason, this primarily acts as a FYI. You'll still need
10+
# to explicitly list this dependency in your own project's MODULE.bazel file.
11+
bazel_dep(name = "rules_cc", version = "0.0.9")
12+
13+
# rules_cc v0.0.10 is not yet cut, so manually pull in the desired version.
14+
# This does not apply to dependent projects, so it needs to be copied to your
15+
# project's MODULE.bazel too.
16+
archive_override(
17+
module_name = "rules_cc",
18+
urls = "https://github.com/bazelbuild/rules_cc/archive/1acf5213b6170f1f0133e273cb85ede0e732048f.zip",
19+
strip_prefix = "rules_cc-1acf5213b6170f1f0133e273cb85ede0e732048f",
20+
integrity = "sha256-NddP6xi6LzsIHT8bMSVJ2NtoURbN+l3xpjvmIgB6aSg=",
21+
)
22+
23+
http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
24+
25+
http_archive(
26+
name = "arm_gcc_linux-x86_64",
27+
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",
28+
strip_prefix = "arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi",
29+
build_file = "//bazel/toolchain:gcc_arm_none_eabi.BUILD",
30+
sha256 = "6cd1bbc1d9ae57312bcd169ae283153a9572bd6a8e4eeae2fedfbc33b115fdbb",
31+
)
32+
33+
http_archive(
34+
name = "arm_gcc_win-x86_64",
35+
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",
36+
strip_prefix = "arm-gnu-toolchain-13.2.Rel1-mingw-w64-i686-arm-none-eabi",
37+
build_file = "//bazel/toolchain:gcc_arm_none_eabi.BUILD",
38+
sha256 = "51d933f00578aa28016c5e3c84f94403274ea7915539f8e56c13e2196437d18f",
39+
)
40+
41+
http_archive(
42+
name = "arm_gcc_mac-x86_64",
43+
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",
44+
strip_prefix = "arm-gnu-toolchain-13.2.Rel1-darwin-x86_64-arm-none-eabi",
45+
build_file = "//bazel/toolchain:gcc_arm_none_eabi.BUILD",
46+
sha256 = "075faa4f3e8eb45e59144858202351a28706f54a6ec17eedd88c9fb9412372cc",
47+
)
48+
49+
http_archive(
50+
name = "arm_gcc_mac-aarch64",
51+
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",
52+
strip_prefix = "arm-gnu-toolchain-13.2.Rel1-darwin-arm64-arm-none-eabi",
53+
build_file = "//bazel/toolchain:gcc_arm_none_eabi.BUILD",
54+
sha256 = "39c44f8af42695b7b871df42e346c09fee670ea8dfc11f17083e296ea2b0d279",
55+
)
56+
57+
# TODO: Provide tinyusb as a proper Bazel module.
58+
http_archive(
59+
name = "tinyusb",
60+
url = "https://github.com/hathach/tinyusb/archive/86c416d4c0fb38432460b3e11b08b9de76941bf5.zip",
61+
strip_prefix = "tinyusb-86c416d4c0fb38432460b3e11b08b9de76941bf5",
62+
build_file = "//src/rp2_common/tinyusb:tinyusb.BUILD",
63+
sha256 = "ac57109bba00d26ffa33312d5f334990ec9a9a4d82bf890ed8b825b4610d1da2",
64+
)
65+
66+
# TODO: Provide btstack as a proper Bazel module.
67+
http_archive(
68+
name = "btstack",
69+
url = "https://github.com/bluekitchen/btstack/archive/72ef1732c954d938091467961e41f4aa9b976b34.zip",
70+
strip_prefix = "btstack-72ef1732c954d938091467961e41f4aa9b976b34",
71+
build_file = "//src/rp2_common/pico_btstack:btstack.BUILD",
72+
sha256 = "f45d72b5d404dd2f8e311287de6f2ba3561fc8ae956737eeb611b277aadc2391",
73+
)
74+
75+
# TODO: Provide btstack as a proper Bazel module.
76+
http_archive(
77+
name = "cyw43-driver",
78+
url = "https://github.com/georgerobotics/cyw43-driver/archive/8ef38a6d32c54f850bff8f189bdca19ded33792a.zip",
79+
strip_prefix = "cyw43-driver-8ef38a6d32c54f850bff8f189bdca19ded33792a",
80+
build_file = "//src/rp2_common/pico_cyw43_driver:cyw43-driver.BUILD",
81+
sha256 = "0b44a19ea58537ee954357606cde5ed20c3a42be77adfebb07b7c0e4740f6228",
82+
)
83+
84+
# TODO: Provide lwip as a proper Bazel module.
85+
http_archive(
86+
name = "lwip",
87+
url = "https://github.com/lwip-tcpip/lwip/archive/239918ccc173cb2c2a62f41a40fd893f57faf1d6.zip",
88+
strip_prefix = "lwip-239918ccc173cb2c2a62f41a40fd893f57faf1d6",
89+
build_file = "//src/rp2_common/pico_lwip:lwip.BUILD",
90+
sha256 = "7ee9e02f2719c0422377e1fcce5a21716ca2e2e855cca56695f9ef7cb020e5dd",
91+
)
92+
93+
register_toolchains(
94+
"//bazel/toolchain:arm_gcc_linux-x86_64",
95+
"//bazel/toolchain:arm_gcc_win-x86_64",
96+
"//bazel/toolchain:arm_gcc_mac-x86_64",
97+
"//bazel/toolchain:arm_gcc_mac-aarch64",
98+
)

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ instructions for other platforms, and just in general, we recommend you see [Ras
5959
3. Setup a `CMakeLists.txt` like:
6060

6161
```cmake
62-
cmake_minimum_required(VERSION 3.13)
62+
cmake_minimum_required(VERSION 3.13...3.27)
6363
6464
# initialize the SDK based on PICO_SDK_PATH
6565
# note: this must happen before project()
@@ -79,7 +79,7 @@ instructions for other platforms, and just in general, we recommend you see [Ras
7979
1. Setup a `CMakeLists.txt` like:
8080
8181
```cmake
82-
cmake_minimum_required(VERSION 3.13)
82+
cmake_minimum_required(VERSION 3.13...3.27)
8383
8484
# initialize pico-sdk from submodule
8585
# note: this must happen before project()

bazel/BUILD.bazel

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
load("@rules_python//python:defs.bzl", "py_binary")
2+
3+
package(default_visibility = ["//visibility:public"])
4+
5+
py_binary(
6+
name = "generate_version_header",
7+
srcs = ["generate_version_header.py"],
8+
visibility = ["//:__subpackages__"],
9+
)
10+
11+
# This isn't actually generated, it just uses the same name
12+
# to make it show up easier in searches.
13+
#
14+
# Rather than generating lists of headers to match CMake, the Bazel build
15+
# opts to have a static header that transitively include two known headers.
16+
# By default, empty header files are included, and users/platforms are expected
17+
# to specify an appropriate `cc_library` to replace them.
18+
#
19+
# You tell bazel which `cc_library` provides the respective headers by
20+
# configuring these `label_flag`s:
21+
#
22+
# # Specify the library that provides "pico_config_extra_headers.h"
23+
# --@pico-sdk//bazel/config:PICO_CONFIG_EXTRA_HEADER=//my_proj:my_custom_headers
24+
#
25+
# # Specify the library that provides "pico_config_platform_headers.h"
26+
# --@pico-sdk//bazel/config:PICO_CONFIG_PLATFORM_HEADER=//my_proj:my_custom_platform_headers
27+
cc_library(
28+
name = "generate_config_header",
29+
hdrs = ["include/pico/config_autogen.h"],
30+
includes = ["include"],
31+
visibility = ["//:__subpackages__"],
32+
deps = [
33+
"//bazel/config:PICO_CONFIG_EXTRA_HEADER",
34+
"//bazel/config:PICO_CONFIG_PLATFORM_HEADER",
35+
],
36+
)
37+
38+
genrule(
39+
name = "empty_extra_headers_file",
40+
outs = ["generated_extra_include/pico_config_extra_headers.h"],
41+
cmd = "echo > $@",
42+
cmd_bat = "copy NUL $@",
43+
visibility = ["//visibility:private"],
44+
)
45+
46+
cc_library(
47+
name = "no_extra_headers",
48+
hdrs = ["generated_extra_include/pico_config_extra_headers.h"],
49+
includes = ["generated_extra_include"],
50+
visibility = ["//visibility:private"],
51+
)
52+
53+
# An empty stub, useful for label_flag flags that need to point to a library,
54+
# but for some purposes the library needs to be a no-op.
55+
cc_library(
56+
name = "empty_cc_lib",
57+
)

bazel/README.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Bazel build
2+
3+
## Using the Pico SDK in a Bazel project.
4+
5+
### Add pico-sdk as a dependency
6+
First, in your `MODULE.bazel` file, add a dependency on the Pico SDK:
7+
```python
8+
bazel_dep(
9+
name = "pico-sdk",
10+
version = "1.6.0-rc1",
11+
)
12+
```
13+
Second, in the same file you'll need to add an explicit dependency on
14+
`rules_cc`, as it's a special-cased Bazel module:
15+
```python
16+
# Note: rules_cc is special-cased repository; a dependency on rules_cc in a
17+
# module will not ensure that the root Bazel module has that same version of
18+
# rules_cc. For that reason, this primarily acts as a FYI. You'll still need
19+
# to explicitly list this dependency in your own project's MODULE.bazel file.
20+
bazel_dep(name = "rules_cc", version = "0.0.9")
21+
22+
# rules_cc v0.0.10 is not yet cut, so manually pull in the desired version.
23+
# This does not apply to dependent projects, so it needs to be copied to your
24+
# project's MODULE.bazel too.
25+
archive_override(
26+
module_name = "rules_cc",
27+
urls = "https://github.com/bazelbuild/rules_cc/archive/1acf5213b6170f1f0133e273cb85ede0e732048f.zip",
28+
strip_prefix = "rules_cc-1acf5213b6170f1f0133e273cb85ede0e732048f",
29+
integrity = "sha256-NddP6xi6LzsIHT8bMSVJ2NtoURbN+l3xpjvmIgB6aSg=",
30+
)
31+
```
32+
33+
### Register toolchains
34+
These toolchains tell Bazel how to compile for ARM cores. Add the following
35+
to the `MODULE.bazel` for your project:
36+
```python
37+
register_toolchains(
38+
"@pico-sdk//bazel/toolchain:arm_gcc_linux-x86_64",
39+
"@pico-sdk//bazel/toolchain:arm_gcc_win-x86_64",
40+
"@pico-sdk//bazel/toolchain:arm_gcc_mac-x86_64",
41+
"@pico-sdk//bazel/toolchain:arm_gcc_mac-aarch64",
42+
)
43+
```
44+
45+
### Enable required .bazelrc flags
46+
To use the toolchains provided by the Pico SDK, you'll need to enable a few
47+
new features. In your project's `.bazelrc`, add the following
48+
```
49+
# Required for new toolchain resolution API.
50+
build --incompatible_enable_cc_toolchain_resolution
51+
build --@rules_cc//cc/toolchains:experimental_enable_rule_based_toolchains
52+
```
53+
54+
### Ready to build!
55+
You're now ready to start building Pico Projects in Bazel! When building,
56+
don't forget to specify `--platforms` so Bazel knows you're targeting the
57+
Raspberry Pi Pico:
58+
```console
59+
$ bazelisk build --platforms=@pico-sdk//bazel/platform:rp2040 //...
60+
```
61+
62+
## SDK configuration
63+
An exhaustive list of build system configuration options is available in
64+
`//bazel/config:BUILD.bazel`.
65+
66+
### Selecting a different board
67+
A different board can be selected specifying `--@pico-sdk//bazel/config:PICO_BOARD`:
68+
```console
69+
$ bazelisk build --platforms=//bazel/platform:rp2040 --@pico-sdk//bazel/config:PICO_BOARD=pico_w //...
70+
```
71+
72+
If you have a bespoke board definition, you can configure the Pico SDK to use it
73+
by pointing `--@pico-sdk//bazel/config:PICO_CONFIG_HEADER` to a `cc_library`
74+
that defines `PICO_BOARD` and either a `PICO_CONFIG_HEADER` define or a
75+
`pico/config_autogen.h` header. Make sure any required `includes`, `hdrs`, and
76+
`deps` are also provided.
77+
78+
## Generating UF2 firmware images
79+
Creation of UF2 images can be done as explicit build steps on a per-binary
80+
rule basis, or through an aspect. Running a wildcard build with the
81+
`pico_uf2_aspect` enabled is the easiest way to create a UF2 for every ELF
82+
firmware image.
83+
84+
```console
85+
$ bazel build --platforms=@pico-sdk//bazel/platform:rp2040 \
86+
--aspects @pico-sdk//tools:uf2_aspect.bzl%pico_uf2_aspect \
87+
--output_groups=+pico_uf2_files \
88+
//...
89+
```
90+
91+
## Building the Pico SDK itself
92+
93+
### First time setup
94+
You'll need Bazel (v7.0.0 or higher) or Bazelisk (a self-updating Bazel
95+
launcher) to build the Pico SDK.
96+
97+
We strongly recommend you set up
98+
[Bazelisk](https://bazel.build/install/bazelisk).
99+
100+
### Building
101+
To build all of the Pico SDK, run the following command:
102+
```console
103+
$ bazelisk build --platforms=//bazel/platform:rp2040 //...
104+
```
105+
106+
## Known issues and limitations
107+
The Bazel build for the Pico SDK is relatively new, but most features and
108+
configuration options available in the CMake build are also available in Bazel.
109+
You are welcome and encouraged to file issues for any problems and limitations
110+
you encounter along the way.
111+
112+
Currently, the following features are not supported:
113+
114+
* "None" variants of pico_double, pico_float, and pico_printf are not yet
115+
supported.
116+
* The pioasm parser cannot be built from source via Bazel.

0 commit comments

Comments
 (0)