mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-06 00:05:42 +08:00
Use existing pkg-config builds and pre-built contents for packages
This commit is contained in:
@@ -7,7 +7,6 @@ namespace SPC\util;
|
||||
use SPC\builder\macos\SystemUtil;
|
||||
use SPC\exception\SPCInternalException;
|
||||
use SPC\exception\WrongUsageException;
|
||||
use SPC\store\pkg\PkgConfig;
|
||||
use SPC\toolchain\ToolchainManager;
|
||||
|
||||
/**
|
||||
@@ -40,7 +39,7 @@ class GlobalEnvManager
|
||||
// Define env vars for unix
|
||||
if (is_unix()) {
|
||||
self::addPathIfNotExists(BUILD_BIN_PATH);
|
||||
self::putenv('PKG_CONFIG=' . PkgConfig::getEnvironment()['PATH'] . '/pkg-config');
|
||||
self::addPathIfNotExists(PKG_ROOT_PATH . '/bin');
|
||||
self::putenv('PKG_CONFIG_PATH=' . BUILD_LIB_PATH . '/pkgconfig');
|
||||
}
|
||||
|
||||
@@ -123,6 +122,14 @@ class GlobalEnvManager
|
||||
self::putenv("YACC={$yacc}");
|
||||
}
|
||||
}
|
||||
|
||||
// init pkg-config for unix
|
||||
if (is_unix()) {
|
||||
if (($found = PkgConfigUtil::findPkgConfig()) === null) {
|
||||
throw new WrongUsageException('Cannot find pkg-config executable. Please run `doctor` to fix this.');
|
||||
}
|
||||
self::putenv("PKG_CONFIG={$found}");
|
||||
}
|
||||
}
|
||||
|
||||
private static function readIniFile(): array
|
||||
|
||||
@@ -14,6 +14,28 @@ use SPC\exception\ExecutionException;
|
||||
*/
|
||||
class PkgConfigUtil
|
||||
{
|
||||
/**
|
||||
* Find the pkg-config executable which is compatible with static builds.
|
||||
*
|
||||
* @return null|string Path to pkg-config executable, or null if not found
|
||||
*/
|
||||
public static function findPkgConfig(): ?string
|
||||
{
|
||||
// Find pkg-config executable
|
||||
$find_list = [
|
||||
PKG_ROOT_PATH . '/bin/pkg-config',
|
||||
BUILD_BIN_PATH . '/pkg-config',
|
||||
];
|
||||
$found = null;
|
||||
foreach ($find_list as $file) {
|
||||
if (file_exists($file) && is_executable($file)) {
|
||||
$found = $file;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $found;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the version of a module.
|
||||
* This method uses `pkg-config --modversion` to get the version of the specified module.
|
||||
|
||||
@@ -8,7 +8,7 @@ use SPC\builder\freebsd\library\BSDLibraryBase;
|
||||
use SPC\builder\linux\library\LinuxLibraryBase;
|
||||
use SPC\builder\macos\library\MacOSLibraryBase;
|
||||
use SPC\store\FileSystem;
|
||||
use SPC\store\pkg\PkgConfig;
|
||||
use SPC\util\PkgConfigUtil;
|
||||
use SPC\util\shell\UnixShell;
|
||||
|
||||
/**
|
||||
@@ -185,7 +185,7 @@ class UnixCMakeExecutor extends Executor
|
||||
$cxx = getenv('CCX');
|
||||
logger()->debug("making cmake tool chain file for {$os} {$target_arch} with CFLAGS='{$cflags}'");
|
||||
$root = BUILD_ROOT_PATH;
|
||||
$pkgConfig = PkgConfig::getEnvironment()['PATH'];
|
||||
$pkgConfigExecutable = PkgConfigUtil::findPkgConfig();
|
||||
$ccLine = '';
|
||||
if ($cc) {
|
||||
$ccLine = 'SET(CMAKE_C_COMPILER ' . $cc . ')';
|
||||
@@ -204,7 +204,7 @@ SET(CMAKE_PREFIX_PATH "{$root}")
|
||||
SET(CMAKE_INSTALL_PREFIX "{$root}")
|
||||
SET(CMAKE_INSTALL_LIBDIR "lib")
|
||||
|
||||
set(PKG_CONFIG_EXECUTABLE "{$pkgConfig}/pkg-config")
|
||||
set(PKG_CONFIG_EXECUTABLE "{$pkgConfigExecutable}")
|
||||
list(APPEND PKG_CONFIG_EXECUTABLE "--static")
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
|
||||
Reference in New Issue
Block a user