Implementation:78 Xiaozhi esp32 build py
| Knowledge Sources | |
|---|---|
| Domains | Build_Systems, Tooling |
| Last Updated | 2026-10-17 00:00 GMT |
Overview
Concrete tool for board discovery and firmware compilation provided by the XiaoZhi firmware, implementing the canonical build entry point that reads config.json, resolves Kconfig options, and invokes idf.py for building.
Description
scripts/build.py is an External Tool Doc — it documents the XiaoZhi build script. It is the canonical way to build firmware for any supported board. Key functionality:
- Board discovery:
--list-boardsscansmain/boards/directories forconfig.jsonfiles and lists all available boards and variants. - Config resolution: Reads the board's
config.json, filtersbuildsby the--nameflag, resolves the Kconfig symbol fromsdkconfig_append. - Build invocation: Calls
_run_idf("set-config", ...)to set eachsdkconfig_appendentry, then_run_idf("build")to compile. - Binary merging:
merge_bin()merges bootloader, partition table, and firmware into a single binary. - Zip output:
zip_bin(name, version)createsreleases/v<version>_<name>.zip. - Customization:
--language,--wake-word,--build-options-jsonflags for locale, wake word model, and additional build options.
The script changes local sdkconfig and build state. It should not be assumed that the build directory represents a previous target after the script runs.
Usage
Reference this implementation when:
- Building firmware for a specific board
- Discovering available boards and variants
- Understanding the build configuration chain
- Customizing builds with language or wake word options
Code Reference
Source Location
- Repository: XiaoZhi ESP32
- File:
scripts/build.py
Signature
# CLI entry point
def main():
parser = argparse.ArgumentParser()
parser.add_argument("board", nargs="?", help="Board directory path")
parser.add_argument("--name", help="Variant name filter")
parser.add_argument("--list-boards", action="store_true")
parser.add_argument("--zip", action="store_true")
parser.add_argument("--language", help="Language/locale override")
parser.add_argument("--wake-word", help="Wake word model override")
parser.add_argument("--build-options-json", help="Additional build options")
args = parser.parse_args()
# ...
# Core build function
def build_board(board_type: str, config_filename: str, name_filter: str = None, ...):
"""Read config.json, resolve sdkconfig_append, invoke idf.py set-config + build."""
# IDF invocation
def _run_idf(command: str, *args):
"""Invoke idf.py with the given command and arguments."""
def merge_bin():
"""Merge bootloader, partition table, and firmware into one binary."""
def zip_bin(name: str, version: str):
"""Create a release zip file."""
Import
# Used as a CLI tool, not imported as a Python module
python3 scripts/build.py --help
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| board | string (path) | Board directory path (e.g., main/boards/bread-compact-wifi)
| |
| --name | string | Variant name to build (e.g., wifi)
| |
| --language | string | Language override (e.g., zh, en)
| |
| --wake-word | string | Wake word model override | |
| --zip | flag | Create release zip after build |
Outputs
| Name | Type | Description |
|---|---|---|
| build/ | Compiled firmware artifacts | |
| build/merged-binary.bin | Merged binary (if merge enabled) | |
| releases/v<ver>_<name>.zip | Release zip (if --zip) |
Usage Examples
Discovering Boards
# List all available boards and variants
python3 scripts/build.py --list-boards
# Output:
# bread-compact-wifi (esp32s3):
# wifi
# m5stack/cores3 (esp32s3):
# wifi
Building Firmware
# Source ESP-IDF environment first
source /path/to/esp-idf/export.sh
# Build a board variant
python3 scripts/build.py main/boards/bread-compact-wifi --name wifi
# Build with zip output
python3 scripts/build.py main/boards/bread-compact-wifi --name wifi --zip
# Build with custom language
python3 scripts/build.py main/boards/bread-compact-wifi --name wifi --language zh