Skip to content

fix(packaging): statically link the MSVC runtime on Windows - #112

Merged
bitdan merged 1 commit into
masterfrom
fix/windows-static-crt
Nov 26, 2026
Merged

bitdan merged 1 commit into
masterfrom
fix/windows-static-crt

Conversation

@bitdan

@bitdan bitdan commented Nov 26, 2026

Copy link
Copy Markdown
Owner

问题

snap-desk.exe 动态链接 MSVC C 运行库,会导入 VCRUNTIME140.dll。没装 Visual C++ 运行库的 Windows(干净系统、Windows 沙盒、WinGet 验证机)上,主程序一启动就报找不到 DLL:

  • WinGet 提交 bitdan.SnapDesk version 0.3.2 microsoft/winget-pkgs#488147 被标为 Validation-Executable-Error:验证机装完后无法运行主程序。
  • 普通用户通过 irm、Scoop、安装包或独立 EXE 安装后同样打不开。开发机一般都装了运行库,所以平时发现不了。

本机安装的 0.3.2 实测导入表里有 vcruntime140.dll;翻译 worker 已经是静态链接的,没有这个依赖。

改动

  • .cargo/config.toml:MSVC 目标加 -C target-feature=+crt-static。cc 编译的 C 依赖(内置 SQLite)会随之改用 /MT;Windows 上 onnxruntime 是运行时加载(load-dynamic),不参与链接。
  • scripts/package-gpui.mjs:Windows 构建后读取主程序的 PE 导入表,仍依赖 vcruntime* / msvcp* 时停止打包,防止以后被改回动态链接(比如有人设置了 RUSTFLAGS,会覆盖配置里的 rustflags)。
  • scripts/package-gpui.test.mjs:导入表解析测试(手工构造的最小 PE + Windows 上的真实 node.exe)。

评审注意

  • 修改 rustflags 后 Rust 缓存会失效,第一次 CI 构建会变慢。
  • CI 在仓库目录执行 cargo install cargo-packager,也会读到这份配置;它在 Windows 上没有预编译的原生库,静态链接没有影响。
  • 下载的 onnxruntime.dll(本地 OCR)仍依赖 VC++ 运行库,加载失败时会提示用户安装,不在本 PR 范围内。
  • 0.3.2 的 WinGet PR 无法改动安装包,下个正式版由 distribute 工作流重新提交。

验证

  • npm test 38 项通过;用导入表检查扫描本机 0.3.2 主程序能识别出 vcruntime140.dll,扫描翻译 worker 结果为空。
  • 静态链接后的实际构建由本 PR 的 CI(windows-2022 cargo test)和 Windows 测试包构建(打包时执行导入表检查)验证。

🤖 Generated with Claude Code

snap-desk.exe imported VCRUNTIME140.dll, so it failed to start on
Windows without the Visual C++ redistributable (clean installs, Windows
Sandbox, the WinGet validation VM). This is why the WinGet submission
was labelled Validation-Executable-Error.

Link the C runtime statically for MSVC targets via .cargo/config.toml,
and have the packaging script read the PE import table of the built
executable and stop if it still depends on vcruntime/msvcp DLLs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bitdan
bitdan merged commit a2d6425 into master Nov 26, 2026
6 checks passed
@bitdan
bitdan deleted the fix/windows-static-crt branch November 26, 2026 12:57
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