From 6d4fd564a34ad7e24ee0a839952ce65e998167b8 Mon Sep 17 00:00:00 2001 From: Gloduck Date: Sat, 15 Aug 2026 13:25:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=20Windows=20ARM64=20?= =?UTF-8?q?=E6=9E=84=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 84 ++++++++++++++++++++++++++++++------- 1 file changed, 69 insertions(+), 15 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2aae452..8b42554 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,10 +3,14 @@ name: Build on: push: branches: [ main ] + tags: [ '*' ] pull_request: branches: [ main ] workflow_dispatch: +permissions: + contents: write + jobs: build-macos: name: Build macOS Universal Binary (x86_64 + arm64) @@ -107,8 +111,15 @@ jobs: retention-days: 30 build-windows: - name: Build Windows (x64) - runs-on: windows-latest + name: Build Windows (${{ matrix.arch }}) + runs-on: ${{ matrix.os }} + strategy: + matrix: + include: + - os: windows-latest + arch: x64 + - os: windows-11-arm + arch: arm64 steps: - name: Checkout code @@ -118,6 +129,7 @@ jobs: uses: actions/setup-node@v4 with: node-version: '22' + architecture: ${{ matrix.arch }} - name: Setup MSBuild uses: microsoft/setup-msbuild@v2 @@ -130,15 +142,50 @@ jobs: - name: Verify build output shell: pwsh + env: + TARGET_ARCH: ${{ matrix.arch }} run: | Write-Host "Checking build output..." - if (Test-Path "build/Release/ztools_native.node") { - Write-Host "✅ .node file built successfully" - Get-Item "build/Release/ztools_native.node" | Format-List - } else { - Write-Host "❌ .node file not found" - exit 1 + if (!(Test-Path "build/Release/ztools_native.node")) { + throw ".node file not found" + } + + Get-Item "build/Release/ztools_native.node" | Format-List + + $peCheck = @' + const fs = require('node:fs'); + + const file = 'build/Release/ztools_native.node'; + const expectedMachines = { x64: 0x8664, arm64: 0xaa64 }; + const arch = process.env.TARGET_ARCH; + const expected = expectedMachines[arch]; + const binary = fs.readFileSync(file); + + if (expected === undefined) { + throw new Error(`Unsupported target architecture: ${arch}`); + } + if (binary.length < 0x40 || binary.readUInt16LE(0) !== 0x5a4d) { + throw new Error(`${file} does not have a valid DOS header`); + } + + const peOffset = binary.readUInt32LE(0x3c); + if (peOffset + 6 > binary.length || binary.readUInt32LE(peOffset) !== 0x00004550) { + throw new Error(`${file} does not have a valid PE header`); + } + + const machine = binary.readUInt16LE(peOffset + 4); + console.log(`PE machine for ${arch}: 0x${machine.toString(16)}`); + if (machine !== expected) { + throw new Error( + `Expected PE machine 0x${expected.toString(16)} for ${arch}, got 0x${machine.toString(16)}`, + ); + } + '@ + + $peCheck | node - + if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE } - name: Run tests @@ -149,12 +196,12 @@ jobs: shell: pwsh run: | New-Item -ItemType Directory -Force -Path artifacts - Copy-Item "build/Release/ztools_native.node" "artifacts/ztools_native-win-x64.node" + Copy-Item "build/Release/ztools_native.node" "artifacts/ztools_native-win-${{ matrix.arch }}.node" - name: Upload artifacts uses: actions/upload-artifact@v4 with: - name: ztools-native-windows + name: ztools-native-windows-${{ matrix.arch }} path: artifacts/ retention-days: 30 @@ -171,18 +218,25 @@ jobs: name: ztools-native-macos path: macos-artifacts - - name: Download Windows artifacts + - name: Download Windows x64 artifacts + uses: actions/download-artifact@v4 + with: + name: ztools-native-windows-x64 + path: windows-x64-artifacts + + - name: Download Windows arm64 artifacts uses: actions/download-artifact@v4 with: - name: ztools-native-windows - path: windows-artifacts + name: ztools-native-windows-arm64 + path: windows-arm64-artifacts - name: Create Release - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v2 with: files: | macos-artifacts/ztools_native-macos-universal.node macos-artifacts/libZToolsNative-macos-universal.dylib - windows-artifacts/ztools_native-win-x64.node + windows-x64-artifacts/ztools_native-win-x64.node + windows-arm64-artifacts/ztools_native-win-arm64.node env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}