Skip to content

fix: 修复 macOS release 二进制因 brew onnxruntime 依赖链无法在其他 Mac 运行 - #7

Merged
LiusCraft merged 1 commit into
mainfrom
fix/macos-release-dylib-bundle
May 5, 2026
Merged

fix: 修复 macOS release 二进制因 brew onnxruntime 依赖链无法在其他 Mac 运行#7
LiusCraft merged 1 commit into
mainfrom
fix/macos-release-dylib-bundle

Conversation

@LiusCraft

Copy link
Copy Markdown
Owner

Background

  • CI release workflow 使用 brew install onnxruntime 安装 onnxruntime,但 brew 版本的 libonnxruntime.dylib 不是自包含的,它依赖了 50+ 个 brew 安装的其他库(protobuf、abseil、onnx 等),路径全部硬编码为 /opt/homebrew/opt/...
  • 编译出的二进制文件将这些 brew 路径写入了 LC_LOAD_DYLIB,用户下载后在其他 Mac 上运行时,dyld 找不到这些 brew 库就会崩溃(KILL

Changes

  • macOS 构建:改用 Microsoft 官方自包含 onnxruntime-osx-arm64-1.21.0.tgz 替代 brew install onnxruntime,dylib 仅依赖系统框架
  • dylib/so 捆绑分发:将 libonnxruntime.dylib/.so 与二进制一起上传到 Release
    • macOS:通过 install_name_tool -id @loader_path/ 实现同目录查找
    • Linux:通过 -Wl,-rpath,\$ORIGIN 实现同样效果
  • ad-hoc 签名:构建后对 macOS 二进制和 dylib 执行 codesign --force --sign -,避免 Gatekeeper 阻止
  • 验证步骤:新增 Fixup macOS binary 步骤,用 otool -L 检查库引用路径

Behavior Impact

  • 用户下载 Release 文件后,只需将 libonnxruntime.dylib/.so 与二进制放在同一目录即可运行,无需安装 brew 或其他依赖
  • CI 测试流程(ci.yml)不变,仍使用 brew

Risks and Rollback

  • onnxruntime 版本固定为 1.21.0(与 Linux 一致),需手动升级
  • 可通过 git revert 回滚此 commit

Verification

  • 本地下载官方 onnxruntime 包 → 编译 → 复制到独立空目录模拟用户下载场景 → 正常启动并通过 VAD 检测请求
  • otool -L 确认二进制引用 @loader_path/libonnxruntime.dylib

Notes

  • 需要 tag 触发后才能在 CI 中验证 Release 效果

改用 Microsoft 官方自包含 onnxruntime 发布包替代 brew 安装,
将 libonnxruntime.dylib/.so 与二进制捆绑分发,通过
@loader_path / $ORIGIN 实现可移植的动态库加载。
同时添加 ad-hoc 签名避免 macOS Gatekeeper 阻止运行。
@LiusCraft
LiusCraft merged commit ff15eb0 into main May 5, 2026
2 checks passed
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