roll: pigweed, pw_toolchain: pw_multibuf: Restructure ChunkIterable

MultiBuf is a byte-oriented view of a list of chunks, and this change
structures MultiBuf accordingly. This replaces the ChunkIterable class
with a private MultiBufChunks base class that provides the
Chunk-oriented view for MultiBuf.

Restructuring this way fixes an issue where MultiBuf data can be
modified from a const reference. MultiBuf originally returned a const
ChunkIterable, but since return values are copied, this becomes a
non-const ChunkIterable, giving mutable access to the multibuf.

  const MultiBuf& const_mb = mb;
  auto chunk_iterable = cmb.Chunks();  // chunk_iterable is non-const
  iterable.front()[0] = std::byte();  // uh oh, chunk data is mutable!

Original-Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/230892

https://pigweed.googlesource.com/pigweed/pigweed
pigweed, pw_toolchain Rolled-Commits: 03da4a376d12ab8..7e7c141c8808200
Roller-URL: https://ci.chromium.org/b/8739051696451980865
GitWatcher: ignore
CQ-Do-Not-Cancel-Tryjobs: true
Change-Id: I8af7a904b5cd447e9e4b483987c21f057851671f
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/quickstart/bazel/+/230736
Commit-Queue: Pigweed Roller <pigweed-roller@pigweed-service-accounts.iam.gserviceaccount.com>
Lint: Lint 🤖 <android-build-ayeaye@system.gserviceaccount.com>
Bot-Commit: Pigweed Roller <pigweed-roller@pigweed-service-accounts.iam.gserviceaccount.com>
1 file changed
tree: ce0e5debefd2b948ee6d328bf7a62a12cd11eadf
  1. .github/
  2. .vscode/
  3. apps/
  4. modules/
  5. system/
  6. targets/
  7. tools/
  8. .bazelignore
  9. .bazelrc
  10. .bazelversion
  11. .buildifier.json
  12. .clang-format
  13. .clangd.shared
  14. .gitignore
  15. .pw_console.yaml
  16. AUTHORS
  17. BUILD.bazel
  18. CONTRIBUTING.md
  19. LICENSE
  20. MODULE.bazel
  21. OWNERS
  22. pigweed.json
  23. README.md
README.md

Pigweed: minimal Bazel example

This repository contains a minimal example of a Bazel-based Pigweed project. It is a LED-blinking service (featuring RPC control!) for the Raspberry Pi Pico. It can also be run on any computer using the included simulator.

Getting the code

git clone https://pigweed.googlesource.com/pigweed/quickstart/bazel pw_bazel_quickstart
cd pw_bazel_quickstart

Dependencies

The only dependency that must be installed is Bazelisk.

Bazelisk is a launcher for the Bazel build system that allows for easy management of multiple Bazel versions.

Instructions for installing Bazelisk can be found here.

Running on the simulator

To run the simulator, type: bazelisk run //apps/blinky:simulator_blinky Then, in a new console, connect to the simulator using: bazelisk run //apps/blinky:simulator_console

Running on hardware

To start, connect a Raspberry Pi Pico, Pico 2, or debug probe via USB.

To run on the Raspberry Pi Pico, type: bazelisk run //apps/blinky:flash_rp2040 Then, in a new console, connect to the device using: bazelisk run //apps/blinky:rp2040_console

Controlling the LED

Once connected with a console, RPCs can be sent to control the LED. Try running:

device.set_led(True)
device.set_led(False)
device.toggle_led()
device.blink(blink_count=3)

Running unit tests on the host device

bazelisk test //... will run the unit tests defined in this project, such as the ones in modules/blinky/blinky_test.cc.

Running unit tests on hardware

bazelisk run @pigweed//targets/rp2040/py:unit_test_server in one console followed by bazelisk test //... --config=rp2040 will also allow running the unit tests on-device.

Next steps

Try poking around the codebase for inspiration about how Pigweed projects can be organized. Most of the relevant code in this quickstart (including RPC definitions) is inside modules/blinky, with some client-side Python code in tools/console.py.