Skip to content

[PHP] Add php-wasm extension compile helper - #3546

Closed
adamziel wants to merge 3 commits into
trunkfrom
codex/compile-extension-helper
Closed

[PHP] Add php-wasm extension compile helper#3546
adamziel wants to merge 3 commits into
trunkfrom
codex/compile-extension-helper

Conversation

@adamziel

@adamziel adamziel commented Apr 28, 2026

Copy link
Copy Markdown
Collaborator

What it does

Adds @php-wasm/compile-extension, a Docker-backed CLI for compiling phpize extension source into PHP.wasm side modules across a PHP version x async mode matrix.

npx @php-wasm/compile-extension \
  --source ./ext-src \
  --name wp_mysql_parser \
  --php-versions 8.1,8.2,8.3,8.4 \
  --async-modes jspi,asyncify \
  --out ./dist

It writes artifacts like wp_mysql_parser-php8.3-jspi.so plus manifest.json, and adds loadExtension({ manifestUrl }) in @php-wasm/universal to pick, fetch, verify, install, and register the matching artifact at runtime.

The README now also documents dependency-backed extensions: Playground-built libraries, vendored non-Playground libraries, CMake dependencies, and plain Makefile dependencies.

Rationale

Extension authors currently have to rediscover the right phpize, Emscripten side-module, JSPI, and Asyncify flags. The CLI gives them one command and one publishable dist/ directory.

Dependencies are the sharp edge: a PHP.wasm side module can only link WebAssembly objects built with the same Emscripten toolchain and async mode. The docs call out that native host libraries from /usr/lib, Homebrew, apt, or npm packages cannot be linked into the .so.

Implementation

Adds packages/php-wasm/compile-extension with CLI parsing, matrix orchestration, Docker image selection, manifest writing with SHA-256 hashes, and config.m4 extension-name detection.

The canonical container recipe runs:

phpize
emconfigure ./configure --enable-<name>
emmake make

Side modules are built with -sSIDE_MODULE=1, -sWASM_BIGINT, -fPIC, -O2, and the matching async flags for jspi or asyncify.

Dependency archives passed through --extra-ldflags are kept out of configure-time LDFLAGS, then force-linked into the final side module with --whole-archive. That lets extensions link WebAssembly .a files without breaking Autoconf compiler smoke tests.

The README includes the author workflow for CMake dependencies:

emcmake cmake \
  -S vendor/libfoo \
  -B vendor/libfoo/build \
  -DCMAKE_INSTALL_PREFIX="$PWD/vendor/libfoo/install" \
  -DBUILD_SHARED_LIBS=OFF
emmake cmake --build vendor/libfoo/build --target install

npx @php-wasm/compile-extension \
  --source . \
  --name my_extension \
  --extra-cflags "-I/build/vendor/libfoo/install/include" \
  --extra-ldflags "/build/vendor/libfoo/install/lib/libfoo.a"

For plain Makefile dependencies, the docs show the same pattern using emmake make, CC=emcc, CXX=em++, AR=emar, and RANLIB=emranlib. The final PHP extension still needs phpize/config.m4; CMake/Make output is treated as dependency code in v1.

loadExtension() fetches manifest.json, matches { phpVersion, asyncMode }, fetches the selected .so, verifies sha256 when present, writes the extension and .ini, and updates PHP_INI_SCAN_DIR.

Testing instructions

Run the focused package checks:

npx nx test php-wasm-compile-extension
npx nx typecheck php-wasm-compile-extension
npx nx lint php-wasm-compile-extension
npx nx build php-wasm-compile-extension

Run the Docker integration test:

npx nx test-compile-extension-integration php-wasm-compile-extension

The integration test builds and loads:

  • a minimal playground_hello extension
  • php-src ext/calendar
  • a zlib_probe extension linked against Playground-built libz
  • external_lib_probe, linked against a vendored non-Playground string-score archive
@adamziel
adamziel force-pushed the codex/compile-extension-helper branch from d98e5b9 to 446b0d2 Compare April 28, 2026 18:08
@adamziel
adamziel changed the base branch from trunk to codex/phpmyadmin-cli-stabilization April 28, 2026 18:09
@adamziel
adamziel force-pushed the codex/compile-extension-helper branch from 446b0d2 to d72542e Compare April 28, 2026 18:21
@adamziel
adamziel force-pushed the codex/phpmyadmin-cli-stabilization branch from e421909 to 7de936f Compare April 28, 2026 18:21
@adamziel
adamziel force-pushed the codex/compile-extension-helper branch 2 times, most recently from c5685a6 to c741c75 Compare April 28, 2026 18:38
@adamziel
adamziel force-pushed the codex/phpmyadmin-cli-stabilization branch from b48e8b7 to 184d0d4 Compare April 28, 2026 18:38
@adamziel
adamziel force-pushed the codex/compile-extension-helper branch from c741c75 to dcbabcf Compare April 28, 2026 19:37
@adamziel
adamziel force-pushed the codex/phpmyadmin-cli-stabilization branch from 184d0d4 to a3cf8e1 Compare April 28, 2026 19:37
@adamziel
adamziel force-pushed the codex/compile-extension-helper branch from dcbabcf to b281fc1 Compare April 28, 2026 19:46
@adamziel
adamziel force-pushed the codex/phpmyadmin-cli-stabilization branch from a3cf8e1 to fbc7354 Compare April 28, 2026 19:46
@adamziel
adamziel force-pushed the codex/compile-extension-helper branch from b281fc1 to 3dc9874 Compare April 28, 2026 22:30
@adamziel
adamziel force-pushed the codex/phpmyadmin-cli-stabilization branch from fbc7354 to 1a24793 Compare April 28, 2026 22:30
@adamziel
adamziel force-pushed the codex/compile-extension-helper branch from 3dc9874 to 05085dd Compare April 28, 2026 22:54
@adamziel
adamziel force-pushed the codex/phpmyadmin-cli-stabilization branch from 1a24793 to 51912e4 Compare April 28, 2026 22:54
Base automatically changed from codex/phpmyadmin-cli-stabilization to trunk April 28, 2026 23:16
@adamziel
adamziel force-pushed the codex/compile-extension-helper branch 3 times, most recently from 22232c3 to ad8b64d Compare April 28, 2026 23:54
@adamziel
adamziel force-pushed the codex/compile-extension-helper branch 2 times, most recently from 91a1130 to badc2a7 Compare April 29, 2026 00:13
@adamziel
adamziel force-pushed the codex/compile-extension-helper branch 5 times, most recently from 604756e to a80f381 Compare April 29, 2026 01:22
@adamziel
adamziel force-pushed the codex/compile-extension-helper branch from a80f381 to 09844a9 Compare April 29, 2026 01:39
@adamziel
adamziel force-pushed the codex/compile-extension-helper branch 8 times, most recently from 0384f94 to 34e6f19 Compare April 29, 2026 09:36
@adamziel
adamziel force-pushed the codex/compile-extension-helper branch from 34e6f19 to f7050e8 Compare April 29, 2026 09:39
@adamziel adamziel changed the title Add php-wasm extension compile helper Apr 29, 2026
@adamziel

Copy link
Copy Markdown
Collaborator Author

Superseded by #3566, which consolidates the extension loader, Blueprint API, compile helper, and bundled extension migration into one trunk-based PR.

@adamziel adamziel closed this Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment