mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-04 23:35:40 +08:00
Merge branch 'main' into feat/xdebug-dynamic
This commit is contained in:
@@ -150,12 +150,13 @@ class LinuxBuilder extends UnixBuilderBase
|
||||
$enable_micro = ($build_target & BUILD_TARGET_MICRO) === BUILD_TARGET_MICRO;
|
||||
$enable_embed = ($build_target & BUILD_TARGET_EMBED) === BUILD_TARGET_EMBED;
|
||||
|
||||
$mimallocLibs = $this->getLib('mimalloc') !== null ? BUILD_LIB_PATH . '/mimalloc.o ' : '';
|
||||
// prepare build php envs
|
||||
$envs_build_php = SystemUtil::makeEnvVarString([
|
||||
'CFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS'),
|
||||
'CPPFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS'),
|
||||
'LDFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS'),
|
||||
'LIBS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_LIBS'),
|
||||
'LIBS' => $mimallocLibs . getenv('SPC_CMD_VAR_PHP_CONFIGURE_LIBS'),
|
||||
]);
|
||||
|
||||
// process micro upx patch if micro sapi enabled
|
||||
@@ -310,9 +311,15 @@ class LinuxBuilder extends UnixBuilderBase
|
||||
shell()->cd(SOURCE_PATH . '/php-src')
|
||||
->exec('sed -i "s|//lib|/lib|g" Makefile')
|
||||
->exec(getenv('SPC_CMD_PREFIX_PHP_MAKE') . ' INSTALL_ROOT=' . BUILD_ROOT_PATH . " {$vars} install");
|
||||
FileSystem::replaceFileStr(BUILD_BIN_PATH . '/php-config', 'prefix=""', 'prefix="' . BUILD_ROOT_PATH . '"');
|
||||
FileSystem::replaceFileStr(BUILD_BIN_PATH . '/phpize', "prefix=''", "prefix='" . BUILD_ROOT_PATH . "'");
|
||||
FileSystem::replaceFileStr(BUILD_BIN_PATH . '/phpize', 's##', 's#/usr/local#');
|
||||
$php_config_str = FileSystem::readFile(BUILD_BIN_PATH . '/php-config');
|
||||
str_replace('prefix=""', 'prefix="' . BUILD_ROOT_PATH . '"', $php_config_str);
|
||||
// move mimalloc to the beginning of libs
|
||||
$php_config_str = preg_replace('/(libs=")(.*?)\s*(' . preg_quote(BUILD_LIB_PATH, '/') . '\/mimalloc\.o)\s*(.*?)"/', '$1$3 $2 $4"', $php_config_str);
|
||||
// move lstdc++ to the end of libs
|
||||
$php_config_str = preg_replace('/(libs=")(.*?)\s*(-lstdc\+\+)\s*(.*?)"/', '$1$2 $4 $3"', $php_config_str);
|
||||
FileSystem::writeFile(BUILD_BIN_PATH . '/php-config', $php_config_str);
|
||||
}
|
||||
|
||||
private function getMakeExtraVars(): array
|
||||
|
||||
12
src/SPC/builder/linux/library/mimalloc.php
Normal file
12
src/SPC/builder/linux/library/mimalloc.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\linux\library;
|
||||
|
||||
class mimalloc extends LinuxLibraryBase
|
||||
{
|
||||
use \SPC\builder\unix\library\mimalloc;
|
||||
|
||||
public const NAME = 'mimalloc';
|
||||
}
|
||||
@@ -148,10 +148,12 @@ class MacOSBuilder extends UnixBuilderBase
|
||||
$enableEmbed = ($build_target & BUILD_TARGET_EMBED) === BUILD_TARGET_EMBED;
|
||||
|
||||
// prepare build php envs
|
||||
$mimallocLibs = $this->getLib('mimalloc') !== null ? BUILD_LIB_PATH . '/mimalloc.o ' : '';
|
||||
$envs_build_php = SystemUtil::makeEnvVarString([
|
||||
'CFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS'),
|
||||
'CPPFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS'),
|
||||
'LDFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS'),
|
||||
'LIBS' => $mimallocLibs . getenv('SPC_CMD_VAR_PHP_CONFIGURE_LIBS'),
|
||||
]);
|
||||
|
||||
if ($this->getLib('postgresql')) {
|
||||
@@ -298,9 +300,13 @@ class MacOSBuilder extends UnixBuilderBase
|
||||
->exec('rm ' . BUILD_ROOT_PATH . '/lib/libphp.a')
|
||||
->exec('ar rcs ' . BUILD_ROOT_PATH . '/lib/libphp.a *.o')
|
||||
->exec('rm -Rf ' . BUILD_ROOT_PATH . '/lib/php-o');
|
||||
FileSystem::replaceFileStr(BUILD_BIN_PATH . '/php-config', 'prefix=""', 'prefix="' . BUILD_ROOT_PATH . '"');
|
||||
FileSystem::replaceFileStr(BUILD_BIN_PATH . '/phpize', "prefix=''", "prefix='" . BUILD_ROOT_PATH . "'");
|
||||
FileSystem::replaceFileStr(BUILD_BIN_PATH . '/phpize', 's##', 's#/usr/local#');
|
||||
$php_config_str = FileSystem::readFile(BUILD_BIN_PATH . '/php-config');
|
||||
str_replace('prefix=""', 'prefix="' . BUILD_ROOT_PATH . '"', $php_config_str);
|
||||
// move mimalloc to the beginning of libs
|
||||
$php_config_str = preg_replace('/(libs=")(.*?)\s*(' . preg_quote(BUILD_LIB_PATH, '/') . '\/mimalloc\.o)\s*(.*?)"/', '$1$3 $2 $4"', $php_config_str);
|
||||
FileSystem::writeFile(BUILD_BIN_PATH . '/php-config', $php_config_str);
|
||||
}
|
||||
|
||||
private function getMakeExtraVars(): array
|
||||
|
||||
12
src/SPC/builder/macos/library/mimalloc.php
Normal file
12
src/SPC/builder/macos/library/mimalloc.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\macos\library;
|
||||
|
||||
class mimalloc extends MacOSLibraryBase
|
||||
{
|
||||
use \SPC\builder\unix\library\mimalloc;
|
||||
|
||||
public const NAME = 'mimalloc';
|
||||
}
|
||||
38
src/SPC/builder/unix/library/mimalloc.php
Normal file
38
src/SPC/builder/unix/library/mimalloc.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\unix\library;
|
||||
|
||||
use SPC\exception\FileSystemException;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\store\FileSystem;
|
||||
|
||||
trait mimalloc
|
||||
{
|
||||
/**
|
||||
* @throws RuntimeException
|
||||
* @throws FileSystemException
|
||||
*/
|
||||
protected function build(): void
|
||||
{
|
||||
$args = '';
|
||||
if (getenv('SPC_LIBC') === 'musl') {
|
||||
$args .= '-DMI_LIBC_MUSL=ON ';
|
||||
}
|
||||
$args .= '-DMI_BUILD_SHARED=OFF ';
|
||||
$args .= '-DMI_INSTALL_TOPLEVEL=ON ';
|
||||
FileSystem::resetDir($this->source_dir . '/build');
|
||||
shell()->cd($this->source_dir . '/build')
|
||||
->execWithEnv(
|
||||
'cmake ' .
|
||||
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' .
|
||||
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
|
||||
'-DCMAKE_BUILD_TYPE=Release ' .
|
||||
$args .
|
||||
'..'
|
||||
)
|
||||
->execWithEnv("make -j{$this->builder->concurrency}")
|
||||
->execWithEnv('make install');
|
||||
}
|
||||
}
|
||||
@@ -69,14 +69,19 @@ class Downloader
|
||||
retry: self::getRetryTime()
|
||||
), true);
|
||||
|
||||
if (($source['prefer-stable'] ?? false) === false) {
|
||||
$url = $data[0]['tarball_url'];
|
||||
} else {
|
||||
$id = 0;
|
||||
while (($data[$id]['prerelease'] ?? false) === true) {
|
||||
++$id;
|
||||
$url = null;
|
||||
for ($i = 0; $i < count($data); ++$i) {
|
||||
if (($data[$i]['prerelease'] ?? false) === true && ($source['prefer-stable'] ?? false)) {
|
||||
continue;
|
||||
}
|
||||
if (!($source['match'] ?? null)) {
|
||||
$url = $data[$i]['tarball_url'] ?? null;
|
||||
break;
|
||||
}
|
||||
if (preg_match('|' . $source['match'] . '|', $data[$i]['tarball_url'])) {
|
||||
$url = $data[$i]['tarball_url'];
|
||||
break;
|
||||
}
|
||||
$url = $data[$id]['tarball_url'] ?? null;
|
||||
}
|
||||
if (!$url) {
|
||||
throw new DownloaderException("failed to find {$name} source");
|
||||
|
||||
@@ -42,6 +42,10 @@ class SPCConfigUtil
|
||||
if ($this->builder->hasCpp()) {
|
||||
$libs .= $this->builder instanceof MacOSBuilder ? ' -lc++' : ' -lstdc++';
|
||||
}
|
||||
// mimalloc must come first
|
||||
if (str_contains($libs, BUILD_LIB_PATH . '/mimalloc.o')) {
|
||||
$libs = BUILD_LIB_PATH . '/mimalloc.o ' . str_replace(BUILD_LIB_PATH . '/mimalloc.o', '', $libs);
|
||||
}
|
||||
return [
|
||||
'cflags' => $cflags,
|
||||
'ldflags' => $ldflags,
|
||||
|
||||
@@ -6,12 +6,12 @@ declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This is GitHub Actions automatic test extension args generator.
|
||||
* You can edit $extensions, $with_libs and $base_combination.
|
||||
* You can edit $test_php_version, $test_os, $zts, $no_strip, $upx, $prefer_pre_built, $extensions, $with_libs and $base_combination.
|
||||
*/
|
||||
|
||||
// --------------------------------- edit area ---------------------------------
|
||||
|
||||
// test php version
|
||||
// test php version (8.1 ~ 8.4 available, multiple for matrix)
|
||||
$test_php_version = [
|
||||
'8.1',
|
||||
'8.2',
|
||||
@@ -21,10 +21,10 @@ $test_php_version = [
|
||||
|
||||
// test os (macos-13, macos-14, ubuntu-latest, windows-latest are available)
|
||||
$test_os = [
|
||||
// 'macos-13',
|
||||
// 'macos-14',
|
||||
// 'ubuntu-latest',
|
||||
'windows-latest',
|
||||
'macos-13',
|
||||
'macos-14',
|
||||
'ubuntu-latest',
|
||||
// 'windows-latest',
|
||||
];
|
||||
|
||||
// whether enable thread safe
|
||||
@@ -40,13 +40,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' => 'gd',
|
||||
'Linux', 'Darwin' => '',
|
||||
'Windows' => 'bz2,ctype,curl,dom,filter,gd,iconv,mbstring,opcache,openssl,pdo,pdo_sqlite,phar,session,simplexml,sqlite3,tokenizer,xml,xmlwriter,yaml,zip,zlib',
|
||||
};
|
||||
|
||||
// If you want to test lib-suggests feature with extension, add them below (comma separated, example `libwebp,libavif`).
|
||||
$with_libs = match (PHP_OS_FAMILY) {
|
||||
'Linux', 'Darwin' => 'freetype',
|
||||
'Linux', 'Darwin' => 'mimalloc',
|
||||
'Windows' => 'libjpeg,libavif,freetype,libwebp',
|
||||
};
|
||||
|
||||
@@ -54,7 +54,7 @@ $with_libs = match (PHP_OS_FAMILY) {
|
||||
// You can use `common`, `bulk`, `minimal` or `none`.
|
||||
// note: combination is only available for *nix platform. Windows must use `none` combination
|
||||
$base_combination = match (PHP_OS_FAMILY) {
|
||||
'Linux', 'Darwin' => 'minimal',
|
||||
'Linux', 'Darwin' => 'bulk',
|
||||
'Windows' => 'none',
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user