Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Windows 上把 VC 运行库静态链接进 twcore.exe。
#
# **不加这一条,twcore.exe 依赖 VCRUNTIME140.dll**,而这个文件不随 Windows
# 自带:它来自「Visual C++ 可再发行组件包」,一般是别的软件顺手装上的。桌面版
# 的安装程序只放 twcore.exe、不装运行库,于是在一台没装过它的机器上,网关
# 根本起不来 —— CI 和多数真机上都装着它,所以看不出来。UCRT 是 Windows 10
# 起系统自带的,静态链接只是顺带把它也带上。
#
# 写在这里而不是 release.yml 里:本机在 Windows 上编出来的和发出去的是同一种。
# **`RUSTFLAGS` 环境变量会整个盖掉这里**(ci.yml 设了 `-D warnings`,所以 CI
# 的测试仍是动态链接的),发版流水线不设它;release.yml 里有一步查 twcore.exe
# 的导入表,这一条哪天没生效会在那里失败。
[target.'cfg(all(windows, target_env = "msvc"))']
rustflags = ["-C", "target-feature=+crt-static"]
25 changes: 25 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,31 @@ jobs:
}
& $exe --help | Out-Null

# **不要用户另装 VC 运行库。**VC 运行库由 `.cargo/config.toml` 静态链接进来;
# 这里查两个 exe 的导入表,里面不许有 Windows 不自带的那几个 DLL。这台
# runner 上装着运行库,exe 照样跑得起来 —— 上一步看不出这件事,只有导入表看得出。
# 用的是链接它的那套 MSVC 里的 dumpbin,arm64 的 exe 一样读得了
- name: No Visual C++ runtime to install
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
$dumpbin = & $vswhere -latest -products * -find "VC\Tools\MSVC\**\bin\Hostx64\x64\dumpbin.exe" |
Select-Object -First 1
if (-not $dumpbin) { throw "dumpbin.exe not found" }
foreach ($t in @("x86_64-pc-windows-msvc", "aarch64-pc-windows-msvc")) {
$exe = "target\$t\release\twcore.exe"
$deps = & $dumpbin /nologo /dependents $exe |
ForEach-Object { $_.Trim() } |
Where-Object { $_ -match '\.dll$' }
if ($LASTEXITCODE -ne 0 -or -not $deps) { throw "could not read the imports of $exe" }
Write-Host "${exe}: $($deps -join ', ')"
$redist = @($deps | Where-Object { $_ -match '^(vcruntime|msvcp|concrt|vccorlib|vcomp)\d' })
if ($redist.Count -gt 0) {
throw "$exe needs the Visual C++ runtime ($($redist -join ', ')) -- the static CRT in .cargo/config.toml did not apply"
}
}

- name: Package
shell: pwsh
run: |
Expand Down
Loading