Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:78 Xiaozhi esp32 Build System Configuration

From Leeroopedia
Knowledge Sources
Domains Build_Systems, Configuration_Management
Last Updated 2026-10-17 00:00 GMT

Overview

A coupled configuration chain that selects a single board target from a JSON manifest through Python build scripts, Kconfig options, and CMake conditionals, enabling one firmware codebase to produce board-specific binaries with correct chip targets, pin assignments, and feature sets.

Description

The build system configuration chain is the mechanism by which XiaoZhi supports 40+ board variants from a single codebase. The chain has five coupled links:

  1. config.json (per-board): Declares the board's chip target, build variants, and sdkconfig_append options. Each board directory has one config.json.
  2. scripts/build.py: The canonical build entry point. Reads config.json, resolves the board's Kconfig symbol, appends sdkconfig_append entries, and invokes idf.py set-config and idf.py build.
  3. main/Kconfig.projbuild: Defines a choice BOARD_TYPE with one config BOARD_TYPE_<NAME> entry per board. Each entry selects the chip target (IDF_TARGET_<CHIP>).
  4. main/CMakeLists.txt: Contains an if/elseif chain that maps CONFIG_BOARD_TYPE_<NAME> to board source files (.cc), locale, font, and asset configuration.
  5. Board source + config.h: The board's C++ implementation and pin configuration header.

The chain is strictly coupled: adding a board requires updating all five links. A missing link causes a build failure, not a silent misconfiguration.

Board identity (the config.json name and GetBoardType() return value) affects OTA compatibility: the server uses the board type to select the correct firmware binary, so changing a board's identity breaks OTA updates for existing devices.

Usage

Use this principle when:

  • A single codebase must produce multiple board-specific firmware binaries
  • Build-time selection of hardware target is needed (no runtime board detection)
  • Each board needs unique pin assignments, chip target, and feature flags
  • The build process should be reproducible from a declarative config file

Theoretical Basis

The configuration chain is a pipeline of transformations:

config.json                scripts/build.py           Kconfig.projbuild
{                          build_board(               choice BOARD_TYPE
  "target":"esp32s3",        board_type,               config BOARD_TYPE_BREAD
  "builds":[{                 name_filter)        →     select IDF_TARGET_ESP32S3
    "name":"wifi",          →  reads config.json    →
    "sdkconfig_append":       appends sdkconfig       CMakeLists.txt
      ["CONFIG_BOARD_       calls idf.py set-config  if(CONFIG_BOARD_TYPE_BREAD)
       TYPE_BREAD=y"]         calls idf.py build        set SRCS bread-compact-wifi.cc
  }]}                       →                    →   endif

The Kconfig choice ensures exactly one board is selected:

choice BOARD_TYPE
    prompt "Board Type"
    config BOARD_TYPE_BREAD
        bool "Bread Compact WiFi"
        select IDF_TARGET_ESP32S3
    config BOARD_TYPE_M5STACK_CORES3
        bool "M5Stack CoreS3"
        select IDF_TARGET_ESP32S3
endchoice

The CMake conditional maps the Kconfig selection to source files:

if(CONFIG_BOARD_TYPE_BREAD)
    set(SRCS boards/bread-compact-wifi/board.cc)
    target_add_binary_assets(boards/bread-compact-wifi/assets)
elseif(CONFIG_BOARD_TYPE_M5STACK_CORES3)
    set(SRCS boards/m5stack/cores3/board.cc)
endif()

Practical Guide

When adding a board to the build chain:

  • Start with config.json: define target, builds, and sdkconfig_append.
  • Add Kconfig entry: one config BOARD_TYPE_<NAME> with select IDF_TARGET_<CHIP>.
  • Add CMake conditional: one elseif(CONFIG_BOARD_TYPE_<NAME>) block with source files.
  • Keep board identity unique: never rename or reuse an existing board's name/type.
  • Use scripts/build.py: it auto-discovers boards from config.json; don't call idf.py directly.
  • Test with --list-boards: verify the board appears in the list before building.

Related Pages

Implemented By

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment