gcc
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGCC 嵌入式工程构建
GCC Embedded Project Build
本 skill 提供基于 CMake + arm-none-eabi-gcc 的嵌入式工程发现、preset 枚举、配置生成、增量编译、全量重建、清理和 ELF 大小分析能力。
范围说明:当前仅支持 CMake 型 GCC 嵌入式工程,不覆盖纯 工程。
MakefileThis skill provides capabilities for embedded project discovery, preset enumeration, configuration generation, incremental compilation, full rebuild, cleaning, and ELF size analysis based on CMake + arm-none-eabi-gcc.
Scope Note: Currently only supports CMake-based GCC embedded projects, does not cover pure projects.
Makefile配置
Configuration
环境级配置(skill/config.json)
Environment-level Configuration (skill/config.json)
skill 目录下的 包含环境级配置,首次使用前确认 路径正确:
config.jsoncmake_exejson
{
"cmake_exe": "cmake",
"toolchain_prefix": "arm-none-eabi-",
"toolchain_path": "",
"operation_mode": 1
}- :cmake 可执行文件路径,默认从 PATH 查找
cmake_exe - :工具链前缀,默认
toolchain_prefix,用于定位 size 等工具arm-none-eabi- - :工具链 bin 目录,为空时从 PATH 查找
toolchain_path - :
operation_mode直接执行 /1输出风险摘要但不阻塞 /2执行前确认3
The in the skill directory contains environment-level configurations. Confirm the path is correct before first use:
config.jsoncmake_exejson
{
"cmake_exe": "cmake",
"toolchain_prefix": "arm-none-eabi-",
"toolchain_path": "",
"operation_mode": 1
}- : Path to the cmake executable, defaults to searching from PATH
cmake_exe - : Toolchain prefix, defaults to
toolchain_prefix, used to locate tools like sizearm-none-eabi- - : Bin directory of the toolchain, defaults to searching from PATH when empty
toolchain_path - :
operation_modeExecute directly /1Output risk summary without blocking /2Confirm before execution3
工程级配置(workspace/.embeddedskills/config.json)
Project-level Configuration (workspace/.embeddedskills/config.json)
工程级共享配置统一保存在工作区的 中:
.embeddedskills/config.jsonjson
{
"gcc": {
"project": "",
"preset": "",
"log_dir": ".embeddedskills/build"
}
}- :默认工程路径(相对 workspace),构建成功后会自动更新
project - :默认 CMake preset 名称,构建成功后会自动更新
preset - :构建日志输出目录,默认
log_dir.embeddedskills/build
Shared project-level configurations are stored uniformly in of the workspace:
.embeddedskills/config.jsonjson
{
"gcc": {
"project": "",
"preset": "",
"log_dir": ".embeddedskills/build"
}
}- : Default project path (relative to workspace), will be updated automatically after successful build
project - : Default CMake preset name, will be updated automatically after successful build
preset - : Build log output directory, defaults to
log_dir.embeddedskills/build
参数解析优先级
Parameter Parsing Priority
参数解析顺序(从高到低):
- CLI 显式参数
- 环境级配置(skill/config.json)
- 工程级配置(.embeddedskills/config.json)
- state.json(上次构建记录)
- 搜索/询问
Parameter parsing order (from highest to lowest):
- Explicit CLI parameters
- Environment-level configuration (skill/config.json)
- Project-level configuration (.embeddedskills/config.json)
- state.json (last build record)
- Search/query
子命令
Subcommands
| 子命令 | 用途 | 风险 |
|---|---|---|
| 搜索当前目录下的 CMake 嵌入式工程 | 低 |
| 列出 CMakePresets.json 中的 configure/build preset | 低 |
| 执行 | 中 |
| 增量编译 | 中 |
| 清理后全量重建 | 中 |
| 清理构建目录 | 高 |
| 分析 ELF 文件大小(text/data/bss 和内存使用) | 低 |
| Subcommand | Purpose | Risk |
|---|---|---|
| Search for CMake-based embedded projects in the current directory | Low |
| List configure/build presets in CMakePresets.json | Low |
| Execute | Medium |
| Incremental compilation via | Medium |
| Clean then perform full rebuild | Medium |
| Clean build directory | High |
| Analyze ELF file size (text/data/bss and memory usage) | Low |
执行流程
Execution Flow
- 读取 ,确认
config.json路径有效cmake_exe - 未指定子命令时默认执行
scan - 未提供工程路径时先执行 搜索工程
scan - 发现多个工程或多个 preset 时列出选项让用户选择,绝不自动猜测
- 按
configure/build/rebuild/clean决定是否需要确认operation_mode - 前自动检测是否已 configure,未配置时提示先执行 configure
build - 成功后返回
build/rebuild,供elf_file继续使用jlink/openocd - 默认分析最近一次构建产物的 .elf 文件
size
- Read and confirm the
config.jsonpath is validcmake_exe - Default to executing when no subcommand is specified
scan - Execute first to search for projects if no project path is provided
scan - List options for users to choose when multiple projects or presets are found, never guess automatically
- Determine whether confirmation is required for based on
configure/build/rebuild/cleanoperation_mode - Automatically check if configured before , prompt to execute configure first if not configured
build - Return after successful
elf_filefor continued use bybuild/rebuildjlink/openocd - defaults to analyzing the .elf file from the most recent build
size
脚本调用
Script Invocation
skill 目录下有三个 Python 脚本,使用标准库实现,无额外依赖。
There are three Python scripts in the skill directory, implemented with standard libraries and no additional dependencies.
gcc_project.py — 工程扫描与 preset 枚举
gcc_project.py — Project Scanning and Preset Enumeration
bash
undefinedbash
undefined扫描工程
Scan projects
python <skill-dir>/scripts/gcc_project.py scan --root <搜索目录> --json
python <skill-dir>/scripts/gcc_project.py scan --root <search directory> --json
列出 preset
List presets
python <skill-dir>/scripts/gcc_project.py presets --project <工程目录> --json
undefinedpython <skill-dir>/scripts/gcc_project.py presets --project <project directory> --json
undefinedgcc_build.py — 配置 / 编译 / 重建 / 清理
gcc_build.py — Configure / Compile / Rebuild / Clean
bash
python <skill-dir>/scripts/gcc_build.py <configure|build|rebuild|clean> \
--cmake <cmake路径> \
--project <工程根目录> \
--preset <preset名称> \
--log-dir <日志目录> \
--jsonbash
python <skill-dir>/scripts/gcc_build.py <configure|build|rebuild|clean> \
--cmake <cmake path> \
--project <project root directory> \
--preset <preset name> \
--log-dir <log directory> \
--jsongcc_size.py — ELF 大小分析
gcc_size.py — ELF Size Analysis
bash
undefinedbash
undefined基本分析
Basic analysis
python <skill-dir>/scripts/gcc_size.py analyze
--elf <elf文件路径>
--toolchain-prefix arm-none-eabi-
--linker-script <链接脚本路径>
--json
--elf <elf文件路径>
--toolchain-prefix arm-none-eabi-
--linker-script <链接脚本路径>
--json
python <skill-dir>/scripts/gcc_size.py analyze
--elf <elf file path>
--toolchain-prefix arm-none-eabi-
--linker-script <linker script path>
--json
--elf <elf file path>
--toolchain-prefix arm-none-eabi-
--linker-script <linker script path>
--json
对比分析
Comparative analysis
python <skill-dir>/scripts/gcc_size.py compare
--elf <elf文件1>
--compare <elf文件2>
--toolchain-prefix arm-none-eabi-
--json
--elf <elf文件1>
--compare <elf文件2>
--toolchain-prefix arm-none-eabi-
--json
undefinedpython <skill-dir>/scripts/gcc_size.py compare
--elf <elf file 1>
--compare <elf file 2>
--toolchain-prefix arm-none-eabi-
--json
--elf <elf file 1>
--compare <elf file 2>
--toolchain-prefix arm-none-eabi-
--json
undefined输出格式
Output Format
所有脚本以 JSON 格式返回,基础字段为 (ok/error)、、、,并可能附带 、、、、、。
statusactionsummarydetailscontextartifactsmetricsstatenext_actionstiming成功示例:
json
{
"status": "ok",
"action": "build",
"summary": "build 成功,errors=0 warnings=2",
"details": { "project": "...", "preset": "Debug", "build_dir": "...", "elf_file": "...", "log_file": "..." },
"metrics": { "errors": 0, "warnings": 2, "flash_bytes": 99328, "ram_bytes": 46080 }
}错误示例:
json
{
"status": "error",
"action": "build",
"error": { "code": "not_configured", "message": "构建目录不存在,请先执行 configure" }
}All scripts return in JSON format, with basic fields (ok/error), , , , and may include , , , , , .
statusactionsummarydetailscontextartifactsmetricsstatenext_actionstimingSuccess Example:
json
{
"status": "ok",
"action": "build",
"summary": "build succeeded, errors=0 warnings=2",
"details": { "project": "...", "preset": "Debug", "build_dir": "...", "elf_file": "...", "log_file": "..." },
"metrics": { "errors": 0, "warnings": 2, "flash_bytes": 99328, "ram_bytes": 46080 }
}Error Example:
json
{
"status": "error",
"action": "build",
"error": { "code": "not_configured", "message": "Build directory does not exist, please execute configure first" }
}核心规则
Core Rules
- 不修改 CMakeLists.txt 或任何 CMake 配置文件
- 当前 skill 仅覆盖 CMake 型 GCC 工程,不对纯 Makefile 工程做识别和构建
- 不自动猜测工程路径或 preset,有歧义时必须询问用户
- 参数解析优先级为:CLI 显式参数 > 环境级配置 > 工程级配置 > > 搜索/询问
.embeddedskills/state.json - 不在自动流程中隐式执行
clean - 构建失败时优先展示首个错误和日志文件路径
- 结果回显中始终包含工程名、preset 名、构建目录路径;构建成功时优先回显
elf_file
- Do not modify CMakeLists.txt or any CMake configuration files
- This skill only covers CMake-based GCC projects, does not identify or build pure Makefile projects
- Never automatically guess project path or preset, must ask users when there is ambiguity
- Parameter parsing priority: Explicit CLI parameters > Environment-level configuration > Project-level configuration > > Search/query
.embeddedskills/state.json - is not implicitly executed in automatic workflows
clean - When build fails, prioritize displaying the first error and log file path
- Always include project name, preset name, build directory path in result echo; prioritize echoing when build succeeds
elf_file