feat: update build configuration for macOS to support Intel architect… #161
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build Precompiled Binaries | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| tags: [ 'v*' ] | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| build: | |
| env: | |
| HAMLIB_VERSION: '4.6.5' | |
| PTHREADS_SOURCEWARE_DIR: 'prebuilt-dll-2-9-1-release' | |
| strategy: | |
| matrix: | |
| include: | |
| - os: ubuntu-latest | |
| target: linux-x64 | |
| - os: ubuntu-24.04-arm | |
| target: linux-arm64 | |
| - os: macos-latest | |
| target: darwin-arm64 | |
| - os: macos-15-intel | |
| target: darwin-x64 | |
| - os: windows-latest | |
| target: win32-x64 | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18' | |
| cache: 'npm' | |
| - name: Install system dependencies (Linux) | |
| if: startsWith(matrix.os, 'ubuntu') | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y autoconf automake libtool pkg-config patchelf | |
| sudo apt-get install -y libusb-1.0-0 libindi1 || true | |
| - name: Install system dependencies (macOS) | |
| if: startsWith(matrix.os, 'macos') | |
| run: | | |
| brew install autoconf automake libtool dylibbundler | |
| pip3 install setuptools --break-system-packages || true | |
| - name: Setup Windows Hamlib | |
| if: matrix.os == 'windows-latest' | |
| shell: pwsh | |
| run: | | |
| $ErrorActionPreference = 'Stop' | |
| $ver = $env:HAMLIB_VERSION | |
| $zipUrl = "https://github.com/Hamlib/Hamlib/releases/download/$ver/hamlib-w64-$ver.zip" | |
| $zipPath = Join-Path $env:RUNNER_TEMP "hamlib-w64-$ver.zip" | |
| Write-Host "Downloading Hamlib $ver..." | |
| Invoke-WebRequest -Uri $zipUrl -OutFile $zipPath | |
| $dest = Join-Path $env:GITHUB_WORKSPACE 'hamlib' | |
| if (Test-Path $dest) { Remove-Item -Recurse -Force $dest } | |
| Add-Type -AssemblyName System.IO.Compression.FileSystem | |
| [System.IO.Compression.ZipFile]::ExtractToDirectory($zipPath, $dest) | |
| $root = $dest | |
| if (!(Test-Path (Join-Path $root 'bin'))) { | |
| $child = Get-ChildItem -Path $dest -Directory | Select-Object -First 1 | |
| if ($null -ne $child) { $root = $child.FullName } | |
| } | |
| Write-Host "HAMLIB root: $root" | |
| "HAMLIB_ROOT=$root" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
| - name: Setup Windows pthread | |
| if: matrix.os == 'windows-latest' | |
| shell: pwsh | |
| run: | | |
| $dir = $env:PTHREADS_SOURCEWARE_DIR | |
| $base = "https://sourceware.org/pub/pthreads-win32/$dir" | |
| $root = Join-Path $env:RUNNER_TEMP 'pthreads-root' | |
| New-Item -ItemType Directory -Path (Join-Path $root 'lib/x64') -Force | Out-Null | |
| foreach ($f in @('pthread.h','sched.h','semaphore.h')) { | |
| Invoke-WebRequest -Uri "$base/include/$f" -OutFile (Join-Path $root $f) | |
| } | |
| Invoke-WebRequest -Uri "$base/lib/x64/pthreadVC2.lib" -OutFile (Join-Path $root 'lib/x64/pthreadVC2.lib') | |
| "PTHREAD_ROOT=$root" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
| - name: Setup MSVC (Windows) | |
| if: matrix.os == 'windows-latest' | |
| uses: ilammy/msvc-dev-cmd@v1 | |
| with: | |
| arch: x64 | |
| - name: Fix Hamlib import library (Windows) | |
| if: matrix.os == 'windows-latest' | |
| shell: pwsh | |
| run: | | |
| $dllPath = Get-ChildItem -Path (Join-Path $env:HAMLIB_ROOT 'bin') -Filter 'libhamlib-*.dll' | Select-Object -First 1 | |
| $defPath = Join-Path $env:RUNNER_TEMP 'libhamlib-4.def' | |
| $libPath = Join-Path $env:HAMLIB_ROOT 'lib/libhamlib-4.lib' | |
| $exports = dumpbin /exports $dllPath.FullName | |
| $defContent = "LIBRARY libhamlib-4.dll`nEXPORTS`n" | |
| $inExports = $false | |
| foreach ($line in $exports -split "`n") { | |
| if ($line -match '^\s+ordinal\s+hint\s+RVA\s+name') { $inExports = $true; continue } | |
| if ($inExports -and $line -match '^\s+\d+\s+[0-9A-F]+\s+[0-9A-F]+\s+(\S+)') { | |
| $defContent += " $($matches[1])`n" | |
| } | |
| } | |
| Set-Content -Path $defPath -Value $defContent -Encoding ASCII | |
| $libDir = Join-Path $env:HAMLIB_ROOT 'lib' | |
| if (-not (Test-Path $libDir)) { New-Item -ItemType Directory -Path $libDir -Force | Out-Null } | |
| lib /def:$defPath /out:$libPath /machine:x64 | |
| - name: Install Node.js dependencies | |
| run: npm ci --ignore-scripts | |
| - name: Build (Linux/macOS - unified) | |
| if: matrix.os != 'windows-latest' | |
| run: | | |
| npm run build:all -- --minimal | |
| npm run verify | |
| - name: Build (Windows - staged) | |
| if: matrix.os == 'windows-latest' | |
| run: | | |
| node scripts/run-prebuildify.js | |
| npm run bundle | |
| npm run verify | |
| - name: Upload prebuilds artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: prebuilds-${{ matrix.target }} | |
| path: prebuilds/** | |
| retention-days: 1 | |
| package: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18' | |
| - name: Download all prebuilds | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: prebuilds-temp | |
| - name: Organize prebuilds | |
| run: | | |
| mkdir -p prebuilds | |
| for platform_dir in prebuilds-temp/prebuilds-*/; do | |
| if [ -d "$platform_dir/prebuilds" ]; then | |
| mv "$platform_dir/prebuilds"/* prebuilds/ 2>/dev/null || true | |
| else | |
| mv "$platform_dir"/* prebuilds/ 2>/dev/null || true | |
| fi | |
| done | |
| - name: Install dependencies | |
| run: npm ci --ignore-scripts | |
| - name: Verify build | |
| run: npm run verify:all | |
| - name: Create build info | |
| run: | | |
| cat > prebuilds/BUILD_INFO.txt << EOF | |
| Node-HamLib Precompiled Binaries | |
| ================================ | |
| Build Time: $(date -u) | |
| Git Commit: ${{ github.sha }} | |
| Git Ref: ${{ github.ref }} | |
| Supported Platforms: | |
| EOF | |
| for dir in prebuilds/*/; do | |
| if [ -d "$dir" ]; then | |
| echo "- $(basename "$dir")" >> prebuilds/BUILD_INFO.txt | |
| fi | |
| done | |
| echo "" >> prebuilds/BUILD_INFO.txt | |
| echo "Installation: Extract to your project's prebuilds/ directory" >> prebuilds/BUILD_INFO.txt | |
| cd prebuilds | |
| zip -r ../node-hamlib-prebuilds.zip . -x "*.DS_Store" | |
| cd .. | |
| - name: Upload unified package | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: node-hamlib-prebuilds | |
| path: node-hamlib-prebuilds.zip | |
| retention-days: 90 | |
| - name: Create GitHub Release | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| uses: ncipollo/release-action@v1 | |
| with: | |
| tag: ${{ github.ref_name }} | |
| name: "Node-HamLib ${{ github.ref_name }}" | |
| artifacts: node-hamlib-prebuilds.zip | |
| body: | | |
| # Node-HamLib ${{ github.ref_name }} | |
| ## Precompiled Binaries | |
| Includes precompiled binaries for: | |
| - Linux x64/ARM64 | |
| - macOS ARM64 (Apple Silicon) & x64 (Intel) | |
| - Windows x64 | |
| ### Installation | |
| ```bash | |
| npm install node-hamlib | |
| ``` | |
| Binaries are automatically detected and used when available. | |
| cleanup: | |
| needs: [build, package] | |
| runs-on: ubuntu-latest | |
| if: always() | |
| steps: | |
| - name: Delete temporary artifacts | |
| uses: geekyeggo/delete-artifact@v5 | |
| with: | |
| name: | | |
| prebuilds-linux-x64 | |
| prebuilds-linux-arm64 | |
| prebuilds-darwin-arm64 | |
| prebuilds-darwin-x64 | |
| prebuilds-win32-x64 | |
| failOnError: false |