Skip to content

Commit b19b6aa

Browse files
Add Bazel build (#101)
* Add initial Bazel build * Add README for Bazel build * Use external registry for Bazel modules * Fix Bazel build on Windows Removes an unused .bzl file and fixes incompatible copts on Windows. * Prepare for BCR-hosted rules_libusb * Explicitly enable exceptions in Bazel build * Ready for BCR-provided dependencies * Set Bazel versions to 1.1.3-rc1 * Add Windows linking fix * Link to Bazelisk in Bazel getting started instructions * Apply buildifier formatting fixes * Add missing platforms dependency Adds a missing bzlmod dep on `platforms` to fix https://pwbug.dev/258836641 --------- Co-authored-by: Ted Pudlik <[email protected]>
1 parent e461b2b commit b19b6aa

File tree

5 files changed

+107
-0
lines changed

5 files changed

+107
-0
lines changed

.bazelrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
common --verbose_failures

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
bazel-*
2+
3+
# Ignore until https://github.com/bazelbuild/bazel/issues/20369 is fixed.
4+
MODULE.bazel.lock

BUILD.bazel

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
cc_binary(
4+
name = "picotool",
5+
srcs = [
6+
"cli.h",
7+
"clipp/clipp.h",
8+
"elf.h",
9+
"main.cpp",
10+
"picoboot_connection/picoboot_connection.c",
11+
"picoboot_connection/picoboot_connection.h",
12+
"picoboot_connection/picoboot_connection_cxx.cpp",
13+
"picoboot_connection/picoboot_connection_cxx.h",
14+
],
15+
copts = select({
16+
"@platforms//os:windows": [],
17+
"//conditions:default": [
18+
"-fexceptions",
19+
"-Wno-delete-non-abstract-non-virtual-dtor",
20+
"-Wno-reorder-ctor",
21+
"-Wno-unused-variable",
22+
],
23+
}),
24+
# TODO: There's probably a nicer way to do share this with CMake.
25+
defines = [
26+
'PICOTOOL_VERSION=\\"1.1.3-rc1\\"',
27+
'SYSTEM_VERSION=\\"host\\"',
28+
'COMPILER_INFO=\\"local\\"',
29+
],
30+
# Windows does not behave nicely with the automagic force_dynamic_linkage_enabled.
31+
dynamic_deps = select({
32+
"@rules_libusb//:force_dynamic_linkage_enabled": ["@libusb//:libusb_dynamic"],
33+
"//conditions:default": [],
34+
}),
35+
includes = ["picoboot_connection"],
36+
deps = [
37+
"@libusb",
38+
"@pico-sdk//src/common/boot_picoboot:boot_picoboot",
39+
"@pico-sdk//src/common/boot_uf2:boot_uf2",
40+
"@pico-sdk//src/common/pico_base:platform_defs",
41+
"@pico-sdk//src/common/pico_binary_info:pico_binary_info",
42+
"@pico-sdk//src/rp2_common/pico_stdio_usb:reset_interface_headers",
43+
],
44+
)

MODULE.bazel

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module(name = "picotool", version="1.1.3-rc1")
2+
3+
bazel_dep(name = "rules_libusb", version="0.1.0-rc1")
4+
bazel_dep(name = "pico-sdk", version="1.6.0-rc1")
5+
bazel_dep(name = "platforms", version="0.0.7")
6+
7+
libusb = use_extension("@rules_libusb//:extensions.bzl", "libusb")
8+
libusb.source_release(min_version = "1.0.22")
9+
use_repo(libusb, "libusb")

bazel/README.md

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
## Prerequisites
2+
3+
You'll need Bazel (v7.0.0 or higher) or Bazelisk (a self-updating Bazel
4+
launcher) to build the Pico SDK.
5+
6+
We strongly recommend you set up
7+
[Bazelisk](https://bazel.build/install/bazelisk).
8+
9+
### Linux
10+
11+
Use your favorite package tool to install dependencies. For example, on Ubuntu:
12+
13+
```console
14+
sudo apt install build-essential libudev-dev
15+
```
16+
17+
On Linux you can add udev rules in order to run picotool without sudo:
18+
19+
```console
20+
sudo cp udev/99-picotool.rules /etc/udev/rules.d/
21+
```
22+
23+
### macOS
24+
25+
To build on macOS, you'll need to ensure Xcode is installed.
26+
27+
```console
28+
xcode-select --install
29+
```
30+
31+
### Windows
32+
33+
To build on Windows, you must install [Visual Studio for Desktop Development With C++](https://visualstudio.microsoft.com/vs/features/cplusplus/).
34+
35+
## Building picotool
36+
37+
From the root of the picotool repository, run Bazel with the following command:
38+
39+
```console
40+
bazelisk build //:picotool
41+
```
42+
43+
## Running picotool
44+
45+
To run picotool, run the binary built by Bazel:
46+
47+
```console
48+
./bazel-bin/picotool
49+
```

0 commit comments

Comments
 (0)