Skip to content

Commit 694fd2f

Browse files
committed
turn pkg-config into a package instead of a library
1 parent a5351e1 commit 694fd2f

File tree

13 files changed

+168
-100
lines changed

13 files changed

+168
-100
lines changed

config/lib.json

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
{
22
"lib-base": {
3-
"type": "root",
4-
"lib-depends-unix": [
5-
"pkg-config"
6-
]
3+
"type": "root"
74
},
85
"php": {
96
"type": "root",
@@ -26,13 +23,6 @@
2623
"type": "target",
2724
"source": "micro"
2825
},
29-
"pkg-config": {
30-
"type": "package",
31-
"source": "pkg-config",
32-
"bin-unix": [
33-
"pkg-config"
34-
]
35-
},
3626
"attr": {
3727
"source": "attr",
3828
"static-libs-unix": [

config/pkg.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,17 @@
6969
},
7070
"zig-x86_64-win": {
7171
"type": "custom"
72+
},
73+
"pkg-config-x86_64-linux": {
74+
"type": "custom"
75+
},
76+
"pkg-config-aarch64-linux": {
77+
"type": "custom"
78+
},
79+
"pkg-config-x86_64-macos": {
80+
"type": "custom"
81+
},
82+
"pkg-config-aarch64-macos": {
83+
"type": "custom"
7284
}
7385
}

config/source.json

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -868,15 +868,6 @@
868868
"path": "LICENSE"
869869
}
870870
},
871-
"pkg-config": {
872-
"type": "url",
873-
"url": "https://dl.static-php.dev/static-php-cli/deps/pkg-config/pkg-config-0.29.2.tar.gz",
874-
"provide-pre-built": true,
875-
"license": {
876-
"type": "file",
877-
"path": "COPYING"
878-
}
879-
},
880871
"postgresql": {
881872
"type": "ghtagtar",
882873
"repo": "postgres/postgres",

src/SPC/builder/freebsd/BSDBuilder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use SPC\builder\unix\UnixBuilderBase;
88
use SPC\exception\WrongUsageException;
99
use SPC\store\FileSystem;
10+
use SPC\store\pkg\PkgConfig;
1011
use SPC\store\SourcePatcher;
1112

1213
class BSDBuilder extends UnixBuilderBase
@@ -26,7 +27,7 @@ public function __construct(array $options = [])
2627
// set PATH
2728
f_putenv('PATH=' . BUILD_ROOT_PATH . '/bin:' . getenv('PATH'));
2829
// set PKG_CONFIG
29-
f_putenv('PKG_CONFIG=' . BUILD_ROOT_PATH . '/bin/pkg-config');
30+
f_putenv('PKG_CONFIG=' . PkgConfig::getEnvironment()['PATH'] . '/bin/pkg-config');
3031
// set PKG_CONFIG_PATH
3132
f_putenv('PKG_CONFIG_PATH=' . BUILD_LIB_PATH . '/pkgconfig/');
3233

src/SPC/builder/freebsd/library/pkgconfig.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/SPC/builder/linux/library/pkgconfig.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/SPC/builder/macos/library/pkgconfig.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/SPC/builder/unix/library/pkgconfig.php

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SPC\doctor\item;
6+
7+
use SPC\doctor\AsCheckItem;
8+
use SPC\doctor\AsFixItem;
9+
use SPC\doctor\CheckResult;
10+
use SPC\doctor\OptionalCheck;
11+
use SPC\store\PackageManager;
12+
use SPC\store\pkg\PkgConfig;
13+
14+
#[OptionalCheck([self::class, 'optionalCheck'])]
15+
class PkgConfigCheck
16+
{
17+
public static function optionalCheck(): bool
18+
{
19+
return PHP_OS_FAMILY !== 'Windows';
20+
}
21+
22+
/** @noinspection PhpUnused */
23+
#[AsCheckItem('if pkg-config is installed', level: 800)]
24+
public function checkPkgConfig(): CheckResult
25+
{
26+
if (PkgConfig::isInstalled()) {
27+
return CheckResult::ok();
28+
}
29+
return CheckResult::fail('pkg-config is not installed', 'install-pkgconfig');
30+
}
31+
32+
#[AsFixItem('install-pkgconfig')]
33+
public function installPkgConfig(): bool
34+
{
35+
$arch = arch2gnu(php_uname('m'));
36+
$os = match (PHP_OS_FAMILY) {
37+
'Windows' => 'win',
38+
'Darwin' => 'macos',
39+
'BSD' => 'freebsd',
40+
default => 'linux',
41+
};
42+
PackageManager::installPackage("pkg-config-{$arch}-{$os}");
43+
return PkgConfig::isInstalled();
44+
}
45+
}

src/SPC/store/pkg/PkgConfig.php

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SPC\store\pkg;
6+
7+
use SPC\store\Downloader;
8+
use SPC\store\FileSystem;
9+
use SPC\store\LockFile;
10+
use SPC\util\SPCTarget;
11+
12+
class PkgConfig extends CustomPackage
13+
{
14+
public static function isInstalled(): bool
15+
{
16+
$arch = arch2gnu(php_uname('m'));
17+
$os = match (PHP_OS_FAMILY) {
18+
'Darwin' => 'macos',
19+
default => 'linux',
20+
};
21+
$name = "pkg-config-{$arch}-{$os}";
22+
return is_file(PKG_ROOT_PATH . "/{$name}/bin/pkg-config");
23+
}
24+
25+
public function getSupportName(): array
26+
{
27+
return [
28+
'pkg-config-x86_64-linux',
29+
'pkg-config-aarch64-linux',
30+
'pkg-config-x86_64-macos',
31+
'pkg-config-aarch64-macos',
32+
];
33+
}
34+
35+
public function fetch(string $name, bool $force = false, ?array $config = null): void
36+
{
37+
$pkgroot = PKG_ROOT_PATH;
38+
$bin = "{$pkgroot}/{$name}/bin/pkg-config";
39+
if ($force) {
40+
FileSystem::removeDir("{$pkgroot}/{$name}");
41+
}
42+
if (file_exists($bin)) {
43+
return;
44+
}
45+
// Use known stable pkg-config source tarball (same as config/source.json)
46+
$pkg = [
47+
'type' => 'url',
48+
'url' => 'https://dl.static-php.dev/static-php-cli/deps/pkg-config/pkg-config-0.29.2.tar.gz',
49+
'filename' => 'pkg-config-0.29.2.tar.gz',
50+
];
51+
Downloader::downloadPackage($name, $pkg, $force);
52+
}
53+
54+
public function extract(string $name): void
55+
{
56+
$pkgroot = PKG_ROOT_PATH;
57+
$prefix = "{$pkgroot}/{$name}";
58+
$bin = "{$prefix}/bin/pkg-config";
59+
if (file_exists($bin)) {
60+
return;
61+
}
62+
$lock = json_decode(FileSystem::readFile(LockFile::LOCK_FILE), true);
63+
$source_type = $lock[$name]['source_type'];
64+
$filename = DOWNLOAD_PATH . '/' . ($lock[$name]['filename'] ?? $lock[$name]['dirname']);
65+
$srcdir = "{$pkgroot}/{$name}/src";
66+
FileSystem::extractPackage($name, $source_type, $filename, $srcdir);
67+
68+
// build from source into package prefix
69+
$env = [
70+
'CFLAGS' => getenv('SPC_DEFAULT_C_FLAGS') ?: '-Os',
71+
'LDFLAGS' => (SPCTarget::isStatic() ? '--static' : ''),
72+
'PKG_CONFIG' => 'pkg-config',
73+
'PKG_CONFIG_PATH' => BUILD_ROOT_PATH . '/lib/pkgconfig',
74+
];
75+
$shell = shell()->appendEnv($env)->cd($srcdir);
76+
$shell->exec("./configure --prefix='{$prefix}' --with-internal-glib --disable-host-tool --without-sysroot --without-system-include-path --without-system-library-path --without-pc-path");
77+
$shell->exec('make -j' . (getenv('SPC_CONCURRENCY') ?: '1'));
78+
$shell->exec('make install-exec');
79+
if (is_file($bin)) {
80+
@shell()->exec('strip ' . $bin);
81+
}
82+
}
83+
84+
public static function getEnvironment(): array
85+
{
86+
$arch = arch2gnu(php_uname('m'));
87+
$os = match (PHP_OS_FAMILY) {
88+
'Darwin' => 'macos',
89+
default => 'linux',
90+
};
91+
$name = "pkg-config-{$arch}-{$os}";
92+
return [
93+
'PATH' => PKG_ROOT_PATH . "/{$name}/bin",
94+
];
95+
}
96+
}

0 commit comments

Comments
 (0)