mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-18 04:44:53 +08:00
Fix grpc build (#1055)
This commit is contained in:
commit
281b958075
@ -252,6 +252,7 @@
|
|||||||
"arg-type-unix": "enable-path",
|
"arg-type-unix": "enable-path",
|
||||||
"cpp-extension": true,
|
"cpp-extension": true,
|
||||||
"lib-depends": [
|
"lib-depends": [
|
||||||
|
"grpc",
|
||||||
"zlib",
|
"zlib",
|
||||||
"openssl",
|
"openssl",
|
||||||
"libcares"
|
"libcares"
|
||||||
|
|||||||
@ -11,7 +11,6 @@ use SPC\store\FileSystem;
|
|||||||
use SPC\util\CustomExt;
|
use SPC\util\CustomExt;
|
||||||
use SPC\util\GlobalEnvManager;
|
use SPC\util\GlobalEnvManager;
|
||||||
use SPC\util\SPCConfigUtil;
|
use SPC\util\SPCConfigUtil;
|
||||||
use SPC\util\SPCTarget;
|
|
||||||
|
|
||||||
#[CustomExt('grpc')]
|
#[CustomExt('grpc')]
|
||||||
class grpc extends Extension
|
class grpc extends Extension
|
||||||
@ -21,18 +20,50 @@ class grpc extends Extension
|
|||||||
if ($this->builder instanceof WindowsBuilder) {
|
if ($this->builder instanceof WindowsBuilder) {
|
||||||
throw new ValidationException('grpc extension does not support windows yet');
|
throw new ValidationException('grpc extension does not support windows yet');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fix deprecated PHP API usage in call.c
|
||||||
FileSystem::replaceFileStr(
|
FileSystem::replaceFileStr(
|
||||||
$this->source_dir . '/src/php/ext/grpc/call.c',
|
"{$this->source_dir}/src/php/ext/grpc/call.c",
|
||||||
'zend_exception_get_default(TSRMLS_C),',
|
'zend_exception_get_default(TSRMLS_C),',
|
||||||
'zend_ce_exception,',
|
'zend_ce_exception,',
|
||||||
);
|
);
|
||||||
if (SPCTarget::getTargetOS() === 'Darwin') {
|
|
||||||
FileSystem::replaceFileRegex(
|
$config_m4 = <<<'M4'
|
||||||
$this->source_dir . '/config.m4',
|
PHP_ARG_ENABLE(grpc, [whether to enable grpc support], [AS_HELP_STRING([--enable-grpc], [Enable grpc support])])
|
||||||
'/GRPC_LIBDIR=.*$/m',
|
|
||||||
'GRPC_LIBDIR=' . BUILD_LIB_PATH . "\n" . 'LDFLAGS="$LDFLAGS -framework CoreFoundation"'
|
if test "$PHP_GRPC" != "no"; then
|
||||||
);
|
PHP_ADD_INCLUDE(PHP_EXT_SRCDIR()/include)
|
||||||
}
|
PHP_ADD_INCLUDE(PHP_EXT_SRCDIR()/src/php/ext/grpc)
|
||||||
|
GRPC_LIBDIR=@@build_lib_path@@
|
||||||
|
PHP_ADD_LIBPATH($GRPC_LIBDIR)
|
||||||
|
PHP_ADD_LIBRARY(grpc,,GRPC_SHARED_LIBADD)
|
||||||
|
LIBS="-lpthread $LIBS"
|
||||||
|
PHP_ADD_LIBRARY(pthread)
|
||||||
|
|
||||||
|
case $host in
|
||||||
|
*darwin*)
|
||||||
|
PHP_ADD_LIBRARY(c++,1,GRPC_SHARED_LIBADD)
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
PHP_ADD_LIBRARY(stdc++,1,GRPC_SHARED_LIBADD)
|
||||||
|
PHP_ADD_LIBRARY(rt,,GRPC_SHARED_LIBADD)
|
||||||
|
PHP_ADD_LIBRARY(rt)
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
PHP_NEW_EXTENSION(grpc, @grpc_c_files@, $ext_shared, , -DGRPC_POSIX_FORK_ALLOW_PTHREAD_ATFORK=1)
|
||||||
|
PHP_SUBST(GRPC_SHARED_LIBADD)
|
||||||
|
PHP_INSTALL_HEADERS([ext/grpc], [php_grpc.h])
|
||||||
|
fi
|
||||||
|
M4;
|
||||||
|
$replace = get_pack_replace();
|
||||||
|
// load grpc c files from src/php/ext/grpc
|
||||||
|
$c_files = glob($this->source_dir . '/src/php/ext/grpc/*.c');
|
||||||
|
$replace['@grpc_c_files@'] = implode(" \\\n ", array_map(fn ($f) => 'src/php/ext/grpc/' . basename($f), $c_files));
|
||||||
|
$config_m4 = str_replace(array_keys($replace), array_values($replace), $config_m4);
|
||||||
|
file_put_contents($this->source_dir . '/config.m4', $config_m4);
|
||||||
|
|
||||||
|
copy($this->source_dir . '/src/php/ext/grpc/php_grpc.h', $this->source_dir . '/php_grpc.h');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,7 +79,6 @@ class grpc extends Extension
|
|||||||
public function patchBeforeMake(): bool
|
public function patchBeforeMake(): bool
|
||||||
{
|
{
|
||||||
parent::patchBeforeMake();
|
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');
|
GlobalEnvManager::putenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS=' . getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS') . ' -Wno-strict-prototypes');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,15 +16,15 @@ $test_php_version = [
|
|||||||
// '8.1',
|
// '8.1',
|
||||||
// '8.2',
|
// '8.2',
|
||||||
// '8.3',
|
// '8.3',
|
||||||
// '8.4',
|
'8.4',
|
||||||
'8.5',
|
'8.5',
|
||||||
// 'git',
|
// 'git',
|
||||||
];
|
];
|
||||||
|
|
||||||
// test os (macos-15-intel, macos-15, ubuntu-latest, windows-latest are available)
|
// test os (macos-15-intel, macos-15, ubuntu-latest, windows-latest are available)
|
||||||
$test_os = [
|
$test_os = [
|
||||||
// 'macos-15-intel', // bin/spc for x86_64
|
'macos-15-intel', // bin/spc for x86_64
|
||||||
// 'macos-15', // bin/spc for arm64
|
'macos-15', // bin/spc for arm64
|
||||||
// 'ubuntu-latest', // bin/spc-alpine-docker for x86_64
|
// 'ubuntu-latest', // bin/spc-alpine-docker for x86_64
|
||||||
'ubuntu-22.04', // bin/spc-gnu-docker for x86_64
|
'ubuntu-22.04', // bin/spc-gnu-docker for x86_64
|
||||||
'ubuntu-24.04', // bin/spc for x86_64
|
'ubuntu-24.04', // bin/spc for x86_64
|
||||||
@ -35,7 +35,7 @@ $test_os = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
// whether enable thread safe
|
// whether enable thread safe
|
||||||
$zts = true;
|
$zts = false;
|
||||||
|
|
||||||
$no_strip = false;
|
$no_strip = false;
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ $prefer_pre_built = false;
|
|||||||
|
|
||||||
// If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`).
|
// If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`).
|
||||||
$extensions = match (PHP_OS_FAMILY) {
|
$extensions = match (PHP_OS_FAMILY) {
|
||||||
'Linux', 'Darwin' => 'pgsql',
|
'Linux', 'Darwin' => 'grpc',
|
||||||
'Windows' => 'com_dotnet',
|
'Windows' => 'com_dotnet',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user