Skip to main content

Independent build tool producing a host PHP binary via static-php-cli

Project description

static-php-build

Bake the PHP extensions you need into a portable host binary, once, at packaging time.

Produce a host PHP binary loading a required extension set by driving static-php-cli (spc).

Install

pip install static-php-build

A build-time / development dependency, not a runtime dependency of a consumer's end users. spc compilers are bundled per host platform; hosts without a bundled spc supply one via --spc PATH.

Usage

# Build a host PHP binary loading the given extensions, write it to ./php
static-php-build --extensions tokenizer,mbstring --out ./php

# Read the required set from the consumer's requirement declaration instead
static-php-build --manifest your_lib:REQUIREMENTS --out ./php

# Pin the PHP version, and forward unmodeled spc options after the `--` separator
static-php-build --extensions tokenizer --out ./php --with-php 8.4 -- --enable-zts

# Use an explicit spc on a host without a bundled one
static-php-build --extensions tokenizer --spc /path/to/spc --out ./php
from static_php_build import BuildRequest, build

report = build(BuildRequest(extensions=["tokenizer", "mbstring"], out="./php"))
print(report.satisfied, report.missing)

Each invocation builds for the host it runs on, so cross-OS coverage means one CI job per OS. A minimal GitHub Actions matrix:

jobs:
  build-php:
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
    runs-on: ${{ matrix.os }}
    steps:
      - run: pipx run static-php-build --extensions tokenizer,mbstring --with-php 8.4 --out dist/php
      - uses: actions/upload-artifact@v4
        with:
          name: php-${{ matrix.os }}
          path: dist/php*

The tool verifies each produced binary via its own php -m read; a non-CLI artifact fails verification and raises. The handoff to static-php-py is the produced binary on disk, loaded at runtime through PHP.local. Full workflow (bundling the artifacts into per-OS wheels): ../../docs/llms/bundling-pipeline.md.

API

Command

static-php-build (--extensions NAMES | --manifest MODULE:ATTR) [--out PATH] [--spc PATH] [--with-php VERSION] [-- <spc args>]

  • --extensions — the required set as comma-separated extension names.
  • --manifestMODULE:ATTR naming an importable object exposing extensions (a consumer's Requirements constant); exactly one of --extensions and --manifest is required.
  • --out — file path receives the binary; directory path receives php/php.exe inside it. Omitted: ./php (./php.exe on Windows).
  • --spc — explicit spc binary; supersedes the bundled spc for the run.
  • --with-php — major.minor PHP version pinned on spc's download step. Omitted: spc default.
  • -- <spc args> — forwarded to spc's build step verbatim; the tool's own flags are never forwarded.
  • Exit codes: 0 success, 1 runtime failure (BuildError), 2 misuse (no extension set resolvable).

Function

build(request: BuildRequest | None = None) -> ExtensionReport

Produces a host binary loading the required extensions, verifies it, writes it to the destination, and returns the report.

  • BuildRequest — frozen data holder grouping the build inputs: extensions, manifest, out, spc, php_version, spc_args, timeout. Exactly one of extensions and manifest names the required set.
  • ExtensionReport — frozen data holder: required, loaded, missing, satisfied.

Exceptions

  • BuildError — base (distinct from static-php-py's PHPError).
  • ProvisioningError — spc download/build failed, output binary absent, or a required extension is missing.
  • UnsupportedHostError — no bundled spc for the host and no --spc supplied; names --spc as the remedy.

Full design: docs/design.md. Concepts: docs/concept.md. Doc index: docs/index.md.

For Agents

Agent-consumable documentation index at ../../docs/llms.txt (llmstxt.org format).

Citation

If you use this project in academic work, cite our paper. BibTeX (placeholder until the paper is released):

@misc{static_php_py_placeholder,
  title  = {{TODO: paper title — not yet released}},
  author = {{TODO: authors}},
  year   = {{TODO}},
  note   = {Paper not yet released. Citation entry will be updated on publication.}
}

License

GPL-2.0 — see LICENSE. Built binaries are produced by static-php-cli.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

static_php_build-0.1.5-py3-none-win_amd64.whl (4.9 MB view details)

Uploaded Python 3Windows x86-64

static_php_build-0.1.5-py3-none-manylinux_2_17_x86_64.musllinux_1_1_x86_64.whl (4.2 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64musllinux: musl 1.1+ x86-64

static_php_build-0.1.5-py3-none-manylinux_2_17_aarch64.musllinux_1_1_aarch64.whl (4.3 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64musllinux: musl 1.1+ ARM64

static_php_build-0.1.5-py3-none-macosx_11_0_x86_64.whl (5.0 MB view details)

Uploaded Python 3macOS 11.0+ x86-64

static_php_build-0.1.5-py3-none-macosx_11_0_arm64.whl (4.9 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

Details for the file static_php_build-0.1.5-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for static_php_build-0.1.5-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 cb040d426528e9de661dca448bbdf2932ea9ca6e4baa1c374a120601b6b0ce45
MD5 efbfbd31eaf992ba78a1cbfa2192c381
BLAKE2b-256 d15abc1021df1886f81bc7426e2c120782265c0304b54e0a4c8aa2e01ead4e9b

See more details on using hashes here.

File details

Details for the file static_php_build-0.1.5-py3-none-manylinux_2_17_x86_64.musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for static_php_build-0.1.5-py3-none-manylinux_2_17_x86_64.musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 78f4e7ba1dc614fd5bec7555ea429740c7dff7069f2615c2d6c8ef260ef29151
MD5 e5220ba4b15d3951976a7ea12c1a51cd
BLAKE2b-256 a632a9436aba4eb1bf5e5adefcc9f6a604d82fe529e8a0e65aafa0a4cc0dbfa0

See more details on using hashes here.

File details

Details for the file static_php_build-0.1.5-py3-none-manylinux_2_17_aarch64.musllinux_1_1_aarch64.whl.

File metadata

File hashes

Hashes for static_php_build-0.1.5-py3-none-manylinux_2_17_aarch64.musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 d8b5f249ae9fad60eff30fe7d08fd5e0ed85241e8d76f008675c133397c9e940
MD5 8e26624f7d77b7d3b1775f6f70f0ae38
BLAKE2b-256 4cc25ac5843169fc2722445d57e27ca42fc901df8831c82e69e5a03f30bf1a71

See more details on using hashes here.

File details

Details for the file static_php_build-0.1.5-py3-none-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for static_php_build-0.1.5-py3-none-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 21e2001e0de344b0683df30973fa8369b3b940256c99177a906ea58407c151d1
MD5 86d2a21cea899a2f708be6f45db5414e
BLAKE2b-256 89dab9ab1c52bb863b77ad67cc6fed7681d784e0c02b521f7a84467c63eb6be3

See more details on using hashes here.

File details

Details for the file static_php_build-0.1.5-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for static_php_build-0.1.5-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3ebafc8f207b9aca5b7b2d948d57538f6660bb558c95e47f961543351b0d95ef
MD5 5adff568a05118cd51531e2c3d7c0db3
BLAKE2b-256 504b6321055c96f171604f7182def01713124653098627df7289d756bae5f294

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page