Skip to content

Commit

Permalink
Add Bazel build (#101)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
armandomontanez and tpudlik authored Jul 17, 2024
1 parent e461b2b commit b19b6aa
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 0 deletions.
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
common --verbose_failures
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bazel-*

# Ignore until https://github.com/bazelbuild/bazel/issues/20369 is fixed.
MODULE.bazel.lock
44 changes: 44 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package(default_visibility = ["//visibility:public"])

cc_binary(
name = "picotool",
srcs = [
"cli.h",
"clipp/clipp.h",
"elf.h",
"main.cpp",
"picoboot_connection/picoboot_connection.c",
"picoboot_connection/picoboot_connection.h",
"picoboot_connection/picoboot_connection_cxx.cpp",
"picoboot_connection/picoboot_connection_cxx.h",
],
copts = select({
"@platforms//os:windows": [],
"//conditions:default": [
"-fexceptions",
"-Wno-delete-non-abstract-non-virtual-dtor",
"-Wno-reorder-ctor",
"-Wno-unused-variable",
],
}),
# TODO: There's probably a nicer way to do share this with CMake.
defines = [
'PICOTOOL_VERSION=\\"1.1.3-rc1\\"',
'SYSTEM_VERSION=\\"host\\"',
'COMPILER_INFO=\\"local\\"',
],
# Windows does not behave nicely with the automagic force_dynamic_linkage_enabled.
dynamic_deps = select({
"@rules_libusb//:force_dynamic_linkage_enabled": ["@libusb//:libusb_dynamic"],
"//conditions:default": [],
}),
includes = ["picoboot_connection"],
deps = [
"@libusb",
"@pico-sdk//src/common/boot_picoboot:boot_picoboot",
"@pico-sdk//src/common/boot_uf2:boot_uf2",
"@pico-sdk//src/common/pico_base:platform_defs",
"@pico-sdk//src/common/pico_binary_info:pico_binary_info",
"@pico-sdk//src/rp2_common/pico_stdio_usb:reset_interface_headers",
],
)
9 changes: 9 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module(name = "picotool", version="1.1.3-rc1")

bazel_dep(name = "rules_libusb", version="0.1.0-rc1")
bazel_dep(name = "pico-sdk", version="1.6.0-rc1")
bazel_dep(name = "platforms", version="0.0.7")

libusb = use_extension("@rules_libusb//:extensions.bzl", "libusb")
libusb.source_release(min_version = "1.0.22")
use_repo(libusb, "libusb")
49 changes: 49 additions & 0 deletions bazel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
## Prerequisites

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).

### Linux

Use your favorite package tool to install dependencies. For example, on Ubuntu:

```console
sudo apt install build-essential libudev-dev
```

On Linux you can add udev rules in order to run picotool without sudo:

```console
sudo cp udev/99-picotool.rules /etc/udev/rules.d/
```

### macOS

To build on macOS, you'll need to ensure Xcode is installed.

```console
xcode-select --install
```

### Windows

To build on Windows, you must install [Visual Studio for Desktop Development With C++](https://visualstudio.microsoft.com/vs/features/cplusplus/).

## Building picotool

From the root of the picotool repository, run Bazel with the following command:

```console
bazelisk build //:picotool
```

## Running picotool

To run picotool, run the binary built by Bazel:

```console
./bazel-bin/picotool
```

0 comments on commit b19b6aa

Please sign in to comment.