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
2 changes: 1 addition & 1 deletion README-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ If you are familiar with this project, you are also welcome to initiate a pull r

The basic principles for contributing are as follows:

- This project uses php-cs-fixer and phpstan as code formatting tools. Before contributing, please run `composer analyze` and `composer cs-fix` on the updated code.
- This project uses php-cs-fixer and phpstan as code formatting tools. Before contributing, please run `composer analyse` and `composer cs-fix` on the updated code.
- If other open source libraries are involved, the corresponding licenses should be provided.
Also, configuration files should be sorted using the command `sort-config` after modification.
For more information about sorting commands, see the documentation.
Expand Down
134 changes: 67 additions & 67 deletions composer.lock

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion config/ext.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,16 @@
},
"ldap": {
"type": "builtin",
"arg-type": "with",
"arg-type": "with-prefix",
"lib-depends": [
"ldap"
],
"lib-suggests": [
"gmp",
"libsodium"
],
"ext-suggests": [
"openssl"
]
},
"mbregex": {
Expand Down Expand Up @@ -229,6 +236,9 @@
"arg-type": "with",
"lib-depends": [
"openssl"
],
"ext-depends": [
"zlib"
]
},
"pcntl": {
Expand Down
12 changes: 12 additions & 0 deletions config/lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@
"libxml2"
]
},
"ldap": {
"source": "ldap",
"static-libs-unix": [
"liblber.a",
"libldap.a"
],
"lib-suggests": [
"openssl",
"gmp",
"libsodium"
]
},
"libavif": {
"source": "libavif",
"static-libs-unix": [
Expand Down
9 changes: 9 additions & 0 deletions config/source.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@
"path": "LICENSE"
}
},
"ldap": {
"type": "filelist",
"url": "https://www.openldap.org/software/download/OpenLDAP/openldap-release/",
"regex": "/href=\"(?<file>openldap-(?<version>[^\"]+)\\.tgz)\"/",
"license": {
"type": "file",
"path": "LICENSE"
}
},
"libavif": {
"type": "ghtar",
"repo": "AOMediaCodec/libavif",
Expand Down
2 changes: 1 addition & 1 deletion src/SPC/builder/linux/LinuxBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function __construct(array $options = [])

// ---------- set necessary compile environments ----------
// set libc
$this->libc = 'musl'; // SystemUtil::selectLibc($this->cc);
$this->libc = $this->getOption('cc', 'gcc') === 'musl-gcc' ? 'musl_wrapper' : 'musl'; // SystemUtil::selectLibc($this->cc);
// concurrency
$this->concurrency = SystemUtil::getCpuCount();
// cflags
Expand Down
2 changes: 1 addition & 1 deletion src/SPC/builder/linux/SystemUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public static function checkCCFlags(array $flags, string $cc): array

public static function checkCCFlag(string $flag, string $cc): string
{
[$ret] = shell()->execWithResult("echo | {$cc} -E -x c - {$flag}");
[$ret] = shell()->execWithResult("echo | {$cc} -E -x c - {$flag} 2>/dev/null");
if ($ret != 0) {
return '';
}
Expand Down
12 changes: 12 additions & 0 deletions src/SPC/builder/linux/library/ldap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace SPC\builder\linux\library;

class ldap extends LinuxLibraryBase
{
use \SPC\builder\unix\library\ldap;

public const NAME = 'ldap';
}
12 changes: 12 additions & 0 deletions src/SPC/builder/macos/library/ldap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace SPC\builder\macos\library;

class ldap extends MacOSLibraryBase
{
use \SPC\builder\unix\library\ldap;

public const NAME = 'ldap';
}
22 changes: 22 additions & 0 deletions src/SPC/builder/traits/UnixBuilderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,26 @@ public function makeCmakeArgs(): string
"-DCMAKE_INSTALL_INCLUDEDIR={$include} " .
"-DCMAKE_TOOLCHAIN_FILE={$this->cmake_toolchain_file}";
}

/**
* Generate configure flags
*/
public function makeAutoconfFlags(int $flag = AUTOCONF_ALL): string
{
$extra = '';
// TODO: add auto pkg-config support
if (($flag & AUTOCONF_LIBS) === AUTOCONF_LIBS) {
$extra .= 'LIBS="' . BUILD_LIB_PATH . '" ';
}
if (($flag & AUTOCONF_CFLAGS) === AUTOCONF_CFLAGS) {
$extra .= 'CFLAGS="-I' . BUILD_INCLUDE_PATH . '" ';
}
if (($flag & AUTOCONF_CPPFLAGS) === AUTOCONF_CPPFLAGS) {
$extra .= 'CPPFLAGS="-I' . BUILD_INCLUDE_PATH . '" ';
}
if (($flag & AUTOCONF_LDFLAGS) === AUTOCONF_LDFLAGS) {
$extra .= 'LDFLAGS="-L' . BUILD_LIB_PATH . '" ';
}
return $extra;
}
}
4 changes: 2 additions & 2 deletions src/SPC/builder/unix/library/curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ protected function build(): void
} else {
$extra .= '-DUSE_NGHTTP2=OFF ';
}
// TODO: ldap is not supported yet
$extra .= '-DCURL_DISABLE_LDAP=ON ';
// lib:ldap
$extra .= $this->builder->getLib('ldap') ? '-DCURL_DISABLE_LDAP=OFF ' : '-DCURL_DISABLE_LDAP=ON ';
// lib:zstd
$extra .= $this->builder->getLib('zstd') ? '-DCURL_ZSTD=ON ' : '-DCURL_ZSTD=OFF ';
// lib:idn2
Expand Down
39 changes: 39 additions & 0 deletions src/SPC/builder/unix/library/ldap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace SPC\builder\unix\library;

trait ldap
{
protected function build(): void
{
$alt = '';
// openssl support
$alt .= $this->builder->getLib('openssl') && $this->builder->getExt('zlib') ? '--with-tls=openssl ' : '';
// gmp support
$alt .= $this->builder->getLib('gmp') ? '--with-mp=gmp ' : '';
// libsodium support
$alt .= $this->builder->getLib('libsodium') ? '--with-argon2=libsodium ' : '';
shell()->cd($this->source_dir)
->exec(
$this->builder->configure_env . ' ' .
$this->builder->makeAutoconfFlags(AUTOCONF_LDFLAGS | AUTOCONF_CPPFLAGS) .
' ./configure ' .
'--enable-static ' .
'--disable-shared ' .
'--disable-slapd ' .
'--disable-slurpd ' .
'--without-systemd ' .
'--without-cyrus-sasl ' .
$alt .
'--prefix='
)
->exec('make clean')
// remove tests and doc to prevent compile failed with error: soelim not found
->exec('sed -i -e "s/SUBDIRS= include libraries clients servers tests doc/SUBDIRS= include libraries clients servers/g" Makefile')
->exec("make -j{$this->builder->concurrency}")
->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
$this->patchPkgconfPrefix(['ldap.pc', 'lber.pc']);
}
}
3 changes: 1 addition & 2 deletions src/SPC/builder/unix/library/postgresql.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,14 @@ protected function build(): void
'--with-ssl=openssl ' .
'--with-readline ' .
'--with-libxml ' .
($this->builder->getLib('ldap') ? '--with-ldap ' : '--without-ldap ') .
($this->builder->getLib('icu') ? '--with-icu ' : '--without-icu ') .
'--without-ldap ' .
'--without-libxslt ' .
'--without-lz4 ' .
'--without-zstd ' .
'--without-perl ' .
'--without-python ' .
'--without-pam ' .
'--without-ldap ' .
'--without-bonjour ' .
'--without-tcl '
);
Expand Down
10 changes: 5 additions & 5 deletions src/SPC/command/BuildCliCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ public function handle(): int
$extensions = array_map('trim', array_filter(explode(',', $this->getArgument('extensions'))));

$rule = BUILD_TARGET_NONE;
$rule = $rule | ($this->getOption('build-cli') ? BUILD_TARGET_CLI : BUILD_TARGET_NONE);
$rule = $rule | ($this->getOption('build-micro') ? BUILD_TARGET_MICRO : BUILD_TARGET_NONE);
$rule = $rule | ($this->getOption('build-fpm') ? BUILD_TARGET_FPM : BUILD_TARGET_NONE);
$rule = $rule | ($this->getOption('build-embed') ? BUILD_TARGET_EMBED : BUILD_TARGET_NONE);
$rule = $rule | ($this->getOption('build-all') ? BUILD_TARGET_ALL : 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);
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>");
Expand Down
12 changes: 10 additions & 2 deletions src/SPC/doctor/item/LinuxMuslCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function checkMusl(): ?CheckResult
// non-exist, need to recognize distro
$distro = SystemUtil::getOSRelease();
return match ($distro['dist']) {
'ubuntu', 'alpine', 'debian' => CheckResult::fail('musl-libc is not installed on your system', 'fix-musl', [$distro]),
'ubuntu', 'alpine', 'debian', 'rhel', 'almalinux' => CheckResult::fail('musl-libc is not installed on your system', 'fix-musl', [$distro]),
default => CheckResult::fail('musl-libc is not installed on your system'),
};
}
Expand All @@ -36,10 +36,18 @@ public function checkMusl(): ?CheckResult
#[AsFixItem('fix-musl')]
public function fixMusl(array $distro): bool
{
$rhel_install = 'wget https://musl.libc.org/releases/musl-1.2.4.tar.gz && tar -zxvf musl-1.2.4.tar.gz && \
rm -f musl-1.2.4.tar.gz && cd musl-1.2.4 &&
if [[ ! "$PATH" =~ (^|:)"/usr/local/musl/bin"(:|$) ]]; then echo "export PATH=/usr/local/musl/bin:$PATH" >> ~/.bash_profile
fi && \
./configure --enable-wrapper=gcc && \
make -j && make install && cd .. && rm -rf musl-1.2.4';
$install_cmd = match ($distro['dist']) {
'ubuntu', 'debian' => 'apt-get install musl musl-tools -y',
'alpine' => 'apk add musl musl-utils musl-dev',
default => throw new RuntimeException('Current linux distro is not supported for auto-install musl packages'),
'rhel' => $rhel_install,
'almalinux' => $rhel_install,
default => throw new RuntimeException('Current linux distro does not have an auto-install script for musl packages yet.'),
};
$prefix = '';
if (get_current_user() !== 'root') {
Expand Down
26 changes: 22 additions & 4 deletions src/SPC/doctor/item/LinuxToolCheckList.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,24 @@ class LinuxToolCheckList
'xz',
];

public const TOOLS_RHEL = [
'perl', 'make', 'bison', 'flex',
'git', 'autoconf', 'automake',
'tar', 'unzip', 'gzip', 'gcc',
'bzip2', 'cmake', 'patch',
'xz', 'wget', // to get musl
];

/** @noinspection PhpUnused */
#[AsCheckItem('if necessary tools are installed', limit_os: 'Linux')]
#[AsCheckItem('if necessary tools are installed', limit_os: 'Linux', level: 999)]
public function checkCliTools(): ?CheckResult
{
$distro = SystemUtil::getOSRelease();

$required = match ($distro['dist']) {
'alpine' => self::TOOLS_ALPINE,
'almalinux' => self::TOOLS_RHEL,
'rhel' => self::TOOLS_RHEL,
default => self::TOOLS_DEBIAN,
};
$missing = [];
Expand All @@ -49,7 +59,11 @@ public function checkCliTools(): ?CheckResult
}
if (!empty($missing)) {
return match ($distro['dist']) {
'ubuntu', 'alpine', 'debian' => CheckResult::fail(implode(', ', $missing) . ' not installed on your system', 'install-linux-tools', [$distro, $missing]),
'ubuntu',
'alpine',
'rhel',
'almalinux',
'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'),
};
}
Expand Down Expand Up @@ -80,15 +94,19 @@ public function fixBuildTools(array $distro, array $missing): bool
$install_cmd = match ($distro['dist']) {
'ubuntu', 'debian' => 'apt-get install -y',
'alpine' => 'apk add',
default => throw new RuntimeException('Current linux distro is not supported for auto-install musl packages'),
'rhel' => 'dnf install -y',
'almalinux' => 'dnf install -y',
default => throw new RuntimeException('Current linux distro does not have an auto-install script for musl packages yet.'),
};
$prefix = '';
if (get_current_user() !== 'root') {
$prefix = 'sudo ';
logger()->warning('Current user is not root, using sudo for running command');
}
try {
shell(true)->exec($prefix . $install_cmd . ' ' . implode(' ', str_replace('xz', 'xz-utils', $missing)));
$is_rhel = in_array($distro['dist'], ['rhel', 'almalinux']);
$to_install = $is_rhel ? $missing : str_replace('xz', 'xz-utils', $missing);
shell(true)->exec($prefix . $install_cmd . ' ' . implode(' ', $to_install));
} catch (RuntimeException) {
return false;
}
Expand Down
7 changes: 7 additions & 0 deletions src/globals/defines.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,11 @@
const PKGCONF_PATCH_CUSTOM = 16;
const PKGCONF_PATCH_ALL = 31;

// autoconf flags
const AUTOCONF_LIBS = 1;
const AUTOCONF_CFLAGS = 2;
const AUTOCONF_CPPFLAGS = 4;
const AUTOCONF_LDFLAGS = 8;
const AUTOCONF_ALL = 15;

ConsoleLogger::$date_format = 'H:i:s';