mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-20 23:35:37 +08:00
Compare commits
11 Commits
76d7002646
...
d66d7b3a73
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d66d7b3a73 | ||
|
|
024542d361 | ||
|
|
7d85aacace | ||
|
|
31b2e6779d | ||
|
|
2b39a6d535 | ||
|
|
e490a1763a | ||
|
|
bf4b35aa0a | ||
|
|
1f7d3ec91d | ||
|
|
23412d6bfa | ||
|
|
bd0042f079 | ||
|
|
0ccf1a1c5d |
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
return (new PhpCsFixer\Config())
|
return (new PhpCsFixer\Config())
|
||||||
->setRiskyAllowed(true)
|
->setRiskyAllowed(true)
|
||||||
|
->setUnsupportedPhpVersionAllowed(true)
|
||||||
->setRules([
|
->setRules([
|
||||||
'@PSR12' => true,
|
'@PSR12' => true,
|
||||||
'@Symfony' => true,
|
'@Symfony' => true,
|
||||||
|
|||||||
@@ -24,8 +24,6 @@ class grpc extends Extension
|
|||||||
if (!is_link(SOURCE_PATH . '/php-src/ext/grpc')) {
|
if (!is_link(SOURCE_PATH . '/php-src/ext/grpc')) {
|
||||||
if (is_dir($this->builder->getLib('grpc')->getSourceDir() . '/src/php/ext/grpc')) {
|
if (is_dir($this->builder->getLib('grpc')->getSourceDir() . '/src/php/ext/grpc')) {
|
||||||
shell()->exec('ln -s ' . $this->builder->getLib('grpc')->getSourceDir() . '/src/php/ext/grpc ' . SOURCE_PATH . '/php-src/ext/grpc');
|
shell()->exec('ln -s ' . $this->builder->getLib('grpc')->getSourceDir() . '/src/php/ext/grpc ' . SOURCE_PATH . '/php-src/ext/grpc');
|
||||||
} elseif (is_dir(BUILD_ROOT_PATH . '/grpc_php_ext_src')) {
|
|
||||||
shell()->exec('ln -s ' . BUILD_ROOT_PATH . '/grpc_php_ext_src ' . SOURCE_PATH . '/php-src/ext/grpc');
|
|
||||||
} else {
|
} else {
|
||||||
throw new \RuntimeException('Cannot find grpc source code');
|
throw new \RuntimeException('Cannot find grpc source code');
|
||||||
}
|
}
|
||||||
@@ -36,6 +34,7 @@ class grpc extends Extension
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function patchBeforeConfigure(): bool
|
public function patchBeforeConfigure(): bool
|
||||||
{
|
{
|
||||||
$libs = ' -l' . join(' -l', $this->getLibraries());
|
$libs = ' -l' . join(' -l', $this->getLibraries());
|
||||||
@@ -57,13 +56,12 @@ class grpc extends Extension
|
|||||||
|
|
||||||
public function getUnixConfigureArg(bool $shared = false): string
|
public function getUnixConfigureArg(bool $shared = false): string
|
||||||
{
|
{
|
||||||
return '--enable-grpc=' . BUILD_ROOT_PATH . '/grpc GRPC_LIB_SUBDIR=' . BUILD_LIB_PATH;
|
return '--enable-grpc=' . ($shared ? 'shared,' : '') . BUILD_ROOT_PATH . '/grpc GRPC_LIB_SUBDIR=' . BUILD_LIB_PATH;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getLibraries(): array
|
private function getLibraries(): array
|
||||||
{
|
{
|
||||||
[, $out] = shell()->execWithResult('$PKG_CONFIG --libs --static grpc');
|
$libs = shell()->execWithResult('$PKG_CONFIG --libs --static grpc')[1][0];
|
||||||
$libs = join(' ', $out) . ' -lupb -lupb_message_lib -lupb_json_lib -lupb_textformat_lib -lupb_mini_descriptor_lib -lupb_wire_lib -lupb_mem_lib -lupb_base_lib -lutf8_range';
|
|
||||||
$filtered = str_replace('-pthread', '', $libs);
|
$filtered = str_replace('-pthread', '', $libs);
|
||||||
$filtered = preg_replace('/-L\S+/', '', $filtered);
|
$filtered = preg_replace('/-L\S+/', '', $filtered);
|
||||||
$filtered = preg_replace('/(?:\S*\/)?lib([a-zA-Z0-9_+-]+)\.a\b/', '-l$1', $filtered);
|
$filtered = preg_replace('/(?:\S*\/)?lib([a-zA-Z0-9_+-]+)\.a\b/', '-l$1', $filtered);
|
||||||
|
|||||||
@@ -4,35 +4,55 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace SPC\builder\unix\library;
|
namespace SPC\builder\unix\library;
|
||||||
|
|
||||||
|
use SPC\builder\linux\SystemUtil;
|
||||||
|
use SPC\store\FileSystem;
|
||||||
use SPC\util\executor\UnixCMakeExecutor;
|
use SPC\util\executor\UnixCMakeExecutor;
|
||||||
|
use SPC\util\SPCTarget;
|
||||||
|
|
||||||
trait grpc
|
trait grpc
|
||||||
{
|
{
|
||||||
|
public function patchBeforeBuild(): bool
|
||||||
|
{
|
||||||
|
FileSystem::replaceFileStr(
|
||||||
|
$this->source_dir . '/third_party/re2/util/pcre.h',
|
||||||
|
["#define UTIL_PCRE_H_\n#include <stdint.h>", '#define UTIL_PCRE_H_'],
|
||||||
|
['#define UTIL_PCRE_H_', "#define UTIL_PCRE_H_\n#include <stdint.h>"],
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
protected function build(): void
|
protected function build(): void
|
||||||
{
|
{
|
||||||
UnixCMakeExecutor::create($this)
|
$cmake = UnixCMakeExecutor::create($this)
|
||||||
->addConfigureArgs(
|
->addConfigureArgs(
|
||||||
'-DgRPC_SSL_PROVIDER=openssl',
|
'-DgRPC_SSL_PROVIDER=package',
|
||||||
'-DgRPC_INSTALL_BINDIR=' . BUILD_BIN_PATH,
|
'-DgRPC_INSTALL_BINDIR=' . BUILD_BIN_PATH,
|
||||||
'-DgRPC_INSTALL_LIBDIR=' . BUILD_LIB_PATH,
|
'-DgRPC_INSTALL_LIBDIR=' . BUILD_LIB_PATH,
|
||||||
'-DgRPC_INSTALL_SHAREDIR=' . BUILD_ROOT_PATH . '/share/grpc',
|
'-DgRPC_INSTALL_SHAREDIR=' . BUILD_ROOT_PATH . '/share/grpc',
|
||||||
'-DOPENSSL_ROOT_DIR=' . BUILD_ROOT_PATH,
|
'-DCMAKE_C_FLAGS="-DGRPC_POSIX_FORK_ALLOW_PTHREAD_ATFORK -L' . BUILD_LIB_PATH . ' -I' . BUILD_INCLUDE_PATH . '"',
|
||||||
'-DOPENSSL_INCLUDE_DIR=' . BUILD_INCLUDE_PATH,
|
'-DCMAKE_CXX_FLAGS="-DGRPC_POSIX_FORK_ALLOW_PTHREAD_ATFORK -L' . BUILD_LIB_PATH . ' -I' . BUILD_INCLUDE_PATH . '"'
|
||||||
'-DCMAKE_CXX_FLAGS="-DGRPC_POSIX_FORK_ALLOW_PTHREAD_ATFORK"'
|
);
|
||||||
)
|
|
||||||
->build();
|
if (PHP_OS_FAMILY === 'Linux' && SPCTarget::isStatic() && !SystemUtil::isMuslDist()) {
|
||||||
|
$cmake->addConfigureArgs(
|
||||||
|
'-DCMAKE_EXE_LINKER_FLAGS="-static-libgcc -static-libstdc++"',
|
||||||
|
'-DCMAKE_SHARED_LINKER_FLAGS="-static-libgcc -static-libstdc++"',
|
||||||
|
'-DCMAKE_CXX_STANDARD_LIBRARIES="-static-libgcc -static-libstdc++"',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$cmake->build();
|
||||||
copy($this->source_dir . '/third_party/re2/re2.pc', BUILD_LIB_PATH . '/pkgconfig/re2.pc');
|
copy($this->source_dir . '/third_party/re2/re2.pc', BUILD_LIB_PATH . '/pkgconfig/re2.pc');
|
||||||
|
|
||||||
//shell()->cd($this->source_dir)
|
// shell()->cd($this->source_dir)
|
||||||
// ->exec('EXTRA_DEFINES=GRPC_POSIX_FORK_ALLOW_PTHREAD_ATFORK EMBED_OPENSSL=false CXXFLAGS="-L' . BUILD_LIB_PATH . ' -I' . BUILD_INCLUDE_PATH . '" make static -j' . $this->builder->concurrency);
|
// ->exec('EXTRA_DEFINES=GRPC_POSIX_FORK_ALLOW_PTHREAD_ATFORK EMBED_OPENSSL=false CXXFLAGS="-L' . BUILD_LIB_PATH . ' -I' . BUILD_INCLUDE_PATH . '" make static -j' . $this->builder->concurrency);
|
||||||
//copy($this->source_dir . '/libs/opt/libgrpc.a', BUILD_LIB_PATH . '/libgrpc.a');
|
// copy($this->source_dir . '/libs/opt/libgrpc.a', BUILD_LIB_PATH . '/libgrpc.a');
|
||||||
//copy($this->source_dir . '/libs/opt/libboringssl.a', BUILD_LIB_PATH . '/libboringssl.a');
|
// copy($this->source_dir . '/libs/opt/libboringssl.a', BUILD_LIB_PATH . '/libboringssl.a');
|
||||||
//if (!file_exists(BUILD_LIB_PATH . '/libcares.a')) {
|
// if (!file_exists(BUILD_LIB_PATH . '/libcares.a')) {
|
||||||
// copy($this->source_dir . '/libs/opt/libcares.a', BUILD_LIB_PATH . '/libcares.a');
|
// copy($this->source_dir . '/libs/opt/libcares.a', BUILD_LIB_PATH . '/libcares.a');
|
||||||
//}
|
// }
|
||||||
//FileSystem::copyDir($this->source_dir . '/include/grpc', BUILD_INCLUDE_PATH . '/grpc');
|
// FileSystem::copyDir($this->source_dir . '/include/grpc', BUILD_INCLUDE_PATH . '/grpc');
|
||||||
//FileSystem::copyDir($this->source_dir . '/include/grpc++', BUILD_INCLUDE_PATH . '/grpc++');
|
// FileSystem::copyDir($this->source_dir . '/include/grpc++', BUILD_INCLUDE_PATH . '/grpc++');
|
||||||
//FileSystem::copyDir($this->source_dir . '/include/grpcpp', BUILD_INCLUDE_PATH . '/grpcpp');
|
// FileSystem::copyDir($this->source_dir . '/include/grpcpp', BUILD_INCLUDE_PATH . '/grpcpp');
|
||||||
//FileSystem::copyDir($this->source_dir . '/src/php/ext/grpc', BUILD_ROOT_PATH . '/grpc_php_ext_src');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,6 +94,9 @@ class SourceManager
|
|||||||
|
|
||||||
// if not, remove the source dir and extract again
|
// if not, remove the source dir and extract again
|
||||||
logger()->notice("Source [{$source}] hash mismatch, removing old source dir and extracting again ...");
|
logger()->notice("Source [{$source}] hash mismatch, removing old source dir and extracting again ...");
|
||||||
|
if ($source === 'micro' || $source === 'grpc') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
FileSystem::removeDir($check);
|
FileSystem::removeDir($check);
|
||||||
$filename = LockFile::getLockFullPath($lock_content);
|
$filename = LockFile::getLockFullPath($lock_content);
|
||||||
$move_path = LockFile::getExtractPath($lock_name, SOURCE_PATH . '/' . $source);
|
$move_path = LockFile::getExtractPath($lock_name, SOURCE_PATH . '/' . $source);
|
||||||
|
|||||||
@@ -106,10 +106,33 @@ class SPCConfigUtil
|
|||||||
foreach (array_reverse($libraries) as $library) {
|
foreach (array_reverse($libraries) as $library) {
|
||||||
$libs = Config::getLib($library, 'static-libs', []);
|
$libs = Config::getLib($library, 'static-libs', []);
|
||||||
foreach ($libs as $lib) {
|
foreach ($libs as $lib) {
|
||||||
if ($withDependencies) {
|
$noExt = str_replace('.a', '', $lib);
|
||||||
|
$noExtNoLib = str_replace('lib', '', $noExt);
|
||||||
|
$pkgconfFileNoExt = BUILD_LIB_PATH . "/pkgconfig/{$noExt}.pc";
|
||||||
|
$pkgconfFileNoExtNoLib = BUILD_LIB_PATH . "/pkgconfig/{$noExtNoLib}.pc";
|
||||||
|
$llibs = null;
|
||||||
|
if (file_exists($pkgconfFileNoExt)) {
|
||||||
|
$llibs = shell()->execWithResult("pkg-config --libs --static {$noExt}")[1][0];
|
||||||
|
} elseif (file_exists($pkgconfFileNoExtNoLib)) {
|
||||||
|
$llibs = shell()->execWithResult("pkg-config --libs --static {$noExtNoLib}")[1][0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($llibs)) {
|
||||||
|
$filtered = str_replace('-pthread', '', $llibs);
|
||||||
|
$filtered = preg_replace('/-L\S+/', '', $filtered);
|
||||||
|
$filtered = preg_replace('/(?:\S*\/)?lib([a-zA-Z0-9_+-]+)\.a\b/', '-l$1', $filtered);
|
||||||
|
$filtered = preg_replace('/\s+/', ' ', $filtered);
|
||||||
|
foreach (explode(' ', $filtered) as $item) {
|
||||||
|
$short_name[] = $item;
|
||||||
|
}
|
||||||
|
} elseif ($withDependencies) {
|
||||||
$noExt = str_replace('.a', '', $lib);
|
$noExt = str_replace('.a', '', $lib);
|
||||||
$requiredLibs = [];
|
$requiredLibs = [];
|
||||||
$pkgconfFile = BUILD_LIB_PATH . "/pkgconfig/{$noExt}.pc";
|
$pkgconfFile = BUILD_LIB_PATH . "/pkgconfig/{$noExt}.pc";
|
||||||
|
if (!file_exists($pkgconfFile)) {
|
||||||
|
$noExtNoLib = str_replace('lib', '', $noExt);
|
||||||
|
$pkgconfFile = BUILD_LIB_PATH . "/pkgconfig/{$noExtNoLib}.pc";
|
||||||
|
}
|
||||||
if (file_exists($pkgconfFile)) {
|
if (file_exists($pkgconfFile)) {
|
||||||
$lines = file($pkgconfFile);
|
$lines = file($pkgconfFile);
|
||||||
foreach ($lines as $value) {
|
foreach ($lines as $value) {
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ class UnixCMakeExecutor extends Executor
|
|||||||
|
|
||||||
protected bool $reset = true;
|
protected bool $reset = true;
|
||||||
|
|
||||||
|
protected array $extra_env = [];
|
||||||
|
|
||||||
public function build(string $build_pos = '..'): void
|
public function build(string $build_pos = '..'): void
|
||||||
{
|
{
|
||||||
// set cmake dir
|
// set cmake dir
|
||||||
@@ -34,7 +36,7 @@ class UnixCMakeExecutor extends Executor
|
|||||||
}
|
}
|
||||||
|
|
||||||
// prepare shell
|
// prepare shell
|
||||||
$shell = shell()->cd($this->build_dir)->initializeEnv($this->library);
|
$shell = shell()->cd($this->build_dir)->initializeEnv($this->library)->appendEnv($this->extra_env);
|
||||||
|
|
||||||
// config
|
// config
|
||||||
$this->steps >= 1 && $shell->exec("cmake {$this->getConfigureArgs()} {$this->getDefaultCMakeArgs()} {$build_pos}");
|
$this->steps >= 1 && $shell->exec("cmake {$this->getConfigureArgs()} {$this->getDefaultCMakeArgs()} {$build_pos}");
|
||||||
@@ -77,6 +79,15 @@ class UnixCMakeExecutor extends Executor
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add extra environment flags
|
||||||
|
*/
|
||||||
|
public function addExtraEnv(array $env): static
|
||||||
|
{
|
||||||
|
$this->extra_env = [...$this->extra_env, ...$env];
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To build steps.
|
* To build steps.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -13,23 +13,23 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
// test php version (8.1 ~ 8.4 available, multiple for matrix)
|
// test php version (8.1 ~ 8.4 available, multiple for matrix)
|
||||||
$test_php_version = [
|
$test_php_version = [
|
||||||
'8.1',
|
// '8.1',
|
||||||
'8.2',
|
// '8.2',
|
||||||
'8.3',
|
// '8.3',
|
||||||
'8.4',
|
'8.4',
|
||||||
];
|
];
|
||||||
|
|
||||||
// test os (macos-13, macos-14, macos-15, ubuntu-latest, windows-latest are available)
|
// test os (macos-13, macos-14, macos-15, ubuntu-latest, windows-latest are available)
|
||||||
$test_os = [
|
$test_os = [
|
||||||
// 'macos-13', // bin/spc for x86_64
|
'macos-13', // bin/spc for x86_64
|
||||||
// 'macos-14', // bin/spc for arm64
|
'macos-14', // bin/spc for arm64
|
||||||
// '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
|
||||||
// 'ubuntu-22.04-arm', // bin/spc-gnu-docker for arm64
|
'ubuntu-22.04-arm', // bin/spc-gnu-docker for arm64
|
||||||
// 'ubuntu-24.04-arm', // bin/spc for arm64
|
'ubuntu-24.04-arm', // bin/spc for arm64
|
||||||
'windows-latest', // .\bin\spc.ps1
|
// 'windows-latest', // .\bin\spc.ps1
|
||||||
];
|
];
|
||||||
|
|
||||||
// whether enable thread safe
|
// whether enable thread safe
|
||||||
@@ -48,7 +48,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' => 'imap,swoole',
|
'Linux', 'Darwin' => 'grpc',
|
||||||
'Windows' => 'curl',
|
'Windows' => 'curl',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user