Skip to content

Commit 09b89a3

Browse files
committed
WIP: use system libraries for grpc without building our own grpc lib
1 parent 9a681a9 commit 09b89a3

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

src/SPC/builder/LibraryBase.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,17 @@ protected function isLibraryInstalled(): bool
375375
return false;
376376
}
377377
}
378+
$pkg_config_path = getenv('PKG_CONFIG_PATH') ?: '';
379+
$search_paths = array_filter(explode(is_unix() ? ':' : ';', $pkg_config_path));
378380
foreach (Config::getLib(static::NAME, 'pkg-configs', []) as $name) {
379-
if (!file_exists(BUILD_LIB_PATH . "/pkgconfig/{$name}.pc")) {
381+
$found = false;
382+
foreach ($search_paths as $path) {
383+
if (file_exists($path . "/{$name}.pc")) {
384+
$found = true;
385+
break;
386+
}
387+
}
388+
if (!$found) {
380389
return false;
381390
}
382391
}

src/SPC/builder/traits/UnixLibraryTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function patchPkgconfPrefix(array $files = [], int $patch_option = PKGCON
3434
$files = array_map(fn ($x) => "{$x}.pc", $conf_pc);
3535
}
3636
foreach ($files as $name) {
37-
$realpath = realpath(BUILD_ROOT_PATH . '/lib/pkgconfig/' . $name);
37+
$realpath = realpath(BUILD_LIB_PATH . '/pkgconfig/' . $name);
3838
if ($realpath === false) {
3939
throw new PatchException('pkg-config prefix patcher', 'Cannot find library [' . static::NAME . '] pkgconfig file [' . $name . '] in ' . BUILD_LIB_PATH . '/pkgconfig/ !');
4040
}

src/SPC/util/SPCConfigUtil.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,17 @@ private function getIncludesString(array $libraries): string
226226
// parse pkg-configs
227227
foreach ($libraries as $library) {
228228
$pc = Config::getLib($library, 'pkg-configs', []);
229+
$pkg_config_path = getenv('PKG_CONFIG_PATH') ?: '';
230+
$search_paths = array_filter(explode(is_unix() ? ':' : ';', $pkg_config_path));
229231
foreach ($pc as $file) {
230-
if (!file_exists(BUILD_LIB_PATH . "/pkgconfig/{$file}.pc")) {
231-
throw new WrongUsageException("pkg-config file '{$file}.pc' for lib [{$library}] does not exist in '" . BUILD_LIB_PATH . "/pkgconfig'. Please build it first.");
232+
$found = false;
233+
foreach ($search_paths as $path) {
234+
if (file_exists($path . "/{$file}.pc")) {
235+
$found = true;
236+
}
237+
}
238+
if (!$found) {
239+
throw new WrongUsageException("pkg-config file '{$file}.pc' for lib [{$library}] does not exist. Please build it first.");
232240
}
233241
}
234242
$pc_cflags = implode(' ', $pc);
@@ -257,9 +265,17 @@ private function getLibsString(array $libraries, bool $use_short_libs = true): s
257265
foreach ($libraries as $library) {
258266
// add pkg-configs libs
259267
$pkg_configs = Config::getLib($library, 'pkg-configs', []);
260-
foreach ($pkg_configs as $pkg_config) {
261-
if (!file_exists(BUILD_LIB_PATH . "/pkgconfig/{$pkg_config}.pc")) {
262-
throw new WrongUsageException("pkg-config file '{$pkg_config}.pc' for lib [{$library}] does not exist in '" . BUILD_LIB_PATH . "/pkgconfig'. Please build it first.");
268+
$pkg_config_path = getenv('PKG_CONFIG_PATH') ?: '';
269+
$search_paths = array_filter(explode(is_unix() ? ':' : ';', $pkg_config_path));
270+
foreach ($pkg_configs as $file) {
271+
$found = false;
272+
foreach ($search_paths as $path) {
273+
if (file_exists($path . "/{$file}.pc")) {
274+
$found = true;
275+
}
276+
}
277+
if (!$found) {
278+
throw new WrongUsageException("pkg-config file '{$file}.pc' for lib [{$library}] does not exist. Please build it first.");
263279
}
264280
}
265281
$pkg_configs = implode(' ', $pkg_configs);

0 commit comments

Comments
 (0)