From 34bd74974112ece68be2325c6da73a55ae01ce53 Mon Sep 17 00:00:00 2001 From: lanyuanxiaoyao Date: Tue, 5 May 2026 18:58:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=20Windows=20arm64=20CGO=20=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E9=93=BE=E5=92=8C=20macOS=20=E7=A3=81=E7=9B=98?= =?UTF-8?q?=E7=A9=BA=E9=97=B4=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Windows arm64: 在 workflow matrix 中设置 CC=clang/CXX=clang++ 并注入构建环境 - macOS: 在 Makefile 关键节点清理中间产物和临时目录释放磁盘空间 - 预检步骤改用 $CC/$CXX 替代硬编码编译器名称,与 matrix 声明保持一致 - 同步新增 release-pipeline spec 需求: Windows arm64 CGO 编译器指定 --- .github/workflows/release.yml | 18 ++++++++++++++---- Makefile | 6 +++++- openspec/specs/release-pipeline/spec.md | 16 ++++++++++++++++ 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index daefe74..c2508d3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -156,12 +156,16 @@ jobs: - arch: amd64 runner: windows-latest msystem: MINGW64 + cc: gcc + cxx: g++ packages: >- make mingw-w64-x86_64-gcc - arch: arm64 runner: windows-11-arm msystem: CLANGARM64 + cc: clang + cxx: clang++ packages: >- make mingw-w64-clang-aarch64-clang @@ -195,6 +199,9 @@ jobs: - name: Preflight Windows release toolchain shell: msys2 {0} + env: + CC: ${{ matrix.cc }} + CXX: ${{ matrix.cxx }} run: | set -euo pipefail command -v go @@ -203,9 +210,11 @@ jobs: bun --version command -v make make --version + command -v "$CC" + "$CC" --version + command -v "$CXX" + "$CXX" --version if [ "${{ matrix.arch }}" = "arm64" ]; then - command -v clang - clang --version if command -v llvm-windres >/dev/null 2>&1; then llvm-windres --version else @@ -213,8 +222,6 @@ jobs: windres --version fi else - command -v gcc - gcc --version command -v windres windres --version fi @@ -228,6 +235,9 @@ jobs: - name: Build Windows release assets shell: msys2 {0} + env: + CC: ${{ matrix.cc }} + CXX: ${{ matrix.cxx }} run: make release-assets-windows - name: Upload Windows release assets diff --git a/Makefile b/Makefile index ee55591..4cc6a56 100644 --- a/Makefile +++ b/Makefile @@ -116,6 +116,7 @@ desktop-build-mac: version-check _desktop-prepare-frontend _desktop-prepare-embe cd backend && CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -ldflags "$(GO_LDFLAGS)" -o ../build/nex-mac-amd64 ./cmd/desktop lipo -create build/nex-mac-arm64 build/nex-mac-amd64 -output build/nex-mac-universal lipo -info build/nex-mac-universal | grep -q 'x86_64 arm64' + rm -f build/nex-mac-arm64 build/nex-mac-amd64 @printf 'Packaging macOS app bundle...\n' rm -rf build/Nex.app mkdir -p build/Nex.app/Contents/MacOS build/Nex.app/Contents/Resources @@ -241,6 +242,7 @@ release-assets-server-macos: version-check tar -C build -czf "$(RELEASE_DIR)/$$asset" nex-server-macos-arm64 asset=$$(go run ./versionctl asset-name server macos universal tar.gz); \ tar -C build -czf "$(RELEASE_DIR)/$$asset" nex-server-macos-universal + rm -f build/nex-server-macos-amd64 build/nex-server-macos-arm64 build/nex-server-macos-universal release-assets-desktop-linux: version-check release-assets-check desktop-build-linux _package-linux-tar _package-linux-appimage _package-linux-deb _package-linux-rpm @@ -251,6 +253,7 @@ release-assets-desktop-windows: version-check release-assets-check desktop-build "$$POWERSHELL" -NoProfile -Command "Compress-Archive -LiteralPath '$(WINDOWS_DESKTOP_BINARY)' -DestinationPath '$(RELEASE_DIR)/$$asset' -Force" release-assets-desktop-macos: version-check release-assets-check desktop-build-mac _package-macos-zip _package-macos-dmg + rm -rf build/Nex.app build/dmg release-assets-checksums: @cd "$(RELEASE_DIR)" && \ @@ -366,7 +369,8 @@ _package-macos-dmg: ln -s /Applications "$$dmgdir/Applications"; \ asset=$$(go run ./versionctl asset-name desktop macos universal dmg); \ hdiutil create -volname Nex -srcfolder "$$dmgdir" -ov -format UDZO "$(RELEASE_DIR)/$$asset"; \ - hdiutil verify "$(RELEASE_DIR)/$$asset" >/dev/null + hdiutil verify "$(RELEASE_DIR)/$$asset" >/dev/null && \ + rm -rf "$$dmgdir" # ============================================ # 共享 helper targets diff --git a/openspec/specs/release-pipeline/spec.md b/openspec/specs/release-pipeline/spec.md index 39a1bf3..c6b7087 100644 --- a/openspec/specs/release-pipeline/spec.md +++ b/openspec/specs/release-pipeline/spec.md @@ -120,6 +120,22 @@ - **THEN** 发布流水线 SHALL 在正式构建前失败 - **AND** 系统 SHALL 在日志中标识缺失的工具链名称 +### Requirement: Windows arm64 CGO 编译器指定 + +系统 SHALL 在 Windows arm64 发布构建中显式指定 `CC=clang` 和 `CXX=clang++` 环境变量,确保 Go cgo 在 MSYS2 CLANGARM64 环境下使用正确的 C 编译器进行 `windows/arm64` 交叉编译。 + +#### Scenario: Windows arm64 构建使用 clang + +- **WHEN** 发布流水线在 `windows-11-arm` runner 上执行 Windows arm64 构建步骤 +- **THEN** 构建步骤 SHALL 将 `CC=clang` 和 `CXX=clang++` 注入 go build 环境 +- **AND** Go cgo SHALL 使用 `clang` 编译 `runtime/cgo` 等 CGO 组件 + +#### Scenario: Windows amd64 构建保持 gcc + +- **WHEN** 发布流水线在 `windows-latest` runner 上执行 Windows amd64 构建步骤 +- **THEN** 构建步骤 MAY 显式指定 `CC=gcc` 和 `CXX=g++` 或依赖 Go 默认编译器探测 +- **AND** 显式指定的 `gcc` SHALL 等价于 MSYS2 MINGW64 默认 C 编译器(`x86_64-w64-mingw32-gcc`) + ### Requirement: 发布流水线 LFS 资产拉取 发布流水线 SHALL 在所有会 checkout 仓库并参与版本校验、web 构建、server 构建或 desktop 构建的 job 中拉取 Git LFS 真实文件,确保发布构建读取到真实二进制资产而非 LFS pointer 文本。