mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-19 05:14:52 +08:00
use pkgconfig to determine libs
This commit is contained in:
parent
1f7d3ec91d
commit
bf4b35aa0a
@ -61,8 +61,7 @@ class grpc extends Extension
|
|||||||
|
|
||||||
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,10 +4,21 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace SPC\builder\unix\library;
|
namespace SPC\builder\unix\library;
|
||||||
|
|
||||||
|
use SPC\store\FileSystem;
|
||||||
use SPC\util\executor\UnixCMakeExecutor;
|
use SPC\util\executor\UnixCMakeExecutor;
|
||||||
|
|
||||||
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)
|
UnixCMakeExecutor::create($this)
|
||||||
|
|||||||
@ -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,9 +13,9 @@ 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',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user