|
| 1 | +name: "PHP extension" |
| 2 | + |
| 3 | +# Builds the secretspec-php-native PHP extension (ext-php-rs) as a prebuilt |
| 4 | +# shared object for each supported PHP minor x platform, smoke tests that it |
| 5 | +# loads and registers its functions, and on a version tag attaches the binaries |
| 6 | +# to the GitHub Release. |
| 7 | +# |
| 8 | +# DISTRIBUTION STATUS (see RELEASE.md): this builds and publishes prebuilt |
| 9 | +# extension binaries. Installing them is documented in the PHP SDK docs |
| 10 | +# (download + `extension=`, or `docker-php-ext-enable`, or build from source with |
| 11 | +# cargo). A one-command PIE install is a follow-up: PIE builds non-Windows |
| 12 | +# extensions from source via phpize, which does not apply to a Cargo/ext-php-rs |
| 13 | +# extension, so the prebuilt-binary path here is what is validated. |
| 14 | +# |
| 15 | +# The SDK itself is exercised on every PR by the devenv-based sdks.yml (both the |
| 16 | +# extension and the ext-ffi fallback); this workflow only builds the |
| 17 | +# distributable extension binaries. |
| 18 | + |
| 19 | +on: |
| 20 | + workflow_dispatch: |
| 21 | + push: |
| 22 | + tags: |
| 23 | + - v** |
| 24 | + pull_request: |
| 25 | + paths: |
| 26 | + - "secretspec-php/**" |
| 27 | + - ".github/workflows/php-ext.yml" |
| 28 | + |
| 29 | +jobs: |
| 30 | + build: |
| 31 | + name: php-${{ matrix.php }}-${{ matrix.target }} |
| 32 | + runs-on: ${{ matrix.runner }} |
| 33 | + permissions: |
| 34 | + contents: write # attach binaries to the release (tag runs only) |
| 35 | + strategy: |
| 36 | + fail-fast: false |
| 37 | + matrix: |
| 38 | + # Full php x target cross-product: the `include` entries share the |
| 39 | + # `target` key with the axis, so they merge in the runner (rather than |
| 40 | + # creating standalone combinations). Non-thread-safe (NTS) is the default |
| 41 | + # CLI/FPM build. 8.1 is omitted (end of life). Windows and ZTS builds are |
| 42 | + # a follow-up (ext-php-rs on Windows needs the PHP SDK dev pack + rust-lld; |
| 43 | + # Windows users can use the ext-ffi backend meanwhile). |
| 44 | + php: ["8.2", "8.3", "8.4"] |
| 45 | + target: |
| 46 | + - x86_64-unknown-linux-gnu |
| 47 | + - aarch64-unknown-linux-gnu |
| 48 | + - aarch64-apple-darwin |
| 49 | + include: |
| 50 | + - { target: x86_64-unknown-linux-gnu, runner: ubuntu-latest } |
| 51 | + - { target: aarch64-unknown-linux-gnu, runner: ubuntu-24.04-arm } |
| 52 | + - { target: aarch64-apple-darwin, runner: macos-latest } |
| 53 | + |
| 54 | + steps: |
| 55 | + - uses: actions/checkout@v5 |
| 56 | + |
| 57 | + - name: Set up PHP ${{ matrix.php }} |
| 58 | + uses: shivammathur/setup-php@v2 |
| 59 | + with: |
| 60 | + php-version: ${{ matrix.php }} |
| 61 | + # php-config + headers, needed by ext-php-rs's build. |
| 62 | + tools: none |
| 63 | + env: |
| 64 | + # Ensure the dev headers are available for the build. |
| 65 | + phpts: nts |
| 66 | + |
| 67 | + - name: Install Linux build dependencies (clang for bindgen, dbus for keyring) |
| 68 | + if: runner.os == 'Linux' |
| 69 | + run: sudo apt-get update && sudo apt-get install -y llvm-dev libclang-dev clang libdbus-1-dev pkg-config |
| 70 | + |
| 71 | + - name: Install Rust (pinned by rust-toolchain.toml) |
| 72 | + run: rustup toolchain install |
| 73 | + |
| 74 | + - name: Build the extension |
| 75 | + # Each runner is the target's native arch, so a plain release build emits |
| 76 | + # the target's binary (no cross-compilation). |
| 77 | + run: cargo build --release -p secretspec-php-native |
| 78 | + |
| 79 | + - name: Stage the extension under its distribution name |
| 80 | + id: stage |
| 81 | + shell: bash |
| 82 | + run: | |
| 83 | + set -euo pipefail |
| 84 | + case "$(uname -s)" in |
| 85 | + Darwin) built="libsecretspec_php_native.dylib" ;; |
| 86 | + *) built="libsecretspec_php_native.so" ;; |
| 87 | + esac |
| 88 | + # dlopen resolves by path, not suffix, so the macOS .dylib ships as .so. |
| 89 | + asset="secretspec-php-native-${{ matrix.php }}-nts-${{ matrix.target }}.so" |
| 90 | + cp "target/release/$built" "$asset" |
| 91 | + echo "asset=$asset" >> "$GITHUB_OUTPUT" |
| 92 | +
|
| 93 | + - name: Smoke test (load the extension, check it registers) |
| 94 | + # Every row builds natively, so the runner can load what it built. |
| 95 | + shell: bash |
| 96 | + run: | |
| 97 | + php -d extension="$PWD/${{ steps.stage.outputs.asset }}" -r ' |
| 98 | + assert(function_exists("secretspec_native_resolve")); |
| 99 | + assert(function_exists("secretspec_native_abi_version")); |
| 100 | + echo secretspec_native_abi_version(), PHP_EOL; |
| 101 | + ' |
| 102 | +
|
| 103 | + - uses: actions/upload-artifact@v4 |
| 104 | + with: |
| 105 | + name: php-ext-${{ matrix.php }}-${{ matrix.target }} |
| 106 | + path: ${{ steps.stage.outputs.asset }} |
| 107 | + |
| 108 | + - name: Publish extension to the release |
| 109 | + if: startsWith(github.ref, 'refs/tags/v') |
| 110 | + shell: bash |
| 111 | + env: |
| 112 | + GH_TOKEN: ${{ github.token }} |
| 113 | + run: | |
| 114 | + set -euo pipefail |
| 115 | + asset="${{ steps.stage.outputs.asset }}" |
| 116 | + if command -v sha256sum >/dev/null; then sha256sum "$asset" > "$asset.sha256" |
| 117 | + else shasum -a 256 "$asset" > "$asset.sha256"; fi |
| 118 | + # cargo-dist's release.yml creates the release for this tag; wait for it. |
| 119 | + for _ in $(seq 1 30); do |
| 120 | + gh release view "${GITHUB_REF_NAME}" >/dev/null 2>&1 && break || sleep 20 |
| 121 | + done |
| 122 | + gh release upload "${GITHUB_REF_NAME}" "$asset" "$asset.sha256" --clobber |
0 commit comments