ci: 修复 xwin 编译 - 添加 Windows MSVC 目标
Some checks failed
Build Windows / Build Windows (push) Failing after 8m30s

问题:
- xwin 编译时需要 x86_64-pc-windows-msvc 目标
- 错误:can't find crate for std

修复:
- 在安装 xwin 前添加 rustup target add x86_64-pc-windows-msvc
- 使用官方 xwin crate(非 git 版本)
- 添加 xwin download 步骤下载预编译 CRT
This commit is contained in:
大麦
2026-03-10 19:28:48 +08:00
parent 7af1c37577
commit 41508bcc7f

View File

@@ -15,36 +15,32 @@ jobs:
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal
source $HOME/.cargo/env
# 添加 Windows MSVC 目标xwin 需要)
rustup target add x86_64-pc-windows-msvc
- name: Install xwin (MinGW CRT)
run: |
source $HOME/.cargo/env
cargo install --git https://github.com/Jake-Shadle/xwin.git xwin --target x86_64-pc-windows-msvc
# 安装 xwin需要 x86_64-pc-windows-msvc 目标)
cargo install xwin
- name: Download MinGW-w64 compiler
- name: Download MinGW CRT
run: |
mkdir -p $HOME/mingw
cd $HOME/mingw
# 下载预编译的 MinGW-w64
curl -L -O x86_64-12.0.0-release-posix-seh-rt_v8-rev0.7z \
https://github.com/niXman/mingw-builds-binaries/releases/download/12.0.0-rt_v8-rev0/x86_64-12.0.0-release-posix-seh-rt_v8-rev0.7z
# 解压
7z x x86_64-12.0.0-release-posix-seh-rt_v8-rev0.7z -y
# 设置环境变量
echo "MINGW_HOME=$HOME/mingw/mingw64" >> $GITHUB_ENV
echo "PATH=$HOME/mingw/mingw64/bin:$PATH" >> $GITHUB_ENV
source $HOME/.cargo/env
# 下载预编译的 MinGW CRT
xwin download --accept-license
- name: Build
run: |
source $HOME/.cargo/env
source $GITHUB_ENV
export CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_LINKER=x86_64-w64-mingw32-gcc
export CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_AR=ar
export CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_RANLIB=ranlib
# 设置 xwin 环境变量
export CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_LINKER=xwin-link
export CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_AR=xwin-lib
export CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_RANLIB=true
# 使用 xwin 提供的 SDK
export XWIN_PATH=$HOME/.cache/xwin
cargo build --release --target x86_64-pc-windows-msvc
@@ -55,7 +51,7 @@ jobs:
cd dist
echo "ReadFlow for Windows" > README.txt
echo "Version: ${GITEA_REF_NAME}" >> README.txt
echo "Built with: MinGW-w64 (precompiled)" >> README.txt
echo "Built with: xwin + MSVC" >> README.txt
echo "Date: $(date)" >> README.txt
zip -r readflow-windows-x86_64.zip readflow.exe README.txt
@@ -76,7 +72,7 @@ jobs:
RELEASE_ID=$(curl -s -X POST "${URL}/api/v1/repos/${REPO}/releases" \
-H "Authorization: token ${TOKEN}" \
-H "Content-Type: application/json" \
-d "{\"tag_name\": \"${TAG}\", \"name\": \"ReadFlow ${TAG}\", \"body\": \"Release ${TAG}\\n\\nBuilt with MinGW-w64 (预编译) + xwin\", \"draft\": false}" \
-d "{\"tag_name\": \"${TAG}\", \"name\": \"ReadFlow ${TAG}\", \"body\": \"Release ${TAG}\\n\\nBuilt with xwin (预编译 MinGW CRT)\", \"draft\": false}" \
| jq -r '.id')
fi