Files
ai-passport/docs/development/engineering/build-and-test.md
T
Shinku 3bacd66efd docs(engineering): 补充 ccache 提速与工具链安装排障
- 记录 IDF_CCACHE_ENABLE / CONFIG_IDF_BUILD_USE_CCACHE 加速重复编译
- 说明 export.sh 需 source 而非 ./ 执行、自定义 IDF_TOOLS_PATH 每次重设
- 增加工具链安装失败恢复:清理 ~/.espressif/dist、macOS 证书包、
  Apple Silicon Rosetta 2、Windows 杀毒扫描排除
- 经验来自 esp-mosaico/esp-mosaico-vibe,双语同步更新
2026-09-09 10:15:12 +08:00

3.8 KiB

简体中文 · English

Build and Test

Use ESP-IDF 5.5.3. On a clean machine or when the toolchain is missing, follow the environment bootstrap first.

Prefer ./tools/validate.sh --firmware for firmware builds and flash its verified build/FoloToy-AI-Passport-full.bin at offset 0x0 only when the target is blank or the merged byte range ends before protected cardid. On a provisioned device, use segmented idf.py flash. Treat idf.py build and idf.py flash as incremental development commands, not the default delivery path.

source <path-to-esp-idf-v5.5.3>/export.sh
idf.py --version             # must report ESP-IDF v5.5.3
./tools/validate.sh --firmware # preferred: build and verify merged 0x0 image
idf.py set-target esp32c3     # fresh checkout or changed target
idf.py build                  # optional incremental application build
idf.py flash monitor          # optional incremental application flash
idf.py fullclean              # remove stale generated build state only

idf.py fullclean does not fully synchronize an existing sdkconfig with changed defaults. Preserve intentional local settings, then run idf.py set-target esp32c3 when the target or tracked defaults must be regenerated.

Speeding up repeated builds

ccache keeps incremental builds fast. ESP-IDF does not enable it by default; enable it for the current terminal, or make it permanent per project:

export IDF_CCACHE_ENABLE=1
idf.py build
CONFIG_IDF_BUILD_USE_CCACHE=y

The ccache cache lives outside build/, so neither idf.py fullclean nor a temporary validation build removes it. When the cache must be cleared, remove the ccache directory itself (default ~/.ccache, or wherever CCACHE_DIR points).

On Windows, slow repeated builds are frequently caused by antivirus or endpoint software scanning build directories in real time; add the ESP-IDF install directory, the tools directory (%USERPROFILE%\.espressif or a custom IDF_TOOLS_PATH), and the project build directory (build/) to the scan exclusions.

The tracked dependencies.lock pins Managed Component resolution. After changing an idf_component.yml, regenerate the lock with ESP-IDF 5.5.3, review version changes, and commit it with the manifest. An ordinary build must not leave an unexplained lock-file diff.

Firmware validation uses a fresh temporary build directory and an isolated sdkconfig generated from the tracked defaults. It does not consume or overwrite a developer's root sdkconfig, and it copies only the verified merged image to build/FoloToy-AI-Passport-full.bin. The gate also enforces the protected Flash layout: protected partition addresses, application size, partition-table MD5, and absence of protected payload data.

The baseline also has a hardware-independent logic test:

cc -std=c11 -Wall -Wextra -Werror -Imain \
  tests/test_ui_pixel_math.c main/ui_pixel_math.c \
  -o /tmp/test_ui_pixel_math
/tmp/test_ui_pixel_math

Use the unified validation entry point:

./tools/validate.sh --static    # repository checks, workflows, links, secrets, host tests
./tools/validate.sh --firmware  # build, merge-bin, offsets, and protected layout
./tools/validate.sh             # complete gate; requires an activated ESP-IDF environment

CI calls the same script. Fix the shared script or environment if local and CI behavior differs; do not duplicate command sequences in workflows.

Hardware-affecting changes must also run the applicable on-device checklist in the hardware guide. Report compilation separately from physical-device validation.

Never upload the app-only build/FoloToy-AI-Passport.bin to the community. Only the validated build/FoloToy-AI-Passport-full.bin contains the complete checked firmware layout.