|
| 1 | +name: Package |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: ['v*'] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: write |
| 9 | + |
| 10 | +jobs: |
| 11 | + package: |
| 12 | + name: ${{ matrix.os }} / ${{ matrix.format }} |
| 13 | + runs-on: ${{ matrix.os }} |
| 14 | + |
| 15 | + strategy: |
| 16 | + fail-fast: false |
| 17 | + matrix: |
| 18 | + include: |
| 19 | + - os: ubuntu-24.04 |
| 20 | + format: DEB |
| 21 | + generators: DEB |
| 22 | + deb_arch: amd64 |
| 23 | + rpm_arch: x86_64 |
| 24 | + - os: ubuntu-24.04 |
| 25 | + format: RPM |
| 26 | + generators: RPM |
| 27 | + deb_arch: amd64 |
| 28 | + rpm_arch: x86_64 |
| 29 | + - os: ubuntu-24.04-arm |
| 30 | + format: DEB |
| 31 | + generators: DEB |
| 32 | + deb_arch: arm64 |
| 33 | + rpm_arch: aarch64 |
| 34 | + - os: ubuntu-24.04-arm |
| 35 | + format: RPM |
| 36 | + generators: RPM |
| 37 | + deb_arch: arm64 |
| 38 | + rpm_arch: aarch64 |
| 39 | + - os: windows-latest |
| 40 | + format: NSIS |
| 41 | + generators: NSIS |
| 42 | + - os: macos-15 |
| 43 | + format: productbuild |
| 44 | + generators: productbuild |
| 45 | + |
| 46 | + steps: |
| 47 | + - name: Checkout |
| 48 | + uses: actions/checkout@v4 |
| 49 | + with: |
| 50 | + fetch-depth: 0 |
| 51 | + |
| 52 | + - name: Install LLVM toolchain (Linux) |
| 53 | + if: runner.os == 'Linux' |
| 54 | + shell: bash |
| 55 | + run: | |
| 56 | + set -euxo pipefail |
| 57 | + sudo apt-get update |
| 58 | + sudo apt-get install -y wget gnupg lsb-release software-properties-common ca-certificates |
| 59 | +
|
| 60 | + codename=$(lsb_release -cs) |
| 61 | + llvm_version="20" |
| 62 | +
|
| 63 | + wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key \ |
| 64 | + | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/llvm-snapshot.gpg |
| 65 | + echo "deb http://apt.llvm.org/${codename}/ llvm-toolchain-${codename}-${llvm_version} main" \ |
| 66 | + | sudo tee /etc/apt/sources.list.d/llvm-${llvm_version}.list |
| 67 | + sudo apt-get update |
| 68 | + sudo apt-get install -y \ |
| 69 | + llvm-${llvm_version}-dev \ |
| 70 | + libclang-${llvm_version}-dev \ |
| 71 | + clang-${llvm_version} \ |
| 72 | + cmake \ |
| 73 | + ninja-build \ |
| 74 | + rpm \ |
| 75 | + libzstd-dev |
| 76 | +
|
| 77 | + llvm_cmakedir="$(llvm-config-${llvm_version} --cmakedir)" |
| 78 | + clang_cmakedir="$(dirname "${llvm_cmakedir}")/clang" |
| 79 | + echo "LLVM_DIR=${llvm_cmakedir}" >> "$GITHUB_ENV" |
| 80 | + echo "Clang_DIR=${clang_cmakedir}" >> "$GITHUB_ENV" |
| 81 | +
|
| 82 | + - name: Install LLVM toolchain (macOS) |
| 83 | + if: runner.os == 'macOS' |
| 84 | + shell: bash |
| 85 | + run: | |
| 86 | + set -euxo pipefail |
| 87 | + brew update |
| 88 | + brew install --quiet cmake ninja llvm@20 |
| 89 | + llvm_prefix="$(brew --prefix llvm@20)" |
| 90 | + echo "CC=/usr/bin/clang" >> "$GITHUB_ENV" |
| 91 | + echo "CXX=/usr/bin/clang++" >> "$GITHUB_ENV" |
| 92 | + echo "LLVM_DIR=${llvm_prefix}/lib/cmake/llvm" >> "$GITHUB_ENV" |
| 93 | + echo "Clang_DIR=${llvm_prefix}/lib/cmake/clang" >> "$GITHUB_ENV" |
| 94 | +
|
| 95 | + - name: Install LLVM toolchain (Windows) |
| 96 | + if: runner.os == 'Windows' |
| 97 | + shell: pwsh |
| 98 | + run: | |
| 99 | + $ver = "19.1.7" |
| 100 | + $archive = "clang+llvm-${ver}-x86_64-pc-windows-msvc.tar.xz" |
| 101 | + $url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-${ver}/${archive}" |
| 102 | + Invoke-WebRequest -Uri $url -OutFile $archive -UseBasicParsing |
| 103 | + tar -xf $archive |
| 104 | + $src = (Get-ChildItem -Directory "clang+llvm-*")[0].FullName |
| 105 | + New-Item -ItemType Directory -Force "C:\Program Files\LLVM" | Out-Null |
| 106 | + Copy-Item "$src\*" "C:\Program Files\LLVM\" -Recurse -Force |
| 107 | + choco install ninja -y --no-progress |
| 108 | +
|
| 109 | + $llvm_prefix = "C:\Program Files\LLVM" |
| 110 | + "LLVM_DIR=$llvm_prefix\lib\cmake\llvm" >> $env:GITHUB_ENV |
| 111 | + "Clang_DIR=$llvm_prefix\lib\cmake\clang" >> $env:GITHUB_ENV |
| 112 | + "$llvm_prefix\bin" >> $env:GITHUB_PATH |
| 113 | +
|
| 114 | + - name: Patch LLVM cmake for DIA SDK (Windows) |
| 115 | + if: runner.os == 'Windows' |
| 116 | + shell: pwsh |
| 117 | + run: | |
| 118 | + # LLVM 18.1.8 was built with VS 2019; its cmake exports hardcode the VS 2019 DIA SDK path. |
| 119 | + # This step runs every time (not gated on cache) and rewrites that path to wherever |
| 120 | + # diaguids.lib actually lives on this runner. |
| 121 | + $old_path = "C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/DIA SDK/lib/amd64/diaguids.lib" |
| 122 | +
|
| 123 | + $dia_file = Get-ChildItem "C:\Program Files\Microsoft Visual Studio" -Filter "diaguids.lib" ` |
| 124 | + -Recurse -ErrorAction SilentlyContinue | |
| 125 | + Where-Object { $_.FullName -like "*amd64*" } | |
| 126 | + Select-Object -First 1 |
| 127 | +
|
| 128 | + if (-not $dia_file) { |
| 129 | + Write-Warning "diaguids.lib not found — linker may fail for PDB targets" |
| 130 | + exit 0 |
| 131 | + } |
| 132 | +
|
| 133 | + $actual = $dia_file.FullName -replace '\\', '/' |
| 134 | + Write-Host "diaguids.lib found at: $actual" |
| 135 | +
|
| 136 | + $patched = 0 |
| 137 | + Get-ChildItem "C:\Program Files\LLVM\lib\cmake" -Filter "*.cmake" -Recurse | |
| 138 | + ForEach-Object { |
| 139 | + $text = [System.IO.File]::ReadAllText($_.FullName) |
| 140 | + if ($text.Contains($old_path)) { |
| 141 | + Write-Host "Patching $($_.Name)" |
| 142 | + $text = $text.Replace($old_path, $actual) |
| 143 | + [System.IO.File]::WriteAllText($_.FullName, $text) |
| 144 | + $patched++ |
| 145 | + } |
| 146 | + } |
| 147 | + Write-Host "Patched $patched cmake file(s)" |
| 148 | +
|
| 149 | + - name: Configure (Linux / macOS) |
| 150 | + if: runner.os != 'Windows' |
| 151 | + shell: bash |
| 152 | + run: | |
| 153 | + set -euxo pipefail |
| 154 | + cmake -S . -B build -G Ninja \ |
| 155 | + -DCMAKE_BUILD_TYPE=Release \ |
| 156 | + -DLLVM_DIR="$LLVM_DIR" \ |
| 157 | + -DClang_DIR="$Clang_DIR" \ |
| 158 | + -DH5CPP_STATIC_LINK_LLVM=ON |
| 159 | +
|
| 160 | + - name: Configure (Windows) |
| 161 | + if: runner.os == 'Windows' |
| 162 | + shell: pwsh |
| 163 | + run: | |
| 164 | + cmake -S . -B build ` |
| 165 | + -G "Visual Studio 17 2022" -A x64 ` |
| 166 | + -DCMAKE_BUILD_TYPE=Release ` |
| 167 | + -DLLVM_DIR="$env:LLVM_DIR" ` |
| 168 | + -DClang_DIR="$env:Clang_DIR" ` |
| 169 | + -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded |
| 170 | +
|
| 171 | + - name: Build |
| 172 | + shell: bash |
| 173 | + run: cmake --build build --parallel --config Release |
| 174 | + |
| 175 | + - name: Package |
| 176 | + shell: bash |
| 177 | + run: | |
| 178 | + set -euxo pipefail |
| 179 | + cd build |
| 180 | + cpack -G "${{ matrix.generators }}" --config CPackConfig.cmake |
| 181 | + env: |
| 182 | + CPACK_DEBIAN_PACKAGE_ARCHITECTURE: ${{ matrix.deb_arch }} |
| 183 | + CPACK_RPM_PACKAGE_ARCHITECTURE: ${{ matrix.rpm_arch }} |
| 184 | + |
| 185 | + - name: Upload artifact |
| 186 | + uses: actions/upload-artifact@v4 |
| 187 | + with: |
| 188 | + name: h5cpp-compiler-${{ matrix.os }}-${{ matrix.format }} |
| 189 | + path: build/h5cpp-compiler-* |
| 190 | + |
| 191 | + publish: |
| 192 | + name: Publish Release |
| 193 | + needs: package |
| 194 | + runs-on: ubuntu-latest |
| 195 | + if: startsWith(github.ref, 'refs/tags/') |
| 196 | + |
| 197 | + steps: |
| 198 | + - name: Download all artifacts |
| 199 | + uses: actions/download-artifact@v4 |
| 200 | + with: |
| 201 | + path: artifacts |
| 202 | + pattern: h5cpp-compiler-* |
| 203 | + |
| 204 | + - name: Create Release and upload assets |
| 205 | + shell: bash |
| 206 | + run: | |
| 207 | + set -euxo pipefail |
| 208 | + tag="${GITHUB_REF_NAME}" |
| 209 | + gh release create "$tag" --generate-notes || true |
| 210 | + find artifacts -type f -name "h5cpp-compiler-*" -print0 | \ |
| 211 | + xargs -0 gh release upload "$tag" --clobber |
| 212 | + env: |
| 213 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments