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.
This document provides guidelines for AI agents making changes to the Pigweed codebase.
Some subdirectories, such as pw_ide, contain their own GEMINI.md file with more specific instructions for that area of the codebase. When working in those areas, please refer to the local GEMINI.md for more detailed guidance.
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.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 only