mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-19 13:24:51 +08:00
rework static lib detection
This commit is contained in:
parent
f31f0d6168
commit
bb96db4395
@ -37,7 +37,7 @@ class grpc extends Extension
|
||||
|
||||
public function patchBeforeConfigure(): bool
|
||||
{
|
||||
$libs = ' -l' . join(' -l', $this->getLibraries());
|
||||
$libs = join(' ', $this->getLibraries());
|
||||
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/configure', '-lgrpc', $libs);
|
||||
return true;
|
||||
}
|
||||
@ -45,8 +45,16 @@ class grpc extends Extension
|
||||
public function patchBeforeMake(): bool
|
||||
{
|
||||
$extra_libs = trim(getenv('SPC_EXTRA_LIBS'));
|
||||
$alibs = join('.a ', $this->getLibraries()) . '.a';
|
||||
$libs = BUILD_LIB_PATH . '/lib' . str_replace(' ', ' ' . BUILD_LIB_PATH . '/lib', $alibs);
|
||||
$libs = array_map(function (string $lib) {
|
||||
if (str_starts_with($lib, '-l')) {
|
||||
$staticLib = substr($lib, 2);
|
||||
$staticLib = BUILD_LIB_PATH . '/lib' . $staticLib . '.a';
|
||||
if (file_exists($staticLib)) {
|
||||
return $staticLib;
|
||||
}
|
||||
}
|
||||
return $lib;
|
||||
}, $this->getLibraries());
|
||||
$extra_libs = str_replace(BUILD_LIB_PATH . '/libgrpc.a', $libs, $extra_libs);
|
||||
f_putenv('SPC_EXTRA_LIBS=' . $extra_libs);
|
||||
// add -Wno-strict-prototypes
|
||||
@ -62,11 +70,9 @@ class grpc extends Extension
|
||||
private function getLibraries(): array
|
||||
{
|
||||
$libs = shell()->execWithResult('$PKG_CONFIG --libs --static grpc')[1][0];
|
||||
$filtered = str_replace('-pthread', '', $libs);
|
||||
$filtered = preg_replace('/-L\S+/', '', $filtered);
|
||||
$filtered = preg_replace('/-L\S+/', '', $libs);
|
||||
$filtered = preg_replace('/(?:\S*\/)?lib([a-zA-Z0-9_+-]+)\.a\b/', '-l$1', $filtered);
|
||||
$out = str_replace('-l', '', $filtered);
|
||||
$out = preg_replace('/\s+/', ' ', $out);
|
||||
$out = preg_replace('/\s+/', ' ', $filtered);
|
||||
return explode(' ', trim($out));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user