Files
arcrun-collector/cmd/arcrun-tray/build-windows.sh
T
Leo 26dd6960c2 feat(t72): Windows 交叉編譯腳本——Mac 上就編得出 Windows 托盤(推翻「要真機」假設)
任務板一直寫「fyne GUI 沙箱編不了 CGo+GL → 歸屬真機」,本機實測推翻一半:
裝 mingw-w64 後 Mac 直接交叉編譯成功,不需 Windows 機器/Docker/fyne-cross。

  CGO_ENABLED=1 GOOS=windows CC=x86_64-w64-mingw32-gcc \
    go build -ldflags "-H windowsgui -s -w"
  → PE32+ executable (GUI) x86-64, for MS Windows

正確說法是「編得出來、但驗不了」——編譯是 Mac 的事,跑起來對不對才是真機的事。

另兩條路實測皆失敗(訊息留在文件):
- CGO_ENABLED=0 → go-gl/gl 無 non-cgo 實作
- CGO_ENABLED=1 無交叉編譯器 → 退回 host clang 報 -mthreads 不支援

體積(解掉 t72 的 zip 疑慮):tray 加 -s -w 40.8MB→23.5MB、collector 6.5MB,
zip 合計 13.9MB=在 jsDelivr 20MB 上限內,Windows 版不會踩到 Mac 版那個坑。

腳本已實跑通過。 未驗=托盤 icon/選資料夾對話框/SmartScreen 實際行為(要真 Windows)。
詳 system-dev/docs/3-specs/rag-wave1/windows-build-and-os-split.md

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-27 18:34:59 +08:00

57 lines
2.6 KiB
Bash
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-windows.sh — 打包 Arcrun RAG 托盤(Windows 未簽章版,daemon-beta t72)。
#
# 🎯 這支腳本的重點:**在 Mac 上就能交叉編譯出 Windows 版**,不需要 Windows 機器、
# 不需要 Docker、不需要 fyne-cross。條件只有一個——裝 mingw-w64。
# (這推翻了先前「fyne GUI 編不了 CGo+GL → 歸屬真機」的假設;2026-07-27 本機實測通過。)
#
# 前置(一次就好):
# brew install mingw-w64 # 提供 x86_64-w64-mingw32-gcc
#
# 用法:
# cd collector/cmd/arcrun-tray && bash build-windows.sh
# 產物:dist-windows/ArcrunRAG-win-unsigned.zip(含 arcrun-tray.exe arcrun-collector.exe
#
# ⚠️ 誠實界定:**本腳本只證明「編得出來」,沒證明「跑起來對」**。
# 托盤 icon 會不會出現、選資料夾對話框、SmartScreen 實際攔截行為,
# **只有真的在 Windows 上跑才驗得到**——那一步歸 leo/真機。
set -euo pipefail
cd "$(dirname "$0")"
OUT="dist-windows"
CC_WIN="${CC_WIN:-x86_64-w64-mingw32-gcc}"
echo "① 檢查交叉編譯器"
if ! command -v "$CC_WIN" >/dev/null 2>&1; then
echo "❌ 找不到 $CC_WIN。先跑:brew install mingw-w64" >&2
exit 1
fi
echo " $($CC_WIN --version | head -1)"
rm -rf "$OUT" && mkdir -p "$OUT"
echo "② 編 collector.exe(純 stdlibCGO_ENABLED=0 即可)"
( cd ../.. && CGO_ENABLED=0 GOOS=windows GOARCH=amd64 \
go build -ldflags "-s -w" -o "cmd/arcrun-tray/$OUT/arcrun-collector.exe" . )
echo "③ 編托盤 GUIfyneCGo+GL,走 mingw-H windowsgui=不彈黑色命令列視窗)"
CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC="$CC_WIN" \
go build -ldflags "-H windowsgui -s -w" -o "$OUT/arcrun-tray.exe" .
echo "④ 打包 zip"
( cd "$OUT" && zip -9 -q ArcrunRAG-win-unsigned.zip arcrun-tray.exe arcrun-collector.exe )
echo
echo "✅ 完成:$OUT/ArcrunRAG-win-unsigned.zip"
ls -lh "$OUT"/*.exe "$OUT"/*.zip | awk '{print " "$9" "$5}'
echo
echo "📏 2026-07-27 本機實測基準(差太多就是哪裡不對):"
echo " arcrun-tray.exe ~23.5 MB(未加 -s -w 是 ~40.8 MB"
echo " arcrun-collector.exe ~6.5 MB"
echo " zip 合計 ~13.9 MB ← **在 jsDelivr 20MB 上限內**Mac 版 21MB 超標故走 GitHub raw"
echo
echo "🔬 驗法(這台機器上驗得到的部分):"
echo " file $OUT/arcrun-tray.exe → 應為 'PE32+ executable (GUI) x86-64, for MS Windows'"
echo " file $OUT/arcrun-collector.exe → 應為 'PE32+ executable (console) x86-64'"
echo "⛔ 驗不到、必須真 Windows 機器的部分:托盤 icon 顯示/選資料夾對話框/SmartScreen 實際行為。"