Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

## 特性

- :elephant: 支持多个 PHP 版本 - PHP 8.1, 8.2, 8.3, 8.4, 8.5
- :elephant: 支持多个 PHP 版本 - PHP 8.1, 8.2, 8.3, 8.4, 8.5, 8.6(预发布)
- :handbag: 构建零依赖的单文件 PHP 可执行程序
- :hamburger: 构建 **[phpmicro](https://github.com/static-php/phpmicro)** 自解压可执行文件(将 PHP 二进制和源码合并为单个文件)
- :pill: 自动构建环境检查器,支持自动修复
Expand Down Expand Up @@ -63,7 +63,7 @@ chmod +x ./spc
首先,创建 `craft.yml` 文件,并从 [扩展列表](https://static-php.dev/en/guide/extensions.html) 或 [命令生成器](https://static-php.dev/en/guide/cli-generator.html) 指定要包含的扩展:

```yml
# PHP version support: 8.1, 8.2, 8.3, 8.4, 8.5
# PHP version support: 8.1, 8.2, 8.3, 8.4, 8.5, 8.6 (pre-release)
php-version: 8.5
# Put your extension list here
extensions: "apcu,bcmath,calendar,ctype,curl,dba,dom,exif,fileinfo,filter,gd,iconv,mbregex,mbstring,mysqli,mysqlnd,opcache,openssl,pcntl,pdo,pdo_mysql,pdo_sqlite,phar,posix,readline,redis,session,simplexml,sockets,sodium,sqlite3,tokenizer,xml,xmlreader,xmlwriter,xsl,zip,zlib"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

## Features

- :elephant: Support multiple PHP versions - PHP 8.1, 8.2, 8.3, 8.4, 8.5
- :elephant: Support multiple PHP versions - PHP 8.1, 8.2, 8.3, 8.4, 8.5, 8.6 (pre-release)
- :handbag: Build single-file PHP executable with zero dependencies
- :hamburger: Build **[phpmicro](https://github.com/static-php/phpmicro)** self-extracting executables (combines PHP binary and source code into one file)
- :pill: Automatic build environment checker with auto-fix capabilities
Expand Down Expand Up @@ -63,7 +63,7 @@ chmod +x ./spc
First, create a `craft.yml` file and specify which extensions you want to include from [extension list](https://static-php.dev/en/guide/extensions.html) or [command generator](https://static-php.dev/en/guide/cli-generator.html):

```yml
# PHP version support: 8.1, 8.2, 8.3, 8.4, 8.5
# PHP version support: 8.1, 8.2, 8.3, 8.4, 8.5, 8.6 (pre-release)
php-version: 8.5
# Put your extension list here
extensions: "apcu,bcmath,calendar,ctype,curl,dba,dom,exif,fileinfo,filter,gd,iconv,mbregex,mbstring,mysqli,mysqlnd,opcache,openssl,pcntl,pdo,pdo_mysql,pdo_sqlite,phar,posix,readline,redis,session,simplexml,sockets,sodium,sqlite3,tokenizer,xml,xmlreader,xmlwriter,xsl,zip,zlib"
Expand Down
2 changes: 1 addition & 1 deletion config/env.ini
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ SPC_CMD_PREFIX_PHP_CONFIGURE="./configure --prefix= --with-valgrind=no --disable
; embed type for php, static (libphp.a) or shared (libphp.so)
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 -fno-ident -fPIE -fvisibility=hidden -fvisibility-inlines-hidden ${SPC_DEFAULT_CFLAGS}"
SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fno-ident -fPIE -fvisibility=hidden ${SPC_DEFAULT_CFLAGS}"
; EXTRA_CXXFLAGS for `configure` and `make` php
SPC_CMD_VAR_PHP_MAKE_EXTRA_CXXFLAGS="-g -fstack-protector-strong -fno-ident -fPIE -fvisibility=hidden -fvisibility-inlines-hidden ${SPC_DEFAULT_CXXFLAGS}"
; EXTRA_LDFLAGS for `make` php, can use -release to set a soname for libphp.so
Expand Down
2 changes: 1 addition & 1 deletion config/pkg/ext/builtin-extensions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ ext-pdo_pgsql:
- ext-pgsql
- postgresql
php-extension:
arg-type@unix: with-path
arg-type@unix: custom
arg-type@windows: '--with-pdo-pgsql=yes'
ext-pdo_sqlite:
type: php-extension
Expand Down
1 change: 1 addition & 0 deletions config/pkg/lib/libwebp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ libwebp:
- libwebp.lib
- libwebpdecoder.lib
- libwebpdemux.lib
- libwebpmux.lib
- libsharpyuv.lib
1 change: 0 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ parameters:
excludePaths:
analyseAndScan:
- ./src/globals/ext-tests/
- ./src/globals/test-extensions.php
4 changes: 3 additions & 1 deletion src/Package/Artifact/php_src.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public function patchGDWin32(): void
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/ext/gd/libgd/gdft.c', '#ifndef MSWIN32', '#ifndef _WIN32');
}
// custom config.w32, because official config.w32 is hard-coded many things
if ($ver_id >= 80500) {
if ($ver_id >= 80600) {
$origin = file_get_contents(ROOT_DIR . '/src/globals/extra/gd_config_86.w32');
} elseif ($ver_id >= 80500) {
$origin = file_get_contents(ROOT_DIR . '/src/globals/extra/gd_config_85.w32');
} elseif ($ver_id >= 80100) {
$origin = file_get_contents(ROOT_DIR . '/src/globals/extra/gd_config_81.w32');
Expand Down
5 changes: 3 additions & 2 deletions src/Package/Command/SwitchPhpVersionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public function handle(): int
* Accepts:
* - Major.Minor format, e.g. 7.4
* - Full version format, e.g. 8.4.5, 8.3.12, etc.
* - Pre-release format, e.g. 8.6.0RC1
*/
private function isValidPhpVersion(string $version): bool
{
Expand All @@ -112,8 +113,8 @@ private function isValidPhpVersion(string $version): bool
return true;
}

// Check full version format (e.g., 8.4.5)
if (preg_match('/^\d+\.\d+\.\d+$/', $version)) {
// Check full version format (e.g., 8.4.5, 8.6.0RC1)
if (preg_match('/^\d+\.\d+\.\d+(?:(?:alpha|beta|RC)\d+)?$/', $version)) {
return true;
}

Expand Down
15 changes: 15 additions & 0 deletions src/Package/Extension/gd.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,29 @@

namespace Package\Extension;

use Package\Target\php;
use StaticPHP\Attribute\Package\BeforeStage;
use StaticPHP\Attribute\Package\CustomPhpConfigureArg;
use StaticPHP\Attribute\Package\Extension;
use StaticPHP\Attribute\PatchDescription;
use StaticPHP\Package\PackageInstaller;
use StaticPHP\Package\PhpExtensionPackage;
use StaticPHP\Util\FileSystem;

#[Extension('gd')]
class gd extends PhpExtensionPackage
{
#[BeforeStage('php', [php::class, 'buildconfForUnix'], 'ext-gd')]
#[PatchDescription('Fix libgd iconv_t fallback typedef guard for shared builds (PHP 8.6+)')]
public function patchBeforeBuildconf(): void
{
FileSystem::replaceFileStr(
"{$this->getBuildDir()}/libgd/gdkanji.c",
"#ifndef HAVE_ICONV_T_DEF\ntypedef void *iconv_t;",
"#ifndef HAVE_ICONV\ntypedef void *iconv_t;",
);
}

#[CustomPhpConfigureArg('Darwin')]
#[CustomPhpConfigureArg('Linux')]
public function getUnixConfigureArg(bool $shared, PackageInstaller $installer): string
Expand Down
18 changes: 16 additions & 2 deletions src/Package/Extension/intl.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,33 @@
use StaticPHP\Package\PackageInstaller;
use StaticPHP\Package\PhpExtensionPackage;
use StaticPHP\Util\FileSystem;
use StaticPHP\Util\GlobalEnvManager;

#[Extension('intl')]
class intl extends PhpExtensionPackage
{
// php.h defines vsnprintf as ap_php_vsnprintf, breaking std::vsnprintf in libc++ <locale>
#[BeforeStage('php', [php::class, 'makeForUnix'], 'ext-intl')]
public function forceLibcxxLocaleBeforePhpHeaders(): void
{
$cxxflags = getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CXXFLAGS') ?: '';
if (!str_contains($cxxflags, '-include locale')) {
GlobalEnvManager::putenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CXXFLAGS=' . trim("{$cxxflags} -include locale"));
}
}

#[BeforeStage('php', [php::class, 'buildconfForWindows'], 'ext-intl')]
#[PatchDescription('Fix intl config.w32: replace hardcoded true with PHP_INTL_SHARED for static build support; add /std:c++17 required by ICU 73+')]
public function patchBeforeBuildconfForWindows(PackageInstaller $installer): void
{
$php_src = $installer->getTargetPackage('php')->getSourceDir();
// Match only the tail of the EXTENSION() call: the source list changes between PHP
// versions (8.6 added intl_icu_compat.c) and a missed replacement silently leaves the
// hardcoded true, which builds intl shared and drops it from the static binary.
FileSystem::replaceFileStr(
"{$php_src}/ext/intl/config.w32",
'EXTENSION("intl", "php_intl.c intl_convert.c intl_convertcpp.cpp intl_error.c ", true,',
'EXTENSION("intl", "php_intl.c intl_convert.c intl_convertcpp.cpp intl_error.c ", PHP_INTL_SHARED,'
'intl_error.c ", true,',
'intl_error.c ", PHP_INTL_SHARED,'
);
// ICU 73+ headers (char16ptr.h etc.) unconditionally include <string_view> which requires C++17.
FileSystem::replaceFileStr(
Expand Down
31 changes: 31 additions & 0 deletions src/Package/Extension/pdo_pgsql.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Package\Extension;

use Package\Target\php;
use StaticPHP\Attribute\Package\CustomPhpConfigureArg;
use StaticPHP\Attribute\Package\Extension;
use StaticPHP\Package\PackageBuilder;
use StaticPHP\Package\PackageInstaller;
use StaticPHP\Package\PhpExtensionPackage;
use StaticPHP\Util\SPCConfigUtil;

#[Extension('pdo_pgsql')]
class pdo_pgsql extends PhpExtensionPackage
{
#[CustomPhpConfigureArg('Darwin')]
#[CustomPhpConfigureArg('Linux')]
public function getUnixConfigureArg(bool $shared, PackageBuilder $builder, PackageInstaller $installer): string
{
if (php::getPHPVersionID() >= 80400) {
// These override pkg-config, so they must carry libpq itself too
$libs = new SPCConfigUtil(['no_php' => true, 'libs_only_deps' => true])->configForResolvedBuild(['postgresql'], $installer)['libs'];
return '--with-pdo-pgsql' . ($shared ? '=shared' : '') .
' PGSQL_CFLAGS=-I' . $builder->getIncludeDir() .
' PGSQL_LIBS="-L' . $builder->getLibDir() . ' ' . $libs . '"';
}
return '--with-pdo-pgsql=' . ($shared ? 'shared,' : '') . $builder->getBuildRootPath();
}
}
10 changes: 5 additions & 5 deletions src/Package/Extension/pgsql.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ class pgsql extends PhpExtensionPackage
public function getUnixConfigureArg(bool $shared, PackageBuilder $builder, PackageInstaller $installer): string
{
if (php::getPHPVersionID() >= 80400) {
$libfiles = new SPCConfigUtil(['libs_only_deps' => true, 'absolute_libs' => true])->getPackageDepsConfig('postgresql', array_keys($installer->getResolvedPackages()))['libs'];
$libfiles = str_replace("{$builder->getLibDir()}/lib", '-l', $libfiles);
$libfiles = str_replace('.a', '', $libfiles);
// These override pkg-config, so they must carry libpq itself too
$libs = new SPCConfigUtil(['no_php' => true, 'libs_only_deps' => true])->configForResolvedBuild(['postgresql'], $installer)['libs'];
return '--with-pgsql' . ($shared ? '=shared' : '') .
' PGSQL_CFLAGS=-I' . $builder->getIncludeDir() .
' PGSQL_LIBS="-L' . $builder->getLibDir() . ' ' . $libfiles . '"';
' PGSQL_LIBS="-L' . $builder->getLibDir() . ' ' . $libs . '"';
}
return '--with-pgsql=' . ($shared ? 'shared,' : '') . $builder->getBuildRootPath();
}
Expand Down Expand Up @@ -67,7 +66,8 @@ public function patchConfigW32ForWindows(TargetPackage $package): void
public function getSharedExtensionEnv(): array
{
$parent = parent::getSharedExtensionEnv();
$parent['CFLAGS'] .= ' -std=c17 -Wno-int-conversion';
// gnu17, not c17: PHP 8.6 headers use typeof
$parent['CFLAGS'] .= ' -std=gnu17 -Wno-int-conversion';
return $parent;
}
}
2 changes: 1 addition & 1 deletion src/Package/Extension/swoole.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function getUnixConfigureArg(bool $shared, PackageBuilder $builder, Packa
$arg = '--enable-swoole' . ($shared ? '=shared' : '');

// commonly used feature: coroutine-time
$arg .= ' --enable-swoole-coro-time --with-pic';
$arg .= ' --enable-swoole-coro-time';

$arg .= $builder->getOption('enable-zts') ? ' --enable-swoole-thread --disable-thread-context' : ' --disable-swoole-thread --enable-thread-context';

Expand Down
33 changes: 32 additions & 1 deletion src/Package/Target/php.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use StaticPHP\Attribute\Package\Stage;
use StaticPHP\Attribute\Package\Target;
use StaticPHP\Attribute\Package\Validate;
use StaticPHP\Attribute\PatchDescription;
use StaticPHP\Config\PackageConfig;
use StaticPHP\DI\ApplicationContext;
use StaticPHP\Exception\WrongUsageException;
Expand Down Expand Up @@ -50,7 +51,7 @@ class php extends TargetPackage
use frankenphp;

/** @var string[] Supported major PHP versions */
public const array SUPPORTED_MAJOR_VERSIONS = ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5'];
public const array SUPPORTED_MAJOR_VERSIONS = ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5', '8.6'];

/**
* Get PHP version ID from php_version.h
Expand Down Expand Up @@ -453,6 +454,36 @@ public function syncExtensionSources(PackageInstaller $installer): void
}
}

#[BeforeStage('php', 'build')]
#[PatchDescription('Replace XtOffsetOf (removed in PHP 8.6) with offsetof in extension sources')]
public function patchExtensionXtOffsetOf(PackageInstaller $installer): void
{
if (self::getPHPVersionID() < 80600) {
return;
}
foreach ($installer->getResolvedPackages(PhpExtensionPackage::class) as $ext) {
// extensions bundled with php-src are already 8.6-clean
if ($ext->getArtifact() === null) {
continue;
}
$build_dir = $ext->getBuildDir();
if (!is_dir($build_dir)) {
continue;
}
foreach (FileSystem::scanDirFiles($build_dir) ?: [] as $file) {
if (!in_array(FileSystem::extname($file), ['c', 'cc', 'cpp', 'cxx', 'h', 'hpp'], true)) {
continue;
}
$content = FileSystem::readFile($file);
if (!str_contains($content, 'XtOffsetOf')) {
continue;
}
logger()->debug("Replacing XtOffsetOf with offsetof in {$file}");
FileSystem::writeFile($file, str_replace('XtOffsetOf', 'offsetof', $content));
}
}
}

#[Stage('postInstall')]
public function postInstall(TargetPackage $package, PackageInstaller $installer): void
{
Expand Down
Loading
Loading