#!/usr/bin/env bash # compile-windows.sh — build Flutter Windows desktop, package into dist/ set -euo pipefail # shellcheck source=scripts/ci/_env.sh . "$(dirname "$0")/_env.sh" TAG="$1" VER="${TAG#client-v}" VER="${VER#v}" # 兼容 build-windows.yml 传裸 v 前缀(如 v1.0.4);pubspec 版本不能带 v echo "==> compile-windows: version=${VER}" # Sync Flutter pubspec version (done in the checkout, before copying out) sed -i "s/^version:.*/version: ${VER}+1/" client/pubspec.yaml # The Forgejo Windows runner checks out under # C:\Windows\System32\config\systemprofile\.cache\act\...\hostexecutor # Building there triggers WOW64 filesystem redirection (System32 -> SysWOW64) # which breaks CMake/Flutter native paths. So copy the Flutter project to a # clean short path OUTSIDE System32 and build there. This replaces the previous # `subst W:` trick, which was fragile due to cmd/MSYS quoting. BUILD_ROOT="/c/jiu-build" BUILD_CLIENT="${BUILD_ROOT}/client" echo "==> copying client/ to ${BUILD_CLIENT}" rm -rf "$BUILD_ROOT" mkdir -p "$BUILD_ROOT" cp -r client "$BUILD_CLIENT" # `cp -r` turns Flutter's plugin symlinks (windows/flutter/ephemeral/.plugin_symlinks/*) # into real directories. flutter's createPluginSymlinks only cleans up *symlinks*, so it # then fails to create a symlink over the copied real dir (errno 183 / PathExists). # Drop all regenerable artifacts so the build below recreates them cleanly. rm -rf "${BUILD_CLIENT}/windows/flutter/ephemeral" \ "${BUILD_CLIENT}/.dart_tool" \ "${BUILD_CLIENT}/build" # Build (run from the clean path; pushd/popd avoids needing $() to save cwd) pushd "$BUILD_CLIENT" > /dev/null flutter create --platforms=windows . --project-name jiu_client flutter build windows --release \ "--dart-define=BASE_URL=https://jiu.51yanmei.com" \ "--dart-define=PUBLIC_URL=https://jiu.51yanmei.com" \ "--dart-define=APP_VERSION=v${VER}" popd > /dev/null # Package the Release folder into a Windows installer with Inno Setup (ISCC). # Inno Setup is installed by provision-windows.sh; check both Program Files dirs. ISCC="" for c in "/c/Program Files (x86)/Inno Setup 6/ISCC.exe" "/c/Program Files/Inno Setup 6/ISCC.exe"; do if [ -f "$c" ]; then ISCC="$c"; break; fi done if [ -z "$ISCC" ]; then echo "ERROR: Inno Setup (ISCC) not found. Run provision-windows.sh first." >&2 exit 1 fi # Run ISCC entirely under the clean build root: 32-bit ISCC would hit WOW64 # redirection if it read the .iss / wrote output under the System32 workspace. cp deploy/windows/jiu-installer.iss "${BUILD_ROOT}/jiu-installer.iss" # 简体中文语言文件随 .iss 一起放到构建目录,供 [Languages] 按相对路径引用。 cp deploy/windows/ChineseSimplified.isl "${BUILD_ROOT}/ChineseSimplified.isl" mkdir -p "${BUILD_ROOT}/dist" echo "==> building installer with Inno Setup (version ${VER})" # MSYS_NO_PATHCONV / MSYS2_ARG_CONV_EXCL disable Git Bash's automatic conversion # of /-leading args into Windows paths, which otherwise mangles ISCC's /D defines # (turning them into extra "script filenames"). MSYS_NO_PATHCONV=1 MSYS2_ARG_CONV_EXCL='*' "$ISCC" \ "/DAppVer=${VER}" \ "/DSrcDir=C:\\jiu-build\\client\\build\\windows\\x64\\runner\\Release" \ "/DOutDir=C:\\jiu-build\\dist" \ "C:\\jiu-build\\jiu-installer.iss" # Copy the installer back to the workspace dist/ via PowerShell (64-bit, so it # can write the System32 workspace path without WOW64 redirection). mkdir -p dist echo "==> copying installer -> dist/jiu-windows-x64-setup.exe" powershell -NoProfile -Command \ "Copy-Item 'C:\\jiu-build\\dist\\jiu-windows-x64-setup.exe' 'dist\\jiu-windows-x64-setup.exe' -Force" echo "==> compile-windows: done — dist/ contents:" ls -lh dist/