#!/bin/bash # Build the Windows release artefacts from current source. # # scripts/build-windows-release.sh [--skip-build] [--arch x64|arm64]... # # For every architecture asked for (both by default) this produces an NSIS # per-user installer plus a portable ZIP in artifacts/, then refreshes # artifacts/SHA256SUMS.txt. Cross-compiled on macOS with cargo-xwin; makensis is # the Homebrew formula of the same name. publish-release.sh maps the installers # onto the "windows" and "windows-arm64" keys of the update manifest. set -euo pipefail cd "$(dirname "$0")/.." export PATH="$HOME/.cargo/bin:$HOME/.rustup/toolchains/stable-aarch64-apple-darwin/bin:/opt/homebrew/opt/llvm/bin:$PATH" export RUSTUP_TOOLCHAIN=stable-aarch64-apple-darwin export RUSTC="$HOME/.rustup/toolchains/stable-aarch64-apple-darwin/bin/rustc" ROOT="$PWD" VERSION=$(python3 -c "import json;print(json.load(open('src-tauri/tauri.conf.json'))['version'])") ARCHES="" SKIP_BUILD=0 usage() { echo "usage: $0 [--skip-build] [--arch x64|arm64]..." >&2 && exit 2; } while [ $# -gt 0 ]; do case "$1" in --skip-build) SKIP_BUILD=1 ;; --arch) shift case "${1:-}" in x64|arm64) ARCHES="$ARCHES $1" ;; *) usage ;; esac ;; *) usage ;; esac shift done [ -n "$ARCHES" ] || ARCHES="x64 arm64" # A build can only verify a signed channel if the release key is compiled in. Derive # it from the signing key when the caller gave us one, and never do this quietly: the # alternative is two installers with the same version number and different trust. if [ -z "${SHIFT_UPDATE_PUBKEY:-}" ] && [ -n "${SHIFT_RELEASE_KEY:-}" ]; then SHIFT_UPDATE_PUBKEY=$(python3 scripts/release-key.py pubkey "${SHIFT_RELEASE_KEY%.ed25519}.pub") export SHIFT_UPDATE_PUBKEY fi if [ -n "${SHIFT_UPDATE_PUBKEY:-}" ]; then echo "== release key baked in: ${SHIFT_UPDATE_PUBKEY:0:12}… ==" else echo "== no release key: this build will report the feed as unsigned ==" fi if [ "$SKIP_BUILD" != "1" ]; then echo "== frontend (Windows target: chrome105) ==" TAURI_ENV_PLATFORM=windows pnpm build fi # One target triple, one expected PE machine and one release-note label per # architecture. The PE check is what stops an x64 binary shipping inside an # arm64 package because a build was pointed at the wrong target. for ARCH in $ARCHES; do case "$ARCH" in x64) TARGET=x86_64-pc-windows-msvc; PE_MACHINE=8664; MACHINE="64 位" ;; arm64) TARGET=aarch64-pc-windows-msvc; PE_MACHINE=aa64; MACHINE=ARM64 ;; esac EXE="src-tauri/target/$TARGET/release/shift.exe" INSTALLER="artifacts/Shift-Setup-$VERSION-win-$ARCH.exe" PORTABLE="artifacts/Shift-Portable-$VERSION-win-$ARCH.zip" NOTES="artifacts/README-Windows-$ARCH.txt" if [ "$SKIP_BUILD" != "1" ]; then echo "== rust cross build ($ARCH: $TARGET) ==" # --features tauri/custom-protocol is mandatory: without it Tauri derives # cfg(dev) and every window loads build.devUrl instead of the bundled assets. CROSS_LOG=$(mktemp /tmp/shift-win-build.XXXXXX) if ! ( cd src-tauri cargo xwin build --target "$TARGET" --release \ --features tauri/custom-protocol >"$CROSS_LOG" 2>&1 ); then sed -n '1,240p' "$CROSS_LOG" exit 1 fi grep -Ev "^warning:|^\s+\||^\s+=|LNK4099|failed to load|^$|^\s+-->|^note:" \ "$CROSS_LOG" || true fi test -f "$EXE" echo "== PE machine check ($ARCH) ==" python3 - "$EXE" "$PE_MACHINE" < “仍要运行”。 3. 卸载请在“设置 > 应用”中移除 Shift,无需手动删除文件。 便携版 ------ 不想安装时,解压 Shift-Portable-{version}-win-{arch}.zip,直接运行其中的 shift.exe。请先完整解压,不要在压缩包的预览窗口里运行。 运行组件 -------- 打开 Shift 主窗口,进入“设置” > “运行组件”: - 首次进入该页会自动检测,之后只在你点击“重新检测”时重新扫描; 扫描范围包括 PATH、WinGet、Chocolatey、Scoop 与常见安装目录。 - 页面显示本机实际使用的组件、版本、路径与来源。 - 缺失组件旁有“安装”,通过 Microsoft WinGet 安装,界面不会阻塞, 完成后自动重新检测。 WinGet 包映射: - Pandoc: JohnMacFarlane.Pandoc - Typst: Typst.Typst - FFmpeg: Gyan.FFmpeg - Poppler: oschwartz10612.Poppler - ImageMagick: ImageMagick.ImageMagick 如果没有 WinGet,界面会给出微软官方安装说明入口。Shift 不会从第三方站点 下载运行库,也不会卸载或覆盖你已有的工具。 校验 ---- PowerShell: Get-FileHash .\\Shift-Setup-{version}-win-{arch}.exe -Algorithm SHA256 """ (stage / "README-Windows.txt").write_bytes(text.replace("\n", "\r\n").encode("utf-8")) PY echo "== NSIS installer ($ARCH) ==" mkdir -p artifacts SIZE_KB=$(( ($(stat -f%z "$EXE" 2>/dev/null || stat -c%s "$EXE") + 1023) / 1024 )) makensis -V2 \ -DSHIFT_EXE="$PWD/$EXE" \ -DLICENSE_FILE="$PWD/LICENSE" \ -DNOTICES_FILE="$PWD/THIRD_PARTY_NOTICES.md" \ -DREADME_FILE="$STAGE/README-Windows.txt" \ -DICONS_DIR="$PWD/src-tauri/icons" \ -DOUT_FILE="$PWD/$INSTALLER" \ -DVERSION="$VERSION" \ -DARCH="$ARCH" \ -DEST_SIZE_KB="$SIZE_KB" \ scripts/windows-installer.nsi echo "== portable ZIP ($ARCH) ==" cp "$EXE" "$STAGE/portable/Shift-$VERSION-Windows-$ARCH/shift.exe" cp LICENSE "$STAGE/portable/Shift-$VERSION-Windows-$ARCH/LICENSE.txt" cp THIRD_PARTY_NOTICES.md "$STAGE/portable/Shift-$VERSION-Windows-$ARCH/THIRD_PARTY_NOTICES.txt" cp "$STAGE/README-Windows.txt" "$STAGE/portable/Shift-$VERSION-Windows-$ARCH/README-Windows.txt" (cd "$STAGE/portable" && zip -q -r -X -9 "$ROOT/$PORTABLE" "Shift-$VERSION-Windows-$ARCH") mv "$STAGE/README-Windows.txt" "$NOTES" done echo "== checksums ==" python3 - "$VERSION" <