[CI] Windows原生构建,去你的交叉编译

This commit is contained in:
2026-01-03 21:50:15 +08:00
parent 2033cbbb16
commit 07624a2447
2 changed files with 27 additions and 41 deletions

View File

@@ -87,19 +87,12 @@ jobs:
echo "✅ Linux版本发布完成" echo "✅ Linux版本发布完成"
build-windows-x64: build-windows-x64:
runs-on: ubuntu # 关键:指定运行在带有 windows 标签的 Runner 上
container: runs-on: windows
image: git.fig-lang.cn/puqiar/fig-ci:base-latest # 移除 container 配置,因为将在宿主机直接运行
options: --network=host # container: ... # 删除这整个 container 部分
steps: steps:
- name: 验证环境
run: |
echo "=== Windows构建环境验证 ==="
xmake --version
clang++ --version | head -1
echo "环境就绪。"
- name: 检出代码 - name: 检出代码
run: | run: |
git clone https://git.fig-lang.cn/${{ github.repository }} . git clone https://git.fig-lang.cn/${{ github.repository }} .
@@ -112,40 +105,34 @@ jobs:
else else
VERSION="${GITHUB_REF#refs/tags/}" VERSION="${GITHUB_REF#refs/tags/}"
fi fi
echo "VERSION=$VERSION" >> $env:GITHUB_ENV
echo "Windows构建版本: $VERSION" echo "Windows构建版本: $VERSION"
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: 构建项目 (Windows x64) - name: 安装 xmake (Windows)
run: | run: |
echo "开始交叉编译Windows版本..." # 这里可以是你预先准备好的离线包或从你的Gitea下载
# 关键使用mingw平台指定clang工具链进行交叉编译 # 例如,如果你已将 xmake Windows 版放在仓库中
xmake f -p mingw -a x86_64 -m release -y --toolchain=clang # 或者使用简单的网络下载确保Runner能访问
xmake build -j$(nproc) curl -fsSL https://xmake.io/shget.text -o xmake.ps1
echo "Windows构建成功。" powershell -ExecutionPolicy Bypass -File xmake.ps1
- name: 构建项目 (Windows Native)
run: |
xmake f -p windows -a x86_64 -m release -y
xmake build -j${env:NUMBER_OF_PROCESSORS}
- name: 打包Windows发布文件 - name: 打包Windows发布文件
run: | run: |
PACKAGE_NAME="Fig-${{ env.VERSION }}-windows-x86_64" $VERSION = $env:VERSION
mkdir -p "${PACKAGE_NAME}" $PACKAGE_NAME = "Fig-${VERSION}-windows-x86_64"
# 注意Windows可执行文件路径根据你的xmake配置调整 New-Item -ItemType Directory -Force -Path $PACKAGE_NAME
# 尝试多种可能的输出路径 Copy-Item build\windows\x86_64\release\Fig.exe $PACKAGE_NAME\
if [ -f "build/mingw/x86_64/release/Fig.exe" ]; then if (Test-Path "src\Module\Library") {
cp build/mingw/x86_64/release/Fig.exe "${PACKAGE_NAME}/" Copy-Item -Recurse src\Module\Library $PACKAGE_NAME\
elif [ -f "build/mingw/x86_64/release/Fig" ]; then }
cp build/mingw/x86_64/release/Fig "${PACKAGE_NAME}/Fig.exe" Compress-Archive -Path $PACKAGE_NAME -DestinationPath "${PACKAGE_NAME}.zip"
else Get-FileHash "${PACKAGE_NAME}.zip" -Algorithm SHA256 | Out-File "${PACKAGE_NAME}.sha256"
echo "错误:未找到Windows构建输出文件" echo "Windows打包完成."
find build/ -name "Fig*" -type f | head -5
exit 1
fi
if [ -d "src/Module/Library" ]; then
cp -r src/Module/Library "${PACKAGE_NAME}/"
fi
zip -r "${PACKAGE_NAME}.zip" "${PACKAGE_NAME}"
sha256sum "${PACKAGE_NAME}.zip" > "${PACKAGE_NAME}.sha256"
echo "Windows打包完成: ${PACKAGE_NAME}.zip"
- name: 发布Windows版本到Gitea - name: 发布Windows版本到Gitea
env: env:
GITEA_TOKEN: ${{ secrets.CI_TOKEN }} GITEA_TOKEN: ${{ secrets.CI_TOKEN }}

View File

@@ -12,13 +12,12 @@ target("Fig")
set_toolchains("clang") set_toolchains("clang")
add_cxxflags("-stdlib=libc++") add_cxxflags("-stdlib=libc++")
add_ldflags("-stdlib=libc++") add_ldflags("-stdlib=libc++")
elseif is_plat("mingw") then elseif is_plat("windows") then
-- 1. CI cross (Linux -> Windows) -- 1. CI cross (Linux -> Windows)
-- 2. local dev (Windows + llvm-mingw) -- 2. local dev (Windows + llvm-mingw)
add_ldflags("-Wl,--stack,268435456") add_ldflags("-Wl,--stack,268435456")
set_toolchains("clang") set_toolchains("clang")
-- static lib -- static lib
add_cxxflags("-target x86_64-w64-mingw32", "-static")
-- add_ldflags("-target x86_64-w64-mingw32", "-static") -- add_ldflags("-target x86_64-w64-mingw32", "-static")
-- add_cxxflags("-stdlib=libc++") -- add_cxxflags("-stdlib=libc++")
-- add_ldflags("-stdlib=libc++") -- add_ldflags("-stdlib=libc++")