Switch static-php-cli to support PHP 8.3 and 8.4 only (#615)

* Update spc self to PHP 8.4 only

* Update workflows

* Fix test-extensions, adjust docs order

* Fix cs-fix and phpunit

* Add PHP_CS_FIXER_IGNORE_ENV

* Add compatibility for PHP 8.3

* Change version description in README, adjust composer.json PHP version limit

* Switch PHP to 8.4 in spc-alpine-docker

* Add deprecation notice
This commit is contained in:
Jerry Ma 2025-03-07 18:06:32 +08:00 committed by GitHub
parent 8a17e2384e
commit 29ea46bd17
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
22 changed files with 1773 additions and 1179 deletions

View File

@ -129,7 +129,7 @@ jobs:
- name: "Setup PHP"
uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.php-version }}
php-version: 8.4
tools: pecl, composer
extensions: curl, openssl, mbstring
ini-values: memory_limit=-1

View File

@ -6,7 +6,7 @@ on:
version:
required: true
description: php version to compile
default: '8.2'
default: '8.4'
type: choice
options:
- '8.4'

View File

@ -113,7 +113,7 @@ jobs:
- name: "Setup PHP"
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
php-version: 8.4
tools: pecl, composer
extensions: curl, openssl, mbstring
ini-values: memory_limit=-1

View File

@ -9,8 +9,8 @@ on:
workflow_dispatch:
env:
PHP_VERSION: 8.2
MICRO_VERSION: 8.2.18
PHP_VERSION: 8.4
MICRO_VERSION: 8.4.4
jobs:
build-release-artifacts:

View File

@ -34,13 +34,13 @@ jobs:
- name: "Setup PHP"
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
php-version: '8.4'
extensions: curl, openssl, mbstring
ini-values: memory_limit=-1
tools: pecl, composer, php-cs-fixer
- name: Run PHP-CS-Fixer fix
run: php-cs-fixer fix --dry-run --diff --ansi
run: PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix --dry-run --diff --ansi
phpstan:
runs-on: ubuntu-latest
@ -52,7 +52,7 @@ jobs:
- name: "Setup PHP"
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
php-version: '8.4'
extensions: curl, openssl, mbstring
ini-values: memory_limit=-1
tools: composer
@ -79,9 +79,6 @@ jobs:
strategy:
matrix:
include:
- php: '8.1'
- php: '8.2'
- php: '8.3'
- php: '8.4'
steps:
@ -125,7 +122,7 @@ jobs:
- name: "Setup PHP"
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
php-version: 8.4
- name: Define
id: gendef
@ -153,7 +150,7 @@ jobs:
- name: "Setup PHP"
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
php-version: 8.4
tools: pecl, composer
extensions: curl, openssl, mbstring
ini-values: memory_limit=-1

1
.gitignore vendored
View File

@ -32,6 +32,7 @@ packlib_files.txt
!/bin/spc*
!/bin/setup-runtime*
!/bin/spc-alpine-docker
!/bin/php-cs-fixer-wrapper
# exclude windows build tools
/php-sdk-binary-tools/

View File

@ -64,6 +64,8 @@ return (new PhpCsFixer\Config())
'php_unit_test_class_requires_covers' => false,
'phpdoc_var_without_name' => false,
'fully_qualified_strict_types' => false,
'operator_linebreak' => false,
'php_unit_data_provider_method_order' => false,
])
->setFinder(
PhpCsFixer\Finder::create()->in([__DIR__ . '/src', __DIR__ . '/tests/SPC'])

View File

@ -58,7 +58,7 @@ static-php-cli简称 `spc`)有许多特性:
### 编译环境需求
- PHP >= 8.1(这是 spc 自身需要的版本,不是支持的构建版本)
- PHP >= 8.4(这是 spc 自身需要的版本,不是支持的构建版本)
- 扩展:`mbstring,tokenizer,phar`
- 系统安装了 `curl``git`
@ -180,6 +180,9 @@ bin/spc --version
# 检查环境依赖,并根据尝试自动安装缺失的编译工具
./bin/spc doctor --auto-fix
# 输出目标项目依赖的扩展列表
./bin/spc dump-extensions /path/to/your/project --format=text
# 拉取所有依赖库
./bin/spc download --all
# 只拉取编译指定扩展需要的所有依赖(推荐)

View File

@ -67,7 +67,7 @@ which can be downloaded directly according to your needs.
You can say I made a PHP builder written in PHP, pretty funny.
But static-php-cli runtime only requires an environment above PHP 8.1 and extensions mentioned below.
- PHP >= 8.1 (This is the version required by spc itself, not the build version)
- PHP >= 8.4 (This is the version required by spc itself, not the build version)
- Extension: `mbstring,tokenizer,phar`
- Supported OS with `curl` and `git` installed
@ -195,7 +195,7 @@ Basic usage for building php with some extensions:
# fetch all libraries
./bin/spc download --all
# dump a list of extensions required by your project
./bin/spc dump-extensions
./bin/spc dump-extensions /path/to/your/project --format=text
# only fetch necessary sources by needed extensions (recommended)
./bin/spc download --for-extensions="openssl,pcntl,mbstring,pdo_sqlite"
# download pre-built libraries first (save time for compiling dependencies)

4
bin/php-cs-fixer-wrapper Executable file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env bash
# get parent dir, and run the php-cs-fixer
PHP_CS_FIXER_IGNORE_ENV=1 "$(dirname "$0")/../vendor/bin/php-cs-fixer" "$@"

View File

@ -25,7 +25,7 @@ __DIR__=$(cd "$(dirname "$0")" && pwd)
__PROJECT__=$(cd "${__DIR__}"/../ && pwd)
# set download dir
__PHP_RUNTIME_URL__="https://dl.static-php.dev/static-php-cli/bulk/php-8.2.13-cli-${__OS_FIXED__}-${__ARCH__}.tar.gz"
__PHP_RUNTIME_URL__="https://dl.static-php.dev/static-php-cli/bulk/php-8.4.4-cli-${__OS_FIXED__}-${__ARCH__}.tar.gz"
__COMPOSER_URL__="https://getcomposer.org/download/latest-stable/composer.phar"
# use china mirror
@ -45,7 +45,7 @@ done
case "$mirror" in
china)
__PHP_RUNTIME_URL__="https://dl.static-php.dev/static-php-cli/bulk/php-8.2.13-cli-${__OS_FIXED__}-${__ARCH__}.tar.gz"
__PHP_RUNTIME_URL__="https://dl.static-php.dev/static-php-cli/bulk/php-8.4.4-cli-${__OS_FIXED__}-${__ARCH__}.tar.gz"
__COMPOSER_URL__="https://mirrors.tencent.com/composer/composer.phar"
;;
@ -61,7 +61,7 @@ test -f "${__PROJECT__}"/downloads/runtime.tar.gz || { echo "Downloading $__PHP_
test -f "${__DIR__}"/php || { tar -xf "${__PROJECT__}"/downloads/runtime.tar.gz -C "${__DIR__}"/ ; }
chmod +x "${__DIR__}"/php
# download composer
test -f "${__DIR__}"/composer || curl -#fSL -o "${__DIR__}"/composer "$__COMPOSER_URL__"
test -f "${__DIR__}"/composer || { echo "Downloading Composer from $__COMPOSER_URL__" && curl -#fSL -o "${__DIR__}"/composer "$__COMPOSER_URL__" ; }
chmod +x "${__DIR__}"/composer
# sanity check for php and composer
"${__DIR__}"/php -v >/dev/null || { echo "Failed to run php" && exit 1; }

View File

@ -51,7 +51,7 @@ if ($action -eq 'add-path') {
}
# get php 8.1 specific version
$API = (Invoke-WebRequest -Uri "https://www.php.net/releases/index.php?json&version=8.3") | ConvertFrom-Json
$API = (Invoke-WebRequest -Uri "https://www.php.net/releases/index.php?json&version=8.4") | ConvertFrom-Json
# php windows download
$PHPRuntimeUrl = "https://windows.php.net/downloads/releases/php-" + $API.version + "-nts-Win32-vs16-x64.zip"

View File

@ -17,6 +17,11 @@ if (PHP_OS_FAMILY === 'Windows' && Phar::running()) {
exec('CHCP 65001');
}
// Print deprecation notice on PHP < 8.4, use red and highlight background
if (PHP_VERSION_ID < 80400) {
echo "\e[43mDeprecation Notice: PHP < 8.4 is deprecated, please upgrade your PHP version.\e[0m\n";
}
try {
(new ConsoleApplication())->run();
} catch (Exception $e) {

View File

@ -50,9 +50,9 @@ else
fi
# Detect docker env is setup
if ! $DOCKER_EXECUTABLE images | grep -q cwcc-spc-$SPC_USE_ARCH; then
if ! $DOCKER_EXECUTABLE images | grep -q cwcc-spc-$SPC_USE_ARCH-v2; then
echo "Docker container does not exist. Building docker image ..."
$DOCKER_EXECUTABLE build -t cwcc-spc-$SPC_USE_ARCH -f- . <<EOF
$DOCKER_EXECUTABLE build -t cwcc-spc-$SPC_USE_ARCH-v2 -f- . <<EOF
FROM $ALPINE_FROM
$SPC_USE_MIRROR
RUN apk update; \
@ -79,21 +79,16 @@ RUN apk update; \
linux-headers \
m4 \
make \
php82 \
php82-common \
php82-pcntl \
php82-phar \
php82-posix \
php82-sodium \
php82-tokenizer \
php82-dom \
php82-xml \
php82-xmlwriter \
composer \
pkgconfig \
wget \
xz
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
RUN curl -#fSL https://getcomposer.org/download/latest-stable/composer.phar -o /usr/local/bin/composer && \
chmod +x /usr/local/bin/composer
WORKDIR /app
ADD ./src /app/src
COPY ./composer.* /app/
@ -124,4 +119,4 @@ MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/pkgroot:/app/pkgroot"
# shellcheck disable=SC2068
# shellcheck disable=SC2086
# shellcheck disable=SC2090
$DOCKER_EXECUTABLE run --rm $INTERACT -e SPC_FIX_DEPLOY_ROOT="$(pwd)" $MOUNT_LIST cwcc-spc-$SPC_USE_ARCH bin/spc $@
$DOCKER_EXECUTABLE run --rm $INTERACT -e SPC_FIX_DEPLOY_ROOT="$(pwd)" $MOUNT_LIST cwcc-spc-$SPC_USE_ARCH-v2 bin/spc $@

View File

@ -9,7 +9,7 @@
}
],
"require": {
"php": ">= 8.1",
"php": ">= 8.3",
"ext-mbstring": "*",
"ext-zlib": "*",
"laravel/prompts": "^0.1.12",
@ -19,7 +19,7 @@
"require-dev": {
"captainhook/captainhook-phar": "^5.23",
"captainhook/hook-installer": "^1.0",
"friendsofphp/php-cs-fixer": "^3.25",
"friendsofphp/php-cs-fixer": "^3.60",
"humbug/box": "^4.5.0 || ^4.6.0",
"nunomaduro/collision": "^7.8",
"phpstan/phpstan": "^1.10",
@ -44,7 +44,7 @@
],
"scripts": {
"analyse": "phpstan analyse --memory-limit 300M",
"cs-fix": "php-cs-fixer fix",
"cs-fix": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix",
"test": "vendor/bin/phpunit tests/ --no-coverage",
"build:phar": "vendor/bin/box compile"
},

2702
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -57,6 +57,55 @@ cd static-php-cli
composer update
```
### Use Precompiled Static PHP Binaries
If you don't want to use Docker and install PHP in the system,
you can directly download the php binary cli program compiled by this project itself. The usage process is as follows:
Deploy the environment using the command, the command will download a static php-cli binary from [self-hosted server](https://dl.static-php.dev/static-php-cli/).
Next, it will automatically download Composer from [getcomposer](https://getcomposer.org/download/latest-stable/composer.phar) or [Aliyun mirror](https://mirrors.aliyun.com/composer/composer.phar).
::: tip
Using precompiled static PHP binaries is currently only supported on Linux and macOS.
The FreeBSD environment is currently not supported due to the lack of an automated build environment.
:::
```bash
bin/setup-runtime
# For users with special network environments such as mainland China, you can use mirror sites (aliyun) to speed up the download speed
bin/setup-runtime --mirror china
```
This script will download two files in total: `bin/php` and `bin/composer`. After the download is complete, there are two ways to use it:
1. Add the `bin/` directory to the PATH: `export PATH="/path/to/your/static-php-cli/bin:$PATH"`, after adding the path,
it is equivalent to installing PHP in the system, you can directly Use commands such as `composer`, `php -v`, or directly use `bin/spc`.
2. Direct call, such as executing static-php-cli command: `bin/php bin/spc --help`, executing Composer: `bin/php bin/composer update`.
### Use Docker
If you don't want to install PHP and Composer runtime environment on your system, you can use the built-in Docker environment build script.
```bash
# To use directly, replace `bin/spc` with `bin/spc-alpine-docker` in all used commands
bin/spc-alpine-docker
```
The first time the command is executed, `docker build` will be used to build a Docker image.
The default built Docker image is the `x86_64` architecture, and the image name is `cwcc-spc-x86_64`.
If you want to build `aarch64` static-php-cli in `x86_64` environment,
you can use qemu to emulate the arm image to run Docker, but the speed will be very slow.
Use command: `SPC_USE_ARCH=aarch64 bin/spc-alpine-docker`.
If it prompts that sudo is required to run after running,
execute the following command once to grant static-php-cli permission to execute sudo:
```bash
export SPC_USE_SUDO=yes
```
### Use System PHP
Below are some example commands for installing PHP and Composer in the system.
@ -84,55 +133,6 @@ and then install the latest version of PHP and tokenizer, XML, and phar extensio
Older versions of Debian may have an older (<= 7.4) version of PHP installed by default, it is recommended to upgrade Debian first.
:::
### Use Docker
If you don't want to install PHP and Composer runtime environment on your system, you can use the built-in Docker environment build script.
```bash
# To use directly, replace `bin/spc` with `bin/spc-alpine-docker` in all used commands
bin/spc-alpine-docker
```
The first time the command is executed, `docker build` will be used to build a Docker image.
The default built Docker image is the `x86_64` architecture, and the image name is `cwcc-spc-x86_64`.
If you want to build `aarch64` static-php-cli in `x86_64` environment,
you can use qemu to emulate the arm image to run Docker, but the speed will be very slow.
Use command: `SPC_USE_ARCH=aarch64 bin/spc-alpine-docker`.
If it prompts that sudo is required to run after running,
execute the following command once to grant static-php-cli permission to execute sudo:
```bash
export SPC_USE_SUDO=yes
```
### Use Precompiled Static PHP Binaries
If you don't want to use Docker and install PHP in the system,
you can directly download the php binary cli program compiled by this project itself. The usage process is as follows:
Deploy the environment using the command, the command will download a static php-cli binary from [self-hosted server](https://dl.static-php.dev/static-php-cli/).
Next, it will automatically download Composer from [getcomposer](https://getcomposer.org/download/latest-stable/composer.phar) or [Aliyun mirror](https://mirrors.aliyun.com/composer/composer.phar).
::: tip
Using precompiled static PHP binaries is currently only supported on Linux and macOS.
The FreeBSD environment is currently not supported due to the lack of an automated build environment.
:::
```bash
bin/setup-runtime
# For users with special network environments such as mainland China, you can use mirror sites (aliyun) to speed up the download speed
bin/setup-runtime --mirror china
```
This script will download two files in total: `bin/php` and `bin/composer`. After the download is complete, there are two ways to use it:
1. Add the `bin/` directory to the PATH: `export PATH="/path/to/your/static-php-cli/bin:$PATH"`, after adding the path,
it is equivalent to installing PHP in the system, you can directly Use commands such as `composer`, `php -v`, or directly use `bin/spc`.
2. Direct call, such as executing static-php-cli command: `bin/php bin/spc --help`, executing Composer: `bin/php bin/composer update`.
## Command - download
Use the command `bin/spc download` to download the source code required for compilation,

View File

@ -50,49 +50,7 @@ cd static-php-cli
composer update
```
### 使用系统 PHP 环境
下面是系统安装 PHP、Composer 的一些示例命令。具体安装方式建议自行搜索或询问 AI 搜索引擎获取答案,这里不多赘述。
```bash
# [macOS], 需要先安装 Homebrew. See https://brew.sh/
# Remember change your composer executable path. For M1/M2 Chip mac, "/opt/homebrew/bin/", for Intel mac, "/usr/local/bin/". Or add it to your own path.
brew install php wget
wget https://getcomposer.org/download/latest-stable/composer.phar -O /path/to/your/bin/composer && chmod +x /path/to/your/bin/composer
# [Debian], you need to make sure your php version >= 8.1 and composer >= 2.0
sudo apt install php-cli composer php-tokenizer
# [Alpine]
apk add bash file wget xz php81 php81-common php81-pcntl php81-tokenizer php81-phar php81-posix php81-xml composer
```
::: tip
目前 Ubuntu 部分版本的 apt 安装的 php 版本较旧,故不提供安装命令。如有需要,建议先添加 ppa 等软件源后,安装最新版的 PHP 以及 tokenizer、xml、phar 扩展。
较老版本的 Debian 默认安装的可能为旧版本(<= 7.4)版本的 PHP建议先升级 Debian。
:::
### 使用 Docker 环境
如果你不愿意在系统安装 PHP 和 Composer 运行环境,可以使用内置的 Docker 环境构建脚本。
```bash
# 直接使用,将所有使用的命令中 `bin/spc` 替换为 `bin/spc-alpine-docker` 即可
bin/spc-alpine-docker
```
首次执行命令会使用 `docker build` 构建一个 Docker 镜像,默认构建的 Docker 镜像为 `x86_64` 架构,镜像名称为 `cwcc-spc-x86_64`
如果你想在 `x86_64` 环境下构建 `aarch64` 的 static-php-cli可以使用 qemu 模拟 arm 镜像运行 Docker但速度会非常慢。使用参数`SPC_USE_ARCH=aarch64 bin/spc-alpine-docker`
如果运行后提示需要 sudo 才能运行,执行一次以下命令可授予 static-php-cli 执行 sudo 的权限:
```bash
export SPC_USE_SUDO=yes
```
### 使用预编译静态 PHP 二进制
### 使用预编译静态 PHP 二进制运行 static-php-cli
如果你不想使用 Docker、在系统内安装 PHP可以直接下载本项目自身编译好的 php 二进制 cli 程序。使用流程如下:
@ -115,6 +73,45 @@ bin/setup-runtime --mirror china
1. 将 `bin/` 目录添加到 PATH 路径中:`export PATH="/path/to/your/static-php-cli/bin:$PATH"`,添加路径后,相当于系统安装了 PHP可直接使用 `composer``php -v` 等命令,也可以直接使用 `bin/spc`
2. 直接调用,比如执行 static-php-cli 命令:`bin/php bin/spc --help`,执行 Composer`bin/php bin/composer update`
### 使用 Docker 环境
如果你不愿意在系统安装 PHP 和 Composer 运行环境,可以使用内置的 Docker 环境构建脚本。
```bash
# 直接使用,将所有使用的命令中 `bin/spc` 替换为 `bin/spc-alpine-docker` 即可
bin/spc-alpine-docker
```
首次执行命令会使用 `docker build` 构建一个 Docker 镜像,默认构建的 Docker 镜像为 `x86_64` 架构,镜像名称为 `cwcc-spc-x86_64`
如果你想在 `x86_64` 环境下构建 `aarch64` 的 static-php-cli可以使用 qemu 模拟 arm 镜像运行 Docker但速度会非常慢。使用参数`SPC_USE_ARCH=aarch64 bin/spc-alpine-docker`
如果运行后提示需要 sudo 才能运行,执行一次以下命令可授予 static-php-cli 执行 sudo 的权限:
```bash
export SPC_USE_SUDO=yes
```
### 使用系统 PHP 环境
下面是系统安装 PHP、Composer 的一些示例命令。具体安装方式建议自行搜索或询问 AI 搜索引擎获取答案,这里不多赘述。
```bash
# [macOS], 需要先安装 Homebrew. See https://brew.sh/
# Remember change your composer executable path. For M1/M2 Chip mac, "/opt/homebrew/bin/", for Intel mac, "/usr/local/bin/". Or add it to your own path.
brew install php wget
wget https://getcomposer.org/download/latest-stable/composer.phar -O /path/to/your/bin/composer && chmod +x /path/to/your/bin/composer
# [Debian], you need to make sure your php version >= 8.4 and composer >= 2.0
sudo apt install php-cli composer php-tokenizer
```
::: tip
目前 Ubuntu 部分版本的 apt 安装的 php 版本较旧,故不提供安装命令。如有需要,建议先添加 ppa 等软件源后,安装最新版的 PHP 以及 tokenizer、xml、phar 扩展。
较老版本的 Debian 默认安装的可能为旧版本(<= 8.3)版本的 PHP建议先升级 Debian 或使用 Docker 或自带的静态二进制环境。
:::
## 命令 download - 下载依赖包
使用命令 `bin/spc download` 可以下载编译需要的源代码,包括 php-src 以及依赖的各种库的源码。

View File

@ -32,7 +32,7 @@ use Symfony\Component\Console\Application;
*/
final class ConsoleApplication extends Application
{
public const VERSION = '2.4.5';
public const VERSION = '2.5.0';
public function __construct()
{

View File

@ -163,6 +163,8 @@ if ($argv[1] === 'download_cmd') {
} else {
passthru('./bin/spc ' . $build_cmd . ' --build-embed', $retcode);
}
} else {
$retcode = 0;
}
exit($retcode);

View File

@ -15,7 +15,7 @@ class SystemUtilTest extends TestCase
public static function setUpBeforeClass(): void
{
if (PHP_OS_FAMILY !== 'Linux') {
self::markTestIncomplete('This test is only for Linux');
self::markTestSkipped('This test is only for Linux');
}
}

View File

@ -15,7 +15,7 @@ class SystemUtilTest extends TestCase
public static function setUpBeforeClass(): void
{
if (PHP_OS_FAMILY !== 'Darwin') {
self::markTestIncomplete('This test is only for macOS');
self::markTestSkipped('This test is only for macOS');
}
}