Compare commits

...

19 Commits
2.1.4 ... 2.1.7

Author SHA1 Message Date
Jerry Ma
4cb1764439 Fix libuuid build source (#411)
* fix libuuid build source

* fix libuuid build source tests
2024-04-12 21:05:51 +08:00
crazywhalecc
847535721c add macOS brew arch check for doctor 2024-04-12 16:34:58 +08:00
Jerry Ma
e3c542d9df add qdbm for dba (#409)
* add qdbm for dba

* add windows support for dba-qdbm

* fix test scripts

* fix test scripts
2024-04-12 15:53:38 +08:00
Jerry Ma
b4ed4ea956 Add ext yac (#407)
* add ext yac

* enable yac for windows

* enable yac test for windows

* correct
2024-04-12 01:43:27 +08:00
Jerry Ma
99aadd3e73 fix openssl build with corrupted pkg-config file (#406)
* fix openssl build with corrupted pkg-config file

* add test

* fix linux openssl

* add exec exit error counter for postgresql
2024-04-12 00:49:15 +08:00
Jerry Ma
c77dc1af6c Add extension simdjson support (#402)
* add extension simdjson support

* add extension simdjson tests

* fix windows build for simdjson
2024-04-02 16:57:59 +08:00
Jerry Ma
9fd56987ef Add extension ds support (#401)
* add extension ds

* add ds tests
2024-04-02 15:54:28 +08:00
crazywhalecc
1e494a2213 bump version 2024-04-02 15:06:54 +08:00
Jerry Ma
da6d9ffb4b Cmake version check (#400)
* add cmake version checker for doctor

* fix linux distro checker message
2024-04-02 15:05:49 +08:00
Jerry Ma
d3a001d808 use old xz mirror, fix CVE-2024-3094 (#399)
* use old xz mirror, fix CVE-2024-3094

* add test
2024-04-02 11:31:29 +08:00
Jerry Ma
d445668d9f trigger tests and nightly builds 2024-03-31 15:36:38 +08:00
Jerry Ma
32f14e16c8 fix pkg-config build for macOS sonoma (#391)
* fix pkg-config build for macOS sonoma

* cs fix

* bump version to 2.1.6 [skip ci]
2024-03-20 21:50:05 +08:00
Jerry Ma
46984b6df1 Fix latest libsodium compatibility (#388)
* fix #384

* bypass password-argon2 micro sanity check

* ignore funding yaml schema [skip ci]

* test linux compatibility for libargon2 and libsodium

* update composer.json to prevent smart-aleck composer [skip ci]
2024-03-16 22:37:39 +08:00
Kévin Dunglas
96c3e6b935 fix: false postive with binutils-gold 2024-03-16 18:53:53 +08:00
Jerry Ma
8092f1e481 Update FUNDING.yml 2024-03-15 22:44:05 +08:00
crazywhalecc
632f904f30 fix install-pkg different arch cache bug 2024-03-15 14:27:51 +08:00
crazywhalecc
8358a985b3 fix retry for windows 2024-03-10 17:09:49 +08:00
crazywhalecc
e21b5676e7 add --retry for download command 2024-03-10 17:09:49 +08:00
crazywhalecc
94b3afe6bc add pdo_sqlsrv for macOS and Linux 2024-03-10 15:30:51 +08:00
34 changed files with 492 additions and 93 deletions

2
.github/FUNDING.yml vendored
View File

@@ -10,4 +10,6 @@ liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username otechie: # Replace with a single Otechie username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
# noinspection YAMLSchemaValidation
buy_me_a_coffee: crazywhalecc
custom: 'https://github.com/crazywhalecc/crazywhalecc/blob/master/FUNDING.md' # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] custom: 'https://github.com/crazywhalecc/crazywhalecc/blob/master/FUNDING.md' # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

View File

@@ -168,4 +168,4 @@ jobs:
bin/spc download --for-extensions="$(php src/globals/test-extensions.php extensions)" --for-libs="$(php src/globals/test-extensions.php libs)" --with-php=${{ matrix.php }} --ignore-cache-sources=php-src --debug bin/spc download --for-extensions="$(php src/globals/test-extensions.php extensions)" --for-libs="$(php src/globals/test-extensions.php libs)" --with-php=${{ matrix.php }} --ignore-cache-sources=php-src --debug
- name: "Run Build Tests (build)" - name: "Run Build Tests (build)"
run: bin/spc build "$(php src/globals/test-extensions.php extensions)" $(php src/globals/test-extensions.php libs_cmd) --build-cli --build-micro --build-fpm --debug run: bin/spc build "$(php src/globals/test-extensions.php extensions)" --with-libs="$(php src/globals/test-extensions.php libs)" --build-cli --build-micro --build-fpm --debug

View File

@@ -54,5 +54,11 @@
}, },
"optimize-autoloader": true, "optimize-autoloader": true,
"sort-packages": true "sort-packages": true
} },
"funding": [
{
"type": "other",
"url": "https://github.com/crazywhalecc/crazywhalecc/blob/master/FUNDING.md"
}
]
} }

View File

@@ -43,7 +43,10 @@
}, },
"dba": { "dba": {
"type": "builtin", "type": "builtin",
"arg-type-windows": "with" "arg-type": "custom",
"lib-suggests": [
"qdbm"
]
}, },
"dom": { "dom": {
"type": "builtin", "type": "builtin",
@@ -57,6 +60,10 @@
"xml" "xml"
] ]
}, },
"ds": {
"type": "external",
"source": "ext-ds"
},
"event": { "event": {
"type": "external", "type": "external",
"source": "ext-event", "source": "ext-event",
@@ -317,6 +324,15 @@
"sqlite" "sqlite"
] ]
}, },
"pdo_sqlsrv": {
"type": "external",
"source": "pdo_sqlsrv",
"arg-type": "with",
"ext-depends": [
"pdo",
"sqlsrv"
]
},
"pgsql": { "pgsql": {
"type": "builtin", "type": "builtin",
"arg-type": "with-prefix", "arg-type": "with-prefix",
@@ -369,6 +385,11 @@
"shmop": { "shmop": {
"type": "builtin" "type": "builtin"
}, },
"simdjson": {
"type": "external",
"source": "ext-simdjson",
"cpp-extension": true
},
"simplexml": { "simplexml": {
"type": "builtin", "type": "builtin",
"arg-type": "custom", "arg-type": "custom",
@@ -605,6 +626,14 @@
"dom" "dom"
] ]
}, },
"yac": {
"type": "external",
"source": "yac",
"arg-type-unix": "custom",
"ext-depends-unix": [
"igbinary"
]
},
"yaml": { "yaml": {
"type": "external", "type": "external",
"source": "yaml", "source": "yaml",

View File

@@ -353,6 +353,9 @@
"source": "libuuid", "source": "libuuid",
"static-libs-unix": [ "static-libs-unix": [
"libuuid.a" "libuuid.a"
],
"headers": [
"uuid/uuid.h"
] ]
}, },
"libuv": { "libuv": {
@@ -525,6 +528,18 @@
"zstd" "zstd"
] ]
}, },
"qdbm": {
"source": "qdbm",
"static-libs-unix": [
"libqdbm.a"
],
"static-libs-windows": [
"qdbm_a.lib"
],
"headers-windows": [
"depot.h"
]
},
"readline": { "readline": {
"source": "readline", "source": "readline",
"static-libs-unix": [ "static-libs-unix": [

View File

@@ -52,6 +52,16 @@
"path": "COPYING" "path": "COPYING"
} }
}, },
"ext-ds": {
"type": "url",
"url": "https://pecl.php.net/get/ds",
"path": "php-src/ext/ds",
"filename": "ds.tgz",
"license": {
"type": "file",
"path": "LICENSE"
}
},
"ext-event": { "ext-event": {
"type": "url", "type": "url",
"url": "https://bitbucket.org/osmanov/pecl-event/get/3.0.8.tar.gz", "url": "https://bitbucket.org/osmanov/pecl-event/get/3.0.8.tar.gz",
@@ -90,6 +100,16 @@
"path": "LICENSE" "path": "LICENSE"
} }
}, },
"ext-simdjson": {
"type": "url",
"url": "https://pecl.php.net/get/simdjson",
"path": "php-src/ext/simdjson",
"filename": "simdjson.tgz",
"license": {
"type": "file",
"path": "LICENSE"
}
},
"ext-snappy": { "ext-snappy": {
"type": "git", "type": "git",
"path": "php-src/ext/snappy", "path": "php-src/ext/snappy",
@@ -224,7 +244,7 @@
"libargon2": { "libargon2": {
"type": "git", "type": "git",
"rev": "master", "rev": "master",
"url": "https://github.com/mpociot/phc-winner-argon2", "url": "https://github.com/static-php/phc-winner-argon2",
"license": { "license": {
"type": "file", "type": "file",
"path": "LICENSE" "path": "LICENSE"
@@ -365,7 +385,7 @@
}, },
"libuuid": { "libuuid": {
"type": "git", "type": "git",
"url": "https://github.com/cloudbase/libuuid.git", "url": "https://github.com/static-php/libuuid.git",
"rev": "master", "rev": "master",
"license": { "license": {
"type": "file", "type": "file",
@@ -495,6 +515,16 @@
"path": "LICENSE.txt" "path": "LICENSE.txt"
} }
}, },
"pdo_sqlsrv": {
"type": "url",
"url": "https://pecl.php.net/get/pdo_sqlsrv",
"path": "php-src/ext/pdo_sqlsrv",
"filename": "pdo_sqlsrv.tgz",
"license": {
"type": "file",
"path": "LICENSE"
}
},
"pkg-config": { "pkg-config": {
"type": "url", "type": "url",
"url": "https://dl.static-php.dev/static-php-cli/deps/pkg-config/pkg-config-0.29.2.tar.gz", "url": "https://dl.static-php.dev/static-php-cli/deps/pkg-config/pkg-config-0.29.2.tar.gz",
@@ -521,6 +551,15 @@
"path": "LICENSE" "path": "LICENSE"
} }
}, },
"qdbm": {
"type": "git",
"url": "https://github.com/static-php/qdbm.git",
"rev": "main",
"license": {
"type": "file",
"path": "COPYING"
}
},
"rar": { "rar": {
"type": "git", "type": "git",
"url": "https://github.com/static-php/php-rar.git", "url": "https://github.com/static-php/php-rar.git",
@@ -636,14 +675,23 @@
} }
}, },
"xz": { "xz": {
"type": "ghrel", "type": "url",
"repo": "tukaani-project/xz", "url": "https://fossies.org/linux/misc/xz-5.4.6.tar.xz",
"match": "xz-.+\\.tar\\.gz",
"license": { "license": {
"type": "file", "type": "file",
"path": "COPYING" "path": "COPYING"
} }
}, },
"yac": {
"type": "url",
"url": "https://pecl.php.net/get/yac",
"path": "php-src/ext/yac",
"filename": "yac.tgz",
"license": {
"type": "file",
"path": "LICENSE"
}
},
"yaml": { "yaml": {
"type": "git", "type": "git",
"path": "php-src/ext/yaml", "path": "php-src/ext/yaml",

View File

@@ -25,7 +25,7 @@ use Symfony\Component\Console\Command\ListCommand;
*/ */
final class ConsoleApplication extends Application final class ConsoleApplication extends Application
{ {
public const VERSION = '2.1.4'; public const VERSION = '2.1.7';
public function __construct() public function __construct()
{ {
@@ -33,6 +33,7 @@ final class ConsoleApplication extends Application
$this->addCommands( $this->addCommands(
[ [
// Common commands
new BuildCliCommand(), new BuildCliCommand(),
new BuildLibsCommand(), new BuildLibsCommand(),
new DoctorCommand(), new DoctorCommand(),

View File

@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
namespace SPC\builder\extension;
use SPC\builder\Extension;
use SPC\util\CustomExt;
#[CustomExt('dba')]
class dba extends Extension
{
public function getUnixConfigureArg(): string
{
$qdbm = $this->builder->getLib('qdbm') ? (' --with-qdbm=' . BUILD_ROOT_PATH) : '';
return '--enable-dba' . $qdbm;
}
public function getWindowsConfigureArg(): string
{
$qdbm = $this->builder->getLib('qdbm') ? ' --with-qdbm' : '';
return '--with-dba' . $qdbm;
}
}

View File

@@ -11,6 +11,11 @@ use SPC\util\CustomExt;
#[CustomExt('password-argon2')] #[CustomExt('password-argon2')]
class password_argon2 extends Extension class password_argon2 extends Extension
{ {
public function getDistName(): string
{
return '';
}
public function runCliCheckUnix(): void public function runCliCheckUnix(): void
{ {
[$ret] = shell()->execWithResult(BUILD_ROOT_PATH . '/bin/php -r "assert(defined(\'PASSWORD_ARGON2I\'));"'); [$ret] = shell()->execWithResult(BUILD_ROOT_PATH . '/bin/php -r "assert(defined(\'PASSWORD_ARGON2I\'));"');

View File

@@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
namespace SPC\builder\extension;
use SPC\builder\Extension;
use SPC\store\FileSystem;
use SPC\util\CustomExt;
#[CustomExt('simdjson')]
class simdjson extends Extension
{
public function patchBeforeBuildconf(): bool
{
$php_ver = $this->builder->getPHPVersionID();
FileSystem::replaceFileRegex(
SOURCE_PATH . '/php-src/ext/simdjson/config.m4',
'/php_version=(`.*`)$/m',
'php_version=' . strval($php_ver)
);
FileSystem::replaceFileStr(
SOURCE_PATH . '/php-src/ext/simdjson/config.m4',
'if test -z "$PHP_CONFIG"; then',
'if false; then'
);
FileSystem::replaceFileStr(
SOURCE_PATH . '/php-src/ext/simdjson/config.w32',
"'yes',",
'PHP_SIMDJSON_SHARED,'
);
return true;
}
}

View File

@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace SPC\builder\extension;
use SPC\builder\Extension;
use SPC\store\FileSystem;
use SPC\util\CustomExt;
#[CustomExt('yac')]
class yac extends Extension
{
public function patchBeforeBuildconf(): bool
{
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/ext/yac/storage/allocator/yac_allocator.h', 'defined(HAVE_SHM_MMAP_ANON)', 'defined(YAC_ALLOCATOR_H)');
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/ext/yac/serializer/igbinary.c', '#ifdef YAC_ENABLE_IGBINARY', '#if 1');
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/ext/yac/serializer/json.c', '#if YAC_ENABLE_JSON', '#if 1');
return true;
}
public function getUnixConfigureArg(): string
{
return '--enable-yac --enable-igbinary --enable-json';
}
}

View File

@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace SPC\builder\linux\library; namespace SPC\builder\linux\library;
use SPC\exception\WrongUsageException;
use SPC\store\FileSystem; use SPC\store\FileSystem;
class libargon2 extends LinuxLibraryBase class libargon2 extends LinuxLibraryBase
@@ -15,10 +14,6 @@ class libargon2 extends LinuxLibraryBase
public function patchBeforeBuild(): bool public function patchBeforeBuild(): bool
{ {
// detect libsodium (The libargon2 conflicts with the libsodium library.)
if ($this->builder->getLib('libsodium') !== null) {
throw new WrongUsageException('libargon2 (required by password-argon2) conflicts with the libsodium library !');
}
FileSystem::replaceFileStr($this->source_dir . '/Makefile', 'LIBRARY_REL ?= lib/x86_64-linux-gnu', 'LIBRARY_REL ?= lib'); FileSystem::replaceFileStr($this->source_dir . '/Makefile', 'LIBRARY_REL ?= lib/x86_64-linux-gnu', 'LIBRARY_REL ?= lib');
return true; return true;
} }

View File

@@ -24,6 +24,7 @@ use SPC\builder\linux\SystemUtil;
use SPC\exception\FileSystemException; use SPC\exception\FileSystemException;
use SPC\exception\RuntimeException; use SPC\exception\RuntimeException;
use SPC\exception\WrongUsageException; use SPC\exception\WrongUsageException;
use SPC\store\FileSystem;
class openssl extends LinuxLibraryBase class openssl extends LinuxLibraryBase
{ {
@@ -76,5 +77,15 @@ class openssl extends LinuxLibraryBase
->exec("make -j{$this->builder->concurrency} CNF_EX_LIBS=\"{$ex_lib}\"") ->exec("make -j{$this->builder->concurrency} CNF_EX_LIBS=\"{$ex_lib}\"")
->exec("make install_sw DESTDIR={$destdir}"); ->exec("make install_sw DESTDIR={$destdir}");
$this->patchPkgconfPrefix(['libssl.pc', 'openssl.pc', 'libcrypto.pc']); $this->patchPkgconfPrefix(['libssl.pc', 'openssl.pc', 'libcrypto.pc']);
// patch for openssl 3.3.0+
if (!str_contains($file = FileSystem::readFile(BUILD_LIB_PATH . '/pkgconfig/libssl.pc'), 'prefix=')) {
FileSystem::writeFile(BUILD_LIB_PATH . '/pkgconfig/libssl.pc', 'prefix=' . BUILD_ROOT_PATH . "\n" . $file);
}
if (!str_contains($file = FileSystem::readFile(BUILD_LIB_PATH . '/pkgconfig/openssl.pc'), 'prefix=')) {
FileSystem::writeFile(BUILD_LIB_PATH . '/pkgconfig/openssl.pc', 'prefix=' . BUILD_ROOT_PATH . "\n" . $file);
}
if (!str_contains($file = FileSystem::readFile(BUILD_LIB_PATH . '/pkgconfig/libcrypto.pc'), 'prefix=')) {
FileSystem::writeFile(BUILD_LIB_PATH . '/pkgconfig/libcrypto.pc', 'prefix=' . BUILD_ROOT_PATH . "\n" . $file);
}
} }
} }

View File

@@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace SPC\builder\linux\library;
class qdbm extends LinuxLibraryBase
{
use \SPC\builder\unix\library\qdbm;
public const NAME = 'qdbm';
}

View File

@@ -23,6 +23,7 @@ namespace SPC\builder\macos\library;
use SPC\exception\FileSystemException; use SPC\exception\FileSystemException;
use SPC\exception\RuntimeException; use SPC\exception\RuntimeException;
use SPC\exception\WrongUsageException; use SPC\exception\WrongUsageException;
use SPC\store\FileSystem;
class openssl extends MacOSLibraryBase class openssl extends MacOSLibraryBase
{ {
@@ -58,5 +59,15 @@ class openssl extends MacOSLibraryBase
->exec("make -j{$this->builder->concurrency} CNF_EX_LIBS=\"{$ex_lib}\"") ->exec("make -j{$this->builder->concurrency} CNF_EX_LIBS=\"{$ex_lib}\"")
->exec("make install_sw DESTDIR={$destdir}"); ->exec("make install_sw DESTDIR={$destdir}");
$this->patchPkgconfPrefix(['libssl.pc', 'openssl.pc', 'libcrypto.pc']); $this->patchPkgconfPrefix(['libssl.pc', 'openssl.pc', 'libcrypto.pc']);
// patch for openssl 3.3.0+
if (!str_contains($file = FileSystem::readFile(BUILD_LIB_PATH . '/pkgconfig/libssl.pc'), 'prefix=')) {
FileSystem::writeFile(BUILD_LIB_PATH . '/pkgconfig/libssl.pc', 'prefix=' . BUILD_ROOT_PATH . "\n" . $file);
}
if (!str_contains($file = FileSystem::readFile(BUILD_LIB_PATH . '/pkgconfig/openssl.pc'), 'prefix=')) {
FileSystem::writeFile(BUILD_LIB_PATH . '/pkgconfig/openssl.pc', 'prefix=' . BUILD_ROOT_PATH . "\n" . $file);
}
if (!str_contains($file = FileSystem::readFile(BUILD_LIB_PATH . '/pkgconfig/libcrypto.pc'), 'prefix=')) {
FileSystem::writeFile(BUILD_LIB_PATH . '/pkgconfig/libcrypto.pc', 'prefix=' . BUILD_ROOT_PATH . "\n" . $file);
}
} }
} }

View File

@@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace SPC\builder\macos\library;
class qdbm extends MacOSLibraryBase
{
use \SPC\builder\unix\library\qdbm;
public const NAME = 'qdbm';
}

View File

@@ -48,7 +48,7 @@ trait UnixLibraryTrait
* @throws RuntimeException * @throws RuntimeException
* @throws WrongUsageException * @throws WrongUsageException
*/ */
public function makeAutoconfEnv(string $prefix = null): string public function makeAutoconfEnv(?string $prefix = null): string
{ {
if ($prefix === null) { if ($prefix === null) {
$prefix = str_replace('-', '_', strtoupper(static::NAME)); $prefix = str_replace('-', '_', strtoupper(static::NAME));

View File

@@ -10,29 +10,37 @@ use SPC\store\FileSystem;
trait libuuid trait libuuid
{ {
public function patchBeforeBuild(): bool
{
FileSystem::replaceFileStr($this->source_dir . '/configure', '-${am__api_version}', '');
return true;
}
/** /**
* @throws FileSystemException * @throws FileSystemException
* @throws RuntimeException * @throws RuntimeException
*/ */
protected function build(): void protected function build(): void
{ {
shell()->cd($this->source_dir) FileSystem::resetDir($this->source_dir . '/build');
->exec('chmod +x configure') shell()->cd($this->source_dir . '/build')
->exec('chmod +x install-sh')
->exec( ->exec(
'./configure ' . 'cmake ' .
'--enable-static --disable-shared ' . "{$this->builder->makeCmakeArgs()} " .
'--prefix=' '..'
) )
->exec('make clean') ->exec("cmake --build . -j {$this->builder->concurrency}");
->exec("make -j{$this->builder->concurrency}") copy($this->source_dir . '/build/libuuid.a', BUILD_LIB_PATH . '/libuuid.a');
->exec('make install DESTDIR=' . BUILD_ROOT_PATH); FileSystem::createDir(BUILD_INCLUDE_PATH . '/uuid');
$this->patchPkgconfPrefix(['uuid.pc']); copy($this->source_dir . '/uuid.h', BUILD_INCLUDE_PATH . '/uuid/uuid.h');
$pc = FileSystem::readFile($this->source_dir . '/uuid.pc.in');
$pc = str_replace([
'@prefix@',
'@exec_prefix@',
'@libdir@',
'@includedir@',
'@LIBUUID_VERSION@',
], [
BUILD_ROOT_PATH,
'${prefix}',
'${prefix}/lib',
'${prefix}/include',
'1.0.3',
], $pc);
FileSystem::writeFile(BUILD_LIB_PATH . '/pkgconfig/uuid.pc', $pc);
} }
} }

View File

@@ -8,7 +8,7 @@ trait pkgconfig
{ {
protected function build(): void protected function build(): void
{ {
$macos_env = "CFLAGS='{$this->builder->arch_c_flags} -Wimplicit-function-declaration' "; $macos_env = "CFLAGS='{$this->builder->arch_c_flags} -Wimplicit-function-declaration -Wno-int-conversion' ";
$linux_env = 'LDFLAGS=--static '; $linux_env = 'LDFLAGS=--static ';
shell()->cd($this->source_dir) shell()->cd($this->source_dir)

View File

@@ -27,26 +27,31 @@ trait postgresql
'libxslt' => 'libxslt', 'libxslt' => 'libxslt',
'icu' => 'icu-i18n', 'icu' => 'icu-i18n',
]; ];
$error_exec_cnt = 0;
foreach ($optional_packages as $lib => $pkg) { foreach ($optional_packages as $lib => $pkg) {
if ($this->getBuilder()->getLib($lib)) { if ($this->getBuilder()->getLib($lib)) {
$packages .= ' ' . $pkg; $packages .= ' ' . $pkg;
$output = shell()->execWithResult("pkg-config --static {$pkg}"); $output = shell()->execWithResult("pkg-config --static {$pkg}");
$error_exec_cnt += $output[0] === 0 ? 0 : 1;
logger()->info(var_export($output[1], true)); logger()->info(var_export($output[1], true));
} }
} }
$output = shell()->execWithResult("pkg-config --cflags-only-I --static {$packages}"); $output = shell()->execWithResult("pkg-config --cflags-only-I --static {$packages}");
$error_exec_cnt += $output[0] === 0 ? 0 : 1;
if (!empty($output[1][0])) { if (!empty($output[1][0])) {
$cppflags = $output[1][0]; $cppflags = $output[1][0];
$envs .= " CPPFLAGS=\"{$cppflags}\""; $envs .= " CPPFLAGS=\"{$cppflags}\"";
} }
$output = shell()->execWithResult("pkg-config --libs-only-L --static {$packages}"); $output = shell()->execWithResult("pkg-config --libs-only-L --static {$packages}");
$error_exec_cnt += $output[0] === 0 ? 0 : 1;
if (!empty($output[1][0])) { if (!empty($output[1][0])) {
$ldflags = $output[1][0]; $ldflags = $output[1][0];
$envs .= $this instanceof MacOSLibraryBase ? " LDFLAGS=\"{$ldflags}\" " : " LDFLAGS=\"{$ldflags} -static\" "; $envs .= $this instanceof MacOSLibraryBase ? " LDFLAGS=\"{$ldflags}\" " : " LDFLAGS=\"{$ldflags} -static\" ";
} }
$output = shell()->execWithResult("pkg-config --libs-only-l --static {$packages}"); $output = shell()->execWithResult("pkg-config --libs-only-l --static {$packages}");
$error_exec_cnt += $output[0] === 0 ? 0 : 1;
if (!empty($output[1][0])) { if (!empty($output[1][0])) {
$libs = $output[1][0]; $libs = $output[1][0];
$libcpp = ''; $libcpp = '';
@@ -55,6 +60,9 @@ trait postgresql
} }
$envs .= " LIBS=\"{$libs}{$libcpp}\" "; $envs .= " LIBS=\"{$libs}{$libcpp}\" ";
} }
if ($error_exec_cnt > 0) {
throw new RuntimeException('Failed to get pkg-config information!');
}
FileSystem::resetDir($this->source_dir . '/build'); FileSystem::resetDir($this->source_dir . '/build');

View File

@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace SPC\builder\unix\library;
use SPC\builder\macos\library\MacOSLibraryBase;
use SPC\exception\FileSystemException;
use SPC\exception\RuntimeException;
use SPC\store\FileSystem;
trait qdbm
{
/**
* @throws FileSystemException
* @throws RuntimeException
*/
protected function build(): void
{
shell()->cd($this->source_dir)
->exec(
'./configure ' .
'--enable-static --disable-shared ' .
'--prefix='
)
->exec('make clean');
FileSystem::replaceFileRegex($this->source_dir . '/Makefile', '/MYLIBS = libqdbm.a.*/m', 'MYLIBS = libqdbm.a');
shell()->cd($this->source_dir)
->exec("make -j{$this->builder->concurrency}" . ($this instanceof MacOSLibraryBase ? ' mac' : ''))
->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
$this->patchPkgconfPrefix(['qdbm.pc']);
}
}

View File

@@ -46,6 +46,9 @@ class WindowsBuilder extends BuilderBase
// make cmake toolchain // make cmake toolchain
$this->cmake_toolchain_file = SystemUtil::makeCmakeToolchainFile(); $this->cmake_toolchain_file = SystemUtil::makeCmakeToolchainFile();
f_mkdir(BUILD_INCLUDE_PATH, recursive: true);
f_mkdir(BUILD_LIB_PATH, recursive: true);
} }
/** /**

View File

@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
namespace SPC\builder\windows\library;
use SPC\store\FileSystem;
class qdbm extends WindowsLibraryBase
{
public const NAME = 'qdbm';
protected function build(): void
{
cmd()->cd($this->source_dir)
->execWithWrapper(
$this->builder->makeSimpleWrapper('nmake'),
'/f VCMakefile'
);
copy($this->source_dir . '\qdbm_a.lib', BUILD_LIB_PATH . '\qdbm_a.lib');
copy($this->source_dir . '\depot.h', BUILD_INCLUDE_PATH . '\depot.h');
// FileSystem::copyDir($this->source_dir . '\include\curl', BUILD_INCLUDE_PATH . '\curl');
}
}

View File

@@ -25,7 +25,7 @@ abstract class BaseCommand extends Command
protected OutputInterface $output; protected OutputInterface $output;
public function __construct(string $name = null) public function __construct(?string $name = null)
{ {
parent::__construct($name); parent::__construct($name);
$this->addOption('debug', null, null, 'Enable debug mode'); $this->addOption('debug', null, null, 'Enable debug mode');

View File

@@ -8,7 +8,7 @@ use Symfony\Component\Console\Input\InputOption;
abstract class BuildCommand extends BaseCommand abstract class BuildCommand extends BaseCommand
{ {
public function __construct(string $name = null) public function __construct(?string $name = null)
{ {
parent::__construct($name); parent::__construct($name);

View File

@@ -39,6 +39,7 @@ class DownloadCommand extends BaseCommand
$this->addOption('for-libs', 'l', InputOption::VALUE_REQUIRED, 'Fetch by libraries, e.g "libcares,openssl,onig"'); $this->addOption('for-libs', 'l', InputOption::VALUE_REQUIRED, 'Fetch by libraries, e.g "libcares,openssl,onig"');
$this->addOption('without-suggestions', null, null, 'Do not fetch suggested sources when using --for-extensions'); $this->addOption('without-suggestions', null, null, 'Do not fetch suggested sources when using --for-extensions');
$this->addOption('ignore-cache-sources', null, InputOption::VALUE_REQUIRED, 'Ignore some source caches, comma separated, e.g "php-src,curl,openssl"', ''); $this->addOption('ignore-cache-sources', null, InputOption::VALUE_REQUIRED, 'Ignore some source caches, comma separated, e.g "php-src,curl,openssl"', '');
$this->addOption('retry', 'R', InputOption::VALUE_REQUIRED, 'Set retry time when downloading failed (default: 0)', '0');
} }
/** /**
@@ -127,6 +128,10 @@ class DownloadCommand extends BaseCommand
return static::FAILURE; return static::FAILURE;
} }
// retry
$retry = intval($this->getOption('retry'));
f_putenv('SPC_RETRY_TIME=' . $retry);
// Use shallow-clone can reduce git resource download // Use shallow-clone can reduce git resource download
if ($this->getOption('shallow-clone')) { if ($this->getOption('shallow-clone')) {
define('GIT_SHALLOW_CLONE', true); define('GIT_SHALLOW_CLONE', true);

View File

@@ -40,6 +40,10 @@ class LinuxToolCheckList
'xz', 'xz',
]; ];
private const PROVIDED_COMMAND = [
'binutils-gold' => 'ld.gold',
];
/** @noinspection PhpUnused */ /** @noinspection PhpUnused */
#[AsCheckItem('if necessary tools are installed', limit_os: 'Linux', level: 999)] #[AsCheckItem('if necessary tools are installed', limit_os: 'Linux', level: 999)]
public function checkCliTools(): ?CheckResult public function checkCliTools(): ?CheckResult
@@ -52,9 +56,9 @@ class LinuxToolCheckList
default => self::TOOLS_DEBIAN, default => self::TOOLS_DEBIAN,
}; };
$missing = []; $missing = [];
foreach ($required as $cmd) { foreach ($required as $package) {
if ($this->findCommand($cmd) === null) { if ($this->findCommand(self::PROVIDED_COMMAND[$package] ?? $package) === null) {
$missing[] = $cmd; $missing[] = $package;
} }
} }
if (!empty($missing)) { if (!empty($missing)) {
@@ -70,6 +74,22 @@ class LinuxToolCheckList
return CheckResult::ok(); return CheckResult::ok();
} }
#[AsCheckItem('if cmake version >= 3.18', limit_os: 'Linux')]
public function checkCMakeVersion(): ?CheckResult
{
$check_cmd = 'cmake --version';
$pattern = '/cmake version (.*)/m';
$out = shell()->execWithResult($check_cmd, false)[1][0];
if (preg_match($pattern, $out, $match)) {
$ver = $match[1];
if (version_compare($ver, '3.18.0') <= 0) {
return CheckResult::fail('cmake version is too low (' . $ver . '), please update it manually!');
}
return CheckResult::ok($match[1]);
}
return CheckResult::fail('Failed to get cmake version');
}
/** @noinspection PhpUnused */ /** @noinspection PhpUnused */
#[AsCheckItem('if necessary linux headers are installed', limit_os: 'Linux')] #[AsCheckItem('if necessary linux headers are installed', limit_os: 'Linux')]
public function checkSystemOSPackages(): ?CheckResult public function checkSystemOSPackages(): ?CheckResult

View File

@@ -37,10 +37,12 @@ class MacOSToolCheckList
#[AsCheckItem('if homebrew has installed', limit_os: 'Darwin', level: 998)] #[AsCheckItem('if homebrew has installed', limit_os: 'Darwin', level: 998)]
public function checkBrew(): ?CheckResult public function checkBrew(): ?CheckResult
{ {
// 检查 homebrew 是否已经安装 if (($path = $this->findCommand('brew')) === null) {
if ($this->findCommand('brew') === null) {
return CheckResult::fail('Homebrew is not installed', 'brew'); return CheckResult::fail('Homebrew is not installed', 'brew');
} }
if ($path !== '/opt/homebrew/bin/brew' && php_uname('m') === 'arm64') {
return CheckResult::fail('Current homebrew (/usr/local/bin/homebrew) is not installed for M1 Mac, please re-install homebrew in /opt/homebrew/ !');
}
return CheckResult::ok(); return CheckResult::ok();
} }

View File

@@ -20,7 +20,7 @@ class OSCheckList
return CheckResult::fail('Current OS is not supported: ' . PHP_OS_FAMILY); return CheckResult::fail('Current OS is not supported: ' . PHP_OS_FAMILY);
} }
$distro = PHP_OS_FAMILY === 'Linux' ? (' ' . SystemUtil::getOSRelease()['dist']) : ''; $distro = PHP_OS_FAMILY === 'Linux' ? (' ' . SystemUtil::getOSRelease()['dist']) : '';
$known_distro = PHP_OS_FAMILY === 'Linux' && in_array(SystemUtil::getOSRelease()['dist'], SystemUtil::getSupportedDistros()); $known_distro = PHP_OS_FAMILY !== 'Linux' || in_array(SystemUtil::getOSRelease()['dist'], SystemUtil::getSupportedDistros());
return CheckResult::ok(PHP_OS_FAMILY . ' ' . php_uname('m') . $distro . ', supported' . ($known_distro ? '' : ' (but not tested on this distro)')); return CheckResult::ok(PHP_OS_FAMILY . ' ' . php_uname('m') . $distro . ', supported' . ($known_distro ? '' : ' (but not tested on this distro)'));
} }
} }

View File

@@ -7,6 +7,7 @@ namespace SPC\store;
use SPC\exception\DownloaderException; use SPC\exception\DownloaderException;
use SPC\exception\FileSystemException; use SPC\exception\FileSystemException;
use SPC\exception\RuntimeException; use SPC\exception\RuntimeException;
use SPC\exception\WrongUsageException;
use SPC\store\source\CustomSourceBase; use SPC\store\source\CustomSourceBase;
/** /**
@@ -26,7 +27,8 @@ class Downloader
{ {
logger()->debug("finding {$name} source from bitbucket tag"); logger()->debug("finding {$name} source from bitbucket tag");
$data = json_decode(self::curlExec( $data = json_decode(self::curlExec(
url: "https://api.bitbucket.org/2.0/repositories/{$source['repo']}/refs/tags" url: "https://api.bitbucket.org/2.0/repositories/{$source['repo']}/refs/tags",
retry: intval(getenv('SPC_RETRY_TIME') ? getenv('SPC_RETRY_TIME') : 0)
), true); ), true);
$ver = $data['values'][0]['name']; $ver = $data['values'][0]['name'];
if (!$ver) { if (!$ver) {
@@ -35,7 +37,8 @@ class Downloader
$url = "https://bitbucket.org/{$source['repo']}/get/{$ver}.tar.gz"; $url = "https://bitbucket.org/{$source['repo']}/get/{$ver}.tar.gz";
$headers = self::curlExec( $headers = self::curlExec(
url: $url, url: $url,
method: 'HEAD' method: 'HEAD',
retry: intval(getenv('SPC_RETRY_TIME') ? getenv('SPC_RETRY_TIME') : 0)
); );
preg_match('/^content-disposition:\s+attachment;\s*filename=("?)(?<filename>.+\.tar\.gz)\1/im', $headers, $matches); preg_match('/^content-disposition:\s+attachment;\s*filename=("?)(?<filename>.+\.tar\.gz)\1/im', $headers, $matches);
if ($matches) { if ($matches) {
@@ -62,7 +65,8 @@ class Downloader
logger()->debug("finding {$name} source from github {$type} tarball"); logger()->debug("finding {$name} source from github {$type} tarball");
$data = json_decode(self::curlExec( $data = json_decode(self::curlExec(
url: "https://api.github.com/repos/{$source['repo']}/{$type}", url: "https://api.github.com/repos/{$source['repo']}/{$type}",
hooks: [[CurlHook::class, 'setupGithubToken']] hooks: [[CurlHook::class, 'setupGithubToken']],
retry: intval(getenv('SPC_RETRY_TIME') ? getenv('SPC_RETRY_TIME') : 0)
), true); ), true);
$url = $data[0]['tarball_url']; $url = $data[0]['tarball_url'];
if (!$url) { if (!$url) {
@@ -72,6 +76,7 @@ class Downloader
url: $url, url: $url,
method: 'HEAD', method: 'HEAD',
hooks: [[CurlHook::class, 'setupGithubToken']], hooks: [[CurlHook::class, 'setupGithubToken']],
retry: intval(getenv('SPC_RETRY_TIME') ? getenv('SPC_RETRY_TIME') : 0)
); );
preg_match('/^content-disposition:\s+attachment;\s*filename=("?)(?<filename>.+\.tar\.gz)\1/im', $headers, $matches); preg_match('/^content-disposition:\s+attachment;\s*filename=("?)(?<filename>.+\.tar\.gz)\1/im', $headers, $matches);
if ($matches) { if ($matches) {
@@ -97,6 +102,7 @@ class Downloader
$data = json_decode(self::curlExec( $data = json_decode(self::curlExec(
url: "https://api.github.com/repos/{$source['repo']}/releases", url: "https://api.github.com/repos/{$source['repo']}/releases",
hooks: [[CurlHook::class, 'setupGithubToken']], hooks: [[CurlHook::class, 'setupGithubToken']],
retry: intval(getenv('SPC_RETRY_TIME') ? getenv('SPC_RETRY_TIME') : 0)
), true); ), true);
$url = null; $url = null;
foreach ($data as $release) { foreach ($data as $release) {
@@ -130,7 +136,7 @@ class Downloader
public static function getFromFileList(string $name, array $source): array public static function getFromFileList(string $name, array $source): array
{ {
logger()->debug("finding {$name} source from file list"); logger()->debug("finding {$name} source from file list");
$page = self::curlExec($source['url']); $page = self::curlExec($source['url'], retry: intval(getenv('SPC_RETRY_TIME') ? getenv('SPC_RETRY_TIME') : 0));
preg_match_all($source['regex'], $page, $matches); preg_match_all($source['regex'], $page, $matches);
if (!$matches) { if (!$matches) {
throw new DownloaderException("Failed to get {$name} version"); throw new DownloaderException("Failed to get {$name} version");
@@ -175,7 +181,7 @@ class Downloader
} }
}; };
self::registerCancelEvent($cancel_func); self::registerCancelEvent($cancel_func);
self::curlDown(url: $url, path: FileSystem::convertPath(DOWNLOAD_PATH . "/{$filename}")); self::curlDown(url: $url, path: FileSystem::convertPath(DOWNLOAD_PATH . "/{$filename}"), retry: intval(getenv('SPC_RETRY_TIME') ? getenv('SPC_RETRY_TIME') : 0));
self::unregisterCancelEvent(); self::unregisterCancelEvent();
logger()->debug("Locking {$filename}"); logger()->debug("Locking {$filename}");
self::lockSource($name, ['source_type' => 'archive', 'filename' => $filename, 'move_path' => $move_path]); self::lockSource($name, ['source_type' => 'archive', 'filename' => $filename, 'move_path' => $move_path]);
@@ -203,7 +209,7 @@ class Downloader
* @throws FileSystemException * @throws FileSystemException
* @throws RuntimeException * @throws RuntimeException
*/ */
public static function downloadGit(string $name, string $url, string $branch, ?string $move_path = null): void public static function downloadGit(string $name, string $url, string $branch, ?string $move_path = null, int $retry = 0): void
{ {
$download_path = FileSystem::convertPath(DOWNLOAD_PATH . "/{$name}"); $download_path = FileSystem::convertPath(DOWNLOAD_PATH . "/{$name}");
if (file_exists($download_path)) { if (file_exists($download_path)) {
@@ -217,14 +223,25 @@ class Downloader
FileSystem::removeDir($download_path); FileSystem::removeDir($download_path);
} }
}; };
self::registerCancelEvent($cancel_func); try {
f_passthru( self::registerCancelEvent($cancel_func);
SPC_GIT_EXEC . ' clone' . $check . f_passthru(
' --config core.autocrlf=false ' . SPC_GIT_EXEC . ' clone' . $check .
"--branch \"{$branch}\" " . (defined('GIT_SHALLOW_CLONE') ? '--depth 1 --single-branch' : '') . " --recursive \"{$url}\" \"{$download_path}\"" ' --config core.autocrlf=false ' .
); "--branch \"{$branch}\" " . (defined('GIT_SHALLOW_CLONE') ? '--depth 1 --single-branch' : '') . " --recursive \"{$url}\" \"{$download_path}\""
self::unregisterCancelEvent(); );
} catch (RuntimeException $e) {
if ($e->getCode() === 2 || $e->getCode() === -1073741510) {
throw new WrongUsageException('Keyboard interrupted, download failed !');
}
if ($retry > 0) {
self::downloadGit($name, $url, $branch, $move_path, $retry - 1);
return;
}
throw $e;
} finally {
self::unregisterCancelEvent();
}
// Lock // Lock
logger()->debug("Locking git source {$name}"); logger()->debug("Locking git source {$name}");
self::lockSource($name, ['source_type' => 'dir', 'dirname' => $name, 'move_path' => $move_path]); self::lockSource($name, ['source_type' => 'dir', 'dirname' => $name, 'move_path' => $move_path]);
@@ -311,7 +328,13 @@ class Downloader
self::downloadFile($name, $url, $filename, $pkg['extract'] ?? null); self::downloadFile($name, $url, $filename, $pkg['extract'] ?? null);
break; break;
case 'git': // Git repo case 'git': // Git repo
self::downloadGit($name, $pkg['url'], $pkg['rev'], $pkg['extract'] ?? null); self::downloadGit(
$name,
$pkg['url'],
$pkg['rev'],
$pkg['extract'] ?? null,
intval(getenv('SPC_RETRY_TIME') ? getenv('SPC_RETRY_TIME') : 0)
);
break; break;
case 'custom': // Custom download method, like API-based download or other case 'custom': // Custom download method, like API-based download or other
$classes = FileSystem::getClassesPsr4(ROOT_DIR . '/src/SPC/store/source', 'SPC\\store\\source'); $classes = FileSystem::getClassesPsr4(ROOT_DIR . '/src/SPC/store/source', 'SPC\\store\\source');
@@ -405,7 +428,13 @@ class Downloader
self::downloadFile($name, $url, $filename, $source['path'] ?? null); self::downloadFile($name, $url, $filename, $source['path'] ?? null);
break; break;
case 'git': // Git repo case 'git': // Git repo
self::downloadGit($name, $source['url'], $source['rev'], $source['path'] ?? null); self::downloadGit(
$name,
$source['url'],
$source['rev'],
$source['path'] ?? null,
intval(getenv('SPC_RETRY_TIME') ? getenv('SPC_RETRY_TIME') : 0)
);
break; break;
case 'custom': // Custom download method, like API-based download or other case 'custom': // Custom download method, like API-based download or other
$classes = FileSystem::getClassesPsr4(ROOT_DIR . '/src/SPC/store/source', 'SPC\\store\\source'); $classes = FileSystem::getClassesPsr4(ROOT_DIR . '/src/SPC/store/source', 'SPC\\store\\source');
@@ -435,57 +464,71 @@ class Downloader
* *
* @throws DownloaderException * @throws DownloaderException
*/ */
public static function curlExec(string $url, string $method = 'GET', array $headers = [], array $hooks = []): string public static function curlExec(string $url, string $method = 'GET', array $headers = [], array $hooks = [], int $retry = 0): string
{ {
foreach ($hooks as $hook) { foreach ($hooks as $hook) {
$hook($method, $url, $headers); $hook($method, $url, $headers);
} }
FileSystem::findCommandPath('curl'); try {
FileSystem::findCommandPath('curl');
$methodArg = match ($method) { $methodArg = match ($method) {
'GET' => '', 'GET' => '',
'HEAD' => '-I', 'HEAD' => '-I',
default => "-X \"{$method}\"", default => "-X \"{$method}\"",
}; };
$headerArg = implode(' ', array_map(fn ($v) => '"-H' . $v . '"', $headers)); $headerArg = implode(' ', array_map(fn ($v) => '"-H' . $v . '"', $headers));
$cmd = SPC_CURL_EXEC . " -sfSL {$methodArg} {$headerArg} \"{$url}\""; $cmd = SPC_CURL_EXEC . " -sfSL {$methodArg} {$headerArg} \"{$url}\"";
if (getenv('CACHE_API_EXEC') === 'yes') { if (getenv('CACHE_API_EXEC') === 'yes') {
if (!file_exists(FileSystem::convertPath(DOWNLOAD_PATH . '/.curl_exec_cache'))) { if (!file_exists(FileSystem::convertPath(DOWNLOAD_PATH . '/.curl_exec_cache'))) {
$cache = []; $cache = [];
} else { } else {
$cache = json_decode(file_get_contents(FileSystem::convertPath(DOWNLOAD_PATH . '/.curl_exec_cache')), true); $cache = json_decode(file_get_contents(FileSystem::convertPath(DOWNLOAD_PATH . '/.curl_exec_cache')), true);
} }
if (isset($cache[$cmd]) && $cache[$cmd]['expire'] >= time()) { if (isset($cache[$cmd]) && $cache[$cmd]['expire'] >= time()) {
return $cache[$cmd]['cache'];
}
f_exec($cmd, $output, $ret);
if ($ret === 2 || $ret === -1073741510) {
throw new RuntimeException('failed http fetch');
}
if ($ret !== 0) {
throw new DownloaderException('failed http fetch');
}
$cache[$cmd]['cache'] = implode("\n", $output);
$cache[$cmd]['expire'] = time() + 3600;
file_put_contents(FileSystem::convertPath(DOWNLOAD_PATH . '/.curl_exec_cache'), json_encode($cache));
return $cache[$cmd]['cache']; return $cache[$cmd]['cache'];
} }
f_exec($cmd, $output, $ret); f_exec($cmd, $output, $ret);
if ($ret === 2 || $ret === -1073741510) {
throw new RuntimeException('failed http fetch');
}
if ($ret !== 0) { if ($ret !== 0) {
throw new DownloaderException('failed http fetch'); throw new DownloaderException('failed http fetch');
} }
$cache[$cmd]['cache'] = implode("\n", $output); return implode("\n", $output);
$cache[$cmd]['expire'] = time() + 3600; } catch (DownloaderException $e) {
file_put_contents(FileSystem::convertPath(DOWNLOAD_PATH . '/.curl_exec_cache'), json_encode($cache)); if ($retry > 0) {
return $cache[$cmd]['cache']; logger()->notice('Retrying curl exec ...');
return self::curlExec($url, $method, $headers, $hooks, $retry - 1);
}
throw $e;
} }
f_exec($cmd, $output, $ret);
if ($ret !== 0) {
throw new DownloaderException('failed http fetch');
}
return implode("\n", $output);
} }
/** /**
* Use curl to download sources from url * Use curl to download sources from url
* *
* @throws DownloaderException
* @throws RuntimeException * @throws RuntimeException
*/ */
public static function curlDown(string $url, string $path, string $method = 'GET', array $headers = [], array $hooks = []): void public static function curlDown(string $url, string $path, string $method = 'GET', array $headers = [], array $hooks = [], int $retry = 0): void
{ {
$used_headers = $headers;
foreach ($hooks as $hook) { foreach ($hooks as $hook) {
$hook($method, $url, $headers); $hook($method, $url, $used_headers);
} }
$methodArg = match ($method) { $methodArg = match ($method) {
@@ -493,10 +536,23 @@ class Downloader
'HEAD' => '-I', 'HEAD' => '-I',
default => "-X \"{$method}\"", default => "-X \"{$method}\"",
}; };
$headerArg = implode(' ', array_map(fn ($v) => '"-H' . $v . '"', $headers)); $headerArg = implode(' ', array_map(fn ($v) => '"-H' . $v . '"', $used_headers));
$check = !defined('DEBUG_MODE') ? 's' : '#'; $check = !defined('DEBUG_MODE') ? 's' : '#';
$cmd = SPC_CURL_EXEC . " -{$check}fSL -o \"{$path}\" {$methodArg} {$headerArg} \"{$url}\""; $cmd = SPC_CURL_EXEC . " -{$check}fSL -o \"{$path}\" {$methodArg} {$headerArg} \"{$url}\"";
f_passthru($cmd); try {
f_passthru($cmd);
} catch (RuntimeException $e) {
var_dump($e->getCode());
if ($e->getCode() === 2 || $e->getCode() === -1073741510) {
throw new WrongUsageException('Keyboard interrupted, download failed !');
}
if ($retry > 0) {
logger()->notice('Retrying curl download ...');
self::curlDown($url, $path, $method, $used_headers, retry: intval(getenv('SPC_RETRY_TIME') ? getenv('SPC_RETRY_TIME') : 0));
return;
}
throw $e;
}
} }
/** /**
@@ -509,7 +565,7 @@ class Downloader
if (PHP_OS_FAMILY === 'Windows') { if (PHP_OS_FAMILY === 'Windows') {
sapi_windows_set_ctrl_handler($callback); sapi_windows_set_ctrl_handler($callback);
} elseif (extension_loaded('pcntl')) { } elseif (extension_loaded('pcntl')) {
pcntl_signal(SIGINT, $callback); pcntl_signal(2, $callback);
} else { } else {
logger()->debug('You have not enabled `pcntl` extension, cannot prevent download file corruption when Ctrl+C'); logger()->debug('You have not enabled `pcntl` extension, cannot prevent download file corruption when Ctrl+C');
} }
@@ -523,7 +579,7 @@ class Downloader
if (PHP_OS_FAMILY === 'Windows') { if (PHP_OS_FAMILY === 'Windows') {
sapi_windows_set_ctrl_handler(null); sapi_windows_set_ctrl_handler(null);
} elseif (extension_loaded('pcntl')) { } elseif (extension_loaded('pcntl')) {
pcntl_signal(SIGINT, SIG_IGN); pcntl_signal(2, SIG_IGN);
} }
} }
} }

View File

@@ -24,6 +24,7 @@ class PackageManager
default => throw new WrongUsageException('Unsupported OS!'), default => throw new WrongUsageException('Unsupported OS!'),
}; };
$config = Config::getPkg("{$pkg_name}-{$arch}-{$os}"); $config = Config::getPkg("{$pkg_name}-{$arch}-{$os}");
$pkg_name = "{$pkg_name}-{$arch}-{$os}";
} }
if ($config === null) { if ($config === null) {
throw new WrongUsageException("Package [{$pkg_name}] does not exist, please check the name and correct it !"); throw new WrongUsageException("Package [{$pkg_name}] does not exist, please check the name and correct it !");

View File

@@ -32,7 +32,10 @@ class PhpSource extends CustomSourceBase
public function getLatestPHPInfo(string $major_version): array public function getLatestPHPInfo(string $major_version): array
{ {
// 查找最新的小版本号 // 查找最新的小版本号
$info = json_decode(Downloader::curlExec(url: "https://www.php.net/releases/index.php?json&version={$major_version}"), true); $info = json_decode(Downloader::curlExec(
url: "https://www.php.net/releases/index.php?json&version={$major_version}",
retry: intval(getenv('SPC_RETRY_TIME') ? getenv('SPC_RETRY_TIME') : 0)
), true);
if (!isset($info['version'])) { if (!isset($info['version'])) {
throw new DownloaderException("Version {$major_version} not found."); throw new DownloaderException("Version {$major_version} not found.");
} }

View File

@@ -13,8 +13,8 @@ declare(strict_types=1);
// If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`). // If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`).
$extensions = match (PHP_OS_FAMILY) { $extensions = match (PHP_OS_FAMILY) {
'Linux', 'Darwin' => 'zlib,openssl,curl,pcntl,posix,mbstring,tokenizer,phar', 'Linux', 'Darwin' => 'uuid',
'Windows' => 'mbstring,pdo_sqlite,mbregex,ffi', 'Windows' => 'mbstring,pdo_sqlite,mbregex',
}; };
// If you want to test lib-suggests feature with extension, add them below (comma separated, example `libwebp,libavif`). // If you want to test lib-suggests feature with extension, add them below (comma separated, example `libwebp,libavif`).
@@ -27,7 +27,7 @@ $with_libs = match (PHP_OS_FAMILY) {
// You can use `common`, `bulk`, `minimal` or `none`. // You can use `common`, `bulk`, `minimal` or `none`.
// note: combination is only available for *nix platform. Windows must use `none` combination // note: combination is only available for *nix platform. Windows must use `none` combination
$base_combination = match (PHP_OS_FAMILY) { $base_combination = match (PHP_OS_FAMILY) {
'Linux', 'Darwin' => 'none', 'Linux', 'Darwin' => 'minimal',
'Windows' => 'none', 'Windows' => 'none',
}; };
@@ -62,7 +62,6 @@ $final_libs = trim($with_libs, $trim_value);
if (PHP_OS_FAMILY === 'Windows') { if (PHP_OS_FAMILY === 'Windows') {
$final_extensions_cmd = '"' . $final_extensions . '"'; $final_extensions_cmd = '"' . $final_extensions . '"';
$final_libs = $final_libs === '' ? '' : ('"' . $final_libs . '"');
} else { } else {
$final_extensions_cmd = $final_extensions; $final_extensions_cmd = $final_extensions;
} }

View File

@@ -0,0 +1,6 @@
<?php
declare(strict_types=1);
assert(function_exists('uuid_create'));
assert(strlen(uuid_create(0)) === 36);