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
7 changes: 4 additions & 3 deletions config/ext.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@
},
"imap": {
"type": "builtin",
"arg-type": "with",
"arg-type": "custom",
"lib-depends": [
"imap"
],
"lib-suggests": [
"kerberos"
"openssl"
]
},
"inotify": {
Expand Down Expand Up @@ -234,7 +234,8 @@
"type": "builtin",
"arg-type": "custom",
"lib-depends": [
"openssl"
"openssl",
"zlib"
],
"ext-depends": [
"zlib"
Expand Down
9 changes: 9 additions & 0 deletions config/lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@
"libxml2"
]
},
"imap": {
"source": "imap",
"static-libs-unix": [
"libc-client.a"
],
"lib-suggests": [
"openssl"
]
},
"ldap": {
"source": "ldap",
"static-libs-unix": [
Expand Down
11 changes: 10 additions & 1 deletion config/source.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@
"path": "LICENSE"
}
},
"imap": {
"type": "git",
"url": "https://github.com/static-php/imap.git",
"rev": "master",
"license": {
"type": "file",
"path": "LICENSE"
}
},
"inotify": {
"type": "url",
"url": "https://pecl.php.net/get/inotify",
Expand Down Expand Up @@ -225,7 +234,7 @@
},
"libpng": {
"type": "git",
"url": "https://git.code.sf.net/p/libpng/code",
"url": "https://github.com/glennrp/libpng.git",
"rev": "libpng16",
"license": {
"type": "file",
Expand Down
2 changes: 1 addition & 1 deletion src/SPC/builder/BuilderBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function buildLibs(array $libraries): void
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);
Expand Down
28 changes: 28 additions & 0 deletions src/SPC/builder/extension/imap.php
Original file line number Diff line number Diff line change
@@ -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;
}
}
63 changes: 63 additions & 0 deletions src/SPC/builder/linux/library/imap.php
Original file line number Diff line number Diff line change
@@ -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
}
}
}
66 changes: 66 additions & 0 deletions src/SPC/builder/macos/library/imap.php
Original file line number Diff line number Diff line change
@@ -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
}
}
}
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 @@ -24,7 +24,6 @@ protected function build(): void
$optional_packages = [
'zstd' => 'libzstd',
'ldap' => 'ldap',
'libpam' => 'libpam',
'libxslt' => 'libxslt',
'icu' => 'icu-i18n',
];
Expand Down Expand Up @@ -74,12 +73,12 @@ protected function build(): void
'--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 ') .
($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 '
);
Expand Down
20 changes: 8 additions & 12 deletions src/SPC/doctor/item/LinuxToolCheckList.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class LinuxToolCheckList
'git', 'autoconf', 'automake',
'tar', 'unzip', 'gzip', 'gcc',
'bzip2', 'cmake', 'patch',
'xz', 'wget', // to get musl
'xz',
];

/** @noinspection PhpUnused */
Expand All @@ -47,8 +47,7 @@ public function checkCliTools(): ?CheckResult

$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 = [];
Expand All @@ -61,8 +60,7 @@ public function checkCliTools(): ?CheckResult
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'),
};
Expand All @@ -74,11 +72,10 @@ public function checkCliTools(): ?CheckResult
#[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();
Expand All @@ -94,8 +91,7 @@ public function fixBuildTools(array $distro, array $missing): bool
$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 = '';
Expand All @@ -104,8 +100,8 @@ public function fixBuildTools(array $distro, array $missing): bool
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;
shell(true)->exec($prefix . $install_cmd . ' ' . implode(' ', $to_install));
} catch (RuntimeException) {
return false;
Expand Down
Loading