From 3bacd66efd86b6f6fcd2a851344f9341bca20c30 Mon Sep 17 00:00:00 2001 From: Shinku <17696928+Shinku-Chen@users.noreply.github.com> Date: Wed, 9 Sep 2026 10:15:12 +0800 Subject: [PATCH] =?UTF-8?q?docs(engineering):=20=E8=A1=A5=E5=85=85=20ccach?= =?UTF-8?q?e=20=E6=8F=90=E9=80=9F=E4=B8=8E=E5=B7=A5=E5=85=B7=E9=93=BE?= =?UTF-8?q?=E5=AE=89=E8=A3=85=E6=8E=92=E9=9A=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 记录 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,双语同步更新 --- docs/CHANGELOG.md | 2 ++ docs/CHANGELOG.zh_CN.md | 2 ++ .../development/engineering/build-and-test.md | 25 ++++++++++++++ .../engineering/build-and-test.zh_CN.md | 20 +++++++++++ .../engineering/environment-setup.md | 34 +++++++++++++++++++ .../engineering/environment-setup.zh_CN.md | 30 ++++++++++++++++ 6 files changed, 113 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 231202f..435b574 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -8,6 +8,8 @@ - Added the supplied 80-byte CW2017 profile for the specified 520 mAh cell, including content/update-flag checks, verified writes, the required restart sequence, and bounded SOC-readiness polling. +- Documented ccache support for faster repeated builds (`IDF_CCACHE_ENABLE=1` or `CONFIG_IDF_BUILD_USE_CCACHE=y`), the activation pitfall of running `export.sh` as `./export.sh` in a subshell, re-setting `IDF_TOOLS_PATH` before every activation, toolchain install-failure recovery (clearing `~/.espressif/dist`, macOS certificate bundle, Apple Silicon Rosetta 2), and Windows antivirus scan exclusions (learned from `esp-mosaico/esp-mosaico-vibe`). + - Reorganized the documentation by function area with a dual entry point: the root `AGENTS.md` is now a thin router (hard constraints + task routing only) and the detailed AI workflow lives in `docs/development/ai-guide.md`; `agent-guide.md` was folded in. `docs/development/` gained a second level (`engineering/`, `ci/`, `release/`), and the `plays/` application archive and `experiences/` moved into a `docs/reference/` area with a dedicated README. Removed `docs/software-design/` (empty scaffold); folded the three `assets/{fonts,images,music}/README` leaves into the `assets/` README; flattened the six `project-completion` sub-documents into a single file; and unified each directory to a single README, eliminating every `INDEX` file and a duplicated experience index. All cross-references and bibliographic links were updated; no content was dropped. - Kept the fixed protected `cardid`/Recovery partitions and CI validation for diff --git a/docs/CHANGELOG.zh_CN.md b/docs/CHANGELOG.zh_CN.md index f3e682f..d267622 100644 --- a/docs/CHANGELOG.zh_CN.md +++ b/docs/CHANGELOG.zh_CN.md @@ -8,6 +8,8 @@ - 加入厂家为优特利 520mAh 电芯生成的 80 字节 CW2017 profile,并实现内容与更新标志检查、写入后校验、规定的重启时序以及有上限的 SOC 就绪等待。 +- 记录加快重复编译的 ccache 用法(`IDF_CCACHE_ENABLE=1` 或 `CONFIG_IDF_BUILD_USE_CCACHE=y`)、把 `export.sh` 写成 `./export.sh` 在子 shell 执行的激活陷阱、每次激活前重设 `IDF_TOOLS_PATH`、工具链安装失败恢复(清理 `~/.espressif/dist`、macOS 证书包、Apple Silicon Rosetta 2)与 Windows 杀毒扫描排除项(经验来自 `esp-mosaico/esp-mosaico-vibe`)。 + - 按功能域整理文档并采用双入口:根目录 `AGENTS.md` 变为薄路由(只保留硬约束与任务路由),详细的 AI 开发工作流下沉到 `docs/development/ai-guide.md`,`agent-guide.md` 并入其中。为 `docs/development/` 增加二级分区(`engineering/`、`ci/`、`release/`),把 `plays/` 应用档案与 `experiences/` 移入带专属 README 的 `docs/reference/` 参考区;删除 `docs/software-design/`(空脚手架);把 `assets/{fonts,images,music}/README` 三个叶子 README 并入 `assets/` README;把 `project-completion` 的六个子文档压平为单文件;并把每个目录统一为单一 README,消除所有 `INDEX` 文件与一处重复经验索引。所有交叉引用与文献链接已更新;未丢弃任何内容。 - 保留固定的 `cardid`/Recovery 保护分区,以及 CI 对合并镜像结构、 diff --git a/docs/development/engineering/build-and-test.md b/docs/development/engineering/build-and-test.md index 3e34224..5c38ba4 100644 --- a/docs/development/engineering/build-and-test.md +++ b/docs/development/engineering/build-and-test.md @@ -29,6 +29,31 @@ 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: + +```bash +export IDF_CCACHE_ENABLE=1 +idf.py build +``` + +```text +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-flash-layout.md): protected partition addresses, application size, partition-table MD5, and absence of protected payload data. diff --git a/docs/development/engineering/build-and-test.zh_CN.md b/docs/development/engineering/build-and-test.zh_CN.md index 5047f40..d95f1c3 100644 --- a/docs/development/engineering/build-and-test.zh_CN.md +++ b/docs/development/engineering/build-and-test.zh_CN.md @@ -27,6 +27,26 @@ idf.py fullclean # 只清空过期生成状态(勿用于清理用 target 或已跟踪 defaults 时,先保留有意的本地设置,再运行 `idf.py set-target esp32c3`。 +### 加速重复编译 + +ccache 能让增量编译保持快速。ESP-IDF 默认未启用;在当前终端启用,或在项目配置里永久启用: + +```bash +export IDF_CCACHE_ENABLE=1 +idf.py build +``` + +```text +CONFIG_IDF_BUILD_USE_CCACHE=y +``` + +ccache 缓存位于 `build/` 之外,因此 `idf.py fullclean` 和临时验证构建都不会清掉它。 +需要清缓存时删除 ccache 目录本身(默认 `~/.ccache`,或 `CCACHE_DIR` 指向的位置)。 + +在 Windows 上,重复编译慢常见原因是杀毒或终端安全软件实时扫描构建目录; +把 ESP-IDF 安装目录、工具链目录(`%USERPROFILE%\.espressif` 或自定义 +`IDF_TOOLS_PATH`)和工程构建目录(`build/`)加入扫描排除项。 + 仓库提交 `dependencies.lock` 以固定 ESP-IDF Managed Components 的解析结果。修改 `idf_component.yml` 后必须使用 ESP-IDF 5.5.3 重新生成锁文件、review 版本变化并与 manifest 一起提交;普通构建不应产生未提交的锁文件差异。 固件门禁使用全新的临时构建目录,并从仓库 `sdkconfig.defaults` 生成隔离的 `sdkconfig`。它不会读取或覆盖开发者根目录的 `sdkconfig`,只把验证通过的合并镜像复制到 `build/FoloToy-AI-Passport-full.bin`。门禁同时强制检查[受保护的 Flash 布局](protected-flash-layout.zh_CN.md):保护分区地址、应用大小、分区表 MD5 以及保护区数据不入包。 diff --git a/docs/development/engineering/environment-setup.md b/docs/development/engineering/environment-setup.md index 4e1edd9..1d82e0c 100644 --- a/docs/development/engineering/environment-setup.md +++ b/docs/development/engineering/environment-setup.md @@ -173,6 +173,40 @@ printf 'IDF_PATH=%s\n' "${IDF_PATH}" Stop if the reported version is not exactly `ESP-IDF v5.5.3`. Do not generate project configuration with another version. +Activation is shell-scoped: run `export.sh` with a leading dot (or `source`), +never as `./export.sh`, which spawns a subshell and leaves the current shell +unconfigured (`IDF_PATH is not set` or `idf.py: command not found` afterward). +If a custom `IDF_TOOLS_PATH` was used during install, set it again before every +`export.sh` call — the script does not remember it from an earlier session. + +### Toolchain install failures + +`install.sh` fetches toolchains themselves from the same mirror nodes. When it +fails at a checksum mismatch or a corrupted download, clear the cache and +retry: + +```bash +rm -rf ~/.espressif/dist +"${AI_PASSPORT_IDF_ROOT}/install.sh" esp32c3 +``` + +On macOS, a certificate error (`[SSL: CERTIFICATE_VERIFY_FAILED]`) is usually a +missing Python certificate bundle; run +`Install Certificates.command` from the Python installation directory, then +retry. On Apple Silicon, `bad CPU type in executable` or +`tool xtensa-esp32-elf has no installed versions` means the toolchain binary is +x86-64 and needs Rosetta 2: + +```bash +/usr/sbin/softwareupdate --install-rosetta --agree-to-license +``` + +On Windows the official ESP-IDF Tools Installer already handles mirrors and +caching; if a manual install still fails at a corrupted archive, the partially +downloaded files live under `%USERPROFILE%\.espressif\dist` — delete that +folder, set `IDF_GITHUB_ASSETS` in the same session as `install.bat`, and +retry. + For mainland China, optionally accelerate Managed Component archives in the current terminal: diff --git a/docs/development/engineering/environment-setup.zh_CN.md b/docs/development/engineering/environment-setup.zh_CN.md index f0c532c..5badb49 100644 --- a/docs/development/engineering/environment-setup.zh_CN.md +++ b/docs/development/engineering/environment-setup.zh_CN.md @@ -147,6 +147,36 @@ printf 'IDF_PATH=%s\n' "${IDF_PATH}" 版本不是严格的 `ESP-IDF v5.5.3` 时必须停止,不得用其他版本生成项目配置。 +激活只对当前 shell 生效:运行 `export.sh` 必须用带点的形式(或 `source`), +不能写成 `./export.sh`——那会在子 shell 中执行,当前 shell 不会配置成功 +(之后报 `IDF_PATH is not set` 或 `idf.py: command not found`)。安装时使用过 +自定义 `IDF_TOOLS_PATH` 的,每次 `export.sh` 前都要重新设置——脚本不会记住 +上一个 session 的值。 + +### 工具链安装失败 + +`install.sh` 的工具链本身也走同一套镜像节点。校验和不匹配或下载损坏时, +清缓存重试: + +```bash +rm -rf ~/.espressif/dist +"${AI_PASSPORT_IDF_ROOT}/install.sh" esp32c3 +``` + +macOS 上证书错误(`[SSL: CERTIFICATE_VERIFY_FAILED]`)通常是 Python 证书包 +缺失:运行 Python 安装目录下的 `Install Certificates.command` 后再试。 +Apple Silicon 上 `bad CPU type in executable` 或 +`tool xtensa-esp32-elf has no installed versions` 表示工具链是 x86-64 二进制, +需要 Rosetta 2: + +```bash +/usr/sbin/softwareupdate --install-rosetta --agree-to-license +``` + +Windows 上官方 ESP-IDF Tools Installer 已处理镜像与缓存;手动安装仍因归档 +损坏失败时,部分下载的文件在 `%USERPROFILE%\.espressif\dist`——删除该目录, +与 `install.bat` 同一 session 设置 `IDF_GITHUB_ASSETS` 后重试。 + 中国大陆环境可在当前终端临时加速 Managed Component 归档下载: ```bash