visionA/local-tool/scripts/bootstrap-linux.sh
jim800121chen fbd585ab73 fix(local-tool): Linux build 支援 webkit2gtk-4.1(Ubuntu 22.10+ / Debian 12+)
使用者在 Linux build 看到:
  pkg-config --cflags ... webkit2gtk-4.0
  Package 'webkit2gtk-4.0' not found

根因:Wails v2.11 預設 cgo pkg-config 指定 webkit2gtk-4.0,但 Ubuntu
22.10 之後的版本已經把系統 package 從 webkit2gtk-4.0 改名為 4.1
(API 大致相容)。使用者 bootstrap 裝的是 libwebkit2gtk-4.1-dev,
pkg-config 找不到 4.0.pc 就 fail。

修法:

1. Makefile wails-linux target 自動偵測 webkit2gtk 版本
   - 優先 pkg-config --exists webkit2gtk-4.1 → wails build -tags webkit2_41
     (Wails v2.10+ 支援的 build tag,切換到 4.1 的 cgo 宣告)
   - 退回 pkg-config --exists webkit2gtk-4.0 → wails build 預設
   - 兩者都沒有 → 清楚錯誤訊息 + 建議安裝指令

2. scripts/bootstrap-linux.sh 裝 webkit2gtk dev package 時也做版本偵測
   - apt-cache show 優先查 4.1,退回 4.0
   - Ubuntu 22.04 及之前 repo 有 4.0;22.10+ / 24.04 repo 只有 4.1
   - 兩個都試過才 err

驗證:
- make -n wails-linux dry-run 正常 parse
- bash -n scripts/bootstrap-linux.sh 語法 OK
- macOS 端 make dmg 仍 work(未改 darwin target)

使用者待做:Linux 端 git pull 拉新版 → 重跑 bootstrap-linux.sh
(確保 webkit2gtk-4.1-dev 安裝)→ make appimage。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 04:11:53 +08:00

83 lines
3.0 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
# visionA-local — Ubuntu 22.04/24.04 x86_64 一鍵 build
#
# 使用方式:
# git clone https://github.com/jim800121/visionA.git
# cd visionA/local-tool
# bash scripts/bootstrap-linux.sh
#
# 環境變數:
# VISIONA_TARGET 預設 appimage可設 wails-linux / payload-linux
set -euo pipefail
TARGET="${VISIONA_TARGET:-appimage}"
GO_VERSION="1.22.5"
log() { printf '\033[1;36m==> %s\033[0m\n' "$*"; }
err() { printf '\033[1;31m!!! %s\033[0m\n' "$*" >&2; exit 1; }
[[ "$(uname -s)" == "Linux" ]] || err "此腳本只支援 Linux"
[[ "$(uname -m)" == "x86_64" ]] || err "此腳本只支援 x86_64"
[[ -f Makefile && -d visiona-local ]] || err "請先 cd 到 local-tool/ 目錄再執行此腳本"
log "[1/5] 安裝系統套件(需要 sudo"
sudo apt update
sudo apt install -y \
git curl ca-certificates build-essential pkg-config \
libgtk-3-dev \
python3 python3-pip python3-venv \
file desktop-file-utils fuse libfuse2
# webkit2gtk優先 4.1Ubuntu 22.10+ / Debian 12+),退回 4.0Ubuntu 20.04 / 22.04)。
# Makefile wails-linux target 會偵測已安裝的版本並自動加 -tags webkit2_41。
if apt-cache show libwebkit2gtk-4.1-dev >/dev/null 2>&1; then
log " → 偵測到 libwebkit2gtk-4.1-dev 可用,安裝中"
sudo apt install -y libwebkit2gtk-4.1-dev
elif apt-cache show libwebkit2gtk-4.0-dev >/dev/null 2>&1; then
log " → 偵測到 libwebkit2gtk-4.0-dev 可用,安裝中"
sudo apt install -y libwebkit2gtk-4.0-dev
else
err "找不到 libwebkit2gtk-4.1-dev 或 libwebkit2gtk-4.0-dev。請手動安裝對應的 webkit2gtk dev packageUbuntu: sudo apt install libwebkit2gtk-4.1-dev"
fi
log "[2/5] 安裝 Go $GO_VERSION"
if ! command -v go >/dev/null || [[ "$(go version 2>/dev/null)" != *"go$GO_VERSION"* ]]; then
curl -fsSL "https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz" -o /tmp/go.tar.gz
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf /tmp/go.tar.gz
rm /tmp/go.tar.gz
fi
export PATH="/usr/local/go/bin:$HOME/go/bin:$PATH"
if ! grep -q '/usr/local/go/bin' "$HOME/.bashrc" 2>/dev/null; then
echo 'export PATH=/usr/local/go/bin:$HOME/go/bin:$PATH' >> "$HOME/.bashrc"
fi
log "[3/5] 安裝 Node 20 + pnpm"
if ! command -v node >/dev/null || [[ "$(node -v)" != v20.* ]]; then
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs
fi
command -v pnpm >/dev/null || sudo npm i -g pnpm
log "[4/5] 安裝 Wails CLI"
if ! command -v wails >/dev/null; then
go install github.com/wailsapp/wails/v2/cmd/wails@latest
fi
wails doctor || log "wails doctor 有警告,繼續"
log "[5/5] 開始 buildtarget=$TARGET"
log "ffmpeg 使用 LGPL v3 buildv2 TDD §4BtbN n7.1 LGPL"
make vendor-python-linux vendor-wheels-linux vendor-ffmpeg-linux
make payload-linux
case "$TARGET" in
payload-linux) ;;
wails-linux) make wails-linux ;;
appimage|*) make wails-linux && make appimage ;;
esac
log "完成 ✅"
log "產出位置:$(pwd)/dist/"
ls -lh dist/ 2>/dev/null || true