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

Uploaded Python 3Windows x86-64

static_php_build-0.2.0-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.2.0-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.2.0-py3-none-macosx_11_0_x86_64.whl (5.0 MB view details)

Uploaded Python 3macOS 11.0+ x86-64

static_php_build-0.2.0-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.2.0-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for static_php_build-0.2.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 19708fa21a868bb4f38ccc1051cb78a186b40baa6673aeb55eb2b883fe1c62e5
MD5 b08f39d6d107bab82d3e8e0fa5e9bb69
BLAKE2b-256 1b11c3261bc0642974d7cf1e96c3f962d1d89ed998362943311878e9149c952e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for static_php_build-0.2.0-py3-none-manylinux_2_17_x86_64.musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 f37cb72c01bb6e988f9fcc1015941e9f41b4a351185ae6fd2a1e85034c9d6f84
MD5 b00958515c00833c7fcbca765a33f53f
BLAKE2b-256 cdd2d9db63a19c44118aa2343ceb84de60cb09b00dd079ed026a92eb09bbe78f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for static_php_build-0.2.0-py3-none-manylinux_2_17_aarch64.musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 3a337b01516ddbc27f8fdca96dd31f3eaa0b7e8940fa145bdefe7a51390a8b21
MD5 1ebb08466c1d7ec7c0ea7b17690256e2
BLAKE2b-256 373fddea6ce31f02d7a6530595cf78c02c430c3007288e9e89949f0d71297acd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for static_php_build-0.2.0-py3-none-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 b63d9e9460ba958712f1937ba0e76257fc27d13b360dd493182c21e786046252
MD5 a22688a7556d09166020f15b8b2044ef
BLAKE2b-256 c9d054e400bcd0a8ada2c0c639827d35d2183dee013bac7620c236947d0fd772

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for static_php_build-0.2.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bf9f696284e2b29801547f8434ed23cd7ca2c2fd2317778300136a272399aea8
MD5 c10be1769bea5e6edd3dbe822747aed6
BLAKE2b-256 6b0afde4dcc98b6cf1a71d060f60310a0f07b88e9f3bb662e88737a7bff954c6

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