diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 05f2b72..b12c566 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -83,9 +83,48 @@ jobs: set -euo pipefail # +crt-static 是否真的生效,只看导入表:出现 VCRUNTIME/MSVCP/msvcr/ucrtbase 说明还得装 # 可再发行包,那就不是"单文件"了,直接 fail。 - DUMPBIN=$(command -v dumpbin || true) + # + # dumpbin 定位链(三级,全不命中才 fail —— 门禁不降级,只是把"猜路径"换成官方定位): + # ① vswhere:VS 官方定位器,安装器自身路径固定,与 VS 版本/版次/安装布局无关; + # ② find 兜底:Program Files 与 Program Files (x86) 两个 VS 根都扫(Build Tools 落在 x86 根); + # ③ PATH:镜像若已把工具链预置进 PATH 则直接可用。 + # PATH 排最后是刻意的:PATH 最不可控,官方定位器优先。 + VSWHERE="C:/Program Files (x86)/Microsoft Visual Studio/Installer/vswhere.exe" + DUMPBIN="" + VIA="" + if [ -x "$VSWHERE" ]; then + # -find 的模式优先用反斜杠(vswhere 官方文档即此形式),再试正斜杠以规避分隔符差异。 + for pattern in 'VC\Tools\MSVC\*\bin\Hostx64\x64\dumpbin.exe' \ + 'VC/Tools/MSVC/*/bin/Hostx64/x64/dumpbin.exe'; do + hit=$("$VSWHERE" -latest -products '*' -find "$pattern" 2>/dev/null | head -n1 || true) + if [ -n "$hit" ]; then + DUMPBIN=${hit//\\//} + VIA="vswhere" + break + fi + done + fi if [ -z "$DUMPBIN" ]; then - DUMPBIN=$(ls -d "C:/Program Files/Microsoft Visual Studio/"*/VC/Tools/MSVC/*/bin/Hostx64/x64/dumpbin.exe 2>/dev/null | head -n1 || true) + # 镜像里的 VS 根形如 <年>/<版次>(2022/Enterprise、2022/BuildTools……), + # 固定层数的 glob 会在 <年>/<版次> 这两级踩空,所以按路径模式扫。 + for root in "C:/Program Files/Microsoft Visual Studio" \ + "C:/Program Files (x86)/Microsoft Visual Studio"; do + [ -d "$root" ] || continue + hit=$(find "$root" -maxdepth 11 -type f \ + -path '*/VC/Tools/MSVC/*/bin/Hostx64/x64/dumpbin.exe' 2>/dev/null | head -n1 || true) + if [ -n "$hit" ]; then + DUMPBIN=$hit + VIA="find: $root" + break + fi + done + fi + if [ -z "$DUMPBIN" ]; then + hit=$(command -v dumpbin || true) + if [ -n "$hit" ]; then + DUMPBIN=$hit + VIA="PATH" + fi fi # 工具缺失同样 fail:windows-latest 自带 VS 工具链,基本找得到; # "找不到就跳过"等于让这道门禁在最需要它的时候静默失效。 @@ -93,6 +132,7 @@ jobs: echo "::error::找不到 dumpbin,无法校验导入表(静态 CRT 门禁不降级)" exit 1 fi + echo "dumpbin: $DUMPBIN(定位自 $VIA)" "$DUMPBIN" -nologo -dependents target/release/unlucky-launcher.exe | tee dependents.txt if grep -Eiq 'VCRUNTIME|MSVCP|MSVCR|ucrtbase\.dll' dependents.txt; then echo "::error::静态 CRT 未生效:exe 仍动态依赖 VC++ 可再发行包"