mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-17 20:34:51 +08:00
turn pkg-config into a package instead of a library
This commit is contained in:
parent
a5351e1546
commit
694fd2f1e0
@ -1,9 +1,6 @@
|
||||
{
|
||||
"lib-base": {
|
||||
"type": "root",
|
||||
"lib-depends-unix": [
|
||||
"pkg-config"
|
||||
]
|
||||
"type": "root"
|
||||
},
|
||||
"php": {
|
||||
"type": "root",
|
||||
@ -26,13 +23,6 @@
|
||||
"type": "target",
|
||||
"source": "micro"
|
||||
},
|
||||
"pkg-config": {
|
||||
"type": "package",
|
||||
"source": "pkg-config",
|
||||
"bin-unix": [
|
||||
"pkg-config"
|
||||
]
|
||||
},
|
||||
"attr": {
|
||||
"source": "attr",
|
||||
"static-libs-unix": [
|
||||
|
||||
@ -69,5 +69,17 @@
|
||||
},
|
||||
"zig-x86_64-win": {
|
||||
"type": "custom"
|
||||
},
|
||||
"pkg-config-x86_64-linux": {
|
||||
"type": "custom"
|
||||
},
|
||||
"pkg-config-aarch64-linux": {
|
||||
"type": "custom"
|
||||
},
|
||||
"pkg-config-x86_64-macos": {
|
||||
"type": "custom"
|
||||
},
|
||||
"pkg-config-aarch64-macos": {
|
||||
"type": "custom"
|
||||
}
|
||||
}
|
||||
|
||||
@ -868,15 +868,6 @@
|
||||
"path": "LICENSE"
|
||||
}
|
||||
},
|
||||
"pkg-config": {
|
||||
"type": "url",
|
||||
"url": "https://dl.static-php.dev/static-php-cli/deps/pkg-config/pkg-config-0.29.2.tar.gz",
|
||||
"provide-pre-built": true,
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "COPYING"
|
||||
}
|
||||
},
|
||||
"postgresql": {
|
||||
"type": "ghtagtar",
|
||||
"repo": "postgres/postgres",
|
||||
|
||||
@ -7,6 +7,7 @@ namespace SPC\builder\freebsd;
|
||||
use SPC\builder\unix\UnixBuilderBase;
|
||||
use SPC\exception\WrongUsageException;
|
||||
use SPC\store\FileSystem;
|
||||
use SPC\store\pkg\PkgConfig;
|
||||
use SPC\store\SourcePatcher;
|
||||
|
||||
class BSDBuilder extends UnixBuilderBase
|
||||
@ -26,7 +27,7 @@ class BSDBuilder extends UnixBuilderBase
|
||||
// set PATH
|
||||
f_putenv('PATH=' . BUILD_ROOT_PATH . '/bin:' . getenv('PATH'));
|
||||
// set PKG_CONFIG
|
||||
f_putenv('PKG_CONFIG=' . BUILD_ROOT_PATH . '/bin/pkg-config');
|
||||
f_putenv('PKG_CONFIG=' . PkgConfig::getEnvironment()['PATH'] . '/bin/pkg-config');
|
||||
// set PKG_CONFIG_PATH
|
||||
f_putenv('PKG_CONFIG_PATH=' . BUILD_LIB_PATH . '/pkgconfig/');
|
||||
|
||||
|
||||
@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\freebsd\library;
|
||||
|
||||
/**
|
||||
* gmp is a template library class for unix
|
||||
*/
|
||||
class pkgconfig extends BSDLibraryBase
|
||||
{
|
||||
use \SPC\builder\unix\library\pkgconfig;
|
||||
|
||||
public const NAME = 'pkg-config';
|
||||
}
|
||||
@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\linux\library;
|
||||
|
||||
/**
|
||||
* gmp is a template library class for unix
|
||||
*/
|
||||
class pkgconfig extends LinuxLibraryBase
|
||||
{
|
||||
use \SPC\builder\unix\library\pkgconfig;
|
||||
|
||||
public const NAME = 'pkg-config';
|
||||
}
|
||||
@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\macos\library;
|
||||
|
||||
/**
|
||||
* gmp is a template library class for unix
|
||||
*/
|
||||
class pkgconfig extends MacOSLibraryBase
|
||||
{
|
||||
use \SPC\builder\unix\library\pkgconfig;
|
||||
|
||||
public const NAME = 'pkg-config';
|
||||
}
|
||||
@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\unix\library;
|
||||
|
||||
use SPC\util\executor\UnixAutoconfExecutor;
|
||||
use SPC\util\SPCTarget;
|
||||
|
||||
trait pkgconfig
|
||||
{
|
||||
protected function build(): void
|
||||
{
|
||||
UnixAutoconfExecutor::create($this)
|
||||
->appendEnv([
|
||||
'CFLAGS' => '-Wimplicit-function-declaration -Wno-int-conversion',
|
||||
'LDFLAGS' => SPCTarget::isStatic() ? '--static' : '',
|
||||
])
|
||||
->configure(
|
||||
'--with-internal-glib',
|
||||
'--disable-host-tool',
|
||||
'--without-sysroot',
|
||||
'--without-system-include-path',
|
||||
'--without-system-library-path',
|
||||
'--without-pc-path',
|
||||
)
|
||||
->make(with_install: 'install-exec');
|
||||
|
||||
shell()->exec('strip ' . BUILD_ROOT_PATH . '/bin/pkg-config');
|
||||
}
|
||||
}
|
||||
45
src/SPC/doctor/item/PkgConfigCheck.php
Normal file
45
src/SPC/doctor/item/PkgConfigCheck.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?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\store\pkg\PkgConfig;
|
||||
|
||||
#[OptionalCheck([self::class, 'optionalCheck'])]
|
||||
class PkgConfigCheck
|
||||
{
|
||||
public static function optionalCheck(): bool
|
||||
{
|
||||
return PHP_OS_FAMILY !== 'Windows';
|
||||
}
|
||||
|
||||
/** @noinspection PhpUnused */
|
||||
#[AsCheckItem('if pkg-config is installed', level: 800)]
|
||||
public function checkPkgConfig(): CheckResult
|
||||
{
|
||||
if (PkgConfig::isInstalled()) {
|
||||
return CheckResult::ok();
|
||||
}
|
||||
return CheckResult::fail('pkg-config is not installed', 'install-pkgconfig');
|
||||
}
|
||||
|
||||
#[AsFixItem('install-pkgconfig')]
|
||||
public function installPkgConfig(): bool
|
||||
{
|
||||
$arch = arch2gnu(php_uname('m'));
|
||||
$os = match (PHP_OS_FAMILY) {
|
||||
'Windows' => 'win',
|
||||
'Darwin' => 'macos',
|
||||
'BSD' => 'freebsd',
|
||||
default => 'linux',
|
||||
};
|
||||
PackageManager::installPackage("pkg-config-{$arch}-{$os}");
|
||||
return PkgConfig::isInstalled();
|
||||
}
|
||||
}
|
||||
96
src/SPC/store/pkg/PkgConfig.php
Normal file
96
src/SPC/store/pkg/PkgConfig.php
Normal file
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\store\pkg;
|
||||
|
||||
use SPC\store\Downloader;
|
||||
use SPC\store\FileSystem;
|
||||
use SPC\store\LockFile;
|
||||
use SPC\util\SPCTarget;
|
||||
|
||||
class PkgConfig extends CustomPackage
|
||||
{
|
||||
public static function isInstalled(): bool
|
||||
{
|
||||
$arch = arch2gnu(php_uname('m'));
|
||||
$os = match (PHP_OS_FAMILY) {
|
||||
'Darwin' => 'macos',
|
||||
default => 'linux',
|
||||
};
|
||||
$name = "pkg-config-{$arch}-{$os}";
|
||||
return is_file(PKG_ROOT_PATH . "/{$name}/bin/pkg-config");
|
||||
}
|
||||
|
||||
public function getSupportName(): array
|
||||
{
|
||||
return [
|
||||
'pkg-config-x86_64-linux',
|
||||
'pkg-config-aarch64-linux',
|
||||
'pkg-config-x86_64-macos',
|
||||
'pkg-config-aarch64-macos',
|
||||
];
|
||||
}
|
||||
|
||||
public function fetch(string $name, bool $force = false, ?array $config = null): void
|
||||
{
|
||||
$pkgroot = PKG_ROOT_PATH;
|
||||
$bin = "{$pkgroot}/{$name}/bin/pkg-config";
|
||||
if ($force) {
|
||||
FileSystem::removeDir("{$pkgroot}/{$name}");
|
||||
}
|
||||
if (file_exists($bin)) {
|
||||
return;
|
||||
}
|
||||
// Use known stable pkg-config source tarball (same as config/source.json)
|
||||
$pkg = [
|
||||
'type' => 'url',
|
||||
'url' => 'https://dl.static-php.dev/static-php-cli/deps/pkg-config/pkg-config-0.29.2.tar.gz',
|
||||
'filename' => 'pkg-config-0.29.2.tar.gz',
|
||||
];
|
||||
Downloader::downloadPackage($name, $pkg, $force);
|
||||
}
|
||||
|
||||
public function extract(string $name): void
|
||||
{
|
||||
$pkgroot = PKG_ROOT_PATH;
|
||||
$prefix = "{$pkgroot}/{$name}";
|
||||
$bin = "{$prefix}/bin/pkg-config";
|
||||
if (file_exists($bin)) {
|
||||
return;
|
||||
}
|
||||
$lock = json_decode(FileSystem::readFile(LockFile::LOCK_FILE), true);
|
||||
$source_type = $lock[$name]['source_type'];
|
||||
$filename = DOWNLOAD_PATH . '/' . ($lock[$name]['filename'] ?? $lock[$name]['dirname']);
|
||||
$srcdir = "{$pkgroot}/{$name}/src";
|
||||
FileSystem::extractPackage($name, $source_type, $filename, $srcdir);
|
||||
|
||||
// build from source into package prefix
|
||||
$env = [
|
||||
'CFLAGS' => getenv('SPC_DEFAULT_C_FLAGS') ?: '-Os',
|
||||
'LDFLAGS' => (SPCTarget::isStatic() ? '--static' : ''),
|
||||
'PKG_CONFIG' => 'pkg-config',
|
||||
'PKG_CONFIG_PATH' => BUILD_ROOT_PATH . '/lib/pkgconfig',
|
||||
];
|
||||
$shell = shell()->appendEnv($env)->cd($srcdir);
|
||||
$shell->exec("./configure --prefix='{$prefix}' --with-internal-glib --disable-host-tool --without-sysroot --without-system-include-path --without-system-library-path --without-pc-path");
|
||||
$shell->exec('make -j' . (getenv('SPC_CONCURRENCY') ?: '1'));
|
||||
$shell->exec('make install-exec');
|
||||
if (is_file($bin)) {
|
||||
@shell()->exec('strip ' . $bin);
|
||||
}
|
||||
}
|
||||
|
||||
public static function getEnvironment(): array
|
||||
{
|
||||
$arch = arch2gnu(php_uname('m'));
|
||||
$os = match (PHP_OS_FAMILY) {
|
||||
'Darwin' => 'macos',
|
||||
default => 'linux',
|
||||
};
|
||||
$name = "pkg-config-{$arch}-{$os}";
|
||||
return [
|
||||
'PATH' => PKG_ROOT_PATH . "/{$name}/bin",
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -5,7 +5,9 @@ declare(strict_types=1);
|
||||
namespace SPC\toolchain;
|
||||
|
||||
use SPC\builder\linux\SystemUtil;
|
||||
use SPC\exception\EnvironmentException;
|
||||
use SPC\exception\WrongUsageException;
|
||||
use SPC\store\pkg\PkgConfig;
|
||||
use SPC\util\GlobalEnvManager;
|
||||
use SPC\util\SPCTarget;
|
||||
|
||||
@ -56,6 +58,10 @@ class ToolchainManager
|
||||
if (SPCTarget::getLibc() === 'glibc' && SystemUtil::isMuslDist()) {
|
||||
throw new WrongUsageException('You are linking against glibc dynamically, which is only supported on glibc distros.');
|
||||
}
|
||||
if (!is_dir(PkgConfig::getEnvironment()['PATH'])) {
|
||||
throw new EnvironmentException('Please install pkg-config first. (You can use `doctor` command to install it)');
|
||||
}
|
||||
GlobalEnvManager::addPathIfNotExists(PkgConfig::getEnvironment()['PATH']);
|
||||
$toolchain = getenv('SPC_TOOLCHAIN');
|
||||
/* @var ToolchainInterface $toolchain */
|
||||
$instance = new $toolchain();
|
||||
|
||||
@ -7,6 +7,7 @@ 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;
|
||||
|
||||
/**
|
||||
@ -39,8 +40,8 @@ class GlobalEnvManager
|
||||
// Define env vars for unix
|
||||
if (is_unix()) {
|
||||
self::addPathIfNotExists(BUILD_BIN_PATH);
|
||||
self::putenv('PKG_CONFIG=' . BUILD_BIN_PATH . '/pkg-config');
|
||||
self::putenv('PKG_CONFIG_PATH=' . BUILD_ROOT_PATH . '/lib/pkgconfig');
|
||||
self::putenv('PKG_CONFIG=' . PkgConfig::getEnvironment()['PATH'] . '/pkg-config');
|
||||
self::putenv('PKG_CONFIG_PATH=' . BUILD_LIB_PATH . '/pkgconfig');
|
||||
}
|
||||
|
||||
$ini = self::readIniFile();
|
||||
|
||||
@ -8,6 +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\shell\UnixShell;
|
||||
|
||||
/**
|
||||
@ -184,6 +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'];
|
||||
$ccLine = '';
|
||||
if ($cc) {
|
||||
$ccLine = 'SET(CMAKE_C_COMPILER ' . $cc . ')';
|
||||
@ -202,7 +204,7 @@ SET(CMAKE_PREFIX_PATH "{$root}")
|
||||
SET(CMAKE_INSTALL_PREFIX "{$root}")
|
||||
SET(CMAKE_INSTALL_LIBDIR "lib")
|
||||
|
||||
set(PKG_CONFIG_EXECUTABLE "{$root}/bin/pkg-config")
|
||||
set(PKG_CONFIG_EXECUTABLE "{$pkgConfig}/pkg-config")
|
||||
list(APPEND PKG_CONFIG_EXECUTABLE "--static")
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user