mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-02 22:35:43 +08:00
Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
46984b6df1 | ||
|
|
96c3e6b935 | ||
|
|
8092f1e481 | ||
|
|
632f904f30 | ||
|
|
8358a985b3 | ||
|
|
e21b5676e7 | ||
|
|
94b3afe6bc | ||
|
|
e4d8e5e4d2 | ||
|
|
88796bc017 | ||
|
|
e23daaa355 | ||
|
|
71017361b5 | ||
|
|
d202de3f50 | ||
|
|
03510073c6 | ||
|
|
8e58592a6e | ||
|
|
96dd5ba87b | ||
|
|
d4c0290195 | ||
|
|
f5d1df5407 | ||
|
|
9664709f21 | ||
|
|
b46655ecfe | ||
|
|
842e0add29 |
2
.github/FUNDING.yml
vendored
2
.github/FUNDING.yml
vendored
@@ -10,4 +10,6 @@ liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
otechie: # Replace with a single Otechie username
|
||||
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']
|
||||
|
||||
3
.github/workflows/tests.yml
vendored
3
.github/workflows/tests.yml
vendored
@@ -164,7 +164,8 @@ jobs:
|
||||
timeout_minutes: 10
|
||||
max_attempts: 3
|
||||
retry_on: error
|
||||
command: bin/spc download --for-extensions="$(php src/globals/test-extensions.php extensions)" --with-php=${{ matrix.php }} --debug
|
||||
command: |
|
||||
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)"
|
||||
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
|
||||
|
||||
@@ -9,3 +9,4 @@ if (-not(Test-Path $PHP_Exec)) {
|
||||
}
|
||||
|
||||
& "$PHP_Exec" ("bin/spc") @args
|
||||
exit $LASTEXITCODE
|
||||
|
||||
@@ -54,5 +54,11 @@
|
||||
},
|
||||
"optimize-autoloader": true,
|
||||
"sort-packages": true
|
||||
}
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"type": "other",
|
||||
"url": "https://github.com/crazywhalecc/crazywhalecc/blob/master/FUNDING.md"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,4 +1,15 @@
|
||||
{
|
||||
"amqp": {
|
||||
"type": "external",
|
||||
"arg-type": "custom",
|
||||
"source": "amqp",
|
||||
"lib-depends": [
|
||||
"librabbitmq"
|
||||
],
|
||||
"ext-depends-windows": [
|
||||
"openssl"
|
||||
]
|
||||
},
|
||||
"apcu": {
|
||||
"type": "external",
|
||||
"source": "apcu"
|
||||
@@ -41,6 +52,9 @@
|
||||
"lib-depends": [
|
||||
"libxml2",
|
||||
"zlib"
|
||||
],
|
||||
"ext-depends-windows": [
|
||||
"xml"
|
||||
]
|
||||
},
|
||||
"event": {
|
||||
@@ -63,8 +77,11 @@
|
||||
"ffi": {
|
||||
"arg-type": "custom",
|
||||
"type": "builtin",
|
||||
"lib-depends": [
|
||||
"lib-depends-unix": [
|
||||
"libffi"
|
||||
],
|
||||
"lib-depends-windows": [
|
||||
"libffi-win"
|
||||
]
|
||||
},
|
||||
"fileinfo": {
|
||||
@@ -300,6 +317,15 @@
|
||||
"sqlite"
|
||||
]
|
||||
},
|
||||
"pdo_sqlsrv": {
|
||||
"type": "external",
|
||||
"source": "pdo_sqlsrv",
|
||||
"arg-type": "with",
|
||||
"ext-depends": [
|
||||
"pdo",
|
||||
"sqlsrv"
|
||||
]
|
||||
},
|
||||
"pgsql": {
|
||||
"type": "builtin",
|
||||
"arg-type": "with-prefix",
|
||||
@@ -510,6 +536,14 @@
|
||||
"tokenizer": {
|
||||
"type": "builtin"
|
||||
},
|
||||
"uuid": {
|
||||
"type": "external",
|
||||
"source": "ext-uuid",
|
||||
"arg-type": "with-prefix",
|
||||
"lib-depends": [
|
||||
"libuuid"
|
||||
]
|
||||
},
|
||||
"uv": {
|
||||
"type": "external",
|
||||
"source": "ext-uv",
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
"libcurl.a"
|
||||
],
|
||||
"static-libs-windows": [
|
||||
"libcurl.lib"
|
||||
"libcurl_a.lib"
|
||||
],
|
||||
"headers": [
|
||||
"curl"
|
||||
@@ -147,7 +147,8 @@
|
||||
"libpng",
|
||||
"libjpeg",
|
||||
"libwebp",
|
||||
"freetype"
|
||||
"freetype",
|
||||
"libtiff"
|
||||
],
|
||||
"lib-suggests": [
|
||||
"zstd",
|
||||
@@ -233,6 +234,17 @@
|
||||
"ffitarget.h"
|
||||
]
|
||||
},
|
||||
"libffi-win": {
|
||||
"source": "libffi-win",
|
||||
"static-libs-windows": [
|
||||
"libffi.lib"
|
||||
],
|
||||
"headers-windows": [
|
||||
"ffi.h",
|
||||
"ffitarget.h",
|
||||
"fficonfig.h"
|
||||
]
|
||||
},
|
||||
"libiconv": {
|
||||
"source": "libiconv",
|
||||
"static-libs-unix": [
|
||||
@@ -293,6 +305,18 @@
|
||||
"zlib"
|
||||
]
|
||||
},
|
||||
"librabbitmq": {
|
||||
"source": "librabbitmq",
|
||||
"static-libs-unix": [
|
||||
"librabbitmq.a"
|
||||
],
|
||||
"static-libs-windows": [
|
||||
"rabbitmq.4.lib"
|
||||
],
|
||||
"lib-depends": [
|
||||
"openssl"
|
||||
]
|
||||
},
|
||||
"libsodium": {
|
||||
"source": "libsodium",
|
||||
"static-libs-unix": [
|
||||
@@ -319,6 +343,18 @@
|
||||
"zlib"
|
||||
]
|
||||
},
|
||||
"libtiff": {
|
||||
"source": "libtiff",
|
||||
"static-libs-unix": [
|
||||
"libtiff.a"
|
||||
]
|
||||
},
|
||||
"libuuid": {
|
||||
"source": "libuuid",
|
||||
"static-libs-unix": [
|
||||
"libuuid.a"
|
||||
]
|
||||
},
|
||||
"libuv": {
|
||||
"source": "libuv",
|
||||
"static-libs-unix": [
|
||||
|
||||
@@ -6,6 +6,16 @@
|
||||
"path": "LICENSE"
|
||||
}
|
||||
},
|
||||
"amqp": {
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/amqp",
|
||||
"path": "php-src/ext/amqp",
|
||||
"filename": "amqp.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
}
|
||||
},
|
||||
"apcu": {
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/APCu",
|
||||
@@ -100,6 +110,16 @@
|
||||
"path": "LICENSE"
|
||||
}
|
||||
},
|
||||
"ext-uuid": {
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/uuid",
|
||||
"path": "php-src/ext/uuid",
|
||||
"filename": "uuid.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
}
|
||||
},
|
||||
"ext-uv": {
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/uv",
|
||||
@@ -204,7 +224,7 @@
|
||||
"libargon2": {
|
||||
"type": "git",
|
||||
"rev": "master",
|
||||
"url": "https://github.com/mpociot/phc-winner-argon2",
|
||||
"url": "https://github.com/static-php/phc-winner-argon2",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
@@ -245,6 +265,15 @@
|
||||
"path": "LICENSE"
|
||||
}
|
||||
},
|
||||
"libffi-win": {
|
||||
"type": "git",
|
||||
"rev": "master",
|
||||
"url": "https://github.com/static-php/libffi-win.git",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
}
|
||||
},
|
||||
"libiconv": {
|
||||
"type": "filelist",
|
||||
"url": "https://ftp.gnu.org/gnu/libiconv/",
|
||||
@@ -298,6 +327,15 @@
|
||||
"path": "LICENSE"
|
||||
}
|
||||
},
|
||||
"librabbitmq": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/alanxz/rabbitmq-c.git",
|
||||
"rev": "master",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
}
|
||||
},
|
||||
"libsodium": {
|
||||
"type": "ghrel",
|
||||
"repo": "jedisct1/libsodium",
|
||||
@@ -316,6 +354,24 @@
|
||||
"path": "COPYING"
|
||||
}
|
||||
},
|
||||
"libtiff": {
|
||||
"type": "filelist",
|
||||
"url": "https://download.osgeo.org/libtiff/",
|
||||
"regex": "/href=\"(?<file>tiff-(?<version>[^\"]+)\\.tar\\.xz)\"/",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE.md"
|
||||
}
|
||||
},
|
||||
"libuuid": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/cloudbase/libuuid.git",
|
||||
"rev": "master",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "COPYING"
|
||||
}
|
||||
},
|
||||
"libuv": {
|
||||
"type": "ghtar",
|
||||
"repo": "libuv/libuv",
|
||||
@@ -439,6 +495,16 @@
|
||||
"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": {
|
||||
"type": "url",
|
||||
"url": "https://dl.static-php.dev/static-php-cli/deps/pkg-config/pkg-config-0.29.2.tar.gz",
|
||||
|
||||
@@ -25,7 +25,7 @@ use Symfony\Component\Console\Command\ListCommand;
|
||||
*/
|
||||
final class ConsoleApplication extends Application
|
||||
{
|
||||
public const VERSION = '2.1.1';
|
||||
public const VERSION = '2.1.5';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
35
src/SPC/builder/extension/amqp.php
Normal file
35
src/SPC/builder/extension/amqp.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\extension;
|
||||
|
||||
use SPC\builder\Extension;
|
||||
use SPC\store\FileSystem;
|
||||
use SPC\util\CustomExt;
|
||||
|
||||
#[CustomExt('amqp')]
|
||||
class amqp extends Extension
|
||||
{
|
||||
public function patchBeforeMake(): bool
|
||||
{
|
||||
if (PHP_OS_FAMILY === 'Windows') {
|
||||
FileSystem::replaceFileRegex(BUILD_INCLUDE_PATH . '\amqp.h', '/^#warning.*/m', '');
|
||||
FileSystem::replaceFileRegex(BUILD_INCLUDE_PATH . '\amqp_framing.h', '/^#warning.*/m', '');
|
||||
FileSystem::replaceFileRegex(BUILD_INCLUDE_PATH . '\amqp_ssl_socket.h', '/^#warning.*/m', '');
|
||||
FileSystem::replaceFileRegex(BUILD_INCLUDE_PATH . '\amqp_tcp_socket.h', '/^#warning.*/m', '');
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getUnixConfigureArg(): string
|
||||
{
|
||||
return '--with-amqp --with-librabbitmq-dir=' . BUILD_ROOT_PATH;
|
||||
}
|
||||
|
||||
public function getWindowsConfigureArg(): string
|
||||
{
|
||||
return '--with-amqp';
|
||||
}
|
||||
}
|
||||
@@ -14,4 +14,9 @@ class ffi extends Extension
|
||||
{
|
||||
return '--with-ffi --enable-zend-signals';
|
||||
}
|
||||
|
||||
public function getWindowsConfigureArg(): string
|
||||
{
|
||||
return '--with-ffi';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,11 @@ use SPC\util\CustomExt;
|
||||
#[CustomExt('password-argon2')]
|
||||
class password_argon2 extends Extension
|
||||
{
|
||||
public function getDistName(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function runCliCheckUnix(): void
|
||||
{
|
||||
[$ret] = shell()->execWithResult(BUILD_ROOT_PATH . '/bin/php -r "assert(defined(\'PASSWORD_ARGON2I\'));"');
|
||||
|
||||
@@ -15,8 +15,8 @@ class swoole extends Extension
|
||||
// enable swoole
|
||||
$arg = '--enable-swoole';
|
||||
|
||||
// commonly-used feature: coroutine-time, thread-context
|
||||
$arg .= ' --enable-swoole-coro-time --enable-thread-context';
|
||||
// commonly-used feature: coroutine-time, disable-thread-context
|
||||
$arg .= ' --enable-swoole-coro-time --disable-thread-context';
|
||||
|
||||
// required feature: curl, openssl (but curl hook is buggy for php 8.0)
|
||||
$arg .= $this->builder->getPHPVersionID() >= 80100 ? ' --enable-swoole-curl' : ' --disable-swoole-curl';
|
||||
|
||||
@@ -4,7 +4,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\linux\library;
|
||||
|
||||
use SPC\exception\WrongUsageException;
|
||||
use SPC\store\FileSystem;
|
||||
|
||||
class libargon2 extends LinuxLibraryBase
|
||||
@@ -15,10 +14,6 @@ class libargon2 extends LinuxLibraryBase
|
||||
|
||||
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');
|
||||
return true;
|
||||
}
|
||||
|
||||
12
src/SPC/builder/linux/library/librabbitmq.php
Normal file
12
src/SPC/builder/linux/library/librabbitmq.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\linux\library;
|
||||
|
||||
class librabbitmq extends LinuxLibraryBase
|
||||
{
|
||||
use \SPC\builder\unix\library\librabbitmq;
|
||||
|
||||
public const NAME = 'librabbitmq';
|
||||
}
|
||||
12
src/SPC/builder/linux/library/libtiff.php
Normal file
12
src/SPC/builder/linux/library/libtiff.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\linux\library;
|
||||
|
||||
class libtiff extends LinuxLibraryBase
|
||||
{
|
||||
use \SPC\builder\unix\library\libtiff;
|
||||
|
||||
public const NAME = 'libtiff';
|
||||
}
|
||||
12
src/SPC/builder/linux/library/libuuid.php
Normal file
12
src/SPC/builder/linux/library/libuuid.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\linux\library;
|
||||
|
||||
class libuuid extends LinuxLibraryBase
|
||||
{
|
||||
use \SPC\builder\unix\library\libuuid;
|
||||
|
||||
public const NAME = 'libuuid';
|
||||
}
|
||||
@@ -28,6 +28,7 @@ class libxml2 extends LinuxLibraryBase
|
||||
'cmake ' .
|
||||
'-DCMAKE_BUILD_TYPE=Release ' .
|
||||
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' .
|
||||
'-DCMAKE_INSTALL_LIBDIR=' . BUILD_LIB_PATH . ' ' .
|
||||
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
|
||||
'-DBUILD_SHARED_LIBS=OFF ' .
|
||||
'-DIconv_IS_BUILT_IN=OFF ' .
|
||||
|
||||
12
src/SPC/builder/macos/library/librabbitmq.php
Normal file
12
src/SPC/builder/macos/library/librabbitmq.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\macos\library;
|
||||
|
||||
class librabbitmq extends MacOSLibraryBase
|
||||
{
|
||||
use \SPC\builder\unix\library\librabbitmq;
|
||||
|
||||
public const NAME = 'librabbitmq';
|
||||
}
|
||||
12
src/SPC/builder/macos/library/libtiff.php
Normal file
12
src/SPC/builder/macos/library/libtiff.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\macos\library;
|
||||
|
||||
class libtiff extends MacOSLibraryBase
|
||||
{
|
||||
use \SPC\builder\unix\library\libtiff;
|
||||
|
||||
public const NAME = 'libtiff';
|
||||
}
|
||||
12
src/SPC/builder/macos/library/libuuid.php
Normal file
12
src/SPC/builder/macos/library/libuuid.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\macos\library;
|
||||
|
||||
class libuuid extends MacOSLibraryBase
|
||||
{
|
||||
use \SPC\builder\unix\library\libuuid;
|
||||
|
||||
public const NAME = 'libuuid';
|
||||
}
|
||||
@@ -29,6 +29,7 @@ class libxml2 extends MacOSLibraryBase
|
||||
// '--debug-find ' .
|
||||
'-DCMAKE_BUILD_TYPE=Release ' .
|
||||
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' .
|
||||
'-DCMAKE_INSTALL_LIBDIR=' . BUILD_LIB_PATH . ' ' .
|
||||
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
|
||||
'-DBUILD_SHARED_LIBS=OFF ' .
|
||||
'-DLIBXML2_WITH_ICONV=ON ' .
|
||||
|
||||
35
src/SPC/builder/unix/library/librabbitmq.php
Normal file
35
src/SPC/builder/unix/library/librabbitmq.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\unix\library;
|
||||
|
||||
use SPC\exception\FileSystemException;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\store\FileSystem;
|
||||
|
||||
trait librabbitmq
|
||||
{
|
||||
/**
|
||||
* @throws RuntimeException
|
||||
* @throws FileSystemException
|
||||
*/
|
||||
protected function build(): void
|
||||
{
|
||||
// CMake needs a clean build directory
|
||||
FileSystem::resetDir($this->source_dir . '/build');
|
||||
// Start build
|
||||
shell()->cd($this->source_dir . '/build')
|
||||
->exec(
|
||||
'cmake ' .
|
||||
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' .
|
||||
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
|
||||
'-DCMAKE_BUILD_TYPE=Release ' .
|
||||
'-DBUILD_SHARED_LIBS=OFF ' .
|
||||
'-DBUILD_STATIC_LIBS=ON ' .
|
||||
'..'
|
||||
)
|
||||
->exec("cmake --build . -j {$this->builder->concurrency}")
|
||||
->exec('make install');
|
||||
}
|
||||
}
|
||||
30
src/SPC/builder/unix/library/libtiff.php
Normal file
30
src/SPC/builder/unix/library/libtiff.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\unix\library;
|
||||
|
||||
use SPC\exception\FileSystemException;
|
||||
use SPC\exception\RuntimeException;
|
||||
|
||||
trait libtiff
|
||||
{
|
||||
/**
|
||||
* @throws FileSystemException
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
protected function build(): void
|
||||
{
|
||||
shell()->cd($this->source_dir)
|
||||
->exec(
|
||||
'./configure ' .
|
||||
'--enable-static --disable-shared ' .
|
||||
'--disable-cxx ' .
|
||||
'--prefix='
|
||||
)
|
||||
->exec('make clean')
|
||||
->exec("make -j{$this->builder->concurrency}")
|
||||
->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
|
||||
$this->patchPkgconfPrefix(['libtiff-4.pc']);
|
||||
}
|
||||
}
|
||||
38
src/SPC/builder/unix/library/libuuid.php
Normal file
38
src/SPC/builder/unix/library/libuuid.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\unix\library;
|
||||
|
||||
use SPC\exception\FileSystemException;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\store\FileSystem;
|
||||
|
||||
trait libuuid
|
||||
{
|
||||
public function patchBeforeBuild(): bool
|
||||
{
|
||||
FileSystem::replaceFileStr($this->source_dir . '/configure', '-${am__api_version}', '');
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FileSystemException
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
protected function build(): void
|
||||
{
|
||||
shell()->cd($this->source_dir)
|
||||
->exec('chmod +x configure')
|
||||
->exec('chmod +x install-sh')
|
||||
->exec(
|
||||
'./configure ' .
|
||||
'--enable-static --disable-shared ' .
|
||||
'--prefix='
|
||||
)
|
||||
->exec('make clean')
|
||||
->exec("make -j{$this->builder->concurrency}")
|
||||
->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
|
||||
$this->patchPkgconfPrefix(['uuid.pc']);
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ trait ncurses
|
||||
'--without-tests ' .
|
||||
'--without-dlsym ' .
|
||||
'--without-debug ' .
|
||||
'-enable-symlinks' .
|
||||
'-enable-symlinks ' .
|
||||
'--bindir=' . BUILD_ROOT_PATH . '/bin ' .
|
||||
'--includedir=' . BUILD_ROOT_PATH . '/include ' .
|
||||
'--libdir=' . BUILD_ROOT_PATH . '/lib ' .
|
||||
|
||||
@@ -85,6 +85,14 @@ class WindowsBuilder extends BuilderBase
|
||||
unlink($makefile . '.originfile');
|
||||
}
|
||||
|
||||
if (($logo = $this->getOption('with-micro-logo')) !== null) {
|
||||
// realpath
|
||||
$logo = realpath($logo);
|
||||
$micro_logo = '--enable-micro-logo=' . $logo . ' ';
|
||||
} else {
|
||||
$micro_logo = '';
|
||||
}
|
||||
|
||||
cmd()->cd(SOURCE_PATH . '\php-src')
|
||||
->exec(
|
||||
"{$this->sdk_prefix} configure.bat --task-args \"" .
|
||||
@@ -94,7 +102,7 @@ class WindowsBuilder extends BuilderBase
|
||||
'--with-extra-includes=' . BUILD_INCLUDE_PATH . ' ' .
|
||||
'--with-extra-libs=' . BUILD_LIB_PATH . ' ' .
|
||||
($enableCli ? '--enable-cli=yes ' : '--enable-cli=no ') .
|
||||
($enableMicro ? '--enable-micro=yes ' : '--enable-micro=no ') .
|
||||
($enableMicro ? ('--enable-micro=yes ' . $micro_logo) : '--enable-micro=no ') .
|
||||
($enableEmbed ? '--enable-embed=yes ' : '--enable-embed=no ') .
|
||||
"{$this->makeExtensionArgs()} " .
|
||||
$zts .
|
||||
@@ -179,10 +187,12 @@ class WindowsBuilder extends BuilderBase
|
||||
SourcePatcher::patchMicro(['phar']);
|
||||
}
|
||||
|
||||
cmd()->cd(SOURCE_PATH . '\php-src')->exec("{$this->sdk_prefix} nmake_micro_wrapper.bat --task-args micro");
|
||||
|
||||
if ($this->phar_patched) {
|
||||
SourcePatcher::patchMicro(['phar'], true);
|
||||
try {
|
||||
cmd()->cd(SOURCE_PATH . '\php-src')->exec("{$this->sdk_prefix} nmake_micro_wrapper.bat --task-args micro");
|
||||
} finally {
|
||||
if ($this->phar_patched) {
|
||||
SourcePatcher::patchMicro(['phar'], true);
|
||||
}
|
||||
}
|
||||
|
||||
$this->deployBinary(BUILD_TARGET_MICRO);
|
||||
|
||||
@@ -12,29 +12,13 @@ class curl extends WindowsLibraryBase
|
||||
|
||||
protected function build(): void
|
||||
{
|
||||
// reset cmake
|
||||
FileSystem::resetDir($this->source_dir . '\build');
|
||||
|
||||
// start build
|
||||
cmd()->cd($this->source_dir)
|
||||
cmd()->cd($this->source_dir . '\winbuild')
|
||||
->execWithWrapper(
|
||||
$this->builder->makeSimpleWrapper('cmake'),
|
||||
'-B build ' .
|
||||
'-A x64 ' .
|
||||
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
|
||||
'-DCMAKE_BUILD_TYPE=Release ' .
|
||||
'-DBUILD_SHARED_LIBS=OFF ' .
|
||||
'-DBUILD_STATIC_LIBS=ON ' .
|
||||
'-DBUILD_CURL_EXE=OFF ' .
|
||||
'-DUSE_ZLIB=ON ' .
|
||||
'-DCURL_USE_OPENSSL=ON ' .
|
||||
'-DCURL_USE_LIBLSSH2=ON ' .
|
||||
'-DUSE_NGHTTP2=ON ' . // php-src with curl needs nghttp2
|
||||
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' '
|
||||
)
|
||||
->execWithWrapper(
|
||||
$this->builder->makeSimpleWrapper('cmake'),
|
||||
"--build build --config Release --target install -j{$this->builder->concurrency}"
|
||||
$this->builder->makeSimpleWrapper('nmake'),
|
||||
'/f Makefile.vc WITH_DEVEL=' . BUILD_ROOT_PATH . ' ' .
|
||||
'WITH_PREFIX=' . BUILD_ROOT_PATH . ' ' .
|
||||
'mode=static RTLIBCFG=static WITH_SSL=static WITH_NGHTTP2=static WITH_SSH2=static ENABLE_IPV6=yes WITH_ZLIB=static MACHINE=x64 DEBUG=no'
|
||||
);
|
||||
FileSystem::copyDir($this->source_dir . '\include\curl', BUILD_INCLUDE_PATH . '\curl');
|
||||
}
|
||||
}
|
||||
|
||||
46
src/SPC/builder/windows/library/libffi_win.php
Normal file
46
src/SPC/builder/windows/library/libffi_win.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\windows\library;
|
||||
|
||||
use SPC\builder\windows\SystemUtil;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\store\FileSystem;
|
||||
|
||||
class libffi_win extends WindowsLibraryBase
|
||||
{
|
||||
public const NAME = 'libffi-win';
|
||||
|
||||
protected function build()
|
||||
{
|
||||
$vs_ver_dir = match (SystemUtil::findVisualStudio()['version']) {
|
||||
'vs17' => '/win32/vs17_x64',
|
||||
'vs16' => '/win32/vs16_x64',
|
||||
default => throw new RuntimeException('Current VS version is not supported yet!'),
|
||||
};
|
||||
|
||||
// start build
|
||||
cmd()->cd($this->source_dir . $vs_ver_dir)
|
||||
->execWithWrapper(
|
||||
$this->builder->makeSimpleWrapper('msbuild'),
|
||||
'libffi-msvc.sln /t:Rebuild /p:Configuration=Release /p:Platform=x64'
|
||||
);
|
||||
FileSystem::createDir(BUILD_LIB_PATH);
|
||||
FileSystem::createDir(BUILD_INCLUDE_PATH);
|
||||
copy($this->source_dir . $vs_ver_dir . '\x64\Release\libffi.lib', BUILD_LIB_PATH . '\libffi.lib');
|
||||
copy($this->source_dir . $vs_ver_dir . '\x64\Release\libffi.pdb', BUILD_LIB_PATH . '\libffi.pdb');
|
||||
copy($this->source_dir . '\include\ffi.h', BUILD_INCLUDE_PATH . '\ffi.h');
|
||||
|
||||
FileSystem::replaceFileStr(BUILD_INCLUDE_PATH . '\ffi.h', '#define LIBFFI_H', "#define LIBFFI_H\n#define FFI_BUILDING");
|
||||
copy($this->source_dir . '\src\x86\ffitarget.h', BUILD_INCLUDE_PATH . '\ffitarget.h');
|
||||
copy($this->source_dir . '\fficonfig.h', BUILD_INCLUDE_PATH . '\fficonfig.h');
|
||||
|
||||
// copy($this->source_dir . '\msvc_build\out\static-Release\X64\libffi.lib', BUILD_LIB_PATH . '\libffi.lib');
|
||||
// copy($this->source_dir . '\msvc_build\include\ffi.h', BUILD_INCLUDE_PATH . '\ffi.h');
|
||||
// copy($this->source_dir . '\msvc_build\include\fficonfig.h', BUILD_INCLUDE_PATH . '\fficonfig.h');
|
||||
// copy($this->source_dir . '\src\x86\ffitarget.h', BUILD_INCLUDE_PATH . '\ffitarget.h');
|
||||
|
||||
// FileSystem::replaceFileStr(BUILD_INCLUDE_PATH . '\ffi.h', '..\..\src\x86\ffitarget.h', 'ffitarget.h');
|
||||
}
|
||||
}
|
||||
36
src/SPC/builder/windows/library/librabbitmq.php
Normal file
36
src/SPC/builder/windows/library/librabbitmq.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\windows\library;
|
||||
|
||||
use SPC\store\FileSystem;
|
||||
|
||||
class librabbitmq extends WindowsLibraryBase
|
||||
{
|
||||
public const NAME = 'librabbitmq';
|
||||
|
||||
protected function build(): void
|
||||
{
|
||||
// reset cmake
|
||||
FileSystem::resetDir($this->source_dir . '\build');
|
||||
|
||||
// start build
|
||||
cmd()->cd($this->source_dir)
|
||||
->execWithWrapper(
|
||||
$this->builder->makeSimpleWrapper('cmake'),
|
||||
'-B build ' .
|
||||
'-A x64 ' .
|
||||
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
|
||||
'-DCMAKE_BUILD_TYPE=Release ' .
|
||||
'-DBUILD_SHARED_LIBS=OFF ' .
|
||||
'-DBUILD_STATIC_LIBS=ON ' .
|
||||
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' '
|
||||
)
|
||||
->execWithWrapper(
|
||||
$this->builder->makeSimpleWrapper('cmake'),
|
||||
"--build build --config Release --target install -j{$this->builder->concurrency}"
|
||||
);
|
||||
rename(BUILD_LIB_PATH . '\librabbitmq.4.lib', BUILD_LIB_PATH . '\rabbitmq.4.lib');
|
||||
}
|
||||
}
|
||||
@@ -23,8 +23,8 @@ class nghttp2 extends WindowsLibraryBase
|
||||
'-A x64 ' .
|
||||
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
|
||||
'-DCMAKE_BUILD_TYPE=Release ' .
|
||||
'-DBUILD_SHARED_LIBS=OFF ' .
|
||||
'-DBUILD_STATIC_LIBS=ON ' .
|
||||
'-DENABLE_SHARED_LIB=OFF ' .
|
||||
'-DENABLE_STATIC_LIB=ON ' .
|
||||
'-DENABLE_STATIC_CRT=ON ' .
|
||||
'-DENABLE_LIB_ONLY=ON ' .
|
||||
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' '
|
||||
|
||||
@@ -37,8 +37,8 @@ class BuildCliCommand extends BuildCommand
|
||||
$this->addOption('with-suggested-exts', 'E', null, 'Build with suggested extensions for selected exts');
|
||||
$this->addOption('with-added-patch', 'P', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Inject patch script outside');
|
||||
$this->addOption('without-micro-ext-test', null, null, 'Disable phpmicro with extension test code');
|
||||
|
||||
$this->addOption('with-upx-pack', null, null, 'Compress / pack binary using UPX tool (linux/windows only)');
|
||||
$this->addOption('with-micro-logo', null, InputOption::VALUE_REQUIRED, 'Use custom .ico for micro.sfx (windows only)');
|
||||
}
|
||||
|
||||
public function handle(): int
|
||||
@@ -63,6 +63,14 @@ class BuildCliCommand extends BuildCommand
|
||||
if ($rule === BUILD_TARGET_ALL) {
|
||||
logger()->warning('--build-all option makes `--no-strip` always true, be aware!');
|
||||
}
|
||||
if (($rule & BUILD_TARGET_MICRO) === BUILD_TARGET_MICRO && $this->getOption('with-micro-logo')) {
|
||||
$logo = $this->getOption('with-micro-logo');
|
||||
if (!file_exists($logo)) {
|
||||
logger()->error('Logo file ' . $logo . ' not exist !');
|
||||
return static::FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
// Check upx
|
||||
$suffix = PHP_OS_FAMILY === 'Windows' ? '.exe' : '';
|
||||
if ($this->getOption('with-upx-pack')) {
|
||||
@@ -96,8 +104,8 @@ class BuildCliCommand extends BuildCommand
|
||||
$indent_texts = [
|
||||
'Build OS' => PHP_OS_FAMILY . ' (' . php_uname('m') . ')',
|
||||
'Build SAPI' => $builder->getBuildTypeName($rule),
|
||||
'Extensions (' . count($extensions) . ')' => implode(', ', $extensions),
|
||||
'Libraries (' . count($libraries) . ')' => implode(', ', $libraries),
|
||||
'Extensions (' . count($extensions) . ')' => implode(',', $extensions),
|
||||
'Libraries (' . count($libraries) . ')' => implode(',', $libraries),
|
||||
'Strip Binaries' => $builder->getOption('no-strip') ? 'no' : 'yes',
|
||||
'Enable ZTS' => $builder->getOption('enable-zts') ? 'yes' : 'no',
|
||||
];
|
||||
|
||||
@@ -36,26 +36,61 @@ class DownloadCommand extends BaseCommand
|
||||
$this->addOption('custom-url', 'U', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Specify custom source download url, e.g "php-src:https://downloads.php.net/~eric/php-8.3.0beta1.tar.gz"');
|
||||
$this->addOption('from-zip', 'Z', InputOption::VALUE_REQUIRED, 'Fetch from zip archive');
|
||||
$this->addOption('for-extensions', 'e', InputOption::VALUE_REQUIRED, 'Fetch by extensions, e.g "openssl,mbstring"');
|
||||
$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('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');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FileSystemException
|
||||
* @throws WrongUsageException
|
||||
*/
|
||||
public function initialize(InputInterface $input, OutputInterface $output): void
|
||||
{
|
||||
if (
|
||||
$input->getOption('all')
|
||||
|| $input->getOption('clean')
|
||||
|| $input->getOption('from-zip')
|
||||
|| $input->getOption('for-extensions')
|
||||
) {
|
||||
// mode: --all
|
||||
if ($input->getOption('all')) {
|
||||
$input->setArgument('sources', implode(',', array_keys(Config::getSources())));
|
||||
parent::initialize($input, $output);
|
||||
return;
|
||||
}
|
||||
// mode: --clean and --from-zip
|
||||
if ($input->getOption('clean') || $input->getOption('from-zip')) {
|
||||
$input->setArgument('sources', '');
|
||||
parent::initialize($input, $output);
|
||||
return;
|
||||
}
|
||||
// mode: normal
|
||||
if (!empty($input->getArgument('sources'))) {
|
||||
$final_sources = array_map('trim', array_filter(explode(',', $input->getArgument('sources'))));
|
||||
} else {
|
||||
$final_sources = [];
|
||||
}
|
||||
// mode: --for-extensions
|
||||
if ($for_ext = $input->getOption('for-extensions')) {
|
||||
$ext = array_map('trim', array_filter(explode(',', $for_ext)));
|
||||
$sources = $this->calculateSourcesByExt($ext, !$input->getOption('without-suggestions'));
|
||||
if (PHP_OS_FAMILY !== 'Windows') {
|
||||
array_unshift($sources, 'pkg-config');
|
||||
}
|
||||
array_unshift($sources, 'php-src', 'micro');
|
||||
$final_sources = array_merge($final_sources, array_diff($sources, $final_sources));
|
||||
}
|
||||
// mode: --for-libs
|
||||
if ($for_lib = $input->getOption('for-libs')) {
|
||||
$lib = array_map('trim', array_filter(explode(',', $for_lib)));
|
||||
$sources = $this->calculateSourcesByLib($lib, !$input->getOption('without-suggestions'));
|
||||
$final_sources = array_merge($final_sources, array_diff($sources, $final_sources));
|
||||
}
|
||||
if (!empty($final_sources)) {
|
||||
$input->setArgument('sources', implode(',', $final_sources));
|
||||
}
|
||||
parent::initialize($input, $output);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws DownloaderException
|
||||
* @throws RuntimeException
|
||||
* @throws FileSystemException
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
@@ -93,6 +128,10 @@ class DownloadCommand extends BaseCommand
|
||||
return static::FAILURE;
|
||||
}
|
||||
|
||||
// retry
|
||||
$retry = intval($this->getOption('retry'));
|
||||
f_putenv('SPC_RETRY_TIME=' . $retry);
|
||||
|
||||
// Use shallow-clone can reduce git resource download
|
||||
if ($this->getOption('shallow-clone')) {
|
||||
define('GIT_SHALLOW_CLONE', true);
|
||||
@@ -107,20 +146,12 @@ class DownloadCommand extends BaseCommand
|
||||
Config::$source['openssl']['regex'] = '/href="(?<file>openssl-(?<version>1.[^"]+)\.tar\.gz)\"/';
|
||||
}
|
||||
|
||||
// --for-extensions
|
||||
if ($for_ext = $this->getOption('for-extensions')) {
|
||||
$ext = array_map('trim', array_filter(explode(',', $for_ext)));
|
||||
$sources = $this->calculateSourcesByExt($ext, !$this->getOption('without-suggestions'));
|
||||
array_unshift($sources, 'php-src', 'micro', 'pkg-config');
|
||||
} else {
|
||||
// get source list that will be downloaded
|
||||
$sources = array_map('trim', array_filter(explode(',', $this->getArgument('sources'))));
|
||||
if (empty($sources)) {
|
||||
logger()->notice('Downloading with --all option will take more times to download, we recommend you to download with --for-extensions option !');
|
||||
$sources = array_keys(Config::getSources());
|
||||
}
|
||||
$chosen_sources = array_map('trim', array_filter(explode(',', $this->getArgument('sources'))));
|
||||
$force_list = array_map('trim', array_filter(explode(',', $this->getOption('ignore-cache-sources'))));
|
||||
|
||||
if ($this->getOption('all')) {
|
||||
logger()->notice('Downloading with --all option will take more times to download, we recommend you to download with --for-extensions option !');
|
||||
}
|
||||
$chosen_sources = $sources;
|
||||
|
||||
// Process -U options
|
||||
$custom_urls = [];
|
||||
@@ -151,7 +182,7 @@ class DownloadCommand extends BaseCommand
|
||||
Downloader::downloadSource($source, $new_config, true);
|
||||
} else {
|
||||
logger()->info("Fetching source {$source} [{$ni}/{$cnt}]");
|
||||
Downloader::downloadSource($source, Config::getSource($source));
|
||||
Downloader::downloadSource($source, Config::getSource($source), in_array($source, $force_list));
|
||||
}
|
||||
}
|
||||
$time = round(microtime(true) - START_TIME, 3);
|
||||
@@ -166,6 +197,10 @@ class DownloadCommand extends BaseCommand
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RuntimeException
|
||||
* @throws WrongUsageException
|
||||
*/
|
||||
private function downloadFromZip(string $path): int
|
||||
{
|
||||
if (!file_exists($path)) {
|
||||
@@ -191,8 +226,10 @@ class DownloadCommand extends BaseCommand
|
||||
if (PHP_OS_FAMILY !== 'Windows') {
|
||||
$abs_path = realpath($path);
|
||||
f_passthru('mkdir ' . DOWNLOAD_PATH . ' && cd ' . DOWNLOAD_PATH . ' && unzip ' . escapeshellarg($abs_path));
|
||||
} else {
|
||||
// Windows TODO
|
||||
throw new WrongUsageException('Windows currently does not support --from-zip !');
|
||||
}
|
||||
// Windows TODO
|
||||
|
||||
if (!file_exists(DOWNLOAD_PATH . '/.lock.json')) {
|
||||
throw new RuntimeException('.lock.json not exist in "downloads/"');
|
||||
@@ -208,7 +245,8 @@ class DownloadCommand extends BaseCommand
|
||||
/**
|
||||
* Calculate the sources by extensions
|
||||
*
|
||||
* @param array $extensions extension list
|
||||
* @param array $extensions extension list
|
||||
* @param bool $include_suggests include suggested libs and extensions (default: true)
|
||||
* @throws FileSystemException
|
||||
* @throws WrongUsageException
|
||||
*/
|
||||
@@ -226,4 +264,22 @@ class DownloadCommand extends BaseCommand
|
||||
}
|
||||
return array_values(array_unique($sources));
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the sources by libraries
|
||||
*
|
||||
* @param array $libs library list
|
||||
* @param bool $include_suggests include suggested libs (default: true)
|
||||
* @throws FileSystemException
|
||||
* @throws WrongUsageException
|
||||
*/
|
||||
private function calculateSourcesByLib(array $libs, bool $include_suggests = true): array
|
||||
{
|
||||
$libs = DependencyUtil::getLibs($libs, $include_suggests);
|
||||
$sources = [];
|
||||
foreach ($libs as $library) {
|
||||
$sources[] = Config::getLib($library, 'source');
|
||||
}
|
||||
return array_values(array_unique($sources));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,10 @@ class LinuxToolCheckList
|
||||
'xz',
|
||||
];
|
||||
|
||||
private const PROVIDED_COMMAND = [
|
||||
'binutils-gold' => 'ld.gold',
|
||||
];
|
||||
|
||||
/** @noinspection PhpUnused */
|
||||
#[AsCheckItem('if necessary tools are installed', limit_os: 'Linux', level: 999)]
|
||||
public function checkCliTools(): ?CheckResult
|
||||
@@ -52,9 +56,9 @@ class LinuxToolCheckList
|
||||
default => self::TOOLS_DEBIAN,
|
||||
};
|
||||
$missing = [];
|
||||
foreach ($required as $cmd) {
|
||||
if ($this->findCommand($cmd) === null) {
|
||||
$missing[] = $cmd;
|
||||
foreach ($required as $package) {
|
||||
if ($this->findCommand(self::PROVIDED_COMMAND[$package] ?? $package) === null) {
|
||||
$missing[] = $package;
|
||||
}
|
||||
}
|
||||
if (!empty($missing)) {
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace SPC\store;
|
||||
use SPC\exception\DownloaderException;
|
||||
use SPC\exception\FileSystemException;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\exception\WrongUsageException;
|
||||
use SPC\store\source\CustomSourceBase;
|
||||
|
||||
/**
|
||||
@@ -26,7 +27,8 @@ class Downloader
|
||||
{
|
||||
logger()->debug("finding {$name} source from bitbucket tag");
|
||||
$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);
|
||||
$ver = $data['values'][0]['name'];
|
||||
if (!$ver) {
|
||||
@@ -35,7 +37,8 @@ class Downloader
|
||||
$url = "https://bitbucket.org/{$source['repo']}/get/{$ver}.tar.gz";
|
||||
$headers = self::curlExec(
|
||||
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);
|
||||
if ($matches) {
|
||||
@@ -62,7 +65,8 @@ class Downloader
|
||||
logger()->debug("finding {$name} source from github {$type} tarball");
|
||||
$data = json_decode(self::curlExec(
|
||||
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);
|
||||
$url = $data[0]['tarball_url'];
|
||||
if (!$url) {
|
||||
@@ -72,6 +76,7 @@ class Downloader
|
||||
url: $url,
|
||||
method: 'HEAD',
|
||||
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);
|
||||
if ($matches) {
|
||||
@@ -97,6 +102,7 @@ class Downloader
|
||||
$data = json_decode(self::curlExec(
|
||||
url: "https://api.github.com/repos/{$source['repo']}/releases",
|
||||
hooks: [[CurlHook::class, 'setupGithubToken']],
|
||||
retry: intval(getenv('SPC_RETRY_TIME') ? getenv('SPC_RETRY_TIME') : 0)
|
||||
), true);
|
||||
$url = null;
|
||||
foreach ($data as $release) {
|
||||
@@ -130,7 +136,7 @@ class Downloader
|
||||
public static function getFromFileList(string $name, array $source): array
|
||||
{
|
||||
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);
|
||||
if (!$matches) {
|
||||
throw new DownloaderException("Failed to get {$name} version");
|
||||
@@ -175,7 +181,7 @@ class Downloader
|
||||
}
|
||||
};
|
||||
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();
|
||||
logger()->debug("Locking {$filename}");
|
||||
self::lockSource($name, ['source_type' => 'archive', 'filename' => $filename, 'move_path' => $move_path]);
|
||||
@@ -203,7 +209,7 @@ class Downloader
|
||||
* @throws FileSystemException
|
||||
* @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}");
|
||||
if (file_exists($download_path)) {
|
||||
@@ -217,14 +223,25 @@ class Downloader
|
||||
FileSystem::removeDir($download_path);
|
||||
}
|
||||
};
|
||||
self::registerCancelEvent($cancel_func);
|
||||
f_passthru(
|
||||
SPC_GIT_EXEC . ' clone' . $check .
|
||||
' --config core.autocrlf=false ' .
|
||||
"--branch \"{$branch}\" " . (defined('GIT_SHALLOW_CLONE') ? '--depth 1 --single-branch' : '') . " --recursive \"{$url}\" \"{$download_path}\""
|
||||
);
|
||||
self::unregisterCancelEvent();
|
||||
|
||||
try {
|
||||
self::registerCancelEvent($cancel_func);
|
||||
f_passthru(
|
||||
SPC_GIT_EXEC . ' clone' . $check .
|
||||
' --config core.autocrlf=false ' .
|
||||
"--branch \"{$branch}\" " . (defined('GIT_SHALLOW_CLONE') ? '--depth 1 --single-branch' : '') . " --recursive \"{$url}\" \"{$download_path}\""
|
||||
);
|
||||
} 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
|
||||
logger()->debug("Locking git source {$name}");
|
||||
self::lockSource($name, ['source_type' => 'dir', 'dirname' => $name, 'move_path' => $move_path]);
|
||||
@@ -246,6 +263,10 @@ class Downloader
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws DownloaderException
|
||||
* @throws FileSystemException
|
||||
*/
|
||||
public static function downloadPackage(string $name, ?array $pkg = null, bool $force = false): void
|
||||
{
|
||||
if ($pkg === null) {
|
||||
@@ -307,13 +328,19 @@ class Downloader
|
||||
self::downloadFile($name, $url, $filename, $pkg['extract'] ?? null);
|
||||
break;
|
||||
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;
|
||||
case 'custom': // Custom download method, like API-based download or other
|
||||
$classes = FileSystem::getClassesPsr4(ROOT_DIR . '/src/SPC/store/source', 'SPC\\store\\source');
|
||||
foreach ($classes as $class) {
|
||||
if (is_a($class, CustomSourceBase::class, true) && $class::NAME === $name) {
|
||||
(new $class())->fetch();
|
||||
(new $class())->fetch($force);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -401,13 +428,19 @@ class Downloader
|
||||
self::downloadFile($name, $url, $filename, $source['path'] ?? null);
|
||||
break;
|
||||
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;
|
||||
case 'custom': // Custom download method, like API-based download or other
|
||||
$classes = FileSystem::getClassesPsr4(ROOT_DIR . '/src/SPC/store/source', 'SPC\\store\\source');
|
||||
foreach ($classes as $class) {
|
||||
if (is_a($class, CustomSourceBase::class, true) && $class::NAME === $name) {
|
||||
(new $class())->fetch();
|
||||
(new $class())->fetch($force);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -431,57 +464,71 @@ class Downloader
|
||||
*
|
||||
* @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) {
|
||||
$hook($method, $url, $headers);
|
||||
}
|
||||
|
||||
FileSystem::findCommandPath('curl');
|
||||
try {
|
||||
FileSystem::findCommandPath('curl');
|
||||
|
||||
$methodArg = match ($method) {
|
||||
'GET' => '',
|
||||
'HEAD' => '-I',
|
||||
default => "-X \"{$method}\"",
|
||||
};
|
||||
$headerArg = implode(' ', array_map(fn ($v) => '"-H' . $v . '"', $headers));
|
||||
$methodArg = match ($method) {
|
||||
'GET' => '',
|
||||
'HEAD' => '-I',
|
||||
default => "-X \"{$method}\"",
|
||||
};
|
||||
$headerArg = implode(' ', array_map(fn ($v) => '"-H' . $v . '"', $headers));
|
||||
|
||||
$cmd = SPC_CURL_EXEC . " -sfSL {$methodArg} {$headerArg} \"{$url}\"";
|
||||
if (getenv('CACHE_API_EXEC') === 'yes') {
|
||||
if (!file_exists(FileSystem::convertPath(DOWNLOAD_PATH . '/.curl_exec_cache'))) {
|
||||
$cache = [];
|
||||
} else {
|
||||
$cache = json_decode(file_get_contents(FileSystem::convertPath(DOWNLOAD_PATH . '/.curl_exec_cache')), true);
|
||||
}
|
||||
if (isset($cache[$cmd]) && $cache[$cmd]['expire'] >= time()) {
|
||||
$cmd = SPC_CURL_EXEC . " -sfSL {$methodArg} {$headerArg} \"{$url}\"";
|
||||
if (getenv('CACHE_API_EXEC') === 'yes') {
|
||||
if (!file_exists(FileSystem::convertPath(DOWNLOAD_PATH . '/.curl_exec_cache'))) {
|
||||
$cache = [];
|
||||
} else {
|
||||
$cache = json_decode(file_get_contents(FileSystem::convertPath(DOWNLOAD_PATH . '/.curl_exec_cache')), true);
|
||||
}
|
||||
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'];
|
||||
}
|
||||
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 implode("\n", $output);
|
||||
} catch (DownloaderException $e) {
|
||||
if ($retry > 0) {
|
||||
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
|
||||
*
|
||||
* @throws DownloaderException
|
||||
* @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) {
|
||||
$hook($method, $url, $headers);
|
||||
$hook($method, $url, $used_headers);
|
||||
}
|
||||
|
||||
$methodArg = match ($method) {
|
||||
@@ -489,10 +536,23 @@ class Downloader
|
||||
'HEAD' => '-I',
|
||||
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' : '#';
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -505,7 +565,7 @@ class Downloader
|
||||
if (PHP_OS_FAMILY === 'Windows') {
|
||||
sapi_windows_set_ctrl_handler($callback);
|
||||
} elseif (extension_loaded('pcntl')) {
|
||||
pcntl_signal(SIGINT, $callback);
|
||||
pcntl_signal(2, $callback);
|
||||
} else {
|
||||
logger()->debug('You have not enabled `pcntl` extension, cannot prevent download file corruption when Ctrl+C');
|
||||
}
|
||||
@@ -519,7 +579,7 @@ class Downloader
|
||||
if (PHP_OS_FAMILY === 'Windows') {
|
||||
sapi_windows_set_ctrl_handler(null);
|
||||
} elseif (extension_loaded('pcntl')) {
|
||||
pcntl_signal(SIGINT, SIG_IGN);
|
||||
pcntl_signal(2, SIG_IGN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ class PackageManager
|
||||
default => throw new WrongUsageException('Unsupported OS!'),
|
||||
};
|
||||
$config = Config::getPkg("{$pkg_name}-{$arch}-{$os}");
|
||||
$pkg_name = "{$pkg_name}-{$arch}-{$os}";
|
||||
}
|
||||
if ($config === null) {
|
||||
throw new WrongUsageException("Package [{$pkg_name}] does not exist, please check the name and correct it !");
|
||||
|
||||
@@ -8,5 +8,5 @@ abstract class CustomSourceBase
|
||||
{
|
||||
public const NAME = 'unknown';
|
||||
|
||||
abstract public function fetch();
|
||||
abstract public function fetch(bool $force = false);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ namespace SPC\store\source;
|
||||
use JetBrains\PhpStorm\ArrayShape;
|
||||
use SPC\exception\DownloaderException;
|
||||
use SPC\exception\FileSystemException;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\store\Downloader;
|
||||
|
||||
class PhpSource extends CustomSourceBase
|
||||
@@ -16,13 +15,12 @@ class PhpSource extends CustomSourceBase
|
||||
|
||||
/**
|
||||
* @throws DownloaderException
|
||||
* @throws RuntimeException
|
||||
* @throws FileSystemException
|
||||
*/
|
||||
public function fetch(): void
|
||||
public function fetch(bool $force = false): void
|
||||
{
|
||||
$major = defined('SPC_BUILD_PHP_VERSION') ? SPC_BUILD_PHP_VERSION : '8.1';
|
||||
Downloader::downloadSource('php-src', self::getLatestPHPInfo($major));
|
||||
Downloader::downloadSource('php-src', self::getLatestPHPInfo($major), $force);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,7 +32,10 @@ class PhpSource extends CustomSourceBase
|
||||
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'])) {
|
||||
throw new DownloaderException("Version {$major_version} not found.");
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ namespace SPC\store\source;
|
||||
|
||||
use SPC\exception\DownloaderException;
|
||||
use SPC\exception\FileSystemException;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\store\Downloader;
|
||||
|
||||
class PostgreSQLSource extends CustomSourceBase
|
||||
@@ -15,12 +14,11 @@ class PostgreSQLSource extends CustomSourceBase
|
||||
|
||||
/**
|
||||
* @throws DownloaderException
|
||||
* @throws RuntimeException
|
||||
* @throws FileSystemException
|
||||
*/
|
||||
public function fetch(): void
|
||||
public function fetch(bool $force = false): void
|
||||
{
|
||||
Downloader::downloadSource('postgresql', self::getLatestInfo());
|
||||
Downloader::downloadSource('postgresql', self::getLatestInfo(), $force);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,13 +13,13 @@ declare(strict_types=1);
|
||||
|
||||
// If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`).
|
||||
$extensions = match (PHP_OS_FAMILY) {
|
||||
'Linux', 'Darwin' => 'pgsql,pdo_pgsql',
|
||||
'Windows' => 'mbstring,pdo_sqlite,mbregex',
|
||||
'Linux', 'Darwin' => 'intl,pdo_sqlite,sqlite3,curl,openssl,tokenizer,bcmath,bz2,calendar,dba,ftp,iconv,mysqli,mbstring,mbregex,xml,simplexml,ctype,dom,pdo,filter,session,zlib,fileinfo,pdo_mysql,posix,sockets,shmop,sodium,sysvmsg,sysvsem,sysvshm,gd,zip,gmp,redis,xmlwriter,phar,exif,xmlreader,readline,pcntl,soap,imagick,ffi,password-argon2,pgsql,pdo_pgsql,imap,ldap,xsl',
|
||||
'Windows' => 'mbstring,pdo_sqlite,mbregex,ffi',
|
||||
};
|
||||
|
||||
// If you want to test lib-suggests feature with extension, add them below (comma separated, example `libwebp,libavif`).
|
||||
$with_libs = match (PHP_OS_FAMILY) {
|
||||
'Linux', 'Darwin' => '',
|
||||
'Linux', 'Darwin' => 'nghttp2',
|
||||
'Windows' => '',
|
||||
};
|
||||
|
||||
@@ -27,7 +27,7 @@ $with_libs = match (PHP_OS_FAMILY) {
|
||||
// You can use `common`, `bulk`, `minimal` or `none`.
|
||||
// note: combination is only available for *nix platform. Windows must use `none` combination
|
||||
$base_combination = match (PHP_OS_FAMILY) {
|
||||
'Linux', 'Darwin' => 'common',
|
||||
'Linux', 'Darwin' => 'none',
|
||||
'Windows' => 'none',
|
||||
};
|
||||
|
||||
@@ -62,6 +62,7 @@ $final_libs = trim($with_libs, $trim_value);
|
||||
|
||||
if (PHP_OS_FAMILY === 'Windows') {
|
||||
$final_extensions_cmd = '"' . $final_extensions . '"';
|
||||
$final_libs = $final_libs === '' ? '' : ('"' . $final_libs . '"');
|
||||
} else {
|
||||
$final_extensions_cmd = $final_extensions;
|
||||
}
|
||||
@@ -69,7 +70,7 @@ if (PHP_OS_FAMILY === 'Windows') {
|
||||
echo match ($argv[1]) {
|
||||
'extensions' => $final_extensions,
|
||||
'libs' => $final_libs,
|
||||
'libs_cmd' => ($final_libs === '' ? '' : (' --with-libs="' . $final_libs . '"')),
|
||||
'cmd' => $final_extensions_cmd . ($final_libs === '' ? '' : (' --with-libs="' . $final_libs . '"')),
|
||||
'libs_cmd' => ($final_libs === '' ? '' : (' --with-libs=' . $final_libs)),
|
||||
'cmd' => $final_extensions_cmd . ($final_libs === '' ? '' : (' --with-libs=' . $final_libs)),
|
||||
default => '',
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user