build-iar

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

构建 IAR Embedded Workbench 工程

Building IAR Embedded Workbench Projects

适用场景

Applicable Scenarios

  • Project Profile
    中标明
    build_system: iar
    或工作区中存在
    .ewp
    /
    .eww
    文件。
  • 用户希望对 IAR EWARM 工程执行编译、重编译或确认固件产物。
  • 烧录或调试流程需要新的
    .out
    (ELF)、
    HEX
    BIN
  • 需要在编译前确认 IAR 环境是否就绪(iarbuild.exe、工具链)。
  • Project Profile
    indicates
    build_system: iar
    or there are
    .ewp
    /
    .eww
    files in the workspace.
  • Users want to compile, recompile, or confirm firmware artifacts for IAR EWARM projects.
  • New
    .out
    (ELF),
    HEX
    , or
    BIN
    files are required for programming or debugging processes.
  • Need to confirm if the IAR environment is ready (iarbuild.exe, toolchain) before compilation.

必要输入

Required Inputs

  • 工作区路径或
    .ewp
    工程文件路径,或一份已有的
    Project Profile
  • 可选的配置名称(configuration)和 IAR 安装路径。
  • Workspace path or
    .ewp
    project file path, or an existing
    Project Profile
    .
  • Optional configuration name and IAR installation path.

自动探测

Auto Detection

  • 脚本自动搜索常见 IAR 安装路径和环境变量(
    IAR_ROOT
    EWARM_ROOT
    )定位 iarbuild.exe。
  • 解析
    .ewp
    工程文件中的 configuration 列表,提取工具链(ARM/RISCV)、芯片型号、输出目录和输出文件名。
  • 若未指定配置,默认使用工程中的第一个 configuration。
  • 在输出目录中搜索 .out(ELF)、HEX、BIN 产物,按
    ELF > HEX > BIN
    排序。
  • 若存在多个同样合理的工程文件或配置,列出候选而不是静默猜测。
  • The script automatically searches common IAR installation paths and environment variables (
    IAR_ROOT
    ,
    EWARM_ROOT
    ) to locate iarbuild.exe.
  • Parses the configuration list in the
    .ewp
    project file to extract toolchain (ARM/RISCV), chip model, output directory, and output file name.
  • If no configuration is specified, the first configuration in the project is used by default.
  • Searches for .out (ELF), HEX, BIN artifacts in the output directory, sorted by
    ELF > HEX > BIN
    .
  • If multiple equally valid project files or configurations exist, lists candidates instead of making silent guesses.

执行步骤

Execution Steps

  1. 先阅读 references/usage.md,确认本次是环境探测、工程扫描、列出配置,还是执行编译。
  2. 若不确定环境是否就绪,先运行自带脚本 scripts/iar_builder.py
    --detect
    模式确认。
  3. 若不确定工程文件位置,使用
    --scan
    搜索工作区。
  4. 使用
    --list-configs --project X.ewp
    确认可用配置,再用
    --project
    +
    --config
    执行编译。
  5. 读取脚本输出的构建结果和产物扫描报告,重点关注首选产物(.out/ELF > HEX > BIN)、错误/警告统计和失败分类。
  6. 将构建配置、产物路径、芯片型号和工具链信息写回
    Project Profile
    ,并在需要时交给下游 skill。
  1. First read references/usage.md to confirm whether this is environment detection, project scanning, listing configurations, or executing compilation.
  2. If unsure whether the environment is ready, first run the
    --detect
    mode of the built-in script scripts/iar_builder.py to confirm.
  3. If unsure of the project file location, use
    --scan
    to search the workspace.
  4. Use
    --list-configs --project X.ewp
    to confirm available configurations, then use
    --project
    +
    --config
    to execute compilation.
  5. Read the build results and artifact scan report output by the script, focusing on the preferred artifacts (.out/ELF > HEX > BIN), error/warning statistics, and failure categories.
  6. Write the build configuration, artifact path, chip model, and toolchain information back to
    Project Profile
    , and pass it to downstream skills when needed.

失败分流

Failure Diversion

  • 当 IAR 未安装或 iarbuild.exe 不可用时,返回
    environment-missing
  • 当工程文件损坏、配置名无效或编译因配置问题失败时,返回
    project-config-error
  • 当编译看似成功但未找到可烧录或可调试产物时,返回
    artifact-missing
  • 当存在多个同样合理的工程文件或配置,且任意选择都不安全时,返回
    ambiguous-context
  • Returns
    environment-missing
    when IAR is not installed or iarbuild.exe is unavailable.
  • Returns
    project-config-error
    when the project file is corrupted, the configuration name is invalid, or compilation fails due to configuration issues.
  • Returns
    artifact-missing
    when compilation appears successful but no programmable or debuggable artifacts are found.
  • Returns
    ambiguous-context
    when multiple equally valid project files or configurations exist and any selection is unsafe.

平台说明

Platform Notes

  • IAR Embedded Workbench 仅在 Windows 上原生运行,iarbuild.exe 命令行编译需要 Windows 环境。
  • 自带脚本在非 Windows 平台上仍可执行工程解析(
    --list-configs
    )、工程扫描(
    --scan
    )和产物扫描(
    --scan-artifacts
    ),但实际编译会被阻塞。
  • 输出中的产物路径应保持为绝对路径,方便下游烧录和调试 skill 直接复用。
  • IAR Embedded Workbench runs natively only on Windows, and iarbuild.exe command-line compilation requires a Windows environment.
  • The built-in script can still perform project parsing (
    --list-configs
    ), project scanning (
    --scan
    ), and artifact scanning (
    --scan-artifacts
    ) on non-Windows platforms, but actual compilation will be blocked.
  • Artifact paths in the output should remain absolute paths for direct reuse by downstream programming and debugging skills.

输出约定

Output Conventions

  • 输出编译命令、工程文件、配置名、芯片型号、工具链和首选产物路径。
  • 输出错误和警告统计,以及关键编译日志证据。
  • artifact_path
    artifact_kind
    target_mcu
    toolchain
    更新
    Project Profile
  • 成功后推荐
    flash-openocd
    debug-gdb-openocd
  • Output compilation commands, project files, configuration names, chip models, toolchains, and preferred artifact paths.
  • Output error and warning statistics, as well as key compilation log evidence.
  • Update
    Project Profile
    with
    artifact_path
    ,
    artifact_kind
    ,
    target_mcu
    , and
    toolchain
    .
  • Recommend
    flash-openocd
    or
    debug-gdb-openocd
    after success.

交接关系

Handover Relationships

  • 当下一步意图是给硬件烧录程序时,将成功构建结果交给
    flash-openocd
  • 当下一步需要符号信息或调试会话时,将成功构建结果交给
    debug-gdb-openocd
  • When the next step is to program hardware, pass the successful build result to
    flash-openocd
    .
  • When the next step requires symbol information or a debugging session, pass the successful build result to
    debug-gdb-openocd
    .