Repository navigation
feat(windows): opt-in shared-engine build (php8ts.dll) so extension DLLs load; dev --xdebug on Windows - #564
Conversation
|
ePHPm Preview — blocked by the analyze gate 🚫 This PHP preview was not published.
Showing 10 of 13 findings. Fix the findings and push again — the preview redeploys and this comment refreshes automatically. |
a65b8bb to
c9f050e
Compare
|
Rebased onto #554's new head (136d0f3). The only conflicts were in dev_xdebug.rs and the three docs. |
136d0f3 to
7eafd1b
Compare
c9f050e to
a5388b8
Compare
e7489a1 to
2706a35
Compare
a5388b8 to
36821fc
Compare
36821fc to
6ed487a
Compare
2706a35 to
31fbc1f
Compare
…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.
6ed487a to
43ae54c
Compare
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.gzplus the Windows Xdebug catalog (ephpm-ext-8.5.11-windows-x86_64.tar.gz), socargo xtask release --target windows --variant sharedcan download its SDK.Problem
The Windows build links PHP statically (
php8embed.lib). Every PHP extension DLL,php_xdebug.dllincluded, imports the engine fromphp8ts.dll, so a staticephpm.execannot load any of them. Found while testing: if a foreignphp8ts.dllis 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:-windows-x86_64-sharedSDK (the official windows.php.net ZTS engine).ephpm-php/build.rsdetects it from its contents (lib/php8ts.lib, never an env var), linksphp8embed(static embed SAPI) +php8ts(import lib), skips the static dependency archives, dropsZEND_ENABLE_STATIC_TSRMLS_CACHE(a TLS variable cannot be imported across a DLL boundary; the wrapper goes throughtsrm_get_ls_cache()), setscfg(php_shared), and bakes the SDK manifest'spreloadlist. A shared SDK withoutephpm-sdk.jsonfails the build.bin\(php8ts.dll, the DLLs it and the extensions import,ext\) besideephpm.exe.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 fromext\, withextension_dirpointed there so[php] extensions = ["redis"]findsext\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-ddefines 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, fetchephpm-ext-<php>-windows-x86_64.tar.gzfrom the catalog (manifestlibcmust bemsvc; a missinglibcis refused for Windows), cachexdebug-<ver>.dllunder%LOCALAPPDATA%, ini path written with/. The static Windows build still refuses, now naming--variant shared.ext_ini::is_zend_extensionreads a DLL's PE export table (objectpefeature). Also fixes feat(dev): ephpm dev --xdebug + Zend-extension support in [php] extensions #554'sbare_names_follow_the_library_in_extension_dir, which failed on Windows (it wrote.sonames).--variant sharedvalidation (Windows x64, GA versions only),-sharedasset + cache dir, runtime copy, output path honoursCARGO_TARGET_DIR.[php] extensionsdoc comment, CLAUDE.md.Why static stays the default
Shared is not strictly better:
ext\, ~36 MB) that must stay together.php.exe8.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 perephpm php -r ''(18 DLL loads).-ts-builds), andzipis 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.ymlis 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 -vreportswith Xdebug v3.5.3, Copyright (c) 2002-2026, by Derick Rethansandwith Zend OPcache v8.5.7.missing=[]with 49 loaded, both normally and under-n. mbstring, pdo_sqlite and intl all work.ephpm dev --xdebugwithEPHPM_EXT_CATALOG_URLpointed at a local mirror ofext-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, bannerXdebug 3.5.3 loaded.breakpoint_seton line 4,rungavestatus=break line=4,stack_getgave#0 {main} line 4,context_getgave$greeting = hello (string)and$n = 42 (int). After resume the HTTP body arrived and Xdebug'sstoppingpacket 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 servewith[php] extensions = ["xdebug"]: the bare name resolves toext\php_xdebug.dlland loads aszend_extension, andphpversion("xdebug")returns 3.5.3 over HTTP.ext\removed:ext is missing. This ephpm was built against the shared PHP engine ..., exit 1.cargo clippy --workspace --all-targets -- -D warningsclean;cargo +nightly fmt --all -- --checkclean. Tests:ephpm-php shared::*(6),ephpm ext_ini/dev_xdebug(31, including the new PE-export and Windows catalog tests),xtask(3 new).cargo test -p ephpm-php --lib sharedpasses. A linked-mode clippy on Windows reports only pre-existing findings (kv_bridge, bindgen output,cli_mainpanics 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)
rerun-if-changedonlib/php8ts.libis 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.ephpm php -d zend_extension=…xdebug.dll -vexits0xC0000005. On its own the same exe only printsFailed loading …. Changes:cargo xtask release --target windowsnow removes thephp8ts.dllandext\that a shared build left in the same output dir.[php] extensionsat startup.ephpm installrefuses on a shared build, because it copies only the exe.ext\. Preload file names are restricted to plain file-name characters, because they are baked into acargo::rustc-envline.zend_extension_entryandextension_version_info, matching feat(dev): ephpm dev --xdebug + Zend-extension support in [php] extensions #554's ELF/Mach-O rule.sqlite3_config()whenHAVE_SQLITE3is set. The official engine'sconfig.w32.hsets it, but its SQLite islibsqlite3.dll, which ephpm.exe doesn't link, so the build failed with LNK2019. build.rs now definesEPHPM_PHP_SHAREDfor the wrapper, which skips the tuning, andtests/sqlite_linkage.rsis gated off onphp_shared.Verification against the published php-sdk#73 assets (Windows 11, MSVC 14.44)
cargo xtask release 8.5.7 --target windows --variant sharedand the same for8.5.11both build. The 8.5.7 SDK cache matched the publishedphp-sdk-8.5.7-windows-x86_64-shared.tar.gzbyte for byte, apart from JSON whitespace inephpm-sdk.json.-n.ephpm dev --xdebugagainst the live catalog, fresh%LOCALAPPDATA%, for both versions:ephpm-ext-<ver>-windows-x86_64.tar.gzfromext-<ver>, then verified and cachedxdebug-3.5.3.dll;$greeting = helloand$n = 42;stoppingand the HTTP body.ephpm servewith[php] extensions = ["./php_xdebug.dll"]: the DLL is detected via its PE exports and emitted as an escaped absolutezend_extension="C:\…", andphpversion("xdebug")returns 3.5.3.ephpmdev_xdebug/ext_ini (37) andephpm-phpshared (6) pass. Stub fmt, clippy, and the tests for ephpm, ephpm-php, xtask and ephpm-config all pass.