This document provides an overview of Pigweed for AI agents that assist with development.
Pigweed is a collection of embedded libraries, called “modules,” that work together to enable faster and more robust development of embedded systems. It provides a comprehensive development environment, including a build system, testing frameworks, and tools for debugging and analysis.
As an AI assistant, your role is to help developers use Pigweed effectively. This includes:
This section provides specific guidance for writing C++ code and tests in Pigweed.
Pigweed places a strong emphasis on testing. Here are some key points to remember:
pw_unit_test framework, which provides a GoogleTest-like API. You should be familiar with the TEST and TEST_F macros for defining test cases, and the EXPECT_* and ASSERT_* macros for assertions._test.cc suffix.PW_TEST_EXPECT_OK and PW_TEST_ASSERT_OK to test functions that return pw::Status or pw::Result.PW_NC_TEST) to verify that code fails to compile under specific conditions. This is particularly useful for testing static assertions and template metaprogramming.This is a condensed version of the Pigweed C++ style guide. For more details, refer to the full style guide.
-std=c++17. C++20 features can be used if the code remains C++17 compatible.clang-format.<cstdlib> instead of <stdlib.h>).pw::string, pw::sync, pw::function) instead of their std counterparts.//).return and continue.else after a return or continue.pw::Status and pw::Result for recoverable errors.PW_ASSERT and PW_CHECK for fatal errors.#pragma once.pw_log module for logging.PW_LOG_DEBUG, PW_LOG_INFO, PW_LOG_WARN, PW_LOG_ERROR, PW_LOG_CRITICAL).pw namespace.pw_tokenizer_*).PW_MY_MODULE_*.* or & next to the type (e.g., int* number).PW_MAYBE_UNUSED macro is deprecated and has been removed. For handling unused variables, the standard C++ attribute [[maybe_unused]] should be used instead.pw format, which uses black.__init__.py.H1: ======== over and under, H2: -------- over and under, H3: ======== under)... code-block:: <language> for code blocks.Pigweed uses gn and bazel as its primary build systems. Here are some common commands:
gn (Meta-build system):
gn gen outninja -C out --quietgn clean outbazel (Build system):
bazelisk and not bazel to ensure the correct bazel version is in use. Note: Use --noshow_progress --noshow_loading_progress to reduce the amount of output produced and avoid polluting the context window.bazelisk build --noshow_progress --noshow_loading_progress //path/to/module:targetbazelisk test --noshow_progress --noshow_loading_progress //path/to/module:targetbazelisk test --noshow_progress --noshow_loading_progress //path/to/module/...Pigweed follows a specific commit message format. A good commit message should be concise and descriptive.
Subject Line:
pw_foo: Add support for bar featureBody:
Explain the “what” and “why” of the change, not the “how”.
Reference any relevant issue trackers.
If you are tempted to write a long commit message, consider if the content is better written in the docs and referred to from the commit.
Use a Bug: or Fixed: line for bug fixes.
Example:
This change adds support for the bar feature to the `pw_foo` module. This is necessary because... Bug: b/123456789
Fuchsia development happens on Gerrit When the user asks for you to read a CL for them, do the following:
pwrev/1234, then the id is 1234. If the URL is https://pigweed-review.googlesource.com/c/pigweed/+/1299104, then the ID is 1299104.https://pigweed-review.googlesource.com, run this shell command to get the diff from the changelist: curl -L https://pigweed-review.googlesource.com/changes/<ID>/revisions/current/patch?raw.Pigweed development happens on Gerrit, and you can help users get changes through the review process by automating parts of the review flow. When the user asks for reading review comments, do this:
curl https://pigweed-review.googlesource.com/changes/<ID>/commentsunresolved=true, and are for latest patch_set onlyFulfill the user‘s request thoroughly. After completing the primary request, you may suggest and, upon user approval, perform directly related follow-up actions. Before suggesting a follow-up, you must analyze the project’s context (e.g., read existing files, check tests) to ensure your suggestion is relevant and adheres to established conventions. Do not take significant actions beyond the clear scope of the original request without first proposing your plan and getting confirmation from the user.
When making repeated mistakes or the user requests work be done in a different way, consider whether this guide is incorrect or incomplete. If you feel certain this file requires updating, propose an addition that would prevent further such mistakes.