Files
arcrun-collector/cmd/arcrun-app/build-win.sh
T
Leo a55488040d Windows 交付改單一 exe+版本號不再手打(leo 08-06 回報②與「整串該機械化」)
## ② 兩個檔很迷惑 → 一個檔
leo 圖一標註:「下載還是 ZIP ⇒ 應該是 MSIX 或 EXE;解開還是 2 個檔 ⇒ 應該只有 1 個檔案」。
舊做法 zip 裡放 Arcrun.exe+arcrun-collector.exe 同層,少解一個檔就永遠不會同步,
而畫面不會說是這個原因。
修:collector 用 go:embed 收進 Arcrun.exe,第一次執行攤到 ~/.arcrun-rag/bin/
    (冪等:sha256 相同不重寫;先寫暫存再 rename,避免留半截執行檔)。
    build-win.sh 直接產單一 Arcrun-win-<ver>.exe,不再打 zip。
    加機械閘:產出的 exe 若比 collector 還小 ⇒ 沒 embed 成功 ⇒ 中止(過去只會
    默默得到一顆「裝了也不會同步」的空殼)。
不走 MSIX:未上架的 MSIX 要使用者先開「開發人員模式」,比 zip 更麻煩。

## 版本號機械化(leo:「這一整串都應該是機械化,不應該每次手工做」)
病根實測:本 repo **一個 git tag 都沒有**,而四支 build 腳本寫的是
`git describe --tags` ⇒ 永遠拿不到 v0.18.x ⇒ 只能靠打包時人工敲 VERSION=
⇒ 兩條打包線各敲各的 ⇒ manifest 宣告 0.18.5、產物其實是 0.18.4。

修:新增 daemon-version.sh 當唯一產生器,沿用 release.mjs 已在跑的原則
   (「版本號由內容算出來,不是由人宣告」),不另立新制:
     MINOR ← DAEMON_LINE(人決定,大改版才動)
     PATCH ← 動過 collector/ 的 commit 數 − DAEMON_PATCH_BASE(機器決定)
   ⇒ 沒改 daemon 重跑打包不會虛增;改了才 +1;四支腳本在同一 commit 必得同號。
   ⇒ 不需要 git tag/Actions/輪詢(守 D20 紅線)。
   校準:DAEMON_LINE=0.18、BASE=87 ⇒ 現在的樹算出 v0.18.7(上次出貨過 0.18.6)。
   build-win/mac/dmg/msix 四支全部改用它。

## icon 漂移根治接上打包
build-win.sh 步驟⓪ 每次都跑 gen-icons.py 重產 icon.ico/trayicon.ico。

## 驗(實測輸出,非推測)
· ./build-win.sh 全程跑通,產出 dist/Arcrun-win-v0.18.7.exe(27,445,248 bytes)
· strings 抽內嵌版本 = v0.18.7、buildTime = 20260806-1233(機器算的,沒人敲)
· 位元組比對該 exe:
    CIS trayicon 在裡面        = True
    Wails「W」圖還在           = False
    collector 有 embed 進去    = True(16,104,960 bytes)
· go vet 全綠(darwin + windows);mac build OK
· 未驗:Windows 真機行為(需封測者實跑)⇒ 狀態 ◐,不是 
· 未做:CHANGELOG 閘、manifest「宣告版本 == 產物版本」驗證閘、前端顯示版本與下載入口
2026-08-06 12:35:54 +08:00

104 lines
5.6 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# build-win.sh — 打包 Arcrun Windows 版(Wailst1962026-08-05
#
# leo 08-05:「Windows 版一定要重編,因為我只有 Mac,我需要人家測試,
# 要做到最完善不要給人家找麻煩」
#
# 🎯 **在 Mac 上就能交叉編譯**,不需要 Windows 機器/Docker。
# 條件只有一個:`brew install mingw-w64`(提供 x86_64-w64-mingw32-gcc)。
# Wails 的 Windows 版要 CGoWebView2 綁定),所以 CGO_ENABLED=1 + mingw。
#
# 與 build-mac.sh 同一個要點:**必須把 collector 同綑進去**。
# daemon 的本體是 `collector direct`(監看/萃卡/上傳),App 只是門面;
# 沒同綑 ⇒ 使用者裝了也不會同步(t194 在 Mac 版就漏過一次)。
#
# ⚠️ 誠實界定(沿用 build-windows.sh 的自陳):
# 本腳本只證明「**編得出來**」,不證明「**跑起來對**」。
# 托盤圖示會不會出現、WebView2 有沒有裝、SmartScreen 攔截行為,
# **只有真的在 Windows 上跑才驗得到**——那一步歸 leo/封測者真機。
set -euo pipefail
cd "$(dirname "$0")"
export PATH="$PATH:$(go env GOPATH)/bin"
# 🔴 2026-08-06:版本號**不再手打、也不再靠 git describe**。
# 舊寫法 `git describe --tags` 在這個 repo 永遠拿不到 v0.18.x(一個 tag 都沒有)
# ⇒ 版本只能靠打包時人工 `VERSION=v0.18.4 ./build-win.sh` 敲 ⇒ manifest 說謊的病根。
# 現在由 daemon-version.sh 從 DAEMON_LINE + collector/ 的 commit 數算出來,
# 兩條打包線(win/mac)在同一個 commit 上必得同一個號碼。理由全文見該腳本。
VERSION="${VERSION:-$(./daemon-version.sh)}"
BUILD_TIME="$(date '+%Y%m%d-%H%M')"
echo "🏷 版本:${VERSION}build ${BUILD_TIME}"
command -v x86_64-w64-mingw32-gcc >/dev/null 2>&1 || {
echo "❌ 缺 mingw-w64Wails Windows 版需要 CGo 交叉編譯器)"
echo " 裝一次就好:brew install mingw-w64"
exit 1
}
echo "⓪ 由 appicon.png 產生 Windows 圖示(icon.icotrayicon.ico"
# 🔴 2026-08-06:不產就會沿用上一次留在磁碟上的檔——而上一次那顆是 `wails init`
# 留下的 Wails 預設「W」圖,leo 封測看到視窗與托盤兩處都是 W。
# 每次 build 都重產 ⇒ 「換了 appicon 卻沒換 Windows」這種漂移不可能再發生。
python3 gen-icons.py
echo "① 編 collector.exe(會被 embed 進 Arcrun.exe,純 stdlib、CGO_ENABLED=0"
# 🔴 2026-08-06:同 build-mac.sh 補回版本注入(Wails 換代時掉的,理由見該檔註解)。
# 2b83c47 當年就修過一次「Mac 有、Windows 漏了」——換代後兩邊又一起掉,這次一起補。
( cd ../.. && GOOS=windows GOARCH=amd64 CGO_ENABLED=0 \
go build -ldflags "-s -w -X main.version=${VERSION} -X main.buildTime=${BUILD_TIME}" \
-o "cmd/arcrun-app/arcrun-collector.exe" . )
# 🔴 同 build-mac.shwails.json 沒 info.productVersion ⇒ exe 內容資訊永遠是 1.0.0。
# Windows 使用者在「內容→詳細資料」看到的版本讀這個欄位;MSIX 送審也會對照。
PLIST_VER="${VERSION#v}"
cp wails.json wails.json.bak
python3 - "$PLIST_VER" <<'PY'
import json, sys
c = json.load(open('wails.json'))
c.setdefault('info', {})
c['info']['productVersion'] = sys.argv[1]
c['info']['productName'] = 'Arcrun'
json.dump(c, open('wails.json', 'w'), indent=2, ensure_ascii=False)
PY
trap 'mv -f wails.json.bak wails.json 2>/dev/null || true' EXIT
echo "② wails buildwindows/amd64CGo 走 mingw"
CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc \
wails build -platform windows/amd64 -clean \
-ldflags "-X main.version=${VERSION} -X main.buildTime=${BUILD_TIME}"
OUT="dist"; mkdir -p "$OUT"
echo "③ 產出**單一執行檔**"
# 🔴 2026-08-06 交付形態改變(leo 封測回報②,圖一標註):
# 「下載還是 ZIP ⇒ 應該是 MSIX 或 EXE」「解開還是 2 個檔 ⇒ 應該只有 1 個檔案」
# 「兩個檔案令人很迷惑,User unfriendly」
#
# 舊做法=zip 裡放 Arcrun.exearcrun-collector.exe 同層。使用者只要少解一個檔、
# 或只把 Arcrun.exe 拖出來,同步就永遠不會動,而畫面不會說是這個原因。
# 新做法=collector 在步驟②被 go:embed 收進 Arcrun.exe(見 bundled_collector_windows.go),
# 第一次執行時攤到 ~/.arcrun-rag/bin/。**下載下來就是一個檔,雙擊就跑。**
#
# 為什麼不出 MSIX:未上架的 MSIX 要使用者先開「開發人員模式」才裝得起來,
# 比 zip 更麻煩。上架 MS Store 後再回頭走 build-msix.sh。
EXE="$(cd "$OUT" && pwd)/Arcrun-win-${VERSION}.exe"
rm -f "$EXE"
cp build/bin/arcrun-app.exe "$EXE"
# 🔴 機械閘:embed 進去的 collector 至少要有幾 MB,否則就是「編了個空殼」。
# (步驟①失敗但 wails build 仍成功時,過去只會得到一個不會同步的 exe。)
APP_SIZE=$(stat -f%z "$EXE" 2>/dev/null || stat -c%s "$EXE")
COL_SIZE=$(stat -f%z arcrun-collector.exe 2>/dev/null || stat -c%s arcrun-collector.exe)
if [ "$APP_SIZE" -lt "$COL_SIZE" ]; then
echo "❌ 產出的 exe${APP_SIZE} bytes)比 collector${COL_SIZE} bytes)還小"
echo " ⇒ collector 沒被 embed 進去,這顆裝了也不會同步。中止。"
exit 1
fi
SIZE=$(ls -lh "$EXE" | awk '{print $5}')
echo "✅ 完成:${EXE}${SIZE},內含同步引擎)"
echo
echo "🔬 使用者流程:下載 → 雙擊 Arcrun.exe(不必解壓縮、不必找第二個檔)"
echo " ⚠️ 未簽章 ⇒ SmartScreen 會攔(「更多資訊」→「仍要執行」)。"
echo " 要免除這一步=上 MS Store(見 build-msix.sh)或買 EV 憑證。"