Merge branch 'main' into libargon2-support

This commit is contained in:
Marcel Pociot
2023-12-19 10:05:45 +01:00
committed by GitHub
38 changed files with 993 additions and 297 deletions

View File

@@ -23,7 +23,7 @@ use Symfony\Component\Console\Command\ListCommand;
*/
final class ConsoleApplication extends Application
{
public const VERSION = '2.0.0-rc8';
public const VERSION = '2.0.0-rc9';
public function __construct()
{

View File

@@ -69,7 +69,7 @@ abstract class BuilderBase
foreach ($libraries as $library) {
// if some libs are not supported (but in config "lib.json", throw exception)
if (!isset($support_lib_list[$library])) {
throw new RuntimeException('library [' . $library . '] is in the lib.json list but not supported to compile, but in the future I will support it!');
throw new WrongUsageException('library [' . $library . '] is in the lib.json list but not supported to compile, but in the future I will support it!');
}
$lib = new ($support_lib_list[$library])($this);
$this->addLib($lib);
@@ -259,6 +259,19 @@ abstract class BuilderBase
throw new RuntimeException('PHP version file format is malformed, please remove it and download again');
}
public function getPHPVersion(): string
{
if (!file_exists(SOURCE_PATH . '/php-src/main/php_version.h')) {
throw new WrongUsageException('PHP source files are not available, you need to download them first');
}
$file = file_get_contents(SOURCE_PATH . '/php-src/main/php_version.h');
if (preg_match('/PHP_VERSION "(.*)"/', $file, $match) !== 0) {
return $match[1];
}
throw new RuntimeException('PHP version file format is malformed, please remove it and download again');
}
/**
* Get build type name string to display.
*

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace SPC\builder\extension;
use SPC\builder\Extension;
use SPC\builder\linux\LinuxBuilder;
use SPC\util\CustomExt;
#[CustomExt('imagick')]
@@ -14,7 +15,9 @@ class imagick extends Extension
{
// imagick may call omp_pause_all which requires -lgomp
$extra_libs = $this->builder->getOption('extra-libs', '');
$extra_libs .= ' -lgomp ';
if ($this->builder instanceof LinuxBuilder) {
$extra_libs .= ' -lgomp ';
}
$this->builder->setOption('extra-libs', $extra_libs);
return true;
}

View File

@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
namespace SPC\builder\extension;
use SPC\builder\Extension;
use SPC\exception\WrongUsageException;
use SPC\util\CustomExt;
#[CustomExt('imap')]
class imap extends Extension
{
/**
* @throws WrongUsageException
*/
public function getUnixConfigureArg(): string
{
if ($this->builder->getOption('enable-zts')) {
throw new WrongUsageException('ext-imap is not thread safe, do not build it with ZTS builds');
}
$arg = '--with-imap=' . BUILD_ROOT_PATH;
if ($this->builder->getLib('openssl') !== null) {
$arg .= ' --with-imap-ssl=' . BUILD_ROOT_PATH;
}
return $arg;
}
}

View File

@@ -5,11 +5,20 @@ declare(strict_types=1);
namespace SPC\builder\extension;
use SPC\builder\Extension;
use SPC\store\FileSystem;
use SPC\util\CustomExt;
#[CustomExt('mongodb')]
class mongodb extends Extension
{
public function patchBeforeBuildconf(): bool
{
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/ext/mongodb/config.m4', 'if test -z "$PHP_CONFIG"; then', 'if false; then');
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/ext/mongodb/config.m4', 'PHP_MONGODB_PHP_VERSION=`${PHP_CONFIG} --version`', 'PHP_MONGODB_PHP_VERSION=' . $this->builder->getPHPVersion());
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/ext/mongodb/config.m4', 'PHP_MONGODB_PHP_VERSION_ID=`${PHP_CONFIG} --vernum`', 'PHP_MONGODB_PHP_VERSION_ID=' . $this->builder->getPHPVersionID());
return true;
}
public function getUnixConfigureArg(): string
{
$arg = ' --enable-mongodb ';

View File

@@ -5,11 +5,25 @@ declare(strict_types=1);
namespace SPC\builder\extension;
use SPC\builder\Extension;
use SPC\exception\RuntimeException;
use SPC\exception\WrongUsageException;
use SPC\util\CustomExt;
#[CustomExt('opcache')]
class opcache extends Extension
{
/**
* @throws WrongUsageException
* @throws RuntimeException
*/
public function getUnixConfigureArg(): string
{
if ($this->builder->getPHPVersionID() < 80000) {
throw new WrongUsageException('Statically compiled PHP with Zend Opcache only available for PHP >= 8.0 !');
}
return '--enable-opcache';
}
public function getDistName(): string
{
return 'Zend Opcache';

View File

@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace SPC\builder\extension;
use SPC\builder\Extension;
use SPC\util\CustomExt;
#[CustomExt('sodium')]
class sodium extends Extension
{
public function patchBeforeBuildconf(): bool
{
// bypass error: unknown warning option '-Wno-logical-op' for macOS
return $this->removeLineContainingString();
}
private function removeLineContainingString(): bool
{
$path = SOURCE_PATH . '/php-src/ext/sodium/config.m4';
$search = '-Wno-logical-op';
if (!file_exists($path)) {
return false;
}
$content = file_get_contents($path);
$lines = preg_split('/\r\n|\n/', $content);
$filteredLines = array_filter($lines, function ($line) use ($search) {
return strpos($line, $search) === false;
});
$newContent = implode("\n", $filteredLines);
file_put_contents($path, $newContent);
return true;
}
}

View File

@@ -16,8 +16,9 @@ class swoole extends Extension
// pgsql hook is buggy for static php
$arg .= ' --disable-swoole-pgsql';
$arg .= $this->builder->getLib('openssl') ? ' --enable-openssl' : ' --disable-openssl --without-openssl';
$arg .= $this->builder->getLib('brotli') ? (' --enable-brotli --with-brotli-dir=' . BUILD_ROOT_PATH) : '';
$arg .= $this->builder->getExt('curl') ? ' --enable-swoole-curl' : ' --disable-swoole-curl';
$arg .= $this->builder->getLib('brotli') ? (' --enable-brotli --with-brotli-dir=' . BUILD_ROOT_PATH) : ' --disable-brotli';
// swoole curl hook is buggy for php 8.0
$arg .= $this->builder->getExt('curl') && $this->builder->getPHPVersionID() >= 80100 ? ' --enable-swoole-curl' : ' --disable-swoole-curl';
return $arg;
}
}

View File

@@ -0,0 +1,63 @@
<?php
declare(strict_types=1);
namespace SPC\builder\linux\library;
use SPC\exception\FileSystemException;
use SPC\exception\RuntimeException;
use SPC\store\FileSystem;
class imap extends LinuxLibraryBase
{
public const NAME = 'imap';
/**
* @throws FileSystemException
*/
public function patchBeforeBuild(): bool
{
$cc = getenv('CC') ?: 'gcc';
// FileSystem::replaceFileStr($this->source_dir . '/Makefile', '-DMAC_OSX_KLUDGE=1', '');
FileSystem::replaceFileStr($this->source_dir . '/src/osdep/unix/Makefile', 'CC=cc', "CC={$cc}");
/* FileSystem::replaceFileStr($this->source_dir . '/src/osdep/unix/Makefile', '-lcrypto -lz', '-lcrypto');
FileSystem::replaceFileStr($this->source_dir . '/src/osdep/unix/Makefile', '-lcrypto', '-lcrypto -lz');
FileSystem::replaceFileStr(
$this->source_dir . '/src/osdep/unix/ssl_unix.c',
"#include <x509v3.h>\n#include <ssl.h>",
"#include <ssl.h>\n#include <x509v3.h>"
);
// SourcePatcher::patchFile('1006_openssl1.1_autoverify.patch', $this->source_dir);
SourcePatcher::patchFile('2014_openssl1.1.1_sni.patch', $this->source_dir); */
FileSystem::replaceFileStr($this->source_dir . '/Makefile', 'SSLINCLUDE=/usr/include/openssl', 'SSLINCLUDE=' . BUILD_INCLUDE_PATH);
FileSystem::replaceFileStr($this->source_dir . '/Makefile', 'SSLLIB=/usr/lib', 'SSLLIB=' . BUILD_LIB_PATH);
return true;
}
/**
* @throws RuntimeException
*/
protected function build(): void
{
if ($this->builder->getLib('openssl')) {
$ssl_options = 'SPECIALAUTHENTICATORS=ssl SSLTYPE=unix.nopwd SSLINCLUDE=' . BUILD_INCLUDE_PATH . ' SSLLIB=' . BUILD_LIB_PATH;
} else {
$ssl_options = 'SSLTYPE=none';
}
shell()->cd($this->source_dir)
->exec('make clean')
->exec('touch ip6')
->exec(
"yes | make slx {$ssl_options}"
);
try {
shell()
->exec("cp -rf {$this->source_dir}/c-client/c-client.a " . BUILD_LIB_PATH . '/libc-client.a')
->exec("cp -rf {$this->source_dir}/c-client/*.c " . BUILD_LIB_PATH . '/')
->exec("cp -rf {$this->source_dir}/c-client/*.h " . BUILD_INCLUDE_PATH . '/')
->exec("cp -rf {$this->source_dir}/src/osdep/unix/*.h " . BUILD_INCLUDE_PATH . '/');
} catch (\Throwable) {
// last command throws an exception, no idea why since it works
}
}
}

View File

@@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace SPC\builder\linux\library;
class tidy extends LinuxLibraryBase
{
use \SPC\builder\unix\library\tidy;
public const NAME = 'tidy';
}

View File

@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
namespace SPC\builder\macos\library;
use SPC\exception\FileSystemException;
use SPC\exception\RuntimeException;
use SPC\store\FileSystem;
use SPC\store\SourcePatcher;
class imap extends MacOSLibraryBase
{
public const NAME = 'imap';
/**
* @throws FileSystemException
* @throws RuntimeException
*/
public function patchBeforeBuild(): bool
{
$cc = getenv('CC') ?: 'clang';
SourcePatcher::patchFile('0001_imap_macos.patch', $this->source_dir);
// FileSystem::replaceFileStr($this->source_dir . '/Makefile', '-DMAC_OSX_KLUDGE=1', '');
FileSystem::replaceFileStr($this->source_dir . '/src/osdep/unix/Makefile', 'CC=cc', "CC={$cc}");
/* FileSystem::replaceFileStr($this->source_dir . '/src/osdep/unix/Makefile', '-lcrypto -lz', '-lcrypto');
FileSystem::replaceFileStr($this->source_dir . '/src/osdep/unix/Makefile', '-lcrypto', '-lcrypto -lz');
FileSystem::replaceFileStr(
$this->source_dir . '/src/osdep/unix/ssl_unix.c',
"#include <x509v3.h>\n#include <ssl.h>",
"#include <ssl.h>\n#include <x509v3.h>"
);
// SourcePatcher::patchFile('1006_openssl1.1_autoverify.patch', $this->source_dir);
SourcePatcher::patchFile('2014_openssl1.1.1_sni.patch', $this->source_dir); */
FileSystem::replaceFileStr($this->source_dir . '/Makefile', 'SSLINCLUDE=/usr/include/openssl', 'SSLINCLUDE=' . BUILD_INCLUDE_PATH);
FileSystem::replaceFileStr($this->source_dir . '/Makefile', 'SSLLIB=/usr/lib', 'SSLLIB=' . BUILD_LIB_PATH);
return true;
}
/**
* @throws RuntimeException
*/
protected function build(): void
{
if ($this->builder->getLib('openssl')) {
$ssl_options = 'SPECIALAUTHENTICATORS=ssl SSLTYPE=unix.nopwd SSLINCLUDE=' . BUILD_INCLUDE_PATH . ' SSLLIB=' . BUILD_LIB_PATH;
} else {
$ssl_options = 'SSLTYPE=none';
}
shell()->cd($this->source_dir)
->exec('make clean')
->exec('touch ip6')
->exec(
"yes | EXTRACFLAGS='-Wimplicit-function-declaration -include $(xcrun --show-sdk-path)/usr/include/poll.h -include $(xcrun --show-sdk-path)/usr/include/time.h -include $(xcrun --show-sdk-path)/usr/include/utime.h' make osx {$ssl_options}"
);
try {
shell()
->exec("cp -rf {$this->source_dir}/c-client/c-client.a " . BUILD_LIB_PATH . '/libc-client.a')
->exec("cp -rf {$this->source_dir}/c-client/*.c " . BUILD_LIB_PATH . '/')
->exec("cp -rf {$this->source_dir}/c-client/*.h " . BUILD_INCLUDE_PATH . '/')
->exec("cp -rf {$this->source_dir}/src/osdep/unix/*.h " . BUILD_INCLUDE_PATH . '/');
} catch (\Throwable) {
// last command throws an exception, no idea why since it works
}
}
}

View File

@@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace SPC\builder\macos\library;
class tidy extends MacOSLibraryBase
{
use \SPC\builder\unix\library\tidy;
public const NAME = 'tidy';
}

View File

@@ -26,6 +26,7 @@ trait freetype
$suggested .= ' ';
shell()->cd($this->source_dir)
->exec('sh autogen.sh')
->exec(
'./configure ' .
'--enable-static --disable-shared --without-harfbuzz --prefix= ' .

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace SPC\builder\unix\library;
use SPC\builder\linux\library\LinuxLibraryBase;
use SPC\builder\macos\library\MacOSLibraryBase;
use SPC\exception\FileSystemException;
use SPC\exception\RuntimeException;
use SPC\store\FileSystem;
@@ -39,8 +40,12 @@ trait imagemagick
}
$ldflags = $this instanceof LinuxLibraryBase ? ('LDFLAGS="-static" ') : '';
// libxml iconv patch
$required_libs .= $this instanceof MacOSLibraryBase ? (' -liconv') : '';
shell()->cd($this->source_dir)
->exec(
'PKG_CONFIG="$PKG_CONFIG --static" ' .
$ldflags .
"LIBS='{$required_libs}' " .
'./configure ' .

View File

@@ -15,6 +15,8 @@ trait ldap
$alt .= $this->builder->getLib('gmp') ? '--with-mp=gmp ' : '';
// libsodium support
$alt .= $this->builder->getLib('libsodium') ? '--with-argon2=libsodium ' : '';
f_putenv('PKG_CONFIG=' . BUILD_ROOT_PATH . '/bin/pkg-config');
f_putenv('PKG_CONFIG_PATH=' . BUILD_LIB_PATH . '/pkgconfig');
shell()->cd($this->source_dir)
->exec(
$this->builder->makeAutoconfFlags(AUTOCONF_LDFLAGS | AUTOCONF_CPPFLAGS) .

View File

@@ -20,17 +20,22 @@ trait postgresql
{
$builddir = BUILD_ROOT_PATH;
$envs = '';
$packages = 'openssl zlib readline libxml-2.0 zlib';
$packages = 'zlib openssl readline libxml-2.0';
$optional_packages = [
'zstd' => 'libzstd',
'ldap' => 'ldap',
'libpam' => 'libpam',
// 'ldap' => 'ldap',
'libxslt' => 'libxslt',
'icu' => 'icu-i18n',
];
f_putenv('PKG_CONFIG=' . BUILD_ROOT_PATH . '/bin/pkg-config');
f_putenv('PKG_CONFIG_PATH=' . BUILD_LIB_PATH . '/pkgconfig');
foreach ($optional_packages as $lib => $pkg) {
if ($this->getBuilder()->getLib($lib)) {
$packages .= ' ' . $pkg;
$output = shell()->execWithResult("pkg-config --static {$pkg}");
logger()->info(var_export($output[1], true));
}
}
@@ -59,8 +64,8 @@ trait postgresql
# 有静态链接配置 参考文件: src/interfaces/libpq/Makefile
shell()->cd($this->source_dir . '/build')
->exec('sed -i.backup "s/invokes exit\'; exit 1;/invokes exit\';/" ../src/interfaces/libpq/Makefile')
->exec('sed -i.backup "293 s/^/#$/" ../src/Makefile.shlib')
->exec('sed -i.backup "441 s/^/#$/" ../src/Makefile.shlib');
->exec('sed -i.backup "278 s/^/# /" ../src/Makefile.shlib')
->exec('sed -i.backup "402 s/^/# /" ../src/Makefile.shlib');
// configure
shell()->cd($this->source_dir . '/build')
@@ -73,25 +78,24 @@ trait postgresql
'--with-readline ' .
'--with-libxml ' .
($this->builder->getLib('icu') ? '--with-icu ' : '--without-icu ') .
($this->builder->getLib('ldap') ? '--with-ldap ' : '--without-ldap ') .
($this->builder->getLib('libpam') ? '--with-pam ' : '--without-pam ') .
'--without-ldap ' .
($this->builder->getLib('libxslt') ? '--with-libxslt ' : '--without-libxslt ') .
($this->builder->getLib('zstd') ? '--with-zstd ' : '--without-zstd ') .
'--without-lz4 ' .
'--without-perl ' .
'--without-python ' .
'--without-pam ' .
'--without-bonjour ' .
'--without-tcl '
);
// ($this->builder->getLib('ldap') ? '--with-ldap ' : '--without-ldap ') .
// build
shell()->cd($this->source_dir . '/build')
->exec($envs . ' make -C src/bin/pg_config install')
->exec($envs . ' make -C src/include install')
->exec($envs . ' make -C src/common install')
->exec($envs . ' make -C src/backend/port install')
->exec($envs . ' make -C src/port install')
->exec($envs . ' make -C src/backend/libpq install')
->exec($envs . ' make -C src/interfaces/libpq install');
// remove dynamic libs

View File

@@ -0,0 +1,32 @@
<?php
declare(strict_types=1);
namespace SPC\builder\unix\library;
use SPC\exception\FileSystemException;
use SPC\exception\RuntimeException;
use SPC\store\FileSystem;
trait tidy
{
/**
* @throws RuntimeException
* @throws FileSystemException
*/
protected function build(): void
{
FileSystem::resetDir($this->source_dir . '/build-dir');
shell()->cd($this->source_dir . '/build-dir')
->exec(
'cmake ' .
"{$this->builder->makeCmakeArgs()} " .
'-DBUILD_SHARED_LIB=OFF ' .
'-DSUPPORT_CONSOLE_APP=OFF ' .
'..'
)
->exec("cmake --build . -j {$this->builder->concurrency}")
->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
$this->patchPkgconfPrefix(['tidy.pc']);
}
}

View File

@@ -16,7 +16,7 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use ZM\Logger\ConsoleColor;
#[AsCommand('build', 'build CLI binary')]
#[AsCommand('build', 'build PHP')]
class BuildCliCommand extends BuildCommand
{
public function configure(): void
@@ -33,6 +33,8 @@ class BuildCliCommand extends BuildCommand
$this->addOption('disable-opcache-jit', null, null, 'disable opcache jit');
$this->addOption('with-hardcoded-ini', 'I', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Patch PHP source code, inject hardcoded INI');
$this->addOption('with-micro-fake-cli', null, null, 'Enable phpmicro fake cli');
$this->addOption('with-suggested-libs', 'L', null, 'Build with suggested libs for selected exts and libs');
$this->addOption('with-suggested-exts', 'E', null, 'Build with suggested extensions for selected exts');
}
public function handle(): int
@@ -42,12 +44,9 @@ class BuildCliCommand extends BuildCommand
// transform string to array
$extensions = array_map('trim', array_filter(explode(',', $this->getArgument('extensions'))));
$rule = BUILD_TARGET_NONE;
$rule |= ($this->getOption('build-cli') ? BUILD_TARGET_CLI : BUILD_TARGET_NONE);
$rule |= ($this->getOption('build-micro') ? BUILD_TARGET_MICRO : BUILD_TARGET_NONE);
$rule |= ($this->getOption('build-fpm') ? BUILD_TARGET_FPM : BUILD_TARGET_NONE);
$rule |= ($this->getOption('build-embed') ? BUILD_TARGET_EMBED : BUILD_TARGET_NONE);
$rule |= ($this->getOption('build-all') ? BUILD_TARGET_ALL : BUILD_TARGET_NONE);
// parse rule with options
$rule = $this->parseRules();
if ($rule === BUILD_TARGET_NONE) {
$this->output->writeln('<error>Please add at least one build target!</error>');
$this->output->writeln("<comment>\t--build-cli\tBuild php-cli SAPI</comment>");
@@ -62,16 +61,27 @@ class BuildCliCommand extends BuildCommand
$builder = BuilderProvider::makeBuilderByInput($this->input);
// calculate dependencies
[$extensions, $libraries, $not_included] = DependencyUtil::getExtLibsByDeps($extensions, $libraries);
/* @phpstan-ignore-next-line */
logger()->info('Build target: ' . ConsoleColor::yellow($builder->getBuildTypeName($rule)));
/* @phpstan-ignore-next-line */
logger()->info('Enabled extensions: ' . ConsoleColor::yellow(implode(', ', $extensions)));
/* @phpstan-ignore-next-line */
logger()->info('Required libraries: ' . ConsoleColor::yellow(implode(', ', $libraries)));
if (!empty($not_included)) {
logger()->warning('some extensions will be enabled due to dependencies: ' . implode(',', $not_included));
// print info
$indent_texts = [
'Build OS' => PHP_OS_FAMILY . ' (' . php_uname('m') . ')',
'Build SAPI' => $builder->getBuildTypeName($rule),
'Extensions (' . count($extensions) . ')' => implode(', ', $extensions),
'Libraries (' . count($libraries) . ')' => implode(', ', $libraries),
'Strip Binaries' => $builder->getOption('no-strip') ? 'no' : 'yes',
'Enable ZTS' => $builder->getOption('enable-zts') ? 'yes' : 'no',
];
if (!empty($this->input->getOption('with-hardcoded-ini'))) {
$indent_texts['Hardcoded INI'] = $this->input->getOption('with-hardcoded-ini');
}
$this->printFormatInfo($indent_texts);
if (!empty($not_included)) {
logger()->warning('Some extensions will be enabled due to dependencies: ' . implode(',', $not_included));
}
logger()->info('Build will start after 2s ...');
sleep(2);
if ($this->input->getOption('with-clean')) {
logger()->info('Cleaning source dir...');
FileSystem::removeDir(SOURCE_PATH);
@@ -140,4 +150,41 @@ class BuildCliCommand extends BuildCommand
return static::FAILURE;
}
}
/**
* Parse build options to rule int.
*/
private function parseRules(): int
{
$rule = BUILD_TARGET_NONE;
$rule |= ($this->getOption('build-cli') ? BUILD_TARGET_CLI : BUILD_TARGET_NONE);
$rule |= ($this->getOption('build-micro') ? BUILD_TARGET_MICRO : BUILD_TARGET_NONE);
$rule |= ($this->getOption('build-fpm') ? BUILD_TARGET_FPM : BUILD_TARGET_NONE);
$rule |= ($this->getOption('build-embed') ? BUILD_TARGET_EMBED : BUILD_TARGET_NONE);
$rule |= ($this->getOption('build-all') ? BUILD_TARGET_ALL : BUILD_TARGET_NONE);
return $rule;
}
private function printFormatInfo(array $indent_texts): void
{
// calculate space count for every line
$maxlen = 0;
foreach ($indent_texts as $k => $v) {
$maxlen = max(strlen($k), $maxlen);
}
foreach ($indent_texts as $k => $v) {
if (is_string($v)) {
/* @phpstan-ignore-next-line */
logger()->info($k . ': ' . str_pad('', $maxlen - strlen($k)) . ConsoleColor::yellow($v));
} elseif (is_array($v) && !is_assoc_array($v)) {
$first = array_shift($v);
/* @phpstan-ignore-next-line */
logger()->info($k . ': ' . str_pad('', $maxlen - strlen($k)) . ConsoleColor::yellow($first));
foreach ($v as $vs) {
/* @phpstan-ignore-next-line */
logger()->info(str_pad('', $maxlen + 2) . ConsoleColor::yellow($vs));
}
}
}
}
}

View File

@@ -12,6 +12,7 @@ use SPC\store\Config;
use SPC\util\DependencyUtil;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Style\SymfonyStyle;
use function Laravel\Prompts\table;
@@ -22,6 +23,13 @@ class AllExtCommand extends BaseCommand
public function configure(): void
{
$this->addArgument('extensions', InputArgument::OPTIONAL, 'List of extensions that will be displayed, comma separated');
$this->addOption(
'columns',
null,
InputOption::VALUE_REQUIRED,
'List of columns that will be displayed, comma separated (lib-depends, lib-suggests, ext-depends, ext-suggests, unix-only)',
'lib-depends,lib-suggests,ext-depends,ext-suggests,unix-only'
);
}
/**
@@ -32,6 +40,16 @@ class AllExtCommand extends BaseCommand
public function handle(): int
{
$extensions = array_map('trim', array_filter(explode(',', $this->getArgument('extensions') ?? '')));
$columns = array_map('trim', array_filter(explode(',', $this->getOption('columns'))));
foreach ($columns as $column) {
if (!in_array($column, ['lib-depends', 'lib-suggests', 'ext-depends', 'ext-suggests', 'unix-only', 'type'])) {
$this->output->writeln('<error>Column name [' . $column . '] is not valid.</error>');
$this->output->writeln('<error>Available column name: lib-depends, lib-suggests, ext-depends, ext-suggests, unix-only, type</error>');
return static::FAILURE;
}
}
array_unshift($columns, 'name');
$style = new SymfonyStyle($this->input, $this->output);
$style->writeln($extensions ? 'Available extensions:' : 'Extensions:');
@@ -51,23 +69,26 @@ class AllExtCommand extends BaseCommand
$lib_suggests = Config::getExt($extension, 'lib-suggests', []);
$ext_suggests = Config::getExt($extension, 'ext-suggests', []);
$data[] = [
$extension,
implode(', ', $libraries),
implode(', ', $lib_suggests),
implode(',', $not_included),
implode(', ', $ext_suggests),
Config::getExt($extension, 'unix-only', false) ? 'true' : 'false',
];
$row = [];
foreach ($columns as $column) {
$row[] = match ($column) {
'name' => $extension,
'type' => Config::getExt($extension, 'type'),
'lib-depends' => implode(', ', $libraries),
'lib-suggests' => implode(', ', $lib_suggests),
'ext-depends' => implode(',', $not_included),
'ext-suggests' => implode(', ', $ext_suggests),
'unix-only' => Config::getExt($extension, 'unix-only', false) ? 'true' : 'false',
default => '',
};
}
$data[] = $row;
}
if ($data === []) {
$style->warning('Unknown extension selected: ' . implode(',', $extensions));
} else {
table(
['Extension', 'lib-depends', 'lib-suggests', 'ext-depends', 'ext-suggests', 'unix-only'],
$data
);
table($columns, $data);
}
return static::SUCCESS;

View File

@@ -21,6 +21,7 @@ class LinuxToolCheckList
'tar', 'unzip', 'gzip',
'bzip2', 'cmake', 'gcc',
'g++', 'patch', 'binutils-gold',
'libtoolize',
];
public const TOOLS_DEBIAN = [
@@ -28,7 +29,7 @@ class LinuxToolCheckList
'git', 'autoconf', 'automake',
'tar', 'unzip', 'gzip',
'bzip2', 'cmake', 'patch',
'xz',
'xz', 'libtoolize',
];
public const TOOLS_RHEL = [
@@ -36,7 +37,7 @@ class LinuxToolCheckList
'git', 'autoconf', 'automake',
'tar', 'unzip', 'gzip', 'gcc',
'bzip2', 'cmake', 'patch',
'xz', 'wget', // to get musl
'xz',
];
/** @noinspection PhpUnused */
@@ -47,8 +48,7 @@ class LinuxToolCheckList
$required = match ($distro['dist']) {
'alpine' => self::TOOLS_ALPINE,
'almalinux' => self::TOOLS_RHEL,
'rhel' => self::TOOLS_RHEL,
'redhat' => self::TOOLS_RHEL,
default => self::TOOLS_DEBIAN,
};
$missing = [];
@@ -61,8 +61,7 @@ class LinuxToolCheckList
return match ($distro['dist']) {
'ubuntu',
'alpine',
'rhel',
'almalinux',
'redhat',
'debian' => CheckResult::fail(implode(', ', $missing) . ' not installed on your system', 'install-linux-tools', [$distro, $missing]),
default => CheckResult::fail(implode(', ', $missing) . ' not installed on your system'),
};
@@ -74,11 +73,10 @@ class LinuxToolCheckList
#[AsCheckItem('if necessary packages are installed', limit_os: 'Linux')]
public function checkSystemOSPackages(): ?CheckResult
{
$distro = SystemUtil::getOSRelease();
if ($distro['dist'] === 'alpine') {
if (SystemUtil::isMuslDist()) {
// check linux-headers installation
if (!file_exists('/usr/include/linux/mman.h')) {
return CheckResult::fail('linux-headers not installed on your system', 'install-linux-tools', [$distro, ['linux-headers']]);
return CheckResult::fail('linux-headers not installed on your system', 'install-linux-tools', [SystemUtil::getOSRelease(), ['linux-headers']]);
}
}
return CheckResult::ok();
@@ -94,8 +92,7 @@ class LinuxToolCheckList
$install_cmd = match ($distro['dist']) {
'ubuntu', 'debian' => 'apt-get install -y',
'alpine' => 'apk add',
'rhel' => 'dnf install -y',
'almalinux' => 'dnf install -y',
'redhat' => 'dnf install -y',
default => throw new RuntimeException('Current linux distro does not have an auto-install script for musl packages yet.'),
};
$prefix = '';
@@ -104,8 +101,10 @@ class LinuxToolCheckList
logger()->warning('Current user is not root, using sudo for running command');
}
try {
$is_rhel = in_array($distro['dist'], ['rhel', 'almalinux']);
$to_install = $is_rhel ? $missing : str_replace('xz', 'xz-utils', $missing);
$is_debian = in_array($distro['dist'], ['debian', 'ubuntu']);
$to_install = $is_debian ? str_replace('xz', 'xz-utils', $missing) : $missing;
// debian, alpine libtool -> libtoolize
$to_install = str_replace('libtoolize', 'libtool', $to_install);
shell(true)->exec($prefix . $install_cmd . ' ' . implode(' ', $to_install));
} catch (RuntimeException) {
return false;

View File

@@ -25,6 +25,7 @@ class MacOSToolCheckList
'autoconf',
'automake',
'tar',
'libtool',
'unzip',
'xz',
'gzip',

View File

@@ -134,6 +134,12 @@ class SourcePatcher
$patch_file = ROOT_DIR . "/src/globals/patch/{$patch_name}";
$patch_str = str_replace('/', DIRECTORY_SEPARATOR, $patch_file);
// copy patch from phar
if (\Phar::running() !== '') {
file_put_contents(SOURCE_PATH . '/' . $patch_name, file_get_contents($patch_file));
$patch_str = str_replace('/', DIRECTORY_SEPARATOR, SOURCE_PATH . '/' . $patch_name);
}
f_passthru(
'cd ' . $cwd . ' && ' .
(PHP_OS_FAMILY === 'Windows' ? 'type' : 'cat') . ' ' . $patch_str . ' | patch -p1 ' . ($reverse ? '-R' : '')

View File

@@ -0,0 +1,220 @@
From 5ab3bd7fa858eec0626a9dd0117ca3b050ef4660 Mon Sep 17 00:00:00 2001
From: crazywhalecc <jesse2061@outlook.com>
Date: Mon, 13 Nov 2023 00:00:52 +0800
Subject: [PATCH] make macOS static compile happy
---
src/c-client/netmsg.c | 1 +
src/c-client/nntp.c | 1 +
src/osdep/amiga/dummy.c | 1 +
src/osdep/amiga/mbx.c | 1 +
src/osdep/amiga/mh.c | 1 +
src/osdep/amiga/mtx.c | 1 +
src/osdep/amiga/unix.c | 1 +
src/osdep/unix/dummy.c | 1 +
src/osdep/unix/mbx.c | 1 +
src/osdep/unix/mh.c | 1 +
src/osdep/unix/mmdf.c | 1 +
src/osdep/unix/mtx.c | 1 +
src/osdep/unix/mx.c | 1 +
src/osdep/unix/tcp_unix.c | 1 +
src/osdep/unix/tenex.c | 2 ++
src/osdep/unix/unix.c | 1 +
16 files changed, 17 insertions(+)
diff --git a/src/c-client/netmsg.c b/src/c-client/netmsg.c
index 187e4eb..f316d0b 100644
--- a/src/c-client/netmsg.c
+++ b/src/c-client/netmsg.c
@@ -29,6 +29,7 @@
#include <stdio.h>
#include <errno.h>
+#include <time.h>
extern int errno; /* just in case */
#include "c-client.h"
#include "netmsg.h"
diff --git a/src/c-client/nntp.c b/src/c-client/nntp.c
index fe90edb..b2f7536 100644
--- a/src/c-client/nntp.c
+++ b/src/c-client/nntp.c
@@ -29,6 +29,7 @@
#include <ctype.h>
#include <stdio.h>
+#include <time.h>
#include "c-client.h"
#include "newsrc.h"
#include "netmsg.h"
diff --git a/src/osdep/amiga/dummy.c b/src/osdep/amiga/dummy.c
index b003a0b..2c65824 100644
--- a/src/osdep/amiga/dummy.c
+++ b/src/osdep/amiga/dummy.c
@@ -35,6 +35,7 @@ extern int errno; /* just in case */
#include "osdep.h"
#include <pwd.h>
#include <sys/stat.h>
+#include <time.h>
#include "dummy.h"
#include "misc.h"
diff --git a/src/osdep/amiga/mbx.c b/src/osdep/amiga/mbx.c
index 1ece5d8..2495965 100644
--- a/src/osdep/amiga/mbx.c
+++ b/src/osdep/amiga/mbx.c
@@ -43,6 +43,7 @@ extern int errno; /* just in case */
#include <pwd.h>
#include <sys/stat.h>
#include <sys/time.h>
+#include <utime.h>
#include "misc.h"
#include "dummy.h"
#include "fdstring.h"
diff --git a/src/osdep/amiga/mh.c b/src/osdep/amiga/mh.c
index 0226b7a..e7c907a 100644
--- a/src/osdep/amiga/mh.c
+++ b/src/osdep/amiga/mh.c
@@ -36,6 +36,7 @@ extern int errno; /* just in case */
#include <pwd.h>
#include <sys/stat.h>
#include <sys/time.h>
+#include <utime.h>
#include "misc.h"
#include "dummy.h"
#include "fdstring.h"
diff --git a/src/osdep/amiga/mtx.c b/src/osdep/amiga/mtx.c
index 8e6f76e..ca7b368 100644
--- a/src/osdep/amiga/mtx.c
+++ b/src/osdep/amiga/mtx.c
@@ -43,6 +43,7 @@ extern int errno; /* just in case */
#include <pwd.h>
#include <sys/stat.h>
#include <sys/time.h>
+#include <utime.h>
#include "misc.h"
#include "dummy.h"
#include "fdstring.h"
diff --git a/src/osdep/amiga/unix.c b/src/osdep/amiga/unix.c
index be3c437..c755fe7 100644
--- a/src/osdep/amiga/unix.c
+++ b/src/osdep/amiga/unix.c
@@ -46,6 +46,7 @@ extern int errno; /* just in case */
#include "osdep.h"
#include <time.h>
#include <sys/stat.h>
+#include <utime.h>
#include "unix.h"
#include "pseudo.h"
#include "fdstring.h"
diff --git a/src/osdep/unix/dummy.c b/src/osdep/unix/dummy.c
index b003a0b..2c65824 100644
--- a/src/osdep/unix/dummy.c
+++ b/src/osdep/unix/dummy.c
@@ -35,6 +35,7 @@ extern int errno; /* just in case */
#include "osdep.h"
#include <pwd.h>
#include <sys/stat.h>
+#include <time.h>
#include "dummy.h"
#include "misc.h"
diff --git a/src/osdep/unix/mbx.c b/src/osdep/unix/mbx.c
index 1ece5d8..2495965 100644
--- a/src/osdep/unix/mbx.c
+++ b/src/osdep/unix/mbx.c
@@ -43,6 +43,7 @@ extern int errno; /* just in case */
#include <pwd.h>
#include <sys/stat.h>
#include <sys/time.h>
+#include <utime.h>
#include "misc.h"
#include "dummy.h"
#include "fdstring.h"
diff --git a/src/osdep/unix/mh.c b/src/osdep/unix/mh.c
index 0226b7a..e7c907a 100644
--- a/src/osdep/unix/mh.c
+++ b/src/osdep/unix/mh.c
@@ -36,6 +36,7 @@ extern int errno; /* just in case */
#include <pwd.h>
#include <sys/stat.h>
#include <sys/time.h>
+#include <utime.h>
#include "misc.h"
#include "dummy.h"
#include "fdstring.h"
diff --git a/src/osdep/unix/mmdf.c b/src/osdep/unix/mmdf.c
index e962434..8cc9fae 100644
--- a/src/osdep/unix/mmdf.c
+++ b/src/osdep/unix/mmdf.c
@@ -34,6 +34,7 @@ extern int errno; /* just in case */
#include "osdep.h"
#include <time.h>
#include <sys/stat.h>
+#include <utime.h>
#include "pseudo.h"
#include "fdstring.h"
#include "misc.h"
diff --git a/src/osdep/unix/mtx.c b/src/osdep/unix/mtx.c
index 8e6f76e..ca7b368 100644
--- a/src/osdep/unix/mtx.c
+++ b/src/osdep/unix/mtx.c
@@ -43,6 +43,7 @@ extern int errno; /* just in case */
#include <pwd.h>
#include <sys/stat.h>
#include <sys/time.h>
+#include <utime.h>
#include "misc.h"
#include "dummy.h"
#include "fdstring.h"
diff --git a/src/osdep/unix/mx.c b/src/osdep/unix/mx.c
index 4549527..9d444c9 100644
--- a/src/osdep/unix/mx.c
+++ b/src/osdep/unix/mx.c
@@ -36,6 +36,7 @@ extern int errno; /* just in case */
#include <pwd.h>
#include <sys/stat.h>
#include <sys/time.h>
+#include <utime.h>
#include "misc.h"
#include "dummy.h"
#include "fdstring.h"
diff --git a/src/osdep/unix/tcp_unix.c b/src/osdep/unix/tcp_unix.c
index 5bad706..5d6cd03 100644
--- a/src/osdep/unix/tcp_unix.c
+++ b/src/osdep/unix/tcp_unix.c
@@ -27,6 +27,7 @@
*/
#include "ip_unix.c"
+#include <poll.h>
#undef write /* don't use redefined write() */
diff --git a/src/osdep/unix/tenex.c b/src/osdep/unix/tenex.c
index eee61fb..61760f0 100644
--- a/src/osdep/unix/tenex.c
+++ b/src/osdep/unix/tenex.c
@@ -46,6 +46,8 @@ extern int errno; /* just in case */
#include "mail.h"
#include "osdep.h"
#include <sys/stat.h>
+#include <time.h>
+#include <utime.h>
#include "misc.h"
#include "dummy.h"
diff --git a/src/osdep/unix/unix.c b/src/osdep/unix/unix.c
index be3c437..c755fe7 100644
--- a/src/osdep/unix/unix.c
+++ b/src/osdep/unix/unix.c
@@ -46,6 +46,7 @@ extern int errno; /* just in case */
#include "osdep.h"
#include <time.h>
#include <sys/stat.h>
+#include <utime.h>
#include "unix.h"
#include "pseudo.h"
#include "fdstring.h"
--
2.39.3 (Apple Git-145)

View File

@@ -0,0 +1,8 @@
<?php
declare(strict_types=1);
# If you want to test new extensions here, just modify it.
$extensions = 'apcu,bcmath,bz2,calendar,ctype,curl,dba,dom,event,exif,fileinfo,filter,ftp,gd,gmp,iconv,imagick,imap,intl,ldap,mbregex,mbstring,mysqli,mysqlnd,opcache,openssl,pcntl,pdo,pdo_mysql,pdo_pgsql,pdo_sqlite,pgsql,phar,posix,protobuf,readline,redis,session,shmop,simplexml,soap,sockets,sodium,sqlite3,swoole,sysvmsg,sysvsem,sysvshm,tokenizer,xml,xmlreader,xmlwriter,xsl,zip,zlib';
echo $extensions;