Add --enable-embed=static support on Windows#22166
Conversation
Seems very much like a concern for here too, in the same breath. There's no reason to support downstream build adjustments in source code here, especially because it's impossible to test them. The entire |
|
I'm sorry, I didn't 100% understand your feedback, are you asking for changes? |
|
Yes. There shouldn't be a |
|
Very good feedback, I'll try and get it changed. Thank you |
PHP's Unix build already documents and accepts --enable-embed=static (see sapi/embed/config.m4) for building php<N>embed as a static library with no DLL at runtime. The Windows config.w32 ignored the static value, leaving php<N>embed.lib as a thin wrapper that still depended on php<N>.dll at runtime. When --enable-embed=static is passed on Windows: * win32/build/confutils.js generates a Makefile rule for php<N>embed .lib that links in PHP core (PHP_GLOBAL_OBJS), statically built extensions (STATIC_EXT_OBJS + STATIC_EXT_LIBS), the embed SAPI objects, and ASM_OBJS in place of the import lib (BUILD_DIR/PHPLIB). The resulting php<N>embed.lib is a self-contained static library with no runtime DLL dependency. * sapi/embed/config.w32 adds /D PHP_EXPORTS /D LIBZEND_EXPORTS /D SAPI_EXPORTS /D TSRM_EXPORTS to CFLAGS_EMBED so php_embed.c references PHP/Zend/SAPI/TSRM symbols directly instead of through __declspec(dllimport) thunks (which would produce LNK2019 with no DLL to import from), and defines PHP_EMBED_STATIC as a gate. * sapi/embed/php_embed.c skips its ZEND_TSRMLS_CACHE_DEFINE() when PHP_EMBED_STATIC is set. In static mode zend.c is in the same link unit and already defines _tsrm_ls_cache; the duplicate from php_embed.c produced LNK4006 and a corrupt binary.
f1c729c to
9eb3202
Compare
Summary
Unix already supports
--enable-embed=static(seesapi/embed/config.m4); the Windowsconfig.w32ignored thestaticvalue andphp_embed.cgot compiled as a DLL consumer regardless. Result: linking embed withoutphp<N>.dllfails withLNK2019on every PHP/Zend symbol referenced fromphp_embed.c, and (under ZTS)LNK4006on_tsrm_ls_cachedue to a duplicate definition betweenzend.candphp_embed.c.When
--enable-embed=staticis passed on Windows:CFLAGS_EMBEDgets/D PHP_EXPORTS /D LIBZEND_EXPORTS /D SAPI_EXPORTS /D TSRM_EXPORTSsophp_embed.creferences core symbols directly instead of through__declspec(dllimport)thunks.php_embed.c'sZEND_TSRMLS_CACHE_DEFINE()is skipped (gated on newPHP_EMBED_STATIC);zend.cprovides the canonical definition.This patches only the source-side adjustments. Producing a fat static lib (composition of
php<N>embed.lib) is a separate Makefile concern handled by downstream build tools.