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.6-py3-none-win_amd64.whl (4.9 MB view details)

Uploaded Python 3Windows x86-64

static_php_build-0.1.6-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.6-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.6-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.6-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.6-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for static_php_build-0.1.6-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 386a9e9a4f9630a8961564ed33317f806966615f7776b3ff2ac40f01dad92c27
MD5 93838e74c57cddc56421ec90afbe9f07
BLAKE2b-256 e8f01e5d2df28350e4867ec62cfcbe835dccdd788faee60461ca9108dea88b13

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for static_php_build-0.1.6-py3-none-manylinux_2_17_x86_64.musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 77aa5279c3d7d092445800046087aab6f5e1cd7d5d90c3ec0fdfc0b48cd08c9e
MD5 0a09d39cd37b01ac53eb3b83cb0ebf63
BLAKE2b-256 f3d052b5a01f6e3b7ab345eb63ca00e4434eb6aeb2910ef1920733d2a55c5a06

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for static_php_build-0.1.6-py3-none-manylinux_2_17_aarch64.musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 fcc11b87e80babf35425403c051cf43ee7253e5bc73f94ff2a3384fbbb56c23d
MD5 5fff685a521ea21d14f0e98a12a65797
BLAKE2b-256 ead2bb2fbdbf7110991f533a995eb69ee9f123a9d149369dd9c6ae8aafd65143

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for static_php_build-0.1.6-py3-none-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 01a972fdeebc825924db618bfd0a0c015ef71da92c3d56cdb02620e4a1d54351
MD5 638d12fb0f515ff4906cb312bc30b3ca
BLAKE2b-256 d2c92864d0dd3ebdf31dc079b6c332cd8b5a00d3a85ac73ce1c636786f996a71

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for static_php_build-0.1.6-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1398179958ad5631345c0777c89d2f13ebf54ba5b43aa58224a38cc879ce6d97
MD5 34d8914e3ae574d36b3ecc734f840eeb
BLAKE2b-256 cc2c979186b41849da949a9bdec5df045392ad10cb6db6b13461bff032c3af8f

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