Fix Windows --nano build: include entry declaration header in extension TU - #134
Merged
matyhtf merged 1 commit intoSep 28, 2026
Merged
Conversation
…on TU On Windows, --nano runs in nano-policy mode (nanoMode=false, nanoPolicyMode=true) using the WINDOWS_DLL backend. RINIT then emits a direct C++ call to php_main() instead of relying on ZendVM eval, but the extension translation unit never included the entry function's declaration header, so the php_main() prototype was missing and MSVC failed with C3861. genExtensionIncludeHeaderFiles() only added declaration headers for stub files and attribute-factory owners, never the entry's source file. Include the entry function's declaration header when nano-policy mode is active so php_main() is visible where RINIT references it. Verified: a minimal --nano program now compiles, links and runs on Windows (previously failed at extension-<target>.cc with 'php_main': identifier not found).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
aot-compiler Windows
--nano编译修复结论
--nano在 Windows 上此前无法编译(MSVCC3861: php_main: identifier not found)。根因是代码生成缺口,已修复并提交到分支fix/windows-nano-policy-entry-header(commiteb2f551e),改动仅 1 文件 +14 行。根因(源码级)
--nano在 Windows 走nanoPolicyMode=true+nanoMode=false(即 bin + 策略,WINDOWS_DLL后端),分流点src/Translator.php:499-505(NanoBuildBackend::composesRuntimeSources('Windows')为 false)。src/Translator.php:1865-1881对 Windows--nano直接生成 C++ 调用php_main()(不走 ZendVM 解释main()),但扩展翻译单元(TU)的 includes 由genExtensionIncludeHeaderFiles()组装,只收 stub 文件与 attribute-factory owner 的声明头,入口main()的源文件两者都不是 → 其声明头php_*_decl.h(含extern void php_main();`)从未被包含 → 未声明 → C3861。nano-entry-*.cc(1194-1208,自带 func_decl.h)封装php_main(),逻辑自洽;Windows 这条路径从未打通。修复
在
genExtensionIncludeHeaderFiles()内、nano-policy 模式且存在main()时,把入口函数的声明头加入扩展 TU 的 includes:门控确保:非 nano 构建(无
--nano)完全不受影响;真 Nano(非 Windows)仅多 include 一个纯前向声明头,无副作用。验证
从源码编译(
php bin/tpc.php nano_min.php --nano -o nano_min_src.exe):extension-nano_min_src.cc第 12 行已含php_nano_min_src_nano_min_537d6b1434_decl.h;Build successful: nano_min_src.exe;nano-policy-build-ok(入口php_main()已被正确派发)。源码构建环境要点(Windows):
cl经vcvars64.bat提供 INCLUDE/LIB;Bash 工具禁 cmd,故用 PowerShell 触发 build.bat。PHP_HOME/PHPX_HOME指向 tpc 发行包(如D:/git/php/tpc_v0.9.3_windows_x64)。phpx\build\phpx.dll(发行包该文件在顶层),需复制到phpx\build\phpx.dll。