Getting Windows Embed Working#1079
Conversation
|
Hi @crazywhalecc this is a bit of a big PR and I'm not even sure if you have hardware to even test this. I can tell you that I have a github workflow that looks like this which I used my personal windows runner with these changes to SPC and it popped out perfectly fine windows binaries that I was able to embed. I haven't tested the output yet thoroughly, so please review for now but hold off on merging until I come back to you after I've tested the binaries a little more thoroughly. |
- Fix php-cs-fixer style issues (single-quote escapes, pre-increment) - Add secur32.lib to LDFLAGS for php8ts.dll (curl SSPI support) - Strip removed libxml2 symbols from .def by scanning headers - Respect #ifdef LIBXML_*_ENABLED guards for disabled features - Two-step archive extraction using Windows native tar
|
Embarrassingly, I have already implemented the Windows embed SAPI in v3 version and fixed several old Windows issues such as tar.exe, sdk wrapper things, single-core build process. Therefore, I'm not sure how much sense it would make to implement it in v2. However, the release of v3 is still some time away, and I haven't ported all the v2 features and extensions yet. |
|
your call, this is working for me today. i dont know this project well only just getting into it this weekend and thought i was helping out. merge it if you want it, i can run my fork if you dont. |
|
https://github.com/crazywhalecc/static-php-cli/blob/v3/src/SPC/builder/windows/WindowsBuilder.php#L192-L201 v3 showing this as TODO as well, not that i knew to look for it before putting this up as I didn't know a v3 was coming. you have it in a branch some where? can i compare implementations? |
|
v3 version is totally refactored and all of APIs and implementations except shell commands are different from v2. It's now under development branch and in different src directory Merging sequence: Most of the updates for version 3 are described in the PR with RFCs that are still open; you can check the issue list. I apologize that now is an awkward time, but I'd prefer you to either keep using your fork or participate adding new features to v3. We now welcome any new feature requests on v3. |
|
No worries at all I have what I need for now, I'll keep playing with fork and when you get V3 working better I will migrate |
Add Windows embed SAPI support & fix archive extraction
Embed SAPI (WindowsBuilder.php)
Implements the buildEmbed() method that was previously stubbed out with a TODO. Windows can now build php8embed.lib and php8embed.dll via --build-embed.
What changed:
Archive extraction fix (FileSystem.php)
Fixes extractArchive() on Windows where the 7za-to-tar pipe breaks with "The pipe has been ended" for large archives.
Root cause: Windows pipes are unreliable for high-throughput streaming between processes. Additionally, MinGW tar (from Git usr/bin on PATH) gets picked up instead of Windows native tar and can't parse C:\ drive letter paths.
Fix: Replace the single piped command with two-step extraction:
Only affects the Windows code path. Linux/macOS extraction is unchanged.
libxml2 2.14+ compatibility (SourcePatcher.php)
Fixes unresolved external symbol errors when linking php8ts.dll with libxml2 >= 2.14.
Root cause: libxml2 2.14 removed many deprecated APIs -- xmlUCSIs* (Unicode block classification), xmlNanoFTP*, xmlNanoHTTP*, xmlShell*, and ~100 other legacy functions. PHP's static ext/libxml/php_libxml2.def still lists all of these as DLL exports. On Windows, the .def file makes every listed symbol a hard linker requirement -- if the symbol doesn't exist in any linked library, the build fails. Linux/macOS are unaffected because they don't use .def files.
This affects all PHP versions (8.2 through 8.5) when built against libxml2 >= 2.14.
Fix: Added patchLibxml2DefForWindows() to SourcePatcher, called from patchBeforeMake() on Windows builds. Rather than maintaining a blocklist of removed symbol prefixes, it scans the installed libxml2 headers (buildroot/include/libxml2/libxml/*.h) for XMLPUBFUN and XMLPUBVAR declarations -- the macros libxml2 uses to mark its entire public API. Any .def entry that doesn't have a matching symbol in the headers is stripped.
This approach is future-proof -- it handles any combination of PHP and libxml2 versions without needing updates as libxml2 continues to deprecate APIs. It also works in plain PHP context without needing Visual Studio tools like dumpbin on PATH.
Checklist before merging
*.phpor*.json, run them locally to ensure your changes are valid:composer cs-fixcomposer analysecomposer testbin/spc dev:sort-configsrc/globals/test-extensions.php.extension testortest extensionsto trigger full test suite.