Make the native runtimes work #11
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 PDF Runtime | |
| on: | |
| workflow_dispatch: | |
| workflow_call: | |
| pull_request: | |
| paths: | |
| - 'packages/pdf-runtime/**' | |
| - '.github/workflows/build-pdf-runtime.yml' | |
| push: | |
| branches: | |
| - main | |
| - next | |
| - feature/pdf-runtime | |
| paths: | |
| - 'packages/pdf-runtime/**' | |
| - '.github/workflows/build-pdf-runtime.yml' | |
| permissions: | |
| contents: read | |
| env: | |
| EMSDK_VERSION: 3.1.72 | |
| jobs: | |
| linux: | |
| name: Linux x64 + musl + WASM | |
| runs-on: ubuntu-24.04 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| target: [linux-x64, linuxmusl-x64, wasm32] | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - if: ${{ !contains(matrix.target, 'linuxmusl') }} | |
| uses: pnpm/action-setup@v5 | |
| with: | |
| version: 10.4.0 | |
| - if: ${{ !contains(matrix.target, 'linuxmusl') }} | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 22 | |
| cache: pnpm | |
| - name: Cache runtime payload | |
| id: payload-cache | |
| uses: actions/cache@v5 | |
| with: | |
| path: packages/pdf-runtime/.cache/payloads/${{ matrix.target }} | |
| key: >- | |
| pdf-runtime-payload-${{ matrix.target }}-${{ hashFiles( | |
| 'packages/pdf-runtime/pdf-runtime-build.json', | |
| 'packages/pdf-runtime/scripts/build-target.sh', | |
| 'packages/pdf-runtime/scripts/fetch-libpdfium.sh', | |
| 'packages/pdf-runtime/build/generate-functions.mjs', | |
| 'packages/pdf-runtime/build/generate-runtime-methods.mjs', | |
| 'packages/pdf-runtime/build/generate-napi-binding.mjs', | |
| 'packages/pdf-runtime/build/CMakeLists.txt', | |
| 'packages/pdf-runtime/build/compile.sh', | |
| 'packages/pdf-runtime/build/compile.esm.sh' | |
| ) }} | |
| - if: steps.payload-cache.outputs.cache-hit == 'true' | |
| name: Restore payload from cache | |
| shell: bash | |
| run: | | |
| mkdir -p "packages/pdf-runtime/npm/${{ matrix.target }}" | |
| cp -R "packages/pdf-runtime/.cache/payloads/${{ matrix.target }}/." \ | |
| "packages/pdf-runtime/npm/${{ matrix.target }}/" | |
| - if: ${{ steps.payload-cache.outputs.cache-hit != 'true' && !contains(matrix.target, 'linuxmusl') }} | |
| run: pnpm install --frozen-lockfile | |
| - if: ${{ steps.payload-cache.outputs.cache-hit != 'true' && !contains(matrix.target, 'linuxmusl') }} | |
| name: Install build tools | |
| run: sudo apt-get update && sudo apt-get install -y cmake clang lld | |
| - if: ${{ steps.payload-cache.outputs.cache-hit != 'true' && matrix.target == 'wasm32' }} | |
| name: Install Emscripten | |
| run: | | |
| git clone https://github.com/emscripten-core/emsdk.git "$RUNNER_TEMP/emsdk" | |
| "$RUNNER_TEMP/emsdk/emsdk" install "$EMSDK_VERSION" | |
| "$RUNNER_TEMP/emsdk/emsdk" activate "$EMSDK_VERSION" | |
| echo "$RUNNER_TEMP/emsdk/upstream/emscripten" >> "$GITHUB_PATH" | |
| echo "$RUNNER_TEMP/emsdk/upstream/bin" >> "$GITHUB_PATH" | |
| - if: ${{ steps.payload-cache.outputs.cache-hit != 'true' && !contains(matrix.target, 'linuxmusl') }} | |
| name: Build target | |
| env: | |
| CC: clang | |
| CXX: clang++ | |
| LDFLAGS: -fuse-ld=lld | |
| run: pnpm --filter @embedpdf/pdf-runtime build:target ${{ matrix.target }} | |
| - if: ${{ steps.payload-cache.outputs.cache-hit != 'true' && contains(matrix.target, 'linuxmusl') }} | |
| name: Build musl target in Alpine | |
| run: | | |
| docker run --rm \ | |
| -v "$GITHUB_WORKSPACE:/workspace" \ | |
| -w /workspace \ | |
| node:22-alpine \ | |
| sh -lc "apk add --no-cache bash cmake clang g++ make python3 curl tar git && corepack enable && pnpm install --frozen-lockfile && pnpm --filter @embedpdf/pdf-runtime build:target ${{ matrix.target }}" | |
| - if: steps.payload-cache.outputs.cache-hit != 'true' | |
| name: Stage payload to cache path | |
| shell: bash | |
| run: | | |
| src="packages/pdf-runtime/npm/${{ matrix.target }}" | |
| dst="packages/pdf-runtime/.cache/payloads/${{ matrix.target }}" | |
| mkdir -p "$dst" | |
| case "${{ matrix.target }}" in | |
| wasm32) | |
| cp "$src/pdfium.js" "$src/pdfium.cjs" "$src/pdfium.wasm" "$dst/" | |
| ;; | |
| win32-*) | |
| cp "$src/pdf-runtime.node" "$src/pdfium.dll" "$dst/" | |
| ;; | |
| *) | |
| cp "$src/pdf-runtime.node" "$dst/" | |
| ;; | |
| esac | |
| - name: Verify payload | |
| shell: bash | |
| run: bash packages/pdf-runtime/scripts/verify-packages.sh ${{ matrix.target }} | |
| - uses: actions/upload-artifact@v6 | |
| with: | |
| name: pdf-runtime-${{ matrix.target }} | |
| path: packages/pdf-runtime/npm/${{ matrix.target }}/ | |
| linux-arm: | |
| name: Linux arm64 + musl | |
| runs-on: ubuntu-24.04-arm | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| target: [linux-arm64, linuxmusl-arm64] | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - if: ${{ !contains(matrix.target, 'linuxmusl') }} | |
| uses: pnpm/action-setup@v5 | |
| with: | |
| version: 10.4.0 | |
| - if: ${{ !contains(matrix.target, 'linuxmusl') }} | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 22 | |
| cache: pnpm | |
| - name: Cache runtime payload | |
| id: payload-cache | |
| uses: actions/cache@v5 | |
| with: | |
| path: packages/pdf-runtime/.cache/payloads/${{ matrix.target }} | |
| key: >- | |
| pdf-runtime-payload-${{ matrix.target }}-${{ hashFiles( | |
| 'packages/pdf-runtime/pdf-runtime-build.json', | |
| 'packages/pdf-runtime/scripts/build-target.sh', | |
| 'packages/pdf-runtime/scripts/fetch-libpdfium.sh', | |
| 'packages/pdf-runtime/build/generate-functions.mjs', | |
| 'packages/pdf-runtime/build/generate-runtime-methods.mjs', | |
| 'packages/pdf-runtime/build/generate-napi-binding.mjs', | |
| 'packages/pdf-runtime/build/CMakeLists.txt', | |
| 'packages/pdf-runtime/build/compile.sh', | |
| 'packages/pdf-runtime/build/compile.esm.sh' | |
| ) }} | |
| - if: steps.payload-cache.outputs.cache-hit == 'true' | |
| name: Restore payload from cache | |
| shell: bash | |
| run: | | |
| mkdir -p "packages/pdf-runtime/npm/${{ matrix.target }}" | |
| cp -R "packages/pdf-runtime/.cache/payloads/${{ matrix.target }}/." \ | |
| "packages/pdf-runtime/npm/${{ matrix.target }}/" | |
| - if: ${{ steps.payload-cache.outputs.cache-hit != 'true' && !contains(matrix.target, 'linuxmusl') }} | |
| run: pnpm install --frozen-lockfile | |
| - if: ${{ steps.payload-cache.outputs.cache-hit != 'true' && !contains(matrix.target, 'linuxmusl') }} | |
| name: Install build tools | |
| run: sudo apt-get update && sudo apt-get install -y cmake clang lld | |
| - if: ${{ steps.payload-cache.outputs.cache-hit != 'true' && !contains(matrix.target, 'linuxmusl') }} | |
| name: Build target | |
| env: | |
| CC: clang | |
| CXX: clang++ | |
| LDFLAGS: -fuse-ld=lld | |
| run: pnpm --filter @embedpdf/pdf-runtime build:target ${{ matrix.target }} | |
| - if: ${{ steps.payload-cache.outputs.cache-hit != 'true' && contains(matrix.target, 'linuxmusl') }} | |
| name: Build musl target in Alpine | |
| run: | | |
| docker run --rm \ | |
| -v "$GITHUB_WORKSPACE:/workspace" \ | |
| -w /workspace \ | |
| node:22-alpine \ | |
| sh -lc "apk add --no-cache bash cmake clang g++ make python3 curl tar git && corepack enable && pnpm install --frozen-lockfile && pnpm --filter @embedpdf/pdf-runtime build:target ${{ matrix.target }}" | |
| - if: steps.payload-cache.outputs.cache-hit != 'true' | |
| name: Stage payload to cache path | |
| shell: bash | |
| run: | | |
| src="packages/pdf-runtime/npm/${{ matrix.target }}" | |
| dst="packages/pdf-runtime/.cache/payloads/${{ matrix.target }}" | |
| mkdir -p "$dst" | |
| cp "$src/pdf-runtime.node" "$dst/" | |
| - name: Verify payload | |
| shell: bash | |
| run: bash packages/pdf-runtime/scripts/verify-packages.sh ${{ matrix.target }} | |
| - uses: actions/upload-artifact@v6 | |
| with: | |
| name: pdf-runtime-${{ matrix.target }} | |
| path: packages/pdf-runtime/npm/${{ matrix.target }}/ | |
| mac: | |
| name: macOS | |
| runs-on: macos-14 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| target: [darwin-arm64, darwin-x64] | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: pnpm/action-setup@v5 | |
| with: | |
| version: 10.4.0 | |
| - uses: actions/setup-node@v6 | |
| with: | |
| node-version: 22 | |
| cache: pnpm | |
| - name: Cache runtime payload | |
| id: payload-cache | |
| uses: actions/cache@v5 | |
| with: | |
| path: packages/pdf-runtime/.cache/payloads/${{ matrix.target }} | |
| key: >- | |
| pdf-runtime-payload-${{ matrix.target }}-${{ hashFiles( | |
| 'packages/pdf-runtime/pdf-runtime-build.json', | |
| 'packages/pdf-runtime/scripts/build-target.sh', | |
| 'packages/pdf-runtime/scripts/fetch-libpdfium.sh', | |
| 'packages/pdf-runtime/build/generate-functions.mjs', | |
| 'packages/pdf-runtime/build/generate-runtime-methods.mjs', | |
| 'packages/pdf-runtime/build/generate-napi-binding.mjs', | |
| 'packages/pdf-runtime/build/CMakeLists.txt', | |
| 'packages/pdf-runtime/build/compile.sh', | |
| 'packages/pdf-runtime/build/compile.esm.sh' | |
| ) }} | |
| - if: steps.payload-cache.outputs.cache-hit == 'true' | |
| name: Restore payload from cache | |
| shell: bash | |
| run: | | |
| mkdir -p "packages/pdf-runtime/npm/${{ matrix.target }}" | |
| cp -R "packages/pdf-runtime/.cache/payloads/${{ matrix.target }}/." \ | |
| "packages/pdf-runtime/npm/${{ matrix.target }}/" | |
| - if: steps.payload-cache.outputs.cache-hit != 'true' | |
| run: pnpm install --frozen-lockfile | |
| - if: steps.payload-cache.outputs.cache-hit != 'true' | |
| name: Build target | |
| run: pnpm --filter @embedpdf/pdf-runtime build:target ${{ matrix.target }} | |
| - if: steps.payload-cache.outputs.cache-hit != 'true' | |
| name: Stage payload to cache path | |
| shell: bash | |
| run: | | |
| src="packages/pdf-runtime/npm/${{ matrix.target }}" | |
| dst="packages/pdf-runtime/.cache/payloads/${{ matrix.target }}" | |
| mkdir -p "$dst" | |
| cp "$src/pdf-runtime.node" "$dst/" | |
| - name: Verify payload | |
| shell: bash | |
| run: bash packages/pdf-runtime/scripts/verify-packages.sh ${{ matrix.target }} | |
| - uses: actions/upload-artifact@v6 | |
| with: | |
| name: pdf-runtime-${{ matrix.target }} | |
| path: packages/pdf-runtime/npm/${{ matrix.target }}/ | |
| win: | |
| name: Windows | |
| runs-on: windows-2022 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| target: [win32-x64, win32-arm64] | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: pnpm/action-setup@v5 | |
| with: | |
| version: 10.4.0 | |
| - uses: actions/setup-node@v6 | |
| with: | |
| node-version: 22 | |
| cache: pnpm | |
| - name: Cache runtime payload | |
| id: payload-cache | |
| uses: actions/cache@v5 | |
| with: | |
| path: packages/pdf-runtime/.cache/payloads/${{ matrix.target }} | |
| key: >- | |
| pdf-runtime-payload-${{ matrix.target }}-${{ hashFiles( | |
| 'packages/pdf-runtime/pdf-runtime-build.json', | |
| 'packages/pdf-runtime/scripts/build-target.sh', | |
| 'packages/pdf-runtime/scripts/fetch-libpdfium.sh', | |
| 'packages/pdf-runtime/build/generate-functions.mjs', | |
| 'packages/pdf-runtime/build/generate-runtime-methods.mjs', | |
| 'packages/pdf-runtime/build/generate-napi-binding.mjs', | |
| 'packages/pdf-runtime/build/CMakeLists.txt', | |
| 'packages/pdf-runtime/build/compile.sh', | |
| 'packages/pdf-runtime/build/compile.esm.sh' | |
| ) }} | |
| - if: steps.payload-cache.outputs.cache-hit == 'true' | |
| name: Restore payload from cache | |
| shell: bash | |
| run: | | |
| mkdir -p "packages/pdf-runtime/npm/${{ matrix.target }}" | |
| cp -R "packages/pdf-runtime/.cache/payloads/${{ matrix.target }}/." \ | |
| "packages/pdf-runtime/npm/${{ matrix.target }}/" | |
| - if: steps.payload-cache.outputs.cache-hit != 'true' | |
| run: pnpm install --frozen-lockfile | |
| - if: steps.payload-cache.outputs.cache-hit != 'true' | |
| name: Build target | |
| shell: bash | |
| run: pnpm --filter @embedpdf/pdf-runtime build:target ${{ matrix.target }} | |
| - if: steps.payload-cache.outputs.cache-hit != 'true' | |
| name: Stage payload to cache path | |
| shell: bash | |
| run: | | |
| src="packages/pdf-runtime/npm/${{ matrix.target }}" | |
| dst="packages/pdf-runtime/.cache/payloads/${{ matrix.target }}" | |
| mkdir -p "$dst" | |
| cp "$src/pdf-runtime.node" "$src/pdfium.dll" "$dst/" | |
| - name: Verify payload | |
| shell: bash | |
| run: bash packages/pdf-runtime/scripts/verify-packages.sh ${{ matrix.target }} | |
| - uses: actions/upload-artifact@v6 | |
| with: | |
| name: pdf-runtime-${{ matrix.target }} | |
| path: packages/pdf-runtime/npm/${{ matrix.target }}/ |