mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-18 12:54:52 +08:00
Merge pull request #869 from crazywhalecc/pkg-config-pkg
turn pkg-config into a package
This commit is contained in:
commit
55836771c9
@ -1,9 +1,6 @@
|
|||||||
{
|
{
|
||||||
"lib-base": {
|
"lib-base": {
|
||||||
"type": "root",
|
"type": "root"
|
||||||
"lib-depends-unix": [
|
|
||||||
"pkg-config"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"php": {
|
"php": {
|
||||||
"type": "root",
|
"type": "root",
|
||||||
|
|||||||
@ -1,4 +1,16 @@
|
|||||||
{
|
{
|
||||||
|
"go-xcaddy-aarch64-linux": {
|
||||||
|
"type": "custom"
|
||||||
|
},
|
||||||
|
"go-xcaddy-aarch64-macos": {
|
||||||
|
"type": "custom"
|
||||||
|
},
|
||||||
|
"go-xcaddy-x86_64-linux": {
|
||||||
|
"type": "custom"
|
||||||
|
},
|
||||||
|
"go-xcaddy-x86_64-macos": {
|
||||||
|
"type": "custom"
|
||||||
|
},
|
||||||
"musl-toolchain-aarch64-linux": {
|
"musl-toolchain-aarch64-linux": {
|
||||||
"type": "url",
|
"type": "url",
|
||||||
"url": "https://dl.static-php.dev/static-php-cli/deps/musl-toolchain/aarch64-musl-toolchain.tgz"
|
"url": "https://dl.static-php.dev/static-php-cli/deps/musl-toolchain/aarch64-musl-toolchain.tgz"
|
||||||
@ -15,6 +27,38 @@
|
|||||||
"nasm-2.16.01/ndisasm.exe": "{php_sdk_path}/bin/ndisasm.exe"
|
"nasm-2.16.01/ndisasm.exe": "{php_sdk_path}/bin/ndisasm.exe"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"pkg-config-aarch64-linux": {
|
||||||
|
"type": "ghrel",
|
||||||
|
"repo": "static-php/static-php-cli-hosted",
|
||||||
|
"match": "pkg-config-aarch64-linux-musl-1.2.5.txz",
|
||||||
|
"extract-files": {
|
||||||
|
"bin/pkg-config": "{pkg_root_path}/bin/pkg-config"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pkg-config-aarch64-macos": {
|
||||||
|
"type": "ghrel",
|
||||||
|
"repo": "static-php/static-php-cli-hosted",
|
||||||
|
"match": "pkg-config-aarch64-darwin.txz",
|
||||||
|
"extract-files": {
|
||||||
|
"bin/pkg-config": "{pkg_root_path}/bin/pkg-config"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pkg-config-x86_64-linux": {
|
||||||
|
"type": "ghrel",
|
||||||
|
"repo": "static-php/static-php-cli-hosted",
|
||||||
|
"match": "pkg-config-x86_64-linux-musl-1.2.5.txz",
|
||||||
|
"extract-files": {
|
||||||
|
"bin/pkg-config": "{pkg_root_path}/bin/pkg-config"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pkg-config-x86_64-macos": {
|
||||||
|
"type": "ghrel",
|
||||||
|
"repo": "static-php/static-php-cli-hosted",
|
||||||
|
"match": "pkg-config-x86_64-darwin.txz",
|
||||||
|
"extract-files": {
|
||||||
|
"bin/pkg-config": "{pkg_root_path}/bin/pkg-config"
|
||||||
|
}
|
||||||
|
},
|
||||||
"strawberry-perl-x86_64-win": {
|
"strawberry-perl-x86_64-win": {
|
||||||
"type": "url",
|
"type": "url",
|
||||||
"url": "https://github.com/StrawberryPerl/Perl-Dist-Strawberry/releases/download/SP_5380_5361/strawberry-perl-5.38.0.1-64bit-portable.zip"
|
"url": "https://github.com/StrawberryPerl/Perl-Dist-Strawberry/releases/download/SP_5380_5361/strawberry-perl-5.38.0.1-64bit-portable.zip"
|
||||||
@ -43,30 +87,18 @@
|
|||||||
"upx-*-win64/upx.exe": "{pkg_root_path}/bin/upx.exe"
|
"upx-*-win64/upx.exe": "{pkg_root_path}/bin/upx.exe"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"go-xcaddy-x86_64-linux": {
|
"zig-aarch64-linux": {
|
||||||
"type": "custom"
|
"type": "custom"
|
||||||
},
|
},
|
||||||
"go-xcaddy-aarch64-linux": {
|
"zig-aarch64-macos": {
|
||||||
"type": "custom"
|
|
||||||
},
|
|
||||||
"go-xcaddy-x86_64-macos": {
|
|
||||||
"type": "custom"
|
|
||||||
},
|
|
||||||
"go-xcaddy-aarch64-macos": {
|
|
||||||
"type": "custom"
|
"type": "custom"
|
||||||
},
|
},
|
||||||
"zig-x86_64-linux": {
|
"zig-x86_64-linux": {
|
||||||
"type": "custom"
|
"type": "custom"
|
||||||
},
|
},
|
||||||
"zig-aarch64-linux": {
|
|
||||||
"type": "custom"
|
|
||||||
},
|
|
||||||
"zig-x86_64-macos": {
|
"zig-x86_64-macos": {
|
||||||
"type": "custom"
|
"type": "custom"
|
||||||
},
|
},
|
||||||
"zig-aarch64-macos": {
|
|
||||||
"type": "custom"
|
|
||||||
},
|
|
||||||
"zig-x86_64-win": {
|
"zig-x86_64-win": {
|
||||||
"type": "custom"
|
"type": "custom"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,10 +25,6 @@ class BSDBuilder extends UnixBuilderBase
|
|||||||
f_putenv('CXX=' . $this->getOption('cxx', 'clang++'));
|
f_putenv('CXX=' . $this->getOption('cxx', 'clang++'));
|
||||||
// set PATH
|
// set PATH
|
||||||
f_putenv('PATH=' . BUILD_ROOT_PATH . '/bin:' . getenv('PATH'));
|
f_putenv('PATH=' . BUILD_ROOT_PATH . '/bin:' . getenv('PATH'));
|
||||||
// set PKG_CONFIG
|
|
||||||
f_putenv('PKG_CONFIG=' . BUILD_ROOT_PATH . '/bin/pkg-config');
|
|
||||||
// set PKG_CONFIG_PATH
|
|
||||||
f_putenv('PKG_CONFIG_PATH=' . BUILD_LIB_PATH . '/pkgconfig/');
|
|
||||||
|
|
||||||
// set arch (default: current)
|
// set arch (default: current)
|
||||||
$this->setOptionIfNotExist('arch', php_uname('m'));
|
$this->setOptionIfNotExist('arch', php_uname('m'));
|
||||||
|
|||||||
38
src/SPC/doctor/item/PkgConfigCheck.php
Normal file
38
src/SPC/doctor/item/PkgConfigCheck.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace SPC\doctor\item;
|
||||||
|
|
||||||
|
use SPC\doctor\AsCheckItem;
|
||||||
|
use SPC\doctor\AsFixItem;
|
||||||
|
use SPC\doctor\CheckResult;
|
||||||
|
use SPC\doctor\OptionalCheck;
|
||||||
|
use SPC\store\PackageManager;
|
||||||
|
use SPC\util\PkgConfigUtil;
|
||||||
|
|
||||||
|
#[OptionalCheck([self::class, 'optionalCheck'])]
|
||||||
|
class PkgConfigCheck
|
||||||
|
{
|
||||||
|
public static function optionalCheck(): bool
|
||||||
|
{
|
||||||
|
return PHP_OS_FAMILY !== 'Windows';
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @noinspection PhpUnused */
|
||||||
|
#[AsCheckItem('if pkg-config is installed or built', level: 800)]
|
||||||
|
public function checkPkgConfig(): CheckResult
|
||||||
|
{
|
||||||
|
if (!($pkgconf = PkgConfigUtil::findPkgConfig())) {
|
||||||
|
return CheckResult::fail('pkg-config is not installed', 'install-pkgconfig');
|
||||||
|
}
|
||||||
|
return CheckResult::ok($pkgconf);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[AsFixItem('install-pkgconfig')]
|
||||||
|
public function installPkgConfig(): bool
|
||||||
|
{
|
||||||
|
PackageManager::installPackage('pkg-config');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -7,6 +7,7 @@ namespace SPC\toolchain;
|
|||||||
use SPC\builder\linux\SystemUtil;
|
use SPC\builder\linux\SystemUtil;
|
||||||
use SPC\exception\WrongUsageException;
|
use SPC\exception\WrongUsageException;
|
||||||
use SPC\util\GlobalEnvManager;
|
use SPC\util\GlobalEnvManager;
|
||||||
|
use SPC\util\PkgConfigUtil;
|
||||||
use SPC\util\SPCTarget;
|
use SPC\util\SPCTarget;
|
||||||
|
|
||||||
class ToolchainManager
|
class ToolchainManager
|
||||||
@ -56,6 +57,15 @@ class ToolchainManager
|
|||||||
if (SPCTarget::getLibc() === 'glibc' && SystemUtil::isMuslDist()) {
|
if (SPCTarget::getLibc() === 'glibc' && SystemUtil::isMuslDist()) {
|
||||||
throw new WrongUsageException('You are linking against glibc dynamically, which is only supported on glibc distros.');
|
throw new WrongUsageException('You are linking against glibc dynamically, which is only supported on glibc distros.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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.');
|
||||||
|
}
|
||||||
|
GlobalEnvManager::putenv("PKG_CONFIG={$found}");
|
||||||
|
}
|
||||||
|
|
||||||
$toolchain = getenv('SPC_TOOLCHAIN');
|
$toolchain = getenv('SPC_TOOLCHAIN');
|
||||||
/* @var ToolchainInterface $toolchain */
|
/* @var ToolchainInterface $toolchain */
|
||||||
$instance = new $toolchain();
|
$instance = new $toolchain();
|
||||||
|
|||||||
@ -39,8 +39,8 @@ class GlobalEnvManager
|
|||||||
// Define env vars for unix
|
// Define env vars for unix
|
||||||
if (is_unix()) {
|
if (is_unix()) {
|
||||||
self::addPathIfNotExists(BUILD_BIN_PATH);
|
self::addPathIfNotExists(BUILD_BIN_PATH);
|
||||||
self::putenv('PKG_CONFIG=' . BUILD_BIN_PATH . '/pkg-config');
|
self::addPathIfNotExists(PKG_ROOT_PATH . '/bin');
|
||||||
self::putenv('PKG_CONFIG_PATH=' . BUILD_ROOT_PATH . '/lib/pkgconfig');
|
self::putenv('PKG_CONFIG_PATH=' . BUILD_LIB_PATH . '/pkgconfig');
|
||||||
}
|
}
|
||||||
|
|
||||||
$ini = self::readIniFile();
|
$ini = self::readIniFile();
|
||||||
|
|||||||
@ -14,6 +14,28 @@ use SPC\exception\ExecutionException;
|
|||||||
*/
|
*/
|
||||||
class PkgConfigUtil
|
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.
|
* Returns the version of a module.
|
||||||
* This method uses `pkg-config --modversion` to get the version of the specified module.
|
* This method uses `pkg-config --modversion` to get the version of the specified module.
|
||||||
|
|||||||
@ -8,6 +8,7 @@ use SPC\builder\freebsd\library\BSDLibraryBase;
|
|||||||
use SPC\builder\linux\library\LinuxLibraryBase;
|
use SPC\builder\linux\library\LinuxLibraryBase;
|
||||||
use SPC\builder\macos\library\MacOSLibraryBase;
|
use SPC\builder\macos\library\MacOSLibraryBase;
|
||||||
use SPC\store\FileSystem;
|
use SPC\store\FileSystem;
|
||||||
|
use SPC\util\PkgConfigUtil;
|
||||||
use SPC\util\shell\UnixShell;
|
use SPC\util\shell\UnixShell;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -184,6 +185,7 @@ class UnixCMakeExecutor extends Executor
|
|||||||
$cxx = getenv('CCX');
|
$cxx = getenv('CCX');
|
||||||
logger()->debug("making cmake tool chain file for {$os} {$target_arch} with CFLAGS='{$cflags}'");
|
logger()->debug("making cmake tool chain file for {$os} {$target_arch} with CFLAGS='{$cflags}'");
|
||||||
$root = BUILD_ROOT_PATH;
|
$root = BUILD_ROOT_PATH;
|
||||||
|
$pkgConfigExecutable = PkgConfigUtil::findPkgConfig();
|
||||||
$ccLine = '';
|
$ccLine = '';
|
||||||
if ($cc) {
|
if ($cc) {
|
||||||
$ccLine = 'SET(CMAKE_C_COMPILER ' . $cc . ')';
|
$ccLine = 'SET(CMAKE_C_COMPILER ' . $cc . ')';
|
||||||
@ -202,7 +204,7 @@ SET(CMAKE_PREFIX_PATH "{$root}")
|
|||||||
SET(CMAKE_INSTALL_PREFIX "{$root}")
|
SET(CMAKE_INSTALL_PREFIX "{$root}")
|
||||||
SET(CMAKE_INSTALL_LIBDIR "lib")
|
SET(CMAKE_INSTALL_LIBDIR "lib")
|
||||||
|
|
||||||
set(PKG_CONFIG_EXECUTABLE "{$root}/bin/pkg-config")
|
set(PKG_CONFIG_EXECUTABLE "{$pkgConfigExecutable}")
|
||||||
list(APPEND PKG_CONFIG_EXECUTABLE "--static")
|
list(APPEND PKG_CONFIG_EXECUTABLE "--static")
|
||||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user