add extra runtime objects for shared libraries built directly by php make too

This commit is contained in:
DubbleClick 2025-07-19 15:10:42 +07:00
parent fff23649cf
commit 01887d652c
13 changed files with 36 additions and 8 deletions

View File

@ -495,6 +495,7 @@
"type": "builtin",
"arg-type": "custom",
"arg-type-windows": "with",
"build-with-php": true,
"lib-depends": [
"openssl",
"zlib"

View File

@ -12,6 +12,7 @@ use SPC\store\FileSystem;
use SPC\toolchain\ToolchainManager;
use SPC\toolchain\ZigToolchain;
use SPC\util\SPCConfigUtil;
use SPC\util\SPCTarget;
class Extension
{
@ -187,6 +188,19 @@ class Extension
*/
public function patchBeforeMake(): bool
{
if (
PHP_OS_FAMILY === 'Linux' &&
$this->isBuildShared() &&
ToolchainManager::getToolchainClass() === ZigToolchain::class &&
($extra = (new ZigToolchain())->getExtraRuntimeObjects())
) {
FileSystem::replaceFileRegex(
$this->source_dir . '/Makefile',
"/^(shared_objects_{$this->getName()}\\s*=.*)$/m",
"$1 {$extra}",
);
return true;
}
return false;
}

View File

@ -13,6 +13,7 @@ class amqp extends Extension
{
public function patchBeforeMake(): bool
{
$patched = parent::patchBeforeMake();
if (PHP_OS_FAMILY === 'Windows') {
FileSystem::replaceFileRegex(BUILD_INCLUDE_PATH . '\amqp.h', '/^#warning.*/m', '');
FileSystem::replaceFileRegex(BUILD_INCLUDE_PATH . '\amqp_framing.h', '/^#warning.*/m', '');
@ -20,7 +21,7 @@ class amqp extends Extension
FileSystem::replaceFileRegex(BUILD_INCLUDE_PATH . '\amqp_tcp_socket.h', '/^#warning.*/m', '');
return true;
}
return false;
return $patched;
}
public function getUnixConfigureArg(bool $shared = false): string

View File

@ -60,13 +60,14 @@ class curl extends Extension
public function patchBeforeMake(): bool
{
$patched = parent::patchBeforeMake();
$extra_libs = getenv('SPC_EXTRA_LIBS');
if ($this->builder instanceof WindowsBuilder && !str_contains($extra_libs, 'secur32.lib')) {
$extra_libs .= ' secur32.lib';
putenv('SPC_EXTRA_LIBS=' . trim($extra_libs));
return true;
}
return false;
return $patched;
}
public function patchBeforeSharedConfigure(): bool

View File

@ -41,10 +41,12 @@ class event extends Extension
*/
public function patchBeforeMake(): bool
{
$patched = parent::patchBeforeMake();
// Prevent event extension compile error on macOS
if ($this->builder instanceof MacOSBuilder) {
FileSystem::replaceFileRegex(SOURCE_PATH . '/php-src/main/php_config.h', '/^#define HAVE_OPENPTY 1$/m', '');
}
return true;
}
return $patched;
}
}

View File

@ -39,6 +39,7 @@ class grpc extends Extension
public function patchBeforeMake(): bool
{
parent::patchBeforeMake();
// add -Wno-strict-prototypes
GlobalEnvManager::putenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS=' . getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS') . ' -Wno-strict-prototypes');
return true;

View File

@ -45,8 +45,9 @@ class imap extends Extension
public function patchBeforeMake(): bool
{
$patched = parent::patchBeforeMake();
if (PHP_OS_FAMILY !== 'Linux' || SystemUtil::isMuslDist()) {
return false;
return $patched;
}
$extra_libs = trim(getenv('SPC_EXTRA_LIBS') . ' -lcrypt');
f_putenv('SPC_EXTRA_LIBS=' . $extra_libs);

View File

@ -12,6 +12,7 @@ class openssl extends Extension
{
public function patchBeforeMake(): bool
{
$patched = parent::patchBeforeMake();
// patch openssl3 with php8.0 bug
if ($this->builder->getPHPVersionID() < 80100) {
$openssl_c = file_get_contents(SOURCE_PATH . '/php-src/ext/openssl/openssl.c');
@ -20,7 +21,7 @@ class openssl extends Extension
return true;
}
return false;
return $patched;
}
public function getUnixConfigureArg(bool $shared = false): string

View File

@ -34,6 +34,7 @@ class opentelemetry extends Extension
public function patchBeforeMake(): bool
{
parent::patchBeforeMake();
// add -Wno-strict-prototypes
GlobalEnvManager::putenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS=' . getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS') . ' -Wno-strict-prototypes');
return true;

View File

@ -26,6 +26,7 @@ class password_argon2 extends Extension
public function patchBeforeMake(): bool
{
$patched = parent::patchBeforeMake();
if ($this->builder->getLib('libsodium') !== null) {
$extraLibs = getenv('SPC_EXTRA_LIBS');
if ($extraLibs !== false) {
@ -36,8 +37,9 @@ class password_argon2 extends Extension
);
$extraLibs = trim(preg_replace('/\s+/', ' ', $extraLibs)); // normalize spacing
f_putenv('SPC_EXTRA_LIBS=' . $extraLibs);
return true;
}
}
return false;
return $patched;
}
}

View File

@ -20,6 +20,7 @@ class rdkafka extends Extension
public function patchBeforeMake(): bool
{
parent::patchBeforeMake();
// when compiling rdkafka with inline builds, it shows some errors, I don't know why.
FileSystem::replaceFileStr(
SOURCE_PATH . '/php-src/ext/rdkafka/rdkafka.c',

View File

@ -14,6 +14,7 @@ class swoole extends Extension
{
public function patchBeforeMake(): bool
{
$patched = parent::patchBeforeMake();
if ($this->builder instanceof MacOSBuilder) {
// Fix swoole with event extension <util.h> conflict bug
$util_path = shell()->execWithResult('xcrun --show-sdk-path', false)[1][0] . '/usr/include/util.h';
@ -24,7 +25,7 @@ class swoole extends Extension
);
return true;
}
return false;
return $patched;
}
public function getExtVersion(): ?string

View File

@ -27,6 +27,7 @@ class xlswriter extends Extension
public function patchBeforeMake(): bool
{
$patched = parent::patchBeforeMake();
if (PHP_OS_FAMILY === 'Windows') {
// fix windows build with openssl extension duplicate symbol bug
SourcePatcher::patchFile('spc_fix_xlswriter_win32.patch', $this->source_dir);
@ -37,6 +38,6 @@ class xlswriter extends Extension
}
return true;
}
return false;
return $patched;
}
}