mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-02 22:35:43 +08:00
Compare commits
31 Commits
feat/updat
...
fix/postgr
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9e00814bfe | ||
|
|
b89ff3c083 | ||
|
|
0cfa2036f0 | ||
|
|
c5882c1f8e | ||
|
|
4531c9fe57 | ||
|
|
223dd10ac6 | ||
|
|
1c28f0f455 | ||
|
|
b3c450291a | ||
|
|
372760e469 | ||
|
|
6cf4c40cd2 | ||
|
|
af75ffaf24 | ||
|
|
ae0217b3a1 | ||
|
|
1e2b4017ac | ||
|
|
19f941797e | ||
|
|
0b863cbc70 | ||
|
|
b09337de09 | ||
|
|
d902e70b4d | ||
|
|
cd2dc5bce4 | ||
|
|
34910d18e9 | ||
|
|
3a17cec521 | ||
|
|
94644d374f | ||
|
|
f8b0c2c980 | ||
|
|
6bbb3c969c | ||
|
|
76025b95c1 | ||
|
|
1be353fd13 | ||
|
|
54001ab868 | ||
|
|
890ff475f1 | ||
|
|
559a2909a9 | ||
|
|
fff2484529 | ||
|
|
d1b194999d | ||
|
|
8650ce4f8f |
@@ -108,8 +108,7 @@ RUN apk update; \
|
||||
wget \
|
||||
xz \
|
||||
gettext-dev \
|
||||
binutils-gold \
|
||||
patchelf
|
||||
binutils-gold
|
||||
|
||||
RUN curl -#fSL https://dl.static-php.dev/static-php-cli/bulk/php-8.4.4-cli-linux-\$(uname -m).tar.gz | tar -xz -C /usr/local/bin && \
|
||||
chmod +x /usr/local/bin/php
|
||||
|
||||
@@ -92,11 +92,6 @@ RUN echo "source scl_source enable devtoolset-10" >> /etc/bashrc
|
||||
RUN source /etc/bashrc
|
||||
RUN yum install -y which
|
||||
|
||||
RUN curl -fsSL -o patchelf.tgz https://github.com/NixOS/patchelf/releases/download/0.18.0/patchelf-0.18.0-$SPC_USE_ARCH.tar.gz && \
|
||||
mkdir -p /patchelf && \
|
||||
tar -xzf patchelf.tgz -C /patchelf --strip-components=1 && \
|
||||
cp /patchelf/bin/patchelf /usr/bin/
|
||||
|
||||
RUN curl -o cmake.tgz -#fSL https://github.com/Kitware/CMake/releases/download/v3.31.4/cmake-3.31.4-linux-$SPC_USE_ARCH.tar.gz && \
|
||||
mkdir /cmake && \
|
||||
tar -xzf cmake.tgz -C /cmake --strip-components 1
|
||||
|
||||
@@ -75,8 +75,10 @@ SPC_MICRO_PATCHES=static_extensions_win32,cli_checks,disable_huge_page,vcruntime
|
||||
; - musl-native: used for alpine linux, can build `musl` and `musl -dynamic` target.
|
||||
; - gnu-native: used for general linux distros, can build gnu target for the installed glibc version only.
|
||||
|
||||
; LEGACY option to specify the target
|
||||
; option to specify the target, superceded by SPC_TARGET if set
|
||||
SPC_LIBC=musl
|
||||
; uncomment to link libc dynamically on musl
|
||||
; SPC_MUSL_DYNAMIC=true
|
||||
|
||||
; Recommended: specify your target here. Zig toolchain will be used.
|
||||
; examples:
|
||||
@@ -115,6 +117,10 @@ SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fno-ident -fPIE
|
||||
; EXTRA_LDFLAGS for `make` php, can use -release to set a soname for libphp.so
|
||||
SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS=""
|
||||
|
||||
; optional, path to openssl conf. This affects where openssl will look for the default CA.
|
||||
; default on Debian/Alpine: /etc/ssl, default on RHEL: /etc/pki/tls
|
||||
OPENSSLDIR=""
|
||||
|
||||
[macos]
|
||||
; build target: macho or macho (possibly we could support macho-universal in the future)
|
||||
; Currently we do not support universal and cross-compilation for macOS.
|
||||
@@ -142,6 +148,8 @@ SPC_CMD_PREFIX_PHP_CONFIGURE="./configure --prefix= --with-valgrind=no --enable-
|
||||
SPC_CMD_VAR_PHP_EMBED_TYPE="static"
|
||||
; EXTRA_CFLAGS for `configure` and `make` php
|
||||
SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fpic -fpie -Werror=unknown-warning-option ${SPC_DEFAULT_C_FLAGS}"
|
||||
; minimum compatible macOS version (LLVM vars, availability not guaranteed)
|
||||
MACOSX_DEPLOYMENT_TARGET=12.0
|
||||
|
||||
[freebsd]
|
||||
; compiler environments
|
||||
|
||||
@@ -43,6 +43,14 @@
|
||||
"calendar": {
|
||||
"type": "builtin"
|
||||
},
|
||||
"com_dotnet": {
|
||||
"support": {
|
||||
"BSD": "no",
|
||||
"Linux": "no",
|
||||
"Darwin": "no"
|
||||
},
|
||||
"type": "builtin"
|
||||
},
|
||||
"ctype": {
|
||||
"type": "builtin"
|
||||
},
|
||||
@@ -127,6 +135,14 @@
|
||||
"sockets"
|
||||
]
|
||||
},
|
||||
"excimer": {
|
||||
"support": {
|
||||
"Windows": "wip",
|
||||
"BSD": "wip"
|
||||
},
|
||||
"type": "external",
|
||||
"source": "ext-excimer"
|
||||
},
|
||||
"exif": {
|
||||
"type": "builtin"
|
||||
},
|
||||
@@ -410,8 +426,7 @@
|
||||
"ext-depends": [
|
||||
"zlib",
|
||||
"session"
|
||||
],
|
||||
"build-with-php": true
|
||||
]
|
||||
},
|
||||
"memcached": {
|
||||
"support": {
|
||||
@@ -500,7 +515,9 @@
|
||||
"mysqlnd"
|
||||
],
|
||||
"lib-depends": [
|
||||
"libsodium",
|
||||
"libsodium"
|
||||
],
|
||||
"lib-suggests": [
|
||||
"openssl"
|
||||
]
|
||||
},
|
||||
@@ -515,7 +532,9 @@
|
||||
"mysqlnd"
|
||||
],
|
||||
"lib-depends": [
|
||||
"libsodium",
|
||||
"libsodium"
|
||||
],
|
||||
"lib-suggests": [
|
||||
"openssl"
|
||||
]
|
||||
},
|
||||
|
||||
@@ -361,6 +361,9 @@
|
||||
"source": "libargon2",
|
||||
"static-libs-unix": [
|
||||
"libargon2.a"
|
||||
],
|
||||
"lib-suggests": [
|
||||
"libsodium"
|
||||
]
|
||||
},
|
||||
"libavif": {
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/amqp",
|
||||
"path": "php-src/ext/amqp",
|
||||
"filename": "amqp.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
@@ -20,6 +21,7 @@
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/APCu",
|
||||
"path": "php-src/ext/apcu",
|
||||
"filename": "apcu.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
@@ -29,6 +31,7 @@
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/ast",
|
||||
"path": "php-src/ext/ast",
|
||||
"filename": "ast.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
@@ -85,6 +88,7 @@
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/dio",
|
||||
"path": "php-src/ext/dio",
|
||||
"filename": "dio.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
@@ -94,6 +98,7 @@
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/ev",
|
||||
"path": "php-src/ext/ev",
|
||||
"filename": "ev.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
@@ -113,6 +118,7 @@
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/ds",
|
||||
"path": "php-src/ext/ds",
|
||||
"filename": "ds.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
@@ -120,13 +126,23 @@
|
||||
},
|
||||
"ext-event": {
|
||||
"type": "url",
|
||||
"url": "https://bitbucket.org/osmanov/pecl-event/get/3.0.8.tar.gz",
|
||||
"url": "https://bitbucket.org/osmanov/pecl-event/get/3.1.4.tar.gz",
|
||||
"path": "php-src/ext/event",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
}
|
||||
},
|
||||
"ext-excimer": {
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/excimer",
|
||||
"path": "php-src/ext/excimer",
|
||||
"filename": "excimer.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
}
|
||||
},
|
||||
"ext-glfw": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mario-deluna/php-glfw",
|
||||
@@ -149,6 +165,7 @@
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/grpc",
|
||||
"path": "php-src/ext/grpc",
|
||||
"filename": "grpc.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": [
|
||||
@@ -160,6 +177,7 @@
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/imagick",
|
||||
"path": "php-src/ext/imagick",
|
||||
"filename": "imagick.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
@@ -169,6 +187,7 @@
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/imap",
|
||||
"path": "php-src/ext/imap",
|
||||
"filename": "imap.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": [
|
||||
@@ -190,6 +209,7 @@
|
||||
"ext-maxminddb": {
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/maxminddb",
|
||||
"filename": "ext-maxminddb.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
@@ -199,6 +219,7 @@
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/memcache",
|
||||
"path": "php-src/ext/memcache",
|
||||
"filename": "memcache.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
@@ -217,6 +238,7 @@
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/simdjson",
|
||||
"path": "php-src/ext/simdjson",
|
||||
"filename": "simdjson.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
@@ -236,6 +258,7 @@
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/ssh2",
|
||||
"path": "php-src/ext/ssh2",
|
||||
"filename": "ssh2.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
@@ -245,6 +268,7 @@
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/trader",
|
||||
"path": "php-src/ext/trader",
|
||||
"filename": "trader.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
@@ -254,6 +278,7 @@
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/uuid",
|
||||
"path": "php-src/ext/uuid",
|
||||
"filename": "uuid.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
@@ -263,6 +288,7 @@
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/uv",
|
||||
"path": "php-src/ext/uv",
|
||||
"filename": "uv.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
@@ -281,6 +307,7 @@
|
||||
"ext-zip": {
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/zip",
|
||||
"filename": "ext-zip.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
@@ -388,6 +415,7 @@
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/igbinary",
|
||||
"path": "php-src/ext/igbinary",
|
||||
"filename": "igbinary.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "COPYING"
|
||||
@@ -414,6 +442,7 @@
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/inotify",
|
||||
"path": "php-src/ext/inotify",
|
||||
"filename": "inotify.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
@@ -693,7 +722,7 @@
|
||||
"libsodium": {
|
||||
"type": "ghrel",
|
||||
"repo": "jedisct1/libsodium",
|
||||
"match": "libsodium-\\d+(\\.\\d+)*\\.tar\\.gz",
|
||||
"match": "libsodium-(?!1\\.0\\.21)\\d+(\\.\\d+)*\\.tar\\.gz",
|
||||
"prefer-stable": true,
|
||||
"provide-pre-built": true,
|
||||
"license": {
|
||||
@@ -818,6 +847,7 @@
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/memcached",
|
||||
"path": "php-src/ext/memcached",
|
||||
"filename": "memcached.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
@@ -858,6 +888,7 @@
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/msgpack",
|
||||
"path": "php-src/ext/msgpack",
|
||||
"filename": "msgpack.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
@@ -960,6 +991,7 @@
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/opentelemetry",
|
||||
"path": "php-src/ext/opentelemetry",
|
||||
"filename": "opentelemetry.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
@@ -969,6 +1001,7 @@
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/parallel",
|
||||
"path": "php-src/ext/parallel",
|
||||
"filename": "parallel.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
@@ -977,6 +1010,7 @@
|
||||
"pcov": {
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/pcov",
|
||||
"filename": "pcov.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
@@ -986,6 +1020,7 @@
|
||||
"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"
|
||||
@@ -1021,6 +1056,7 @@
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/protobuf",
|
||||
"path": "php-src/ext/protobuf",
|
||||
"filename": "protobuf.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
@@ -1082,6 +1118,7 @@
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/redis",
|
||||
"path": "php-src/ext/redis",
|
||||
"filename": "redis.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": [
|
||||
@@ -1121,6 +1158,7 @@
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/sqlsrv",
|
||||
"path": "php-src/ext/sqlsrv",
|
||||
"filename": "sqlsrv.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
@@ -1186,6 +1224,7 @@
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/xhprof",
|
||||
"path": "php-src/ext/xhprof-src",
|
||||
"filename": "xhprof.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
@@ -1195,6 +1234,7 @@
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/xlswriter",
|
||||
"path": "php-src/ext/xlswriter",
|
||||
"filename": "xlswriter.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
@@ -1215,6 +1255,7 @@
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/yac",
|
||||
"path": "php-src/ext/yac",
|
||||
"filename": "yac.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
|
||||
@@ -549,22 +549,24 @@ otherwise it will be executed repeatedly in other events.
|
||||
|
||||
The following are the supported `patch_point` event names and corresponding locations:
|
||||
|
||||
| Event name | Event description |
|
||||
|------------------------------|----------------------------------------------------------------------------------------------------|
|
||||
| before-libs-extract | Triggered before the dependent libraries extracted |
|
||||
| after-libs-extract | Triggered after the compiled dependent libraries extracted |
|
||||
| before-php-extract | Triggered before PHP source code extracted |
|
||||
| after-php-extract | Triggered after PHP source code extracted |
|
||||
| before-micro-extract | Triggered before phpmicro extract |
|
||||
| after-micro-extract | Triggered after phpmicro extracted |
|
||||
| before-exts-extract | Triggered before the extension (to be compiled) extracted to the PHP source directory |
|
||||
| after-exts-extract | Triggered after the extension extracted to the PHP source directory |
|
||||
| before-library[*name*]-build | Triggered before the library named `name` is compiled (such as `before-library[postgresql]-build`) |
|
||||
| after-library[*name*]-build | Triggered after the library named `name` is compiled |
|
||||
| before-php-buildconf | Triggered before compiling PHP command `./buildconf` |
|
||||
| before-php-configure | Triggered before compiling PHP command `./configure` |
|
||||
| before-php-make | Triggered before compiling PHP command `make` |
|
||||
| before-sanity-check | Triggered after compiling PHP but before running extended checks |
|
||||
| Event name | Event description |
|
||||
|---------------------------------|----------------------------------------------------------------------------------------------------|
|
||||
| before-libs-extract | Triggered before the dependent libraries extracted |
|
||||
| after-libs-extract | Triggered after the compiled dependent libraries extracted |
|
||||
| before-php-extract | Triggered before PHP source code extracted |
|
||||
| after-php-extract | Triggered after PHP source code extracted |
|
||||
| before-micro-extract | Triggered before phpmicro extract |
|
||||
| after-micro-extract | Triggered after phpmicro extracted |
|
||||
| before-exts-extract | Triggered before the extension (to be compiled) extracted to the PHP source directory |
|
||||
| after-exts-extract | Triggered after the extension extracted to the PHP source directory |
|
||||
| before-library[*name*]-build | Triggered before the library named `name` is compiled (such as `before-library[postgresql]-build`) |
|
||||
| after-library[*name*]-build | Triggered after the library named `name` is compiled |
|
||||
| after-shared-ext[*name*]-build | Triggered after the shared extension named `name` is compiled |
|
||||
| before-shared-ext[*name*]-build | Triggered before the shared extension named `name` is compiled |
|
||||
| before-php-buildconf | Triggered before compiling PHP command `./buildconf` |
|
||||
| before-php-configure | Triggered before compiling PHP command `./configure` |
|
||||
| before-php-make | Triggered before compiling PHP command `make` |
|
||||
| before-sanity-check | Triggered after compiling PHP but before running extended checks |
|
||||
|
||||
The following is a simple example of temporarily modifying the PHP source code.
|
||||
Enable the CLI function to search for the `php.ini` configuration in the current working directory:
|
||||
|
||||
@@ -500,6 +500,8 @@ bin/spc dev:sort-config ext
|
||||
| after-exts-extract | 在要编译的扩展解压到 PHP 源码目录后触发 |
|
||||
| before-library[*name*]-build | 在名称为 `name` 的库编译前触发(如 `before-library[postgresql]-build`) |
|
||||
| after-library[*name*]-build | 在名称为 `name` 的库编译后触发 |
|
||||
| after-shared-ext[*name*]-build | 在名称为 `name` 的共享扩展编译后触发(如 `after-shared-ext[redis]-build`) |
|
||||
| before-shared-ext[*name*]-build | 在名称为 `name` 的共享扩展编译前触发 |
|
||||
| before-php-buildconf | 在编译 PHP 命令 `./buildconf` 前触发 |
|
||||
| before-php-configure | 在编译 PHP 命令 `./configure` 前触发 |
|
||||
| before-php-make | 在编译 PHP 命令 `make` 前触发 |
|
||||
|
||||
@@ -34,7 +34,7 @@ use Symfony\Component\Console\Application;
|
||||
*/
|
||||
final class ConsoleApplication extends Application
|
||||
{
|
||||
public const string VERSION = '2.7.11';
|
||||
public const string VERSION = '2.8.0';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
@@ -160,7 +160,7 @@ abstract class BuilderBase
|
||||
}
|
||||
if (!$skip_extract) {
|
||||
$this->emitPatchPoint('before-php-extract');
|
||||
SourceManager::initSource(sources: [$this->getPhpSrcName()], source_only: true);
|
||||
SourceManager::initSource(sources: ['php-src'], source_only: true);
|
||||
$this->emitPatchPoint('after-php-extract');
|
||||
if ($this->getPHPVersionID() >= 80000) {
|
||||
$this->emitPatchPoint('before-micro-extract');
|
||||
@@ -319,7 +319,7 @@ abstract class BuilderBase
|
||||
public function getPHPVersionFromArchive(?string $file = null): false|string
|
||||
{
|
||||
if ($file === null) {
|
||||
$lock = LockFile::get($this->getPhpSrcName());
|
||||
$lock = LockFile::get('php-src');
|
||||
if ($lock === null) {
|
||||
return false;
|
||||
}
|
||||
@@ -498,14 +498,6 @@ abstract class BuilderBase
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the php-src name to use for lock file lookups (supports version-specific names like php-src-8.2)
|
||||
*/
|
||||
protected function getPhpSrcName(): string
|
||||
{
|
||||
return getenv('SPC_PHP_SRC_NAME') ?: 'php-src';
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate micro extension test php code.
|
||||
*/
|
||||
|
||||
@@ -398,13 +398,12 @@ class Extension
|
||||
$dependency->buildShared([...$visited, $this->getName()]);
|
||||
}
|
||||
}
|
||||
if (Config::getExt($this->getName(), 'type') === 'addon') {
|
||||
return;
|
||||
}
|
||||
$this->builder->emitPatchPoint('before-shared-ext[' . $this->getName() . ']-build');
|
||||
match (PHP_OS_FAMILY) {
|
||||
'Darwin', 'Linux' => $this->buildUnixShared(),
|
||||
default => throw new WrongUsageException(PHP_OS_FAMILY . ' build shared extensions is not supported yet'),
|
||||
};
|
||||
$this->builder->emitPatchPoint('after-shared-ext[' . $this->getName() . ']-build');
|
||||
} catch (SPCException $e) {
|
||||
$e->bindExtensionInfo(['extension_name' => $this->getName()]);
|
||||
throw $e;
|
||||
@@ -455,12 +454,17 @@ class Extension
|
||||
|
||||
// process *.so file
|
||||
$soFile = BUILD_MODULES_PATH . '/' . $this->getName() . '.so';
|
||||
$soDest = $soFile;
|
||||
preg_match('/-release\s+(\S*)/', getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS'), $matches);
|
||||
if (!empty($matches[1])) {
|
||||
$soDest = str_replace('.so', '-' . $matches[1] . '.so', $soFile);
|
||||
}
|
||||
if (!file_exists($soFile)) {
|
||||
throw new ValidationException("extension {$this->getName()} build failed: {$soFile} not found", validation_module: "Extension {$this->getName()} build");
|
||||
}
|
||||
/** @var UnixBuilderBase $builder */
|
||||
$builder = $this->builder;
|
||||
$builder->deployBinary($soFile, $soFile, false);
|
||||
$builder->deployBinary($soFile, $soDest, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -538,7 +542,7 @@ class Extension
|
||||
*/
|
||||
protected function getSharedExtensionEnv(): array
|
||||
{
|
||||
$config = (new SPCConfigUtil($this->builder))->getExtensionConfig($this);
|
||||
$config = (new SPCConfigUtil($this->builder, ['no_php' => true]))->getExtensionConfig($this);
|
||||
[$staticLibs, $sharedLibs] = $this->splitLibsIntoStaticAndShared($config['libs']);
|
||||
$preStatic = PHP_OS_FAMILY === 'Darwin' ? '' : '-Wl,--start-group ';
|
||||
$postStatic = PHP_OS_FAMILY === 'Darwin' ? '' : ' -Wl,--end-group ';
|
||||
@@ -546,6 +550,7 @@ class Extension
|
||||
'CFLAGS' => $config['cflags'],
|
||||
'CXXFLAGS' => $config['cflags'],
|
||||
'LDFLAGS' => $config['ldflags'],
|
||||
'EXTRA_LDFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS'),
|
||||
'LIBS' => clean_spaces("{$preStatic} {$staticLibs} {$postStatic} {$sharedLibs}"),
|
||||
'LD_LIBRARY_PATH' => BUILD_LIB_PATH,
|
||||
];
|
||||
|
||||
17
src/SPC/builder/extension/com_dotnet.php
Normal file
17
src/SPC/builder/extension/com_dotnet.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\extension;
|
||||
|
||||
use SPC\builder\Extension;
|
||||
use SPC\util\CustomExt;
|
||||
|
||||
#[CustomExt('com_dotnet')]
|
||||
class com_dotnet extends Extension
|
||||
{
|
||||
public function getWindowsConfigureArg(bool $shared = false): string
|
||||
{
|
||||
return '--enable-com-dotnet=yes';
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,9 @@ class memcache extends Extension
|
||||
|
||||
public function patchBeforeBuildconf(): bool
|
||||
{
|
||||
if (!$this->isBuildStatic()) {
|
||||
return false;
|
||||
}
|
||||
FileSystem::replaceFileStr(
|
||||
SOURCE_PATH . '/php-src/ext/memcache/config9.m4',
|
||||
'if test -d $abs_srcdir/src ; then',
|
||||
@@ -44,6 +47,24 @@ EOF
|
||||
return true;
|
||||
}
|
||||
|
||||
public function patchBeforeSharedConfigure(): bool
|
||||
{
|
||||
if (!$this->isBuildShared()) {
|
||||
return false;
|
||||
}
|
||||
FileSystem::replaceFileStr(
|
||||
SOURCE_PATH . '/php-src/ext/memcache/config9.m4',
|
||||
'if test -d $abs_srcdir/main ; then',
|
||||
'if test -d $abs_srcdir/src ; then',
|
||||
);
|
||||
FileSystem::replaceFileStr(
|
||||
SOURCE_PATH . '/php-src/ext/memcache/config9.m4',
|
||||
'export CPPFLAGS="$CPPFLAGS $INCLUDES -I$abs_srcdir/main"',
|
||||
'export CPPFLAGS="$CPPFLAGS $INCLUDES"',
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function getExtraEnv(): array
|
||||
{
|
||||
return ['CFLAGS' => '-std=c17'];
|
||||
|
||||
@@ -24,25 +24,6 @@ class password_argon2 extends Extension
|
||||
}
|
||||
}
|
||||
|
||||
public function patchBeforeMake(): bool
|
||||
{
|
||||
$patched = parent::patchBeforeMake();
|
||||
if ($this->builder->getLib('libsodium') !== null) {
|
||||
$extraLibs = getenv('SPC_EXTRA_LIBS');
|
||||
if ($extraLibs !== false) {
|
||||
$extraLibs = str_replace(
|
||||
[BUILD_LIB_PATH . '/libargon2.a', BUILD_LIB_PATH . '/libsodium.a'],
|
||||
['', BUILD_LIB_PATH . '/libargon2.a ' . BUILD_LIB_PATH . '/libsodium.a'],
|
||||
$extraLibs,
|
||||
);
|
||||
$extraLibs = trim(preg_replace('/\s+/', ' ', $extraLibs)); // normalize spacing
|
||||
f_putenv('SPC_EXTRA_LIBS=' . $extraLibs);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return $patched;
|
||||
}
|
||||
|
||||
public function getConfigureArg(bool $shared = false): string
|
||||
{
|
||||
if ($this->builder->getLib('openssl') !== null) {
|
||||
|
||||
@@ -45,4 +45,11 @@ class spx extends Extension
|
||||
FileSystem::copy($this->source_dir . '/src/php_spx.h', $this->source_dir . '/php_spx.h');
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getSharedExtensionEnv(): array
|
||||
{
|
||||
$env = parent::getSharedExtensionEnv();
|
||||
$env['SPX_SHARED_LIBADD'] = $env['LIBS'];
|
||||
return $env;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,11 +283,14 @@ class LinuxBuilder extends UnixBuilderBase
|
||||
|
||||
// process libphp.so for shared embed
|
||||
$libphpSo = BUILD_LIB_PATH . '/libphp.so';
|
||||
$libphpSoDest = BUILD_LIB_PATH . '/libphp.so';
|
||||
if (file_exists($libphpSo)) {
|
||||
// post actions: rename libphp.so to libphp-<release>.so if -release is set in LDFLAGS
|
||||
$this->processLibphpSoFile($libphpSo);
|
||||
// deploy libphp.so
|
||||
$this->deployBinary($libphpSo, $libphpSo, false);
|
||||
preg_match('/-release\s+(\S*)/', getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS'), $matches);
|
||||
if (!empty($matches[1])) {
|
||||
$libphpSoDest = str_replace('.so', '-' . $matches[1] . '.so', $libphpSo);
|
||||
}
|
||||
$this->deployBinary($libphpSo, $libphpSoDest, false);
|
||||
}
|
||||
|
||||
// process shared extensions build-with-php
|
||||
@@ -324,74 +327,6 @@ class LinuxBuilder extends UnixBuilderBase
|
||||
]);
|
||||
}
|
||||
|
||||
private function processLibphpSoFile(string $libphpSo): void
|
||||
{
|
||||
$ldflags = getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS') ?: '';
|
||||
$libDir = BUILD_LIB_PATH;
|
||||
$modulesDir = BUILD_MODULES_PATH;
|
||||
$realLibName = 'libphp.so';
|
||||
$cwd = getcwd();
|
||||
|
||||
if (preg_match('/-release\s+(\S+)/', $ldflags, $matches)) {
|
||||
$release = $matches[1];
|
||||
$realLibName = "libphp-{$release}.so";
|
||||
$libphpRelease = "{$libDir}/{$realLibName}";
|
||||
if (!file_exists($libphpRelease) && file_exists($libphpSo)) {
|
||||
rename($libphpSo, $libphpRelease);
|
||||
}
|
||||
if (file_exists($libphpRelease)) {
|
||||
chdir($libDir);
|
||||
if (file_exists($libphpSo)) {
|
||||
unlink($libphpSo);
|
||||
}
|
||||
symlink($realLibName, 'libphp.so');
|
||||
shell()->exec(sprintf(
|
||||
'patchelf --set-soname %s %s',
|
||||
escapeshellarg($realLibName),
|
||||
escapeshellarg($libphpRelease)
|
||||
));
|
||||
}
|
||||
if (is_dir($modulesDir)) {
|
||||
chdir($modulesDir);
|
||||
foreach ($this->getExts() as $ext) {
|
||||
if (!$ext->isBuildShared()) {
|
||||
continue;
|
||||
}
|
||||
$name = $ext->getName();
|
||||
$versioned = "{$name}-{$release}.so";
|
||||
$unversioned = "{$name}.so";
|
||||
$src = "{$modulesDir}/{$versioned}";
|
||||
$dst = "{$modulesDir}/{$unversioned}";
|
||||
if (is_file($src)) {
|
||||
rename($src, $dst);
|
||||
shell()->exec(sprintf(
|
||||
'patchelf --set-soname %s %s',
|
||||
escapeshellarg($unversioned),
|
||||
escapeshellarg($dst)
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
chdir($cwd);
|
||||
}
|
||||
|
||||
$target = "{$libDir}/{$realLibName}";
|
||||
if (file_exists($target)) {
|
||||
[, $output] = shell()->execWithResult('readelf -d ' . escapeshellarg($target));
|
||||
$output = implode("\n", $output);
|
||||
if (preg_match('/SONAME.*\[(.+)]/', $output, $sonameMatch)) {
|
||||
$currentSoname = $sonameMatch[1];
|
||||
if ($currentSoname !== basename($target)) {
|
||||
shell()->exec(sprintf(
|
||||
'patchelf --set-soname %s %s',
|
||||
escapeshellarg(basename($target)),
|
||||
escapeshellarg($target)
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Patch micro.sfx after UPX compression.
|
||||
* micro needs special section handling in LinuxBuilder.
|
||||
|
||||
@@ -21,6 +21,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\linux\library;
|
||||
|
||||
use SPC\builder\linux\SystemUtil;
|
||||
use SPC\store\FileSystem;
|
||||
|
||||
class openssl extends LinuxLibraryBase
|
||||
@@ -51,6 +52,9 @@ class openssl extends LinuxLibraryBase
|
||||
$zlib_extra = '';
|
||||
}
|
||||
|
||||
$openssl_dir = getenv('OPENSSLDIR') ?: null;
|
||||
// TODO: in v3 use the following: $openssl_dir ??= SystemUtil::getOSRelease()['dist'] === 'redhat' ? '/etc/pki/tls' : '/etc/ssl';
|
||||
$openssl_dir ??= '/etc/ssl';
|
||||
$ex_lib = trim($ex_lib);
|
||||
|
||||
shell()->cd($this->source_dir)->initializeEnv($this)
|
||||
@@ -58,7 +62,7 @@ class openssl extends LinuxLibraryBase
|
||||
"{$env} ./Configure no-shared {$extra} " .
|
||||
'--prefix=' . BUILD_ROOT_PATH . ' ' .
|
||||
'--libdir=' . BUILD_LIB_PATH . ' ' .
|
||||
'--openssldir=/etc/ssl ' .
|
||||
"--openssldir={$openssl_dir} " .
|
||||
"{$zlib_extra}" .
|
||||
'enable-pie ' .
|
||||
'no-legacy ' .
|
||||
|
||||
@@ -72,12 +72,8 @@ trait UnixSystemUtilTrait
|
||||
if (!is_file($symbol_file)) {
|
||||
throw new SPCInternalException("The symbol file {$symbol_file} does not exist, please check if nm command is available.");
|
||||
}
|
||||
// https://github.com/ziglang/zig/issues/24662
|
||||
if (ToolchainManager::getToolchainClass() === ZigToolchain::class) {
|
||||
return '-Wl,--export-dynamic';
|
||||
}
|
||||
// macOS
|
||||
if (SPCTarget::getTargetOS() !== 'Linux') {
|
||||
// macOS/zig
|
||||
if (SPCTarget::getTargetOS() !== 'Linux' || ToolchainManager::getToolchainClass() === ZigToolchain::class) {
|
||||
return "-Wl,-exported_symbols_list,{$symbol_file}";
|
||||
}
|
||||
return "-Wl,--dynamic-list={$symbol_file}";
|
||||
|
||||
@@ -235,8 +235,10 @@ abstract class UnixBuilderBase extends BuilderBase
|
||||
$lens .= ' -static';
|
||||
}
|
||||
$dynamic_exports = '';
|
||||
$embedType = 'static';
|
||||
// if someone changed to EMBED_TYPE=shared, we need to add LD_LIBRARY_PATH
|
||||
if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'shared') {
|
||||
$embedType = 'shared';
|
||||
if (PHP_OS_FAMILY === 'Darwin') {
|
||||
$ext_path = 'DYLD_LIBRARY_PATH=' . BUILD_LIB_PATH . ':$DYLD_LIBRARY_PATH ';
|
||||
} else {
|
||||
@@ -255,18 +257,19 @@ abstract class UnixBuilderBase extends BuilderBase
|
||||
}
|
||||
}
|
||||
$cc = getenv('CC');
|
||||
|
||||
[$ret, $out] = shell()->cd($sample_file_path)->execWithResult("{$cc} -o embed embed.c {$lens} {$dynamic_exports}");
|
||||
if ($ret !== 0) {
|
||||
throw new ValidationException(
|
||||
'embed failed sanity check: build failed. Error message: ' . implode("\n", $out),
|
||||
validation_module: 'static libphp.a sanity check'
|
||||
'embed failed to build. Error message: ' . implode("\n", $out),
|
||||
validation_module: $embedType . ' libphp embed build sanity check'
|
||||
);
|
||||
}
|
||||
[$ret, $output] = shell()->cd($sample_file_path)->execWithResult($ext_path . './embed');
|
||||
if ($ret !== 0 || trim(implode('', $output)) !== 'hello') {
|
||||
throw new ValidationException(
|
||||
'embed failed sanity check: run failed. Error message: ' . implode("\n", $output),
|
||||
validation_module: 'static libphp.a sanity check'
|
||||
'embed failed to run. Error message: ' . implode("\n", $output),
|
||||
validation_module: $embedType . ' libphp embed run sanity check'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,11 @@ trait gettext
|
||||
->addConfigureArgs(
|
||||
'--disable-java',
|
||||
'--disable-c++',
|
||||
'--with-included-gettext',
|
||||
'--disable-d',
|
||||
'--disable-rpath',
|
||||
'--disable-modula2',
|
||||
'--disable-libasprintf',
|
||||
'--with-included-libintl',
|
||||
"--with-iconv-prefix={$this->getBuildRootPath()}",
|
||||
);
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ trait postgresql
|
||||
// fix aarch64 build on glibc 2.17 (e.g. CentOS 7)
|
||||
if (SPCTarget::getLibcVersion() === '2.17' && GNU_ARCH === 'aarch64') {
|
||||
try {
|
||||
FileSystem::replaceFileStr("{$this->source_dir}/src/port/pg_popcount_aarch64.c", 'HWCAP_SVE', '0');
|
||||
// FileSystem::replaceFileStr("{$this->source_dir}/src/port/pg_popcount_aarch64.c", 'HWCAP_SVE', '0');
|
||||
FileSystem::replaceFileStr(
|
||||
"{$this->source_dir}/src/port/pg_crc32c_armv8_choose.c",
|
||||
'#if defined(__linux__) && !defined(__aarch64__) && !defined(HWCAP2_CRC32)',
|
||||
@@ -50,7 +50,7 @@ trait postgresql
|
||||
$config = $spc->config(libraries: $libs, include_suggest_lib: $this->builder->getOption('with-suggested-libs', false));
|
||||
|
||||
$env_vars = [
|
||||
'CFLAGS' => $config['cflags'],
|
||||
'CFLAGS' => $config['cflags'] . ' -std=c17',
|
||||
'CPPFLAGS' => '-DPIC',
|
||||
'LDFLAGS' => $config['ldflags'],
|
||||
'LIBS' => $config['libs'],
|
||||
|
||||
@@ -30,7 +30,6 @@ class curl extends WindowsLibraryBase
|
||||
'-DCMAKE_BUILD_TYPE=Release ' .
|
||||
'-DBUILD_SHARED_LIBS=OFF ' .
|
||||
'-DBUILD_STATIC_LIBS=ON ' .
|
||||
'-DCURL_STATICLIB=ON ' .
|
||||
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' .
|
||||
'-DBUILD_CURL_EXE=OFF ' . // disable curl.exe
|
||||
'-DBUILD_TESTING=OFF ' . // disable tests
|
||||
@@ -42,9 +41,9 @@ class curl extends WindowsLibraryBase
|
||||
'-DCURL_USE_OPENSSL=OFF ' . // disable openssl due to certificate issue
|
||||
'-DCURL_ENABLE_SSL=ON ' .
|
||||
'-DUSE_NGHTTP2=ON ' . // enable nghttp2
|
||||
'-DSHARE_LIB_OBJECT=OFF ' . // disable shared lib object
|
||||
'-DCURL_USE_LIBSSH2=ON ' . // enable libssh2
|
||||
'-DENABLE_IPV6=ON ' . // enable ipv6
|
||||
'-DNGHTTP2_CFLAGS="/DNGHTTP2_STATICLIB" ' .
|
||||
$alt
|
||||
)
|
||||
->execWithWrapper(
|
||||
@@ -53,5 +52,7 @@ class curl extends WindowsLibraryBase
|
||||
);
|
||||
// move libcurl.lib to libcurl_a.lib
|
||||
rename(BUILD_LIB_PATH . '\libcurl.lib', BUILD_LIB_PATH . '\libcurl_a.lib');
|
||||
|
||||
FileSystem::replaceFileStr(BUILD_INCLUDE_PATH . '\curl\curl.h', '#ifdef CURL_STATICLIB', '#if 1');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,11 +29,16 @@ class nghttp2 extends WindowsLibraryBase
|
||||
'-DBUILD_SHARED_LIBS=OFF ' .
|
||||
'-DENABLE_STATIC_CRT=ON ' .
|
||||
'-DENABLE_LIB_ONLY=ON ' .
|
||||
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' '
|
||||
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' .
|
||||
'-DENABLE_STATIC_CRT=ON ' .
|
||||
'-DENABLE_DOC=OFF ' .
|
||||
'-DBUILD_TESTING=OFF '
|
||||
)
|
||||
->execWithWrapper(
|
||||
$this->builder->makeSimpleWrapper('cmake'),
|
||||
"--build build --config Release --target install -j{$this->builder->concurrency}"
|
||||
);
|
||||
|
||||
FileSystem::replaceFileStr(BUILD_INCLUDE_PATH . '\nghttp2\nghttp2.h', '#ifdef NGHTTP2_STATICLIB', '#if 1');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,6 @@ class BuildPHPCommand extends BuildCommand
|
||||
$this->addOption('with-micro-logo', null, InputOption::VALUE_REQUIRED, 'Use custom .ico for micro.sfx (windows only)');
|
||||
$this->addOption('enable-micro-win32', null, null, 'Enable win32 mode for phpmicro (Windows only)');
|
||||
$this->addOption('with-frankenphp-app', null, InputOption::VALUE_REQUIRED, 'Path to a folder to be embedded in FrankenPHP');
|
||||
$this->addOption('with-php', null, InputOption::VALUE_REQUIRED, 'PHP version to build (e.g., 8.2, 8.3, 8.4). Uses php-src-X.Y if available, otherwise php-src');
|
||||
}
|
||||
|
||||
public function handle(): int
|
||||
@@ -121,31 +120,6 @@ class BuildPHPCommand extends BuildCommand
|
||||
logger()->warning('Some cases micro.sfx cannot be packed via UPX due to dynamic size bug, be aware!');
|
||||
}
|
||||
}
|
||||
|
||||
// Determine which php-src to use based on --with-php option
|
||||
$php_version = $this->getOption('with-php');
|
||||
if ($php_version !== null) {
|
||||
// Check if version-specific php-src exists in lock file
|
||||
$version_specific_name = "php-src-{$php_version}";
|
||||
$lock_file_path = DOWNLOAD_PATH . '/.lock.json';
|
||||
if (file_exists($lock_file_path)) {
|
||||
$lock_content = json_decode(file_get_contents($lock_file_path), true);
|
||||
if (isset($lock_content[$version_specific_name])) {
|
||||
// Use version-specific php-src
|
||||
f_putenv("SPC_PHP_SRC_NAME={$version_specific_name}");
|
||||
logger()->info("Building with PHP {$php_version} (using {$version_specific_name})");
|
||||
} else {
|
||||
logger()->error('No php-src found in downloads. Please run download command first.');
|
||||
return static::FAILURE;
|
||||
}
|
||||
} else {
|
||||
logger()->error('Lock file not found. Please download sources first.');
|
||||
return static::FAILURE;
|
||||
}
|
||||
} else {
|
||||
f_putenv('SPC_PHP_SRC_NAME=php-src');
|
||||
}
|
||||
|
||||
// create builder
|
||||
$builder = BuilderProvider::makeBuilderByInput($this->input);
|
||||
$include_suggest_ext = $this->getOption('with-suggested-exts');
|
||||
|
||||
@@ -9,9 +9,7 @@ use SPC\exception\DownloaderException;
|
||||
use SPC\exception\SPCException;
|
||||
use SPC\store\Config;
|
||||
use SPC\store\Downloader;
|
||||
use SPC\store\FileSystem;
|
||||
use SPC\store\LockFile;
|
||||
use SPC\store\source\CustomSourceBase;
|
||||
use SPC\util\DependencyUtil;
|
||||
use SPC\util\SPCTarget;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
@@ -29,10 +27,10 @@ class DownloadCommand extends BaseCommand
|
||||
|
||||
public function configure(): void
|
||||
{
|
||||
$this->addArgument('sources', InputArgument::OPTIONAL, 'The sources will be compiled, comma separated');
|
||||
$this->addArgument('sources', InputArgument::REQUIRED, 'The sources will be compiled, comma separated');
|
||||
$this->addOption('shallow-clone', null, null, 'Clone shallow');
|
||||
$this->addOption('with-openssl11', null, null, 'Use openssl 1.1');
|
||||
$this->addOption('with-php', null, InputOption::VALUE_REQUIRED, 'version in major.minor format, comma-separated for multiple versions (default 8.4)', '8.4');
|
||||
$this->addOption('with-php', null, InputOption::VALUE_REQUIRED, 'version in major.minor format (default 8.4)', '8.4');
|
||||
$this->addOption('clean', null, null, 'Clean old download cache and source before fetch');
|
||||
$this->addOption('all', 'A', null, 'Fetch all sources that static-php-cli needed');
|
||||
$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"');
|
||||
@@ -45,31 +43,10 @@ class DownloadCommand extends BaseCommand
|
||||
$this->addOption('retry', 'R', InputOption::VALUE_REQUIRED, 'Set retry time when downloading failed (default: 0)', '0');
|
||||
$this->addOption('prefer-pre-built', 'P', null, 'Download pre-built libraries when available');
|
||||
$this->addOption('no-alt', null, null, 'Do not download alternative sources');
|
||||
$this->addOption('update', null, null, 'Check and update downloaded sources');
|
||||
}
|
||||
|
||||
public function initialize(InputInterface $input, OutputInterface $output): void
|
||||
{
|
||||
// mode: --update
|
||||
if ($input->getOption('update') && empty($input->getArgument('sources')) && empty($input->getOption('for-extensions')) && empty($input->getOption('for-libs'))) {
|
||||
if (!file_exists(LockFile::LOCK_FILE)) {
|
||||
parent::initialize($input, $output);
|
||||
return;
|
||||
}
|
||||
$lock_content = json_decode(file_get_contents(LockFile::LOCK_FILE), true);
|
||||
if (is_array($lock_content)) {
|
||||
// Filter out pre-built sources
|
||||
$sources_to_check = array_filter($lock_content, function ($name) {
|
||||
return
|
||||
!str_contains($name, '-Linux-') &&
|
||||
!str_contains($name, '-Windows-') &&
|
||||
!str_contains($name, '-Darwin-');
|
||||
}, ARRAY_FILTER_USE_KEY);
|
||||
$input->setArgument('sources', implode(',', array_keys($sources_to_check)));
|
||||
}
|
||||
parent::initialize($input, $output);
|
||||
return;
|
||||
}
|
||||
// mode: --all
|
||||
if ($input->getOption('all')) {
|
||||
$input->setArgument('sources', implode(',', array_keys(Config::getSources())));
|
||||
@@ -117,29 +94,17 @@ class DownloadCommand extends BaseCommand
|
||||
return $this->downloadFromZip($path);
|
||||
}
|
||||
|
||||
if ($this->getOption('update')) {
|
||||
return $this->handleUpdate();
|
||||
}
|
||||
|
||||
// Define PHP major version(s)
|
||||
$php_versions_str = $this->getOption('with-php');
|
||||
$php_versions = array_map('trim', explode(',', $php_versions_str));
|
||||
|
||||
// Validate all versions
|
||||
foreach ($php_versions as $ver) {
|
||||
if ($ver !== 'git' && !preg_match('/^\d+\.\d+$/', $ver)) {
|
||||
// If not git, we need to check the version format
|
||||
if (!preg_match('/^\d+\.\d+(\.\d+)?$/', $ver)) {
|
||||
logger()->error("bad version arg: {$ver}, x.y or x.y.z required!");
|
||||
return static::FAILURE;
|
||||
}
|
||||
// Define PHP major version
|
||||
$ver = $this->php_major_ver = $this->getOption('with-php');
|
||||
define('SPC_BUILD_PHP_VERSION', $ver);
|
||||
if ($ver !== 'git' && !preg_match('/^\d+\.\d+$/', $ver)) {
|
||||
// If not git, we need to check the version format
|
||||
if (!preg_match('/^\d+\.\d+(\.\d+)?$/', $ver)) {
|
||||
logger()->error("bad version arg: {$ver}, x.y or x.y.z required!");
|
||||
return static::FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
// Set the first version as the default for backward compatibility
|
||||
$this->php_major_ver = $php_versions[0];
|
||||
define('SPC_BUILD_PHP_VERSION', $this->php_major_ver);
|
||||
|
||||
// retry
|
||||
$retry = (int) $this->getOption('retry');
|
||||
f_putenv('SPC_DOWNLOAD_RETRIES=' . $retry);
|
||||
@@ -160,20 +125,6 @@ class DownloadCommand extends BaseCommand
|
||||
|
||||
$chosen_sources = array_map('trim', array_filter(explode(',', $this->getArgument('sources'))));
|
||||
|
||||
// Handle multiple PHP versions
|
||||
// If php-src is in the sources, replace it with version-specific sources
|
||||
if (in_array('php-src', $chosen_sources)) {
|
||||
// Remove php-src from the list
|
||||
$chosen_sources = array_diff($chosen_sources, ['php-src']);
|
||||
// Add version-specific php-src for each version
|
||||
foreach ($php_versions as $ver) {
|
||||
$version_specific_name = "php-src-{$ver}";
|
||||
$chosen_sources[] = $version_specific_name;
|
||||
// Store the version for this specific php-src
|
||||
f_putenv("SPC_PHP_VERSION_{$version_specific_name}={$ver}");
|
||||
}
|
||||
}
|
||||
|
||||
$sss = $this->getOption('ignore-cache-sources');
|
||||
if ($sss === false) {
|
||||
// false is no-any-ignores, that is, default.
|
||||
@@ -250,16 +201,7 @@ class DownloadCommand extends BaseCommand
|
||||
logger()->info("[{$ni}/{$cnt}] Downloading source {$source} from custom git: {$new_config['url']}");
|
||||
Downloader::downloadSource($source, $new_config, true);
|
||||
} else {
|
||||
// Handle version-specific php-src (php-src-8.2, php-src-8.3, etc.)
|
||||
if (preg_match('/^php-src-[\d.]+$/', $source)) {
|
||||
$config = Config::getSource('php-src');
|
||||
if ($config === null) {
|
||||
logger()->error('php-src configuration not found in source.json');
|
||||
return static::FAILURE;
|
||||
}
|
||||
} else {
|
||||
$config = Config::getSource($source);
|
||||
}
|
||||
$config = Config::getSource($source);
|
||||
// Prefer pre-built, we need to search pre-built library
|
||||
if ($this->getOption('prefer-pre-built') && ($config['provide-pre-built'] ?? false) === true) {
|
||||
// We need to replace pattern
|
||||
@@ -280,9 +222,8 @@ class DownloadCommand extends BaseCommand
|
||||
logger()->warning("Pre-built content not found for {$source}, fallback to source download");
|
||||
}
|
||||
logger()->info("[{$ni}/{$cnt}] Downloading source {$source}");
|
||||
$force_download = $force_all || in_array($source, $force_list) || str_starts_with($source, 'php-src-') && in_array('php-src', $force_list);
|
||||
try {
|
||||
Downloader::downloadSource($source, $config, $force_download);
|
||||
Downloader::downloadSource($source, $config, $force_all || in_array($source, $force_list));
|
||||
} catch (SPCException $e) {
|
||||
// if `--no-alt` option is set, we will not download alternative sources
|
||||
if ($this->getOption('no-alt')) {
|
||||
@@ -300,7 +241,7 @@ class DownloadCommand extends BaseCommand
|
||||
logger()->notice("Trying to download alternative sources for {$source}");
|
||||
$alt_config = array_merge($config, $alt_sources);
|
||||
}
|
||||
Downloader::downloadSource($source, $alt_config, $force_download);
|
||||
Downloader::downloadSource($source, $alt_config, $force_all || in_array($source, $force_list));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -421,284 +362,4 @@ class DownloadCommand extends BaseCommand
|
||||
}
|
||||
return static::FAILURE;
|
||||
}
|
||||
|
||||
private function handleUpdate(): int
|
||||
{
|
||||
logger()->info('Checking sources for updates...');
|
||||
|
||||
// Get lock file content
|
||||
$lock_file_path = LockFile::LOCK_FILE;
|
||||
if (!file_exists($lock_file_path)) {
|
||||
logger()->warning('No lock file found. Please download sources first using "bin/spc download"');
|
||||
return static::FAILURE;
|
||||
}
|
||||
|
||||
$lock_content = json_decode(file_get_contents($lock_file_path), true);
|
||||
if ($lock_content === null || !is_array($lock_content)) {
|
||||
logger()->error('Failed to parse lock file');
|
||||
return static::FAILURE;
|
||||
}
|
||||
|
||||
// Filter sources to check
|
||||
$sources_arg = $this->getArgument('sources');
|
||||
if (!empty($sources_arg)) {
|
||||
$requested_sources = array_map('trim', array_filter(explode(',', $sources_arg)));
|
||||
$sources_to_check = [];
|
||||
foreach ($requested_sources as $source) {
|
||||
if (isset($lock_content[$source])) {
|
||||
$sources_to_check[$source] = $lock_content[$source];
|
||||
} else {
|
||||
logger()->warning("Source '{$source}' not found in lock file, skipping");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$sources_to_check = $lock_content;
|
||||
}
|
||||
|
||||
// Filter out pre-built sources (they are derivatives)
|
||||
$sources_to_check = array_filter($sources_to_check, function ($lock_item, $name) {
|
||||
// Skip pre-built sources (they contain OS/arch in the name)
|
||||
if (str_contains($name, '-Linux-') || str_contains($name, '-Windows-') || str_contains($name, '-Darwin-')) {
|
||||
logger()->debug("Skipping pre-built source: {$name}");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}, ARRAY_FILTER_USE_BOTH);
|
||||
|
||||
if (empty($sources_to_check)) {
|
||||
logger()->warning('No sources to check');
|
||||
return static::FAILURE;
|
||||
}
|
||||
|
||||
$total = count($sources_to_check);
|
||||
$current = 0;
|
||||
$updated_sources = [];
|
||||
|
||||
foreach ($sources_to_check as $name => $lock_item) {
|
||||
++$current;
|
||||
try {
|
||||
// Handle version-specific php-src (php-src-8.2, php-src-8.3, etc.)
|
||||
if (preg_match('/^php-src-[\d.]+$/', $name)) {
|
||||
$config = Config::getSource('php-src');
|
||||
} else {
|
||||
$config = Config::getSource($name);
|
||||
}
|
||||
|
||||
if ($config === null) {
|
||||
logger()->warning("[{$current}/{$total}] Source '{$name}' not found in source config, skipping");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check and update based on source type
|
||||
$source_type = $lock_item['source_type'] ?? 'unknown';
|
||||
|
||||
if ($source_type === SPC_SOURCE_ARCHIVE) {
|
||||
if ($this->checkArchiveSourceUpdate($name, $lock_item, $config, $current, $total)) {
|
||||
$updated_sources[] = $name;
|
||||
}
|
||||
} elseif ($source_type === SPC_SOURCE_GIT) {
|
||||
if ($this->checkGitSourceUpdate($name, $lock_item, $config, $current, $total)) {
|
||||
$updated_sources[] = $name;
|
||||
}
|
||||
} elseif ($source_type === SPC_SOURCE_LOCAL) {
|
||||
logger()->debug("[{$current}/{$total}] Source '{$name}' is local, skipping");
|
||||
} else {
|
||||
logger()->warning("[{$current}/{$total}] Unknown source type '{$source_type}' for '{$name}', skipping");
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
logger()->error("[{$current}/{$total}] Error checking '{$name}': {$e->getMessage()}");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Output summary
|
||||
if (empty($updated_sources)) {
|
||||
logger()->info('All sources are up to date.');
|
||||
} else {
|
||||
logger()->info('Updated sources: ' . implode(', ', $updated_sources));
|
||||
|
||||
// Write updated sources to file
|
||||
$date = date('Y-m-d');
|
||||
$update_file = DOWNLOAD_PATH . '/.update-' . $date . '.txt';
|
||||
if (file_exists($update_file)) {
|
||||
$existing_content = file_get_contents($update_file);
|
||||
$existing_sources = array_map('trim', explode(',', $existing_content));
|
||||
$updated_sources = array_unique(array_merge($existing_sources, $updated_sources));
|
||||
}
|
||||
$content = implode(',', $updated_sources);
|
||||
file_put_contents($update_file, $content);
|
||||
logger()->debug("Updated sources written to: {$update_file}");
|
||||
}
|
||||
|
||||
return static::SUCCESS;
|
||||
}
|
||||
|
||||
private function checkCustomSourceUpdate(string $name, array $lock, array $config, int $current, int $total): ?array
|
||||
{
|
||||
$classes = FileSystem::getClassesPsr4(ROOT_DIR . '/src/SPC/store/source', 'SPC\store\source');
|
||||
foreach ($classes as $class) {
|
||||
// Support php-src and php-src-X.Y patterns
|
||||
$matches = ($class::NAME === $name) ||
|
||||
($class::NAME === 'php-src' && preg_match('/^php-src(-[\d.]+)?$/', $name));
|
||||
if (is_a($class, CustomSourceBase::class, true) && $matches) {
|
||||
try {
|
||||
$config['source_name'] = $name;
|
||||
return (new $class())->update($lock, $config);
|
||||
} catch (\Throwable $e) {
|
||||
logger()->warning("[{$current}/{$total}] Failed to check '{$name}': {$e->getMessage()}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
logger()->debug("[{$current}/{$total}] Custom source handler for '{$name}' not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check and update an archive source
|
||||
*
|
||||
* @param string $name Source name
|
||||
* @param array $lock Lock file entry
|
||||
* @param array $config Source configuration
|
||||
* @param int $current Current progress number
|
||||
* @param int $total Total sources to check
|
||||
* @return bool True if updated, false otherwise
|
||||
*/
|
||||
private function checkArchiveSourceUpdate(string $name, array $lock, array $config, int $current, int $total): bool
|
||||
{
|
||||
$type = $config['type'] ?? 'unknown';
|
||||
$locked_filename = $lock['filename'] ?? '';
|
||||
|
||||
// Skip local types that don't support version detection
|
||||
if (in_array($type, ['local', 'unknown'])) {
|
||||
logger()->debug("[{$current}/{$total}] Source '{$name}' (type: {$type}) doesn't support version detection, skipping");
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$latest_info = match ($type) {
|
||||
'ghtar' => Downloader::getLatestGithubTarball($name, $config),
|
||||
'ghtagtar' => Downloader::getLatestGithubTarball($name, $config, 'tags'),
|
||||
'ghrel' => Downloader::getLatestGithubRelease($name, $config),
|
||||
'pie' => Downloader::getPIEInfo($name, $config),
|
||||
'bitbuckettag' => Downloader::getLatestBitbucketTag($name, $config),
|
||||
'filelist' => Downloader::getFromFileList($name, $config),
|
||||
'url' => Downloader::getLatestUrlInfo($name, $config),
|
||||
'custom' => $this->checkCustomSourceUpdate($name, $lock, $config, $current, $total),
|
||||
default => null,
|
||||
};
|
||||
|
||||
if ($latest_info === null) {
|
||||
logger()->warning("[{$current}/{$total}] Could not get version info for '{$name}' (type: {$type})");
|
||||
return false;
|
||||
}
|
||||
|
||||
$latest_filename = $latest_info[1] ?? '';
|
||||
|
||||
// Compare filenames
|
||||
if ($locked_filename !== $latest_filename) {
|
||||
logger()->info("[{$current}/{$total}] Update available for '{$name}': {$locked_filename} → {$latest_filename}");
|
||||
$this->downloadSourceForUpdate($name, $config, $current, $total);
|
||||
return true;
|
||||
}
|
||||
|
||||
logger()->info("[{$current}/{$total}] Source '{$name}' is up to date");
|
||||
return false;
|
||||
} catch (DownloaderException $e) {
|
||||
logger()->warning("[{$current}/{$total}] Failed to check '{$name}': {$e->getMessage()}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check and update a git source
|
||||
*
|
||||
* @param string $name Source name
|
||||
* @param array $lock Lock file entry
|
||||
* @param array $config Source configuration
|
||||
* @param int $current Current progress number
|
||||
* @param int $total Total sources to check
|
||||
* @return bool True if updated, false otherwise
|
||||
*/
|
||||
private function checkGitSourceUpdate(string $name, array $lock, array $config, int $current, int $total): bool
|
||||
{
|
||||
$locked_hash = $lock['hash'] ?? '';
|
||||
$url = $config['url'] ?? '';
|
||||
$branch = $config['rev'] ?? 'main';
|
||||
|
||||
if (empty($url)) {
|
||||
logger()->warning("[{$current}/{$total}] No URL found for git source '{$name}'");
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$remote_hash = $this->getRemoteGitCommit($url, $branch);
|
||||
|
||||
if ($remote_hash === null) {
|
||||
logger()->warning("[{$current}/{$total}] Could not fetch remote commit for '{$name}'");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Compare hashes (use first 7 chars for display)
|
||||
$locked_short = substr($locked_hash, 0, 7);
|
||||
$remote_short = substr($remote_hash, 0, 7);
|
||||
|
||||
if ($locked_hash !== $remote_hash) {
|
||||
logger()->info("[{$current}/{$total}] Update available for '{$name}': {$locked_short} → {$remote_short}");
|
||||
$this->downloadSourceForUpdate($name, $config, $current, $total);
|
||||
return true;
|
||||
}
|
||||
|
||||
logger()->info("[{$current}/{$total}] Source '{$name}' is up to date");
|
||||
return false;
|
||||
} catch (\Throwable $e) {
|
||||
logger()->warning("[{$current}/{$total}] Failed to check '{$name}': {$e->getMessage()}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Download a source after removing old lock entry
|
||||
*
|
||||
* @param string $name Source name
|
||||
* @param array $config Source configuration
|
||||
* @param int $current Current progress number
|
||||
* @param int $total Total sources to check
|
||||
*/
|
||||
private function downloadSourceForUpdate(string $name, array $config, int $current, int $total): void
|
||||
{
|
||||
logger()->info("[{$current}/{$total}] Downloading '{$name}'...");
|
||||
|
||||
// Remove old lock entry
|
||||
LockFile::put($name, null);
|
||||
|
||||
// Download new version
|
||||
Downloader::downloadSource($name, $config, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get remote git commit hash without cloning
|
||||
*
|
||||
* @param string $url Git repository URL
|
||||
* @param string $branch Branch or tag to check
|
||||
* @return null|string Remote commit hash or null on failure
|
||||
*/
|
||||
private function getRemoteGitCommit(string $url, string $branch): ?string
|
||||
{
|
||||
try {
|
||||
$cmd = SPC_GIT_EXEC . ' ls-remote ' . escapeshellarg($url) . ' ' . escapeshellarg($branch);
|
||||
f_exec($cmd, $output, $ret);
|
||||
|
||||
if ($ret !== 0 || empty($output)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Output format: "commit_hash\trefs/heads/branch" or "commit_hash\tHEAD"
|
||||
$parts = preg_split('/\s+/', $output[0]);
|
||||
return $parts[0] ?? null;
|
||||
} catch (\Throwable $e) {
|
||||
logger()->debug("Failed to fetch remote git commit: {$e->getMessage()}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,9 @@ class SwitchPhpVersionCommand extends BaseCommand
|
||||
$this->addArgument(
|
||||
'php-major-version',
|
||||
InputArgument::REQUIRED,
|
||||
'PHP major version (supported: 7.4, 8.0, 8.1, 8.2, 8.3, 8.4)',
|
||||
'PHP major version (supported: 7.4, 8.0, 8.1, 8.2, 8.3, 8.4, 8.5)',
|
||||
null,
|
||||
fn () => ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
|
||||
fn () => ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5']
|
||||
);
|
||||
$this->no_motd = true;
|
||||
|
||||
@@ -32,7 +32,7 @@ class SwitchPhpVersionCommand extends BaseCommand
|
||||
public function handle(): int
|
||||
{
|
||||
$php_ver = $this->input->getArgument('php-major-version');
|
||||
if (!in_array($php_ver, ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4'])) {
|
||||
if (!in_array($php_ver, ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5'])) {
|
||||
// match x.y.z
|
||||
preg_match('/^\d+\.\d+\.\d+$/', $php_ver, $matches);
|
||||
if (!$matches) {
|
||||
|
||||
@@ -22,7 +22,6 @@ class LinuxToolCheckList
|
||||
'bzip2', 'cmake', 'gcc',
|
||||
'g++', 'patch', 'binutils-gold',
|
||||
'libtoolize', 'which',
|
||||
'patchelf',
|
||||
];
|
||||
|
||||
public const TOOLS_DEBIAN = [
|
||||
@@ -31,7 +30,6 @@ class LinuxToolCheckList
|
||||
'tar', 'unzip', 'gzip', 'gcc', 'g++',
|
||||
'bzip2', 'cmake', 'patch',
|
||||
'xz', 'libtoolize', 'which',
|
||||
'patchelf',
|
||||
];
|
||||
|
||||
public const TOOLS_RHEL = [
|
||||
@@ -39,8 +37,7 @@ class LinuxToolCheckList
|
||||
'git', 'autoconf', 'automake',
|
||||
'tar', 'unzip', 'gzip', 'gcc', 'g++',
|
||||
'bzip2', 'cmake', 'patch', 'which',
|
||||
'xz', 'libtool', 'gettext-devel',
|
||||
'patchelf', 'file',
|
||||
'xz', 'libtool', 'gettext-devel', 'file',
|
||||
];
|
||||
|
||||
public const TOOLS_ARCH = [
|
||||
|
||||
@@ -220,39 +220,6 @@ class Downloader
|
||||
return [$source['url'] . end($versions), end($versions), key($versions)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get latest version from direct URL (detect redirect and filename)
|
||||
*
|
||||
* @param string $name Source name
|
||||
* @param array $source Source meta info: [url]
|
||||
* @return array<int, string> [url, filename]
|
||||
*/
|
||||
public static function getLatestUrlInfo(string $name, array $source): array
|
||||
{
|
||||
logger()->debug("finding {$name} source from direct url");
|
||||
$url = $source['url'];
|
||||
$headers = self::curlExec(
|
||||
url: $url,
|
||||
method: 'HEAD',
|
||||
retries: self::getRetryAttempts()
|
||||
);
|
||||
|
||||
// Find redirect location if any
|
||||
if (preg_match('/^location:\s+(?<url>.+)$/im', $headers, $matches)) {
|
||||
$url = trim($matches['url']);
|
||||
// If it's a relative URL, we need to handle it, but usually it's absolute for downloads
|
||||
}
|
||||
|
||||
// Find filename from content-disposition
|
||||
if (preg_match('/^content-disposition:\s+attachment;\s*filename=("?)(?<filename>.+)\1/im', $headers, $matches)) {
|
||||
$filename = trim($matches['filename']);
|
||||
} else {
|
||||
$filename = $source['filename'] ?? basename($url);
|
||||
}
|
||||
|
||||
return [$url, $filename];
|
||||
}
|
||||
|
||||
/**
|
||||
* Download file from URL
|
||||
*
|
||||
@@ -280,7 +247,7 @@ class Downloader
|
||||
if ($download_as === SPC_DOWNLOAD_PRE_BUILT) {
|
||||
$name = self::getPreBuiltLockName($name);
|
||||
}
|
||||
LockFile::lockSource($name, ['source_type' => SPC_SOURCE_ARCHIVE, 'url' => $url, 'filename' => $filename, 'move_path' => $move_path, 'lock_as' => $download_as]);
|
||||
LockFile::lockSource($name, ['source_type' => SPC_SOURCE_ARCHIVE, 'filename' => $filename, 'move_path' => $move_path, 'lock_as' => $download_as]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -339,7 +306,7 @@ class Downloader
|
||||
}
|
||||
// Lock
|
||||
logger()->debug("Locking git source {$name}");
|
||||
LockFile::lockSource($name, ['source_type' => SPC_SOURCE_GIT, 'url' => $url, 'rev' => $branch, 'dirname' => $name, 'move_path' => $move_path, 'lock_as' => $lock_as]);
|
||||
LockFile::lockSource($name, ['source_type' => SPC_SOURCE_GIT, 'dirname' => $name, 'move_path' => $move_path, 'lock_as' => $lock_as]);
|
||||
|
||||
/*
|
||||
// 复制目录过去
|
||||
@@ -689,7 +656,8 @@ class Downloader
|
||||
self::downloadFile($name, $url, $filename, $conf['path'] ?? $conf['extract'] ?? null, $download_as);
|
||||
break;
|
||||
case 'url': // Direct download URL
|
||||
[$url, $filename] = self::getLatestUrlInfo($name, $conf);
|
||||
$url = $conf['url'];
|
||||
$filename = $conf['filename'] ?? basename($conf['url']);
|
||||
self::downloadFile($name, $url, $filename, $conf['path'] ?? $conf['extract'] ?? null, $download_as);
|
||||
break;
|
||||
case 'git': // Git repo
|
||||
@@ -699,8 +667,6 @@ class Downloader
|
||||
LockFile::lockSource($name, [
|
||||
'source_type' => SPC_SOURCE_LOCAL,
|
||||
'dirname' => $conf['dirname'],
|
||||
'url' => null,
|
||||
'path' => $conf['path'] ?? null,
|
||||
'move_path' => $conf['path'] ?? $conf['extract'] ?? null,
|
||||
'lock_as' => $download_as,
|
||||
]);
|
||||
@@ -716,11 +682,7 @@ class Downloader
|
||||
...FileSystem::getClassesPsr4(ROOT_DIR . '/src/SPC/store/pkg', 'SPC\store\pkg'),
|
||||
];
|
||||
foreach ($classes as $class) {
|
||||
// Support php-src and php-src-X.Y patterns
|
||||
$matches = ($class::NAME === $name) ||
|
||||
($class::NAME === 'php-src' && preg_match('/^php-src(-[\d.]+)?$/', $name));
|
||||
if (is_a($class, CustomSourceBase::class, true) && $matches) {
|
||||
$conf['source_name'] = $name; // Pass the actual source name
|
||||
if (is_a($class, CustomSourceBase::class, true) && $class::NAME === $name) {
|
||||
(new $class())->fetch($force, $conf, $download_as);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -155,7 +155,6 @@ class LockFile
|
||||
* @param string $name Source name
|
||||
* @param array{
|
||||
* source_type: string,
|
||||
* url: ?string,
|
||||
* dirname?: ?string,
|
||||
* filename?: ?string,
|
||||
* move_path: ?string,
|
||||
|
||||
@@ -39,14 +39,7 @@ class SourceManager
|
||||
|
||||
// start check
|
||||
foreach ($sources_extracted as $source => $item) {
|
||||
$extract_dir_name = $source;
|
||||
// Handle version-specific php-src (php-src-8.2, php-src-8.3, etc.)
|
||||
$source_config = Config::getSource($source);
|
||||
if ($source_config === null && preg_match('/^php-src-[\d.]+$/', $source)) {
|
||||
$source_config = Config::getSource('php-src');
|
||||
$extract_dir_name = 'php-src';
|
||||
}
|
||||
if ($source_config === null) {
|
||||
if (Config::getSource($source) === null) {
|
||||
throw new WrongUsageException("Source [{$source}] does not exist, please check the name and correct it !");
|
||||
}
|
||||
// check source downloaded
|
||||
@@ -63,12 +56,12 @@ class SourceManager
|
||||
$lock_content = LockFile::get($lock_name);
|
||||
|
||||
// check source dir exist
|
||||
$check = LockFile::getExtractPath($lock_name, SOURCE_PATH . '/' . $extract_dir_name);
|
||||
$check = LockFile::getExtractPath($lock_name, SOURCE_PATH . '/' . $source);
|
||||
// $check = $lock[$lock_name]['move_path'] === null ? (SOURCE_PATH . '/' . $source) : (SOURCE_PATH . '/' . $lock[$lock_name]['move_path']);
|
||||
if (!is_dir($check)) {
|
||||
logger()->debug("Extracting source [{$source}] to {$check} ...");
|
||||
$filename = LockFile::getLockFullPath($lock_content);
|
||||
FileSystem::extractSource($extract_dir_name, $lock_content['source_type'], $filename, $check);
|
||||
FileSystem::extractSource($source, $lock_content['source_type'], $filename, $check);
|
||||
LockFile::putLockSourceHash($lock_content, $check);
|
||||
continue;
|
||||
}
|
||||
@@ -96,7 +89,7 @@ class SourceManager
|
||||
logger()->notice("Source [{$source}] hash mismatch, removing old source dir and extracting again ...");
|
||||
FileSystem::removeDir($check);
|
||||
$filename = LockFile::getLockFullPath($lock_content);
|
||||
$move_path = LockFile::getExtractPath($lock_name, SOURCE_PATH . '/' . $extract_dir_name);
|
||||
$move_path = LockFile::getExtractPath($lock_name, SOURCE_PATH . '/' . $source);
|
||||
FileSystem::extractSource($source, $lock_content['source_type'], $filename, $move_path);
|
||||
LockFile::putLockSourceHash($lock_content, $check);
|
||||
}
|
||||
|
||||
@@ -25,13 +25,4 @@ abstract class CustomSourceBase
|
||||
* @param int $lock_as Lock type constant
|
||||
*/
|
||||
abstract public function fetch(bool $force = false, ?array $config = null, int $lock_as = SPC_DOWNLOAD_SOURCE): void;
|
||||
|
||||
/**
|
||||
* Update the source from its repository
|
||||
*
|
||||
* @param array $lock Lock file entry
|
||||
* @param array $config Optional configuration array
|
||||
* @return null|array Latest version info [url, filename], or null if no update needed
|
||||
*/
|
||||
abstract public function update(array $lock, ?array $config = null): ?array;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ namespace SPC\store\source;
|
||||
use JetBrains\PhpStorm\ArrayShape;
|
||||
use SPC\exception\DownloaderException;
|
||||
use SPC\store\Downloader;
|
||||
use SPC\store\LockFile;
|
||||
|
||||
class PhpSource extends CustomSourceBase
|
||||
{
|
||||
@@ -15,46 +14,12 @@ class PhpSource extends CustomSourceBase
|
||||
|
||||
public function fetch(bool $force = false, ?array $config = null, int $lock_as = SPC_DOWNLOAD_SOURCE): void
|
||||
{
|
||||
$source_name = $config['source_name'] ?? 'php-src';
|
||||
|
||||
// Try to extract version from source name (e.g., "php-src-8.2" -> "8.2")
|
||||
if (preg_match('/^php-src-([\d.]+)$/', $source_name, $matches)) {
|
||||
$major = $matches[1];
|
||||
} else {
|
||||
$major = defined('SPC_BUILD_PHP_VERSION') ? SPC_BUILD_PHP_VERSION : '8.4';
|
||||
}
|
||||
|
||||
$major = defined('SPC_BUILD_PHP_VERSION') ? SPC_BUILD_PHP_VERSION : '8.4';
|
||||
if ($major === 'git') {
|
||||
Downloader::downloadSource($source_name, ['type' => 'git', 'url' => 'https://github.com/php/php-src.git', 'rev' => 'master'], $force);
|
||||
Downloader::downloadSource('php-src', ['type' => 'git', 'url' => 'https://github.com/php/php-src.git', 'rev' => 'master'], $force);
|
||||
} else {
|
||||
Downloader::downloadSource($source_name, $this->getLatestPHPInfo($major), $force);
|
||||
Downloader::downloadSource('php-src', $this->getLatestPHPInfo($major), $force);
|
||||
}
|
||||
|
||||
if ($source_name !== 'php-src') {
|
||||
LockFile::put('php-src', LockFile::get($source_name));
|
||||
}
|
||||
}
|
||||
|
||||
public function update(array $lock, ?array $config = null): ?array
|
||||
{
|
||||
$source_name = $config['source_name'] ?? 'php-src';
|
||||
|
||||
// Try to extract version from source name (e.g., "php-src-8.2" -> "8.2")
|
||||
if (preg_match('/^php-src-([\d.]+)$/', $source_name, $matches)) {
|
||||
$major = $matches[1];
|
||||
} else {
|
||||
$major = defined('SPC_BUILD_PHP_VERSION') ? SPC_BUILD_PHP_VERSION : '8.4';
|
||||
}
|
||||
|
||||
if ($major === 'git') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$latest_php = $this->getLatestPHPInfo($major);
|
||||
$latest_url = $latest_php['url'];
|
||||
$filename = basename($latest_url);
|
||||
|
||||
return [$latest_url, $filename];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,13 +15,6 @@ class PostgreSQLSource extends CustomSourceBase
|
||||
Downloader::downloadSource('postgresql', self::getLatestInfo(), $force);
|
||||
}
|
||||
|
||||
public function update(array $lock, ?array $config = null): ?array
|
||||
{
|
||||
$latest = $this->getLatestInfo();
|
||||
$filename = basename($latest['url']);
|
||||
return [$latest['url'], $filename];
|
||||
}
|
||||
|
||||
public function getLatestInfo(): array
|
||||
{
|
||||
[, $filename, $version] = Downloader::getFromFileList('postgresql', [
|
||||
|
||||
@@ -80,7 +80,6 @@ class SPCConfigUtil
|
||||
$libs = $this->getLibsString($libraries, !$this->absolute_libs);
|
||||
|
||||
// additional OS-specific libraries (e.g. macOS -lresolv)
|
||||
// embed
|
||||
if ($extra_libs = SPCTarget::getRuntimeLibs()) {
|
||||
$libs .= " {$extra_libs}";
|
||||
}
|
||||
|
||||
@@ -27,10 +27,10 @@ class SPCTarget
|
||||
return true;
|
||||
}
|
||||
if (ToolchainManager::getToolchainClass() === GccNativeToolchain::class) {
|
||||
return PHP_OS_FAMILY === 'Linux' && SystemUtil::isMuslDist();
|
||||
return PHP_OS_FAMILY === 'Linux' && SystemUtil::isMuslDist() && !getenv('SPC_MUSL_DYNAMIC');
|
||||
}
|
||||
if (ToolchainManager::getToolchainClass() === ClangNativeToolchain::class) {
|
||||
return PHP_OS_FAMILY === 'Linux' && SystemUtil::isMuslDist();
|
||||
return PHP_OS_FAMILY === 'Linux' && SystemUtil::isMuslDist() && !getenv('SPC_MUSL_DYNAMIC');
|
||||
}
|
||||
// if SPC_LIBC is set, it means the target is static, remove it when 3.0 is released
|
||||
if ($target = getenv('SPC_TARGET')) {
|
||||
|
||||
@@ -14,22 +14,22 @@ declare(strict_types=1);
|
||||
// test php version (8.1 ~ 8.4 available, multiple for matrix)
|
||||
$test_php_version = [
|
||||
// '8.1',
|
||||
'8.2',
|
||||
'8.3',
|
||||
'8.4',
|
||||
// '8.2',
|
||||
// '8.3',
|
||||
// '8.4',
|
||||
'8.5',
|
||||
// 'git',
|
||||
];
|
||||
|
||||
// test os (macos-15-intel, macos-15, ubuntu-latest, windows-latest are available)
|
||||
$test_os = [
|
||||
'macos-15-intel', // bin/spc for x86_64
|
||||
'macos-15', // bin/spc for arm64
|
||||
'ubuntu-latest', // bin/spc-alpine-docker for x86_64
|
||||
// 'macos-15-intel', // bin/spc for x86_64
|
||||
// 'macos-15', // bin/spc for arm64
|
||||
// 'ubuntu-latest', // bin/spc-alpine-docker for x86_64
|
||||
'ubuntu-22.04', // bin/spc-gnu-docker for x86_64
|
||||
'ubuntu-24.04', // bin/spc for x86_64
|
||||
// 'ubuntu-22.04-arm', // bin/spc-gnu-docker for arm64
|
||||
// 'ubuntu-24.04-arm', // bin/spc for arm64
|
||||
// 'ubuntu-24.04', // bin/spc for x86_64
|
||||
'ubuntu-22.04-arm', // bin/spc-gnu-docker for arm64
|
||||
'ubuntu-24.04-arm', // bin/spc for arm64
|
||||
// 'windows-2022', // .\bin\spc.ps1
|
||||
// 'windows-2025',
|
||||
];
|
||||
@@ -50,13 +50,13 @@ $prefer_pre_built = false;
|
||||
|
||||
// If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`).
|
||||
$extensions = match (PHP_OS_FAMILY) {
|
||||
'Linux', 'Darwin' => 'mysqli,gmp',
|
||||
'Windows' => 'bcmath',
|
||||
'Linux', 'Darwin' => 'pgsql',
|
||||
'Windows' => 'com_dotnet',
|
||||
};
|
||||
|
||||
// If you want to test shared extensions, add them below (comma separated, example `bcmath,openssl`).
|
||||
$shared_extensions = match (PHP_OS_FAMILY) {
|
||||
'Linux' => 'grpc,mysqlnd_parsec,mysqlnd_ed25519',
|
||||
'Linux' => '',
|
||||
'Darwin' => '',
|
||||
'Windows' => '',
|
||||
};
|
||||
@@ -66,7 +66,7 @@ $with_suggested_libs = false;
|
||||
|
||||
// If you want to test extra libs for extensions, add them below (comma separated, example `libwebp,libavif`). Unnecessary, when $with_suggested_libs is true.
|
||||
$with_libs = match (PHP_OS_FAMILY) {
|
||||
'Linux', 'Darwin' => 'libwebp',
|
||||
'Linux', 'Darwin' => '',
|
||||
'Windows' => '',
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user