2024-11-09 22:07:52 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace SPC\builder\extension;
|
|
|
|
|
|
|
|
|
|
use SPC\builder\Extension;
|
|
|
|
|
use SPC\builder\windows\WindowsBuilder;
|
2025-08-06 20:43:23 +08:00
|
|
|
use SPC\exception\ValidationException;
|
2024-11-09 22:07:52 +08:00
|
|
|
use SPC\store\FileSystem;
|
|
|
|
|
use SPC\util\CustomExt;
|
|
|
|
|
use SPC\util\GlobalEnvManager;
|
2025-07-23 13:55:09 +07:00
|
|
|
use SPC\util\SPCConfigUtil;
|
2025-07-22 17:17:11 +07:00
|
|
|
use SPC\util\SPCTarget;
|
2024-11-09 22:07:52 +08:00
|
|
|
|
|
|
|
|
#[CustomExt('grpc')]
|
|
|
|
|
class grpc extends Extension
|
|
|
|
|
{
|
|
|
|
|
public function patchBeforeBuildconf(): bool
|
|
|
|
|
{
|
|
|
|
|
if ($this->builder instanceof WindowsBuilder) {
|
2025-08-06 20:43:23 +08:00
|
|
|
throw new ValidationException('grpc extension does not support windows yet');
|
2024-11-09 22:07:52 +08:00
|
|
|
}
|
2025-07-22 17:17:11 +07:00
|
|
|
if (SPCTarget::getTargetOS() === 'Darwin') {
|
|
|
|
|
FileSystem::replaceFileRegex(
|
|
|
|
|
SOURCE_PATH . '/php-src/ext/grpc/config.m4',
|
|
|
|
|
'/GRPC_LIBDIR=.*$/m',
|
|
|
|
|
'GRPC_LIBDIR=' . BUILD_LIB_PATH . "\n" . 'LDFLAGS="$LDFLAGS -framework CoreFoundation"'
|
|
|
|
|
);
|
2024-11-09 22:07:52 +08:00
|
|
|
}
|
2025-07-22 16:26:37 +07:00
|
|
|
return true;
|
2024-11-09 22:07:52 +08:00
|
|
|
}
|
2025-07-21 09:41:36 +07:00
|
|
|
|
2025-07-21 00:32:43 +07:00
|
|
|
public function patchBeforeConfigure(): bool
|
|
|
|
|
{
|
2025-07-23 14:10:28 +07:00
|
|
|
$util = new SPCConfigUtil($this->builder, ['libs_only_deps' => true]);
|
2025-11-04 13:36:29 +08:00
|
|
|
$config = $util->getExtensionConfig($this);
|
2025-07-23 13:55:09 +07:00
|
|
|
$libs = $config['libs'];
|
2025-07-21 00:32:43 +07:00
|
|
|
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/configure', '-lgrpc', $libs);
|
|
|
|
|
return true;
|
2024-11-09 22:07:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function patchBeforeMake(): bool
|
|
|
|
|
{
|
2025-07-19 15:10:42 +07:00
|
|
|
parent::patchBeforeMake();
|
2024-11-09 22:07:52 +08:00
|
|
|
// 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;
|
|
|
|
|
}
|
2025-09-18 18:16:03 +02:00
|
|
|
|
|
|
|
|
protected function getSharedExtensionEnv(): array
|
|
|
|
|
{
|
|
|
|
|
$env = parent::getSharedExtensionEnv();
|
2025-09-18 21:29:46 +02:00
|
|
|
$env['CPPFLAGS'] = $env['CXXFLAGS'] . ' -Wno-attributes';
|
2025-09-18 18:17:48 +02:00
|
|
|
return $env;
|
2025-09-18 18:16:03 +02:00
|
|
|
}
|
2024-11-09 22:07:52 +08:00
|
|
|
}
|