Add frankenphp build

This commit is contained in:
crazywhalecc
2026-04-12 23:17:50 +08:00
parent 4ddc137eae
commit 8cc5c82595
4 changed files with 256 additions and 6 deletions

View File

@@ -447,12 +447,26 @@ trait windows
}
#[BuildFor('Windows')]
public function buildWin(TargetPackage $package): void
public function buildWin(TargetPackage $package, PackageInstaller $installer): void
{
if ($package->getName() === 'frankenphp') {
/* @var php $this */
$package->runStage([$this, 'buildFrankenphpForWindows']);
return;
}
if ($package->getName() !== 'php') {
return;
}
// maintainer can skip build though ...
if (
$installer->isPackageResolved('php-embed')
&& $installer->getTargetPackage('php-embed')->getBuildOption('maintainer-skip-build')
&& file_exists(BUILD_LIB_PATH . '\php8embed.lib')
) {
return;
}
$package->runStage([$this, 'buildconfForWindows']);
$package->runStage([$this, 'configureForWindows']);
$package->runStage([$this, 'makeForWindows']);
@@ -467,6 +481,32 @@ trait windows
// php-src patches from micro
SourcePatcher::patchPhpSrc();
/* wsyslog.h is generated by mc.exe from win32/build/wsyslog.mc but is absent in some
PHP tarballs (e.g. 8.4.x). wsyslog.c still #includes it for the PHP_SYSLOG_*_TYPE
event-ID constants. Recreate the missing header with the correct mc.exe-encoded values:
MessageId=N + Severity bits (Success=0x00, Info=0x40, Warning=0x80, Error=0xC0)
combined into a 32-bit DWORD (Facility=0, Customer=0).
*/
$wsyslog_h = "{$package->getSourceDir()}\\win32\\wsyslog.h";
if (!file_exists($wsyslog_h)) {
$shim = <<<'HEADER'
/* Auto-generated compatibility shim: wsyslog.h (from win32/build/wsyslog.mc) */
#ifndef WSYSLOG_H
#define WSYSLOG_H
#include "syslog.h"
/* Event IDs generated by mc.exe from wsyslog.mc (Facility=0, Customer=0) */
#define PHP_SYSLOG_SUCCESS_TYPE ((DWORD)0x00000001L)
#define PHP_SYSLOG_INFO_TYPE ((DWORD)0x40000002L)
#define PHP_SYSLOG_WARNING_TYPE ((DWORD)0x80000003L)
#define PHP_SYSLOG_ERROR_TYPE ((DWORD)0xC0000004L)
#endif /* WSYSLOG_H */
HEADER;
FileSystem::writeFile($wsyslog_h, $shim);
}
// php 8.1 bug
if ($this->getPHPVersionID() >= 80100 && $this->getPHPVersionID() < 80200) {
logger()->info('Patching PHP 8.1 windows Fiber bug');
@@ -656,22 +696,24 @@ C_CODE;
$ts = $package->getBuildOption('enable-zts', false) ? '_TS' : '';
$build_dir = "{$source_dir}\\x64\\{$rel_type}{$ts}";
// Build include flags pointing to source dirs (like PHP Windows build does)
// Note: embed.c uses #include <sapi/embed/php_embed.h>, so we need $source_dir itself
$zts_define = $ts ? ' /D ZTS=1' : '';
$include_flags = sprintf(
'/I"%s" /I"%s\main" /I"%s\Zend" /I"%s\TSRM" /I"%s" ' .
'/D ZEND_WIN32=1 /D PHP_WIN32=1 /D WIN32 /D _WINDOWS /D WINDOWS=1 /D _MBCS /D _USE_MATH_DEFINES',
'/D ZEND_WIN32=1 /D PHP_WIN32=1 /D WIN32 /D _WINDOWS /D WINDOWS=1 /D _MBCS /D _USE_MATH_DEFINES%s',
$build_dir,
$source_dir,
$source_dir,
$source_dir,
$source_dir
$source_dir,
$zts_define
);
// MSVC cl.exe format: compiler flags must come before /link, linker flags after
// ldflags contains /LIBPATH which must be after /link
// /FORCE:MULTIPLE: in ZTS mode both zend.obj and php_embed.obj (both packed into the fat php8embed.lib) define _tsrm_ls_cache as a __declspec(thread) variable.
$compile_cmd = sprintf(
'cl.exe /nologo /O2 /MT /Z7 %s embed.c /Fe:embed.exe /link /LIBPATH:"%s\lib" %s %s',
'cl.exe /nologo /O2 /MT /Z7 %s embed.c /Fe:embed.exe /link /FORCE:MULTIPLE /LIBPATH:"%s\lib" %s %s',
$include_flags,
BUILD_ROOT_PATH,
$config['libs'],