Skip to content

feat(windows): opt-in shared-engine build (php8ts.dll) so extension DLLs load; dev --xdebug on Windows - #564

Merged
luthermonson merged 3 commits into
mainfrom
feat/windows-shared-php
Oct 16, 2026
Merged

luthermonson merged 3 commits into
mainfrom
feat/windows-shared-php

Conversation

@luthermonson

@luthermonson luthermonson commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Builds on #554 (merged). Its php-sdk side, ephpm/php-sdk#73, is merged, and the 8.5.11 release publishes php-sdk-8.5.11-windows-x86_64-shared.tar.gz plus the Windows Xdebug catalog (ephpm-ext-8.5.11-windows-x86_64.tar.gz), so cargo xtask release --target windows --variant shared can download its SDK.

Problem

The Windows build links PHP statically (php8embed.lib). Every PHP extension DLL, php_xdebug.dll included, imports the engine from php8ts.dll, so a static ephpm.exe cannot load any of them. Found while testing: if a foreign php8ts.dll is reachable (cwd/PATH), the static exe loads it as a second engine and segfaults instead of failing cleanly.

Change

Opt-in cargo xtask release --target windows --variant shared:

  • Link: the php-sdk -windows-x86_64-shared SDK (the official windows.php.net ZTS engine). ephpm-php/build.rs detects it from its contents (lib/php8ts.lib, never an env var), links php8embed (static embed SAPI) + php8ts (import lib), skips the static dependency archives, drops ZEND_ENABLE_STATIC_TSRMLS_CACHE (a TLS variable cannot be imported across a DLL boundary; the wrapper goes through tsrm_get_ls_cache()), sets cfg(php_shared), and bakes the SDK manifest's preload list. A shared SDK without ephpm-sdk.json fails the build.
  • Ship: xtask copies the SDK's bin\ (php8ts.dll, the DLLs it and the extensions import, ext\) beside ephpm.exe.
  • Extension parity (crates/ephpm-php/src/shared.rs): the official engine compiles fewer extensions in than the static SDK. The preload list (mbstring, openssl, curl, intl, pdo_mysql, ... and opcache on 8.3/8.4) loads at startup by absolute path from ext\, with extension_dir pointed there so [php] extensions = ["redis"] finds ext\php_redis.dll. Server: first lines of the generated php.ini (ahead of [php] extensions, so operator extensions load after their dependencies, and every operator setting can override). ephpm php: startup -d defines queued before the user's own (so also under -n, like the static build). Missing runtime files fail closed with a message naming the file.
  • ephpm dev --xdebug (feat(dev): ephpm dev --xdebug + Zend-extension support in [php] extensions #554): on a shared build, fetch ephpm-ext-<php>-windows-x86_64.tar.gz from the catalog (manifest libc must be msvc; a missing libc is refused for Windows), cache xdebug-<ver>.dll under %LOCALAPPDATA%, ini path written with /. The static Windows build still refuses, now naming --variant shared. ext_ini::is_zend_extension reads a DLL's PE export table (object pe feature). Also fixes feat(dev): ephpm dev --xdebug + Zend-extension support in [php] extensions #554's bare_names_follow_the_library_in_extension_dir, which failed on Windows (it wrote .so names).
  • xtask: --variant shared validation (Windows x64, GA versions only), -shared asset + cache dir, runtime copy, output path honours CARGO_TARGET_DIR.
  • Docs: xdebug guide (Windows section), install, php-extensions (also fixes its stale "NTS on Windows" row; Windows is ZTS, Windows build: tree says NTS (ZTS=0), shipped binary reports ZTS — build defines, worker clamp and docs all disagree #326), CLI reference, [php] extensions doc comment, CLAUDE.md.

Why static stays the default

Shared is not strictly better:

  • Static is one file; shared is a directory (exe + ~20 DLLs + ext\, ~36 MB) that must stay together.
  • Static is faster on CPU-bound PHP. PHP 8.5.7, interleaved, CLI, OPcache off, same loop: static (v0.11.2 release) 172-188 ms, shared 217-220 ms, stock php.exe 8.5.11 222-244 ms. The shared build runs at stock-PHP speed; the static build is about 20% faster. Startup: 61 ms vs 77 ms per ephpm php -r '' (18 DLL loads).
  • Shared's gains: extension DLLs load (Xdebug, PECL -ts- builds), and zip is present (the static Windows SDK lacks it: 47 vs 49 extensions).

So shared is the debugging / extension build and static the default. Release artifacts are unchanged; publishing a shared Windows artifact from release.yml is a follow-up (CI files untouched here).

Verification (Windows 11, MSVC 14.44, PHP 8.5.7 shared SDK from php-sdk#73's script)

  • cargo xtask release 8.5 --target windows --variant shared: builds and stages the runtime.
  • ephpm php -d zend_extension=C:/.../php_xdebug.dll -v reports with Xdebug v3.5.3, Copyright (c) 2002-2026, by Derick Rethans and with Zend OPcache v8.5.7.
  • Extension parity: a script checking the static set reports missing=[] with 49 loaded, both normally and under -n. mbstring, pdo_sqlite and intl all work.
  • ephpm dev --xdebug with EPHPM_EXT_CATALOG_URL pointed at a local mirror of ext-8.5.7/ephpm-ext-8.5.7-windows-x86_64.tar.gz: downloaded, verified, cached ...\ephpm\ext\20250925-zts-x86_64\xdebug-3.5.3.dll, banner Xdebug 3.5.3 loaded.
  • DBGp step session (PowerShell port of the stand-in client; there is no Windows Python on this host): connected from 127.0.0.1, breakpoint_set on line 4, run gave status=break line=4, stack_get gave #0 {main} line 4, context_get gave $greeting = hello (string) and $n = 42 (int). After resume the HTTP body arrived and Xdebug's stopping packet did not, which is the known deferred request shutdown (fix(php): finish each PHP request when it ends (session hang + cross-tenant teardown) #541).
  • ephpm serve with [php] extensions = ["xdebug"]: the bare name resolves to ext\php_xdebug.dll and loads as zend_extension, and phpversion("xdebug") returns 3.5.3 over HTTP.
  • With ext\ removed: ext is missing. This ephpm was built against the shared PHP engine ..., exit 1.
  • Stub mode: cargo clippy --workspace --all-targets -- -D warnings clean; cargo +nightly fmt --all -- --check clean. Tests: ephpm-php shared::* (6), ephpm ext_ini/dev_xdebug (31, including the new PE-export and Windows catalog tests), xtask (3 new).
  • Linked shared mode: cargo test -p ephpm-php --lib shared passes. A linked-mode clippy on Windows reports only pre-existing findings (kv_bridge, bindgen output, cli_main panics doc), none in new code.

Not done: CI does not build the shared variant (no workflow changes, per the CI freeze). Clustered mode and worker mode were not exercised on the shared build.

Review fixes (rebased onto #554 + main at 5b11f0e)

  • build.rs: rerun-if-changed on lib/php8ts.lib is printed only when the file exists. Cargo treats a missing path as always stale, so before this every PHP-linked build on every platform reran bindgen and the C wrapper. Verified: a second Linux build is now a no-op.
  • Static exe beside php8ts.dll (the known crash): reproduced with the v0.11.3 release exe placed next to a shared runtime: ephpm php -d zend_extension=…xdebug.dll -v exits 0xC0000005. On its own the same exe only prints Failed loading …. Changes:
    • A static cargo xtask release --target windows now removes the php8ts.dll and ext\ that a shared build left in the same output dir.
    • The static Windows build refuses a non-empty [php] extensions at startup.
    • The caveat is documented in install, php-extensions, the xdebug guide, the config reference and doc comment, and CLAUDE.md.
  • ephpm install refuses on a shared build, because it copies only the exe.
  • shared.rs: an unknown exe directory is now an error, never a cwd-relative ext\. Preload file names are restricted to plain file-name characters, because they are baked into a cargo::rustc-env line.
  • PE Zend-extension detection requires both zend_extension_entry and extension_version_info, matching feat(dev): ephpm dev --xdebug + Zend-extension support in [php] extensions #554's ELF/Mach-O rule.
  • Link fix after fix(php): pdo_sqlite serializes under threaded PHP; run it on the SDK's SQLite #563: fix(php): pdo_sqlite serializes under threaded PHP; run it on the SDK's SQLite #563 calls sqlite3_config() when HAVE_SQLITE3 is set. The official engine's config.w32.h sets it, but its SQLite is libsqlite3.dll, which ephpm.exe doesn't link, so the build failed with LNK2019. build.rs now defines EPHPM_PHP_SHARED for the wrapper, which skips the tuning, and tests/sqlite_linkage.rs is gated off on php_shared.

Verification against the published php-sdk#73 assets (Windows 11, MSVC 14.44)

  • cargo xtask release 8.5.7 --target windows --variant shared and the same for 8.5.11 both build. The 8.5.7 SDK cache matched the published php-sdk-8.5.7-windows-x86_64-shared.tar.gz byte for byte, apart from JSON whitespace in ephpm-sdk.json.
  • Extension parity: 49 extensions on 8.5.7 and 50 on 8.5.11, none of the static set missing, with or without -n.
  • ephpm dev --xdebug against the live catalog, fresh %LOCALAPPDATA%, for both versions:
    • downloaded ephpm-ext-<ver>-windows-x86_64.tar.gz from ext-<ver>, then verified and cached xdebug-3.5.3.dll;
    • a DBGp client stopped at line 4 and saw $greeting = hello and $n = 42;
    • resume gave stopping and the HTTP body.
  • ephpm serve with [php] extensions = ["./php_xdebug.dll"]: the DLL is detected via its PE exports and emitted as an escaped absolute zend_extension="C:\…", and phpversion("xdebug") returns 3.5.3.
  • Linked shared tests: ephpm dev_xdebug/ext_ini (37) and ephpm-php shared (6) pass. Stub fmt, clippy, and the tests for ephpm, ephpm-php, xtask and ephpm-config all pass.

@ephpm

ephpm Bot commented Oct 10, 2026

Copy link
Copy Markdown

ePHPm Preview — blocked by the analyze gate 🚫

This PHP preview was not published. ephpm analyze returned quarantine (13 finding(s)) on the pull request's code before it could be served.

ephpm analyze reached the quarantine threshold (exit 2)

Rule Location Message
dangerous-sinks/eval examples/analyze-demo/public/index.php:18 call to eval() — dangerous sink
dangerous-sinks/system examples/analyze-demo/public/index.php:13 call to system() — dangerous sink
obfuscation-scan/eval-of-request examples/analyze-demo/public/index.php:18 eval() argument references request input ($_POST) — executes attacker-controlled data
dangerous-sinks/assert examples/analyze-demo/src/Router.php:9 call to assert() — dangerous sink
obfuscation-scan/dynamic-call examples/kv-redis-predis.php:53 dynamic call via $var() — variable-driven code execution (heuristic)
obfuscation-scan/dynamic-call examples/kv-redis-predis.php:57 dynamic call via $var() — variable-driven code execution (heuristic)
obfuscation-scan/dynamic-call tests/cli-conformance/034-oop-magic.php:42 dynamic call via $var() — variable-driven code execution (heuristic)
obfuscation-scan/dynamic-call tests/cli-conformance/017-generators-closures.php:37 dynamic call via $var() — variable-driven code execution (heuristic)
obfuscation-scan/dynamic-call tests/cli-conformance/017-generators-closures.php:41 dynamic call via $var() — variable-driven code execution (heuristic)
obfuscation-scan/dynamic-call tests/cli-conformance/017-generators-closures.php:46 dynamic call via $var() — variable-driven code execution (heuristic)

Showing 10 of 13 findings.

Fix the findings and push again — the preview redeploys and this comment refreshes automatically.

@ephpm
ephpm Bot had a problem deploying to preview-pr-564 October 10, 2026 23:57 Failure
@ephpm
ephpm Bot had a problem deploying to preview-pr-564 October 10, 2026 23:57 Failure
@ephpm
ephpm Bot had a problem deploying to preview-pr-564 October 10, 2026 23:57 Failure
@luthermonson
luthermonson force-pushed the feat/windows-shared-php branch from a65b8bb to c9f050e Compare October 11, 2026 02:34
@ephpm
ephpm Bot had a problem deploying to preview-pr-564 October 11, 2026 02:34 Failure
@ephpm
ephpm Bot had a problem deploying to preview-pr-564 October 11, 2026 02:34 Failure
@ephpm
ephpm Bot had a problem deploying to preview-pr-564 October 11, 2026 02:35 Failure
@luthermonson

Copy link
Copy Markdown
Contributor Author

Rebased onto #554's new head (136d0f3). The only conflicts were in dev_xdebug.rs and the three docs. CatalogOs now has LinuxGnu, Macos, and Windows, and check() validates both the manifest os and libc. Windows still requires libc: msvc. A Windows catalog checked against a Linux target now fails with OsMismatch rather than LibcMismatch, and the test was updated to match. cargo test -p ephpm dev_xdebug passes (28 tests), and clippy and fmt are clean on Windows.

@luthermonson
luthermonson force-pushed the feat/windows-shared-php branch from c9f050e to a5388b8 Compare October 11, 2026 03:25
@ephpm
ephpm Bot had a problem deploying to preview-pr-564 October 11, 2026 03:26 Failure
@ephpm
ephpm Bot had a problem deploying to preview-pr-564 October 11, 2026 03:26 Failure
@ephpm
ephpm Bot had a problem deploying to preview-pr-564 October 11, 2026 03:26 Failure
@luthermonson
luthermonson force-pushed the feat/dev-xdebug branch 3 times, most recently from e7489a1 to 2706a35 Compare October 13, 2026 18:11
@luthermonson
luthermonson force-pushed the feat/windows-shared-php branch from a5388b8 to 36821fc Compare October 13, 2026 18:51
@ephpm
ephpm Bot had a problem deploying to preview-pr-564 October 13, 2026 18:51 Failure
@ephpm
ephpm Bot had a problem deploying to preview-pr-564 October 13, 2026 18:51 Failure
@ephpm
ephpm Bot had a problem deploying to preview-pr-564 October 13, 2026 18:51 Failure
@luthermonson
luthermonson force-pushed the feat/windows-shared-php branch from 36821fc to 6ed487a Compare October 16, 2026 12:30
@luthermonson
luthermonson changed the base branch from feat/dev-xdebug to main October 16, 2026 12:30
…LLs load; dev --xdebug on Windows

The Windows build links PHP statically (php8embed.lib). Every PHP extension
DLL, php_xdebug.dll included, imports the engine from php8ts.dll, so a
static ephpm.exe cannot load any of them (and if a foreign php8ts.dll is
reachable it loads a second engine and crashes).

`cargo xtask release --target windows --variant shared` links the php-sdk
`-windows-x86_64-shared` SDK instead: the official windows.php.net ZTS
engine (php8ts.dll + php8ts.lib + its small static php8embed.lib), and
copies the SDK's bin\ (php8ts.dll, dependency DLLs, ext\) beside ephpm.exe.

- ephpm-php/build.rs: the SDK is detected as shared from its contents
  (lib/php8ts.lib), never an env var: links php8embed (static) + php8ts
  (dylib), no static dep archives, drops ZEND_ENABLE_STATIC_TSRMLS_CACHE
  (a TLS variable cannot be imported across a DLL), sets cfg php_shared and
  bakes ephpm-sdk.json's `preload` list. A shared SDK without the manifest
  fails the build.
- ephpm-php/src/shared.rs: the official engine compiles fewer extensions in
  than the static SDK; the preload list (mbstring, openssl, curl, intl,
  pdo_mysql, ... opcache on 8.3/8.4) is loaded at startup by absolute path
  from ext\ beside the exe, with extension_dir pointed there. Server: first
  in the generated php.ini (before [php] extensions). `ephpm php`: as startup
  -d defines before the user's (so also under -n). Missing runtime files
  fail closed with a message naming the file.
- dev --xdebug: on a shared build, fetch the catalog's
  ephpm-ext-<php>-windows-x86_64.tar.gz (manifest libc "msvc", required),
  cache xdebug-<ver>.dll; the static Windows build still refuses, now
  pointing at --variant shared. ext_ini detects zend_extension_entry in a
  DLL's PE export table. #554's bare-name test now uses the platform's file
  names (it failed on Windows).
- xtask: --variant shared (Windows x64, GA versions), own cache dir and
  asset name, runtime copy, honours CARGO_TARGET_DIR for the output path.

Static stays the default: single file, and ~20% faster on a CPU-bound loop
(173-188 ms vs 217-220 ms, PHP 8.5.7, same as stock php.exe).

Verified on Windows 11 with PHP 8.5.7: `ephpm php -d zend_extension=... -v`
reports "with Xdebug v3.5.3"; 49 extensions loaded, none of the static set
missing; `ephpm dev --xdebug` fetched the Windows catalog tarball from a
local mirror, verified and cached it, and a DBGp client stopped on a line
breakpoint, read stack and locals, resumed, and got the HTTP response.
- build.rs: watch lib/php8ts.lib only when it exists; a missing
  rerun-if-changed path is always stale and reran bindgen + the C wrapper
  on every PHP-linked build on every platform.
- xtask: a static Windows release removes the php8ts.dll and ext\ an
  earlier --variant shared build left in the same output directory. The
  static exe beside a php8ts.dll crashes (0xC0000005) when asked to load an
  extension DLL: Windows binds the DLL to that second engine.
- The static Windows build refuses a non-empty [php] extensions at startup
  instead of loading nothing or crashing.
- ephpm install refuses on a shared build (it copies only the exe).
- shared.rs: an unknown executable directory is an error, never a
  cwd-relative ext\; preload file names are restricted to plain file-name
  characters in build.rs and parse_preload (they are baked into a
  cargo::rustc-env line).
- Zend-extension detection on PE requires both zend_extension_entry and
  extension_version_info, matching ELF/Mach-O.
- dev_xdebug: the refuse-test skips on a linked shared build; Windows-aware
  cache-dir and --xdebug-path messages.
- Docs: the static-exe crash caveat (install, php-extensions, xdebug guide,
  config reference/doc comment, CLAUDE.md).
#563 calls sqlite3_config() at module startup when HAVE_SQLITE3 is set and
neither SQLite extension is a DLL. The official engine's config.w32.h sets
HAVE_SQLITE3, but there sqlite3/pdo_sqlite are DLLs and SQLite is
libsqlite3.dll, which ephpm.exe does not link, so the shared build failed
with LNK2019 sqlite3_config. build.rs now defines EPHPM_PHP_SHARED for the
wrapper, which skips the tuning there; tests/sqlite_linkage.rs (which calls
sqlite3_* directly) is gated off on php_shared.
@luthermonson
luthermonson force-pushed the feat/windows-shared-php branch from 6ed487a to 43ae54c Compare October 16, 2026 13:41
@luthermonson
luthermonson merged commit 4f35f8e into main Oct 16, 2026
12 checks passed
@luthermonson
luthermonson deleted the feat/windows-shared-php branch October 16, 2026 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant