|
9 | 9 | use SPC\store\FileSystem;
|
10 | 10 | use SPC\util\CustomExt;
|
11 | 11 | use SPC\util\GlobalEnvManager;
|
| 12 | +use SPC\util\SPCConfigUtil; |
12 | 13 | use SPC\util\SPCTarget;
|
13 | 14 |
|
14 | 15 | #[CustomExt('grpc')]
|
@@ -40,37 +41,17 @@ public function patchBeforeBuildconf(): bool
|
40 | 41 |
|
41 | 42 | public function patchBeforeConfigure(): bool
|
42 | 43 | {
|
43 |
| - $libs = join(' ', $this->getLibraries()); |
| 44 | + $util = new SPCConfigUtil($this->builder); |
| 45 | + $config = $util->config(['grpc']); |
| 46 | + $libs = $config['libs']; |
44 | 47 | FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/configure', '-lgrpc', $libs);
|
45 | 48 | return true;
|
46 | 49 | }
|
47 | 50 |
|
48 | 51 | public function patchBeforeMake(): bool
|
49 | 52 | {
|
50 |
| - $extra_libs = trim(getenv('SPC_EXTRA_LIBS')); |
51 |
| - $libs = array_map(function (string $lib) { |
52 |
| - if (str_starts_with($lib, '-l')) { |
53 |
| - $staticLib = substr($lib, 2); |
54 |
| - $staticLib = BUILD_LIB_PATH . '/lib' . $staticLib . '.a'; |
55 |
| - if (file_exists($staticLib)) { |
56 |
| - return $staticLib; |
57 |
| - } |
58 |
| - } |
59 |
| - return $lib; |
60 |
| - }, $this->getLibraries()); |
61 |
| - $extra_libs = str_replace(BUILD_LIB_PATH . '/libgrpc.a', join(' ', $libs), $extra_libs); |
62 |
| - f_putenv('SPC_EXTRA_LIBS=' . $extra_libs); |
63 | 53 | // add -Wno-strict-prototypes
|
64 | 54 | GlobalEnvManager::putenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS=' . getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS') . ' -Wno-strict-prototypes');
|
65 | 55 | return true;
|
66 | 56 | }
|
67 |
| - |
68 |
| - private function getLibraries(): array |
69 |
| - { |
70 |
| - $libs = shell()->execWithResult('$PKG_CONFIG --libs --static grpc')[1][0]; |
71 |
| - $filtered = preg_replace('/-L\S+/', '', $libs); |
72 |
| - $filtered = preg_replace('/(?:\S*\/)?lib([a-zA-Z0-9_+-]+)\.a\b/', '-l$1', $filtered); |
73 |
| - $out = preg_replace('/\s+/', ' ', $filtered); |
74 |
| - return explode(' ', trim($out)); |
75 |
| - } |
76 | 57 | }
|
0 commit comments