Skip to content

feat(build): expose Cargo build artifact output#139

Merged
ZR233 merged 1 commit into
mainfrom
codex/export-cargo-build-artifact
Jun 18, 2026
Merged

feat(build): expose Cargo build artifact output#139
ZR233 merged 1 commit into
mainfrom
codex/export-cargo-build-artifact

Conversation

@ZR233

@ZR233 ZR233 commented Jun 18, 2026

Copy link
Copy Markdown
Member

问题

下游调用 ostool::build::cargo_build 后只能知道构建成功,无法直接拿到 Cargo JSON 输出中解析出的可执行产物路径。需要使用该路径的调用方只能自行按 target/<target>/<profile>/<bin> 规则拼接,容易和 Cargo 实际选择的 bin、profile、target-dir 或后续构建逻辑产生偏差。

修改

  • 新增 public 类型 ostool::build::CargoBuildOutput,暴露:
    • elf_path():Cargo 解析出的可执行 ELF 路径。
    • cargo_artifact_dir():该可执行产物所在目录。
  • 新增 ostool::build::cargo_build_with_output(...) -> anyhow::Result<CargoBuildOutput>,复用现有 Cargo build pipeline,在完成 runtime artifact 状态更新和 post-build commands 后返回构建产物信息。
  • 保留原有 cargo_build(...) -> anyhow::Result<()>,改为调用新函数后丢弃返回值,避免破坏现有调用方。
  • 更新 public API 编译测试,确认新类型和新函数可被外部使用。

设计说明

该接口不改变现有 cargo_build 的返回类型,降低兼容性影响;同时输出值从内部 CargoBuildOutcome / ResolvedCargoArtifact 转换而来,保证下游拿到的路径和 ostool 当前选择、记录的 Cargo artifact 保持一致。

验证

  • cargo fmt
  • cargo test

@ZR233 ZR233 force-pushed the codex/export-cargo-build-artifact branch from 328c87d to 272e9da Compare June 18, 2026 06:11
@ZR233 ZR233 force-pushed the codex/export-cargo-build-artifact branch from 272e9da to 2422bcc Compare June 18, 2026 06:15
@ZR233 ZR233 merged commit 03c1b68 into main Jun 18, 2026
2 checks passed
@ZR233 ZR233 deleted the codex/export-cargo-build-artifact branch June 18, 2026 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant