Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reference pr that shall not be merged #214

Closed
wants to merge 67 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
4576ddd
[WIP] imap support
DubbleClick Sep 26, 2023
97e2fc0
use Filesystem methods, extra args
DubbleClick Sep 27, 2023
f8cbb79
add libpam (can't compile with musl yet)
DubbleClick Sep 28, 2023
ab7d33e
compiling libpam with gcc, patching imap libs in php-src/configure
DubbleClick Sep 28, 2023
dd9e27d
fix compilation with openssl
DubbleClick Sep 29, 2023
359f53f
remove unnecessary space
DubbleClick Sep 29, 2023
ce1381a
throw error when compiling imap with zts
DubbleClick Sep 29, 2023
98bdd53
Merge branch 'main' into imap
DubbleClick Sep 30, 2023
8f9e803
add comma
DubbleClick Oct 1, 2023
4717658
run cs fix
DubbleClick Oct 1, 2023
fdd34bb
add linux OS debug message
crazywhalecc Oct 3, 2023
a7814c2
add imap lib suggests
crazywhalecc Oct 3, 2023
7fdcef8
Merge branch 'main' into imap
crazywhalecc Oct 3, 2023
cb017ff
add SoucePatcher::patchFile
crazywhalecc Oct 3, 2023
2b9ce4d
remove redundant function and adjust patch functions
crazywhalecc Oct 3, 2023
225fa0e
enable `--with-clean` for real
crazywhalecc Oct 3, 2023
c2715e8
change imap-openssl patches
crazywhalecc Oct 3, 2023
3b1e2b9
fix imap on debian systems
DubbleClick Oct 3, 2023
b93a568
fix distro detection to properly detect any redhat distro
DubbleClick Oct 3, 2023
ece3fd9
fix auto-fix for rhel
DubbleClick Oct 3, 2023
9774445
bring in fixes from c++ branch (sslinclude path, ssllib typo)
DubbleClick Oct 3, 2023
3b65971
fix -lstdc++ coming first in php-config for embed-sapi, which causes …
DubbleClick Oct 3, 2023
554986d
fix openssl requiring zlib extension (require zlib in pkgconfig instead)
DubbleClick Oct 3, 2023
ee966ad
patch openssl pc for macos too
DubbleClick Oct 3, 2023
f00b60f
always put lstdc++ last
DubbleClick Oct 4, 2023
6d71557
fix libpam build on musl includes
DubbleClick Oct 4, 2023
0fb081f
add zstd to imagick when it's active
DubbleClick Oct 4, 2023
b051150
add c++ support for linux systems
DubbleClick Oct 1, 2023
55e2776
run cs fix
DubbleClick Oct 1, 2023
b1b4a29
optimize musl install
DubbleClick Oct 1, 2023
6fb0b66
fix opcache loading wrong libstdc++.so.6
DubbleClick Oct 1, 2023
8f17577
move everything for libsnappy too
DubbleClick Oct 1, 2023
7b1432d
fix compilation errors (did ldap compilation work for you without -lz?)
DubbleClick Oct 2, 2023
dd82673
fix pgsql + intl + ldap
DubbleClick Oct 2, 2023
c1c8131
only run necessary musl install steps
DubbleClick Oct 2, 2023
904b730
return false|int instead of bool|int in replaceFile methods
DubbleClick Oct 2, 2023
4700071
fix libxml pc patch
DubbleClick Oct 2, 2023
ebc880b
add pam tools for alpine (package names need to be adjusted)
DubbleClick Oct 4, 2023
d17d336
remove --disable-opcache-jit on building embed
DubbleClick Oct 5, 2023
ccd22d2
fix imap build (without libpam) on aarch64 - CC=cc has to be replaced…
DubbleClick Oct 10, 2023
958d91e
add -lsharpyuv to dependencies when patching pkgconfig
DubbleClick Oct 10, 2023
956da46
allow patchBeforeMake to patch extra_libs on linux as well (worked on…
DubbleClick Oct 10, 2023
46a16b8
get build-cli working for imagick (undefined references, like always)
DubbleClick Oct 10, 2023
e9f3192
use prebuilt musl-gcc (gcc 12.2+ fails to build musl-cross-compile)
DubbleClick Oct 10, 2023
2e9e10d
fix bash profile file for non-bash systems
DubbleClick Oct 10, 2023
dd273d4
make fixmusl return bool again
DubbleClick Oct 10, 2023
f151a31
support alpine again, just use preinstalled gcc and g++
DubbleClick Oct 11, 2023
c1c4420
answer imap without openssl automatically
DubbleClick Oct 11, 2023
394426f
full libiconv path instead of -liconv
DubbleClick Oct 11, 2023
f999045
move imap zts check to extension rather than lib
DubbleClick Oct 11, 2023
acb9fc3
simplify build
mhpcc Oct 12, 2023
de18ed3
update icu
mhpcc Oct 13, 2023
2067ce4
intl doesn't work anymore?!
DubbleClick Oct 13, 2023
9c0a6bd
make php-cs-fixer happy
DubbleClick Oct 13, 2023
7a010ca
icu 73.2 flags
DubbleClick Oct 13, 2023
4993bdf
imagemagick doesn't require all libs, suggest them instead
DubbleClick Oct 13, 2023
461640f
Merge branch 'main' into cplusplus
crazywhalecc Oct 14, 2023
51f4fea
Merge branch 'main' into cplusplus
crazywhalecc Oct 14, 2023
99b181d
Merge branch 'main' into cplusplus
crazywhalecc Oct 14, 2023
1efb3c7
Merge branch 'main' into cplusplus
crazywhalecc Oct 14, 2023
7a0f17c
Merge branch 'main' into cplusplus
crazywhalecc Oct 14, 2023
8f7480e
Merge branch 'main' into cplusplus
crazywhalecc Oct 14, 2023
733b71d
refactor imap code to be more understandable
DubbleClick Oct 15, 2023
314c04e
testing changes to use cross-toolchain
DubbleClick Oct 15, 2023
c8438ff
Merge remote-tracking branch 'orig/main' into cplusplus
DubbleClick Oct 15, 2023
c3162c6
remove ext-zip dependency
DubbleClick Oct 16, 2023
6cf8a4b
introduce disable-opcache-jit option to allow frankenphp to compile o…
DubbleClick Oct 16, 2023
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
10 changes: 5 additions & 5 deletions config/ext.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,14 @@
},
"imap": {
"type": "builtin",
"arg-type": "with",
"arg-type": "custom",
"lib-depends": [
"imap"
],
"lib-suggests": [
"kerberos"
"kerberos",
"libpam",
"openssl"
]
},
"inotify": {
Expand Down Expand Up @@ -235,9 +237,7 @@
"type": "builtin",
"arg-type": "with",
"lib-depends": [
"openssl"
],
"ext-depends": [
"openssl",
"zlib"
]
},
Expand Down
30 changes: 24 additions & 6 deletions config/lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,27 @@
"libMagickWand-7.Q16HDRI.a"
],
"lib-depends": [
"zlib",
"zlib"
],
"lib-suggests": [
"zstd",
"xz",
"libzip",
"libpng",
"libjpeg",
"libxml2",
"bzip2",
"libwebp",
"libjpeg",
"freetype"
]
},
"imap": {
"source": "imap",
"static-libs-unix": [
"libc-client.a"
],
"lib-suggests": [
"zstd",
"xz",
"libzip",
"libxml2"
"openssl"
]
},
"ldap": {
Expand All @@ -151,6 +160,15 @@
"libsodium"
]
},
"libpam": {
"source": "libpam",
"static-libs-unix": [
"libpam.a"
],
"lib-suggests": [
"openssl"
]
},
"libavif": {
"source": "libavif",
"static-libs-unix": [
Expand Down
19 changes: 18 additions & 1 deletion config/source.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
},
"icu": {
"type": "url",
"url": "https://github.com/unicode-org/icu/releases/download/release-73-1/icu4c-73_1-src.tgz",
"url": "https://github.com/unicode-org/icu/releases/download/release-73-2/icu4c-73_2-src.tgz",
"license": {
"type": "file",
"path": "LICENSE"
Expand All @@ -153,6 +153,15 @@
"path": "LICENSE"
}
},
"imap": {
"type": "git",
"url": "https://github.com/uw-imap/imap.git",
"rev": "master",
"license": {
"type": "file",
"path": "LICENSE"
}
},
"ldap": {
"type": "filelist",
"url": "https://www.openldap.org/software/download/OpenLDAP/openldap-release/",
Expand All @@ -162,6 +171,14 @@
"path": "LICENSE"
}
},
"libpam": {
"type": "ghtar",
"repo": "linux-pam/linux-pam",
"license": {
"type": "file",
"path": "Copyright"
}
},
"libavif": {
"type": "ghtar",
"repo": "AOMediaCodec/libavif",
Expand Down
4 changes: 2 additions & 2 deletions src/SPC/builder/extension/iconv.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public function patchBeforeConfigure(): bool
{
// macOS need to link iconv dynamically, we add it to extra-libs
$extra_libs = $this->builder->getOption('extra-libs', '');
if (!str_contains($extra_libs, '-liconv')) {
$extra_libs .= ' -liconv';
if (!str_contains($extra_libs, 'iconv')) {
$extra_libs .= ' ' . BUILD_LIB_PATH . '/libiconv.a';
}
$this->builder->setOption('extra-libs', $extra_libs);
return true;
Expand Down
24 changes: 20 additions & 4 deletions src/SPC/builder/extension/imagick.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,27 @@ class imagick extends Extension
{
public function patchBeforeBuildconf(): bool
{
// linux need to link library manually, we add it to extra-libs
$extra_libs = $this->builder->getOption('extra-libs', '');
if (!str_contains($extra_libs, 'libMagickCore')) {
$extra_libs .= ' /usr/lib/libMagick++-7.Q16HDRI.a /usr/lib/libMagickCore-7.Q16HDRI.a /usr/lib/libMagickWand-7.Q16HDRI.a';
}
$LIB_PATH = BUILD_LIB_PATH;
// always add these even if they aren't needed, php-imagick pulls MagickWand before MagickCore which leads to undefined references
$extra_libs .= " {$LIB_PATH}/libMagick++-7.Q16HDRI.a {$LIB_PATH}/libMagickWand-7.Q16HDRI.a {$LIB_PATH}/libMagickCore-7.Q16HDRI.a ";
$extra_libs .= $this->builder->getLib('libzip') ? "{$LIB_PATH}/libzip.a " : '';
$extra_libs .= $this->builder->getLib('libjpeg') ? "{$LIB_PATH}/libjpeg.a " : '';
$extra_libs .= $this->builder->getLib('libpng') ? "{$LIB_PATH}/libpng.a " : '';
$extra_libs .= $this->builder->getLib('libwebp') ? "{$LIB_PATH}/libwebp.a " : '';
$extra_libs .= $this->builder->getLib('zstd') ? "{$LIB_PATH}/libzstd.a " : '';
$extra_libs .= $this->builder->getLib('freetype') ? "{$LIB_PATH}/libfreetype.a " : '';
$this->builder->setOption('extra-libs', $extra_libs);
return true;
}

public function patchBeforeMake(): bool
{
$extra_libs = $this->builder->getOption('extra-libs', '');
$LIB_PATH = BUILD_LIB_PATH;
// always add these even if they aren't needed, php-imagick pulls MagickWand before MagickCore which leads to undefined references
$extra_libs .= " {$LIB_PATH}/libMagick++-7.Q16HDRI.a {$LIB_PATH}/libMagickWand-7.Q16HDRI.a {$LIB_PATH}/libMagickCore-7.Q16HDRI.a ";
$extra_libs .= '-lgomp ';
$this->builder->setOption('extra-libs', $extra_libs);
return true;
}
Expand Down
47 changes: 47 additions & 0 deletions src/SPC/builder/extension/imap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace SPC\builder\extension;

use SPC\builder\Extension;
use SPC\exception\FileSystemException;
use SPC\exception\WrongUsageException;
use SPC\store\FileSystem;
use SPC\util\CustomExt;

#[CustomExt('imap')]
class imap extends Extension
{
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;
}

/**
* @throws FileSystemException
*/
public function patchBeforeConfigure(): bool
{
if (!$this->builder->getLib('libpam')) {
return false;
}
$extra_libs = $this->builder->getOption('extra-libs', '');
if (!str_contains($extra_libs, 'lpam') && !str_contains($extra_libs, 'libpam.a')) {
$extra_libs .= ' ' . BUILD_LIB_PATH . '/libpam.a';
}
$this->builder->setOption('extra-libs', $extra_libs);
return (bool) FileSystem::replaceFileStr(
SOURCE_PATH . '/php-src/configure',
'DLIBS="-l$IMAP_LIB $DLIBS"',
'DLIBS="-l$IMAP_LIB $DLIBS -lpam"'
);
}
}
62 changes: 37 additions & 25 deletions src/SPC/builder/linux/LinuxBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,24 @@ class LinuxBuilder extends BuilderBase
public function __construct(array $options = [])
{
$this->options = $options;

logger()->debug('Current OS: ' . SystemUtil::getOSRelease()['dist'] . ' ' . SystemUtil::getOSRelease()['ver']);
// ---------- set necessary options ----------
// set C Compiler (default: alpine: gcc, others: musl-gcc)
$this->setOptionIfNotExist('cc', match (SystemUtil::getOSRelease()['dist']) {
'alpine' => 'gcc',
default => 'musl-gcc'
});
// set C++ Compiler (default: g++)
$this->setOptionIfNotExist('cxx', 'g++');
if (SystemUtil::getOSRelease()['dist'] === 'alpine') {
$this->setOptionIfNotExist('cc', 'gcc');
$this->setOptionIfNotExist('cxx', 'g++');
} else {
$arch = arch2gnu(php_uname('m'));
$this->setOptionIfNotExist('library_path', '/usr/local/musl/lib');
$this->setOptionIfNotExist('cc', "{$arch}-linux-musl-gcc");
$this->setOptionIfNotExist('cxx', "{$arch}-linux-musl-g++");
}
// set arch (default: current)
$this->setOptionIfNotExist('arch', php_uname('m'));
$this->setOptionIfNotExist('gnu-arch', arch2gnu($this->getOption('arch')));

// ---------- set necessary compile environments ----------
// set libc
$this->libc = $this->getOption('cc', 'gcc') === 'musl-gcc' ? 'musl_wrapper' : 'musl'; // SystemUtil::selectLibc($this->cc);
$this->libc = str_ends_with($this->getOption('cc', 'gcc'), 'musl-gcc') ? 'musl_wrapper' : 'musl'; // SystemUtil::selectLibc($this->cc);
// concurrency
$this->concurrency = SystemUtil::getCpuCount();
// cflags
Expand Down Expand Up @@ -134,7 +136,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
} else {
$extra_libs .= (empty($extra_libs) ? '' : ' ') . implode(' ', array_map(fn ($x) => "-Xcompiler {$x}", array_filter($this->getAllStaticLibFiles())));
}
// add libstdc++, some extensions or libraries need it (C++ cannot be linked statically)
// add libstdc++, some extensions or libraries need it
$extra_libs .= (empty($extra_libs) ? '' : ' ') . ($this->hasCppExtension() ? '-lstdc++ ' : '');
$this->setOption('extra-libs', $extra_libs);

Expand All @@ -144,7 +146,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
switch ($this->libc) {
case 'musl_wrapper':
case 'glibc':
$cflags .= ' -static-libgcc -I"' . BUILD_INCLUDE_PATH . '"';
$cflags .= ' -static-libgcc -static-libstdc++ -I"' . BUILD_INCLUDE_PATH . '"';
break;
case 'musl':
if (str_ends_with($this->getOption('cc'), 'clang') && SystemUtil::findCommand('lld')) {
Expand Down Expand Up @@ -179,6 +181,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
$maxExecutionTimers = '';
$zts = '';
}
$disable_jit = $this->getOption('disable-opcache-jit', false) ? '--disable-opcache-jit ' : '';

$enableCli = ($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI;
$enableFpm = ($build_target & BUILD_TARGET_FPM) === BUILD_TARGET_FPM;
Expand All @@ -187,6 +190,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void

shell()->cd(SOURCE_PATH . '/php-src')
->exec(
(SystemUtil::getOSRelease()['dist'] === 'alpine' ? '' : 'LD_LIBRARY_PATH=/usr/local/musl/x86_64-linux-musl/lib ') .
'./configure ' .
'--prefix= ' .
'--with-valgrind=no ' .
Expand All @@ -197,11 +201,12 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
'--disable-phpdbg ' .
($enableCli ? '--enable-cli ' : '--disable-cli ') .
($enableFpm ? '--enable-fpm ' : '--disable-fpm ') .
($enableEmbed ? '--enable-embed=static --disable-opcache-jit ' : '--disable-embed ') .
($enableEmbed ? '--enable-embed=static ' : '--disable-embed ') .
($enableMicro ? '--enable-micro=all-static ' : '--disable-micro ') .
$disable_jit .
$json_74 .
$zts .
$maxExecutionTimers .
($enableMicro ? '--enable-micro=all-static ' : '--disable-micro ') .
$this->makeExtensionArgs() . ' ' .
$envs
);
Expand All @@ -212,22 +217,28 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void

if ($enableCli) {
logger()->info('building cli');
$this->buildCli($extra_libs, $use_lld);
$this->buildCli($use_lld);
}
if ($enableFpm) {
logger()->info('building fpm');
$this->buildFpm($extra_libs, $use_lld);
$this->buildFpm($use_lld);
}
if ($enableMicro) {
logger()->info('building micro');
$this->buildMicro($extra_libs, $use_lld, $cflags);
$this->buildMicro($use_lld, $cflags);
}
if ($enableEmbed) {
logger()->info('building embed');
if ($enableMicro) {
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/Makefile', 'OVERALL_TARGET =', 'OVERALL_TARGET = libphp.la');
}
$this->buildEmbed($extra_libs, $use_lld);
$this->buildEmbed($use_lld);
// php-config puts extra_libs in wrong order, fix it here...
FileSystem::replaceFileRegex(
BUILD_ROOT_PATH . '/bin/php-config',
'/libs="\s*(.*)\s*-lstdc\+\+\s+(.*)"/',
'libs="$1 $2 -lstdc++"'
);
}

if (php_uname('m') === $this->getOption('arch')) {
Expand All @@ -241,11 +252,11 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
* @throws RuntimeException
* @throws FileSystemException
*/
public function buildCli(string $extra_libs, string $use_lld): void
public function buildCli(string $use_lld): void
{
$vars = SystemUtil::makeEnvVarString([
'EXTRA_CFLAGS' => '-g -Os -fno-ident ' . implode(' ', array_map(fn ($x) => "-Xcompiler {$x}", $this->tune_c_flags)),
'EXTRA_LIBS' => $extra_libs,
'EXTRA_LIBS' => $this->getOption('extra-libs'),
'EXTRA_LDFLAGS_PROGRAM' => "{$use_lld} -all-static",
]);
shell()->cd(SOURCE_PATH . '/php-src')
Expand All @@ -264,8 +275,9 @@ public function buildCli(string $extra_libs, string $use_lld): void
*
* @throws RuntimeException
* @throws FileSystemException
* @throws WrongUsageException
*/
public function buildMicro(string $extra_libs, string $use_lld, string $cflags): void
public function buildMicro(string $use_lld, string $cflags): void
{
if ($this->getPHPVersionID() < 80000) {
throw new RuntimeException('phpmicro only support PHP >= 8.0!');
Expand All @@ -278,7 +290,7 @@ public function buildMicro(string $extra_libs, string $use_lld, string $cflags):
$enable_fake_cli = $this->getOption('with-micro-fake-cli', false) ? ' -DPHP_MICRO_FAKE_CLI' : '';
$vars = SystemUtil::makeEnvVarString([
'EXTRA_CFLAGS' => '-g -Os -fno-ident ' . implode(' ', array_map(fn ($x) => "-Xcompiler {$x}", $this->tune_c_flags)) . $enable_fake_cli,
'EXTRA_LIBS' => $extra_libs,
'EXTRA_LIBS' => $this->getOption('extra-libs'),
'EXTRA_LDFLAGS_PROGRAM' => "{$cflags} {$use_lld} -all-static",
]);
shell()->cd(SOURCE_PATH . '/php-src')
Expand All @@ -302,11 +314,11 @@ public function buildMicro(string $extra_libs, string $use_lld, string $cflags):
* @throws FileSystemException
* @throws RuntimeException
*/
public function buildFpm(string $extra_libs, string $use_lld): void
public function buildFpm(string $use_lld): void
{
$vars = SystemUtil::makeEnvVarString([
'EXTRA_CFLAGS' => '-g -Os -fno-ident ' . implode(' ', array_map(fn ($x) => "-Xcompiler {$x}", $this->tune_c_flags)),
'EXTRA_LIBS' => $extra_libs,
'EXTRA_LIBS' => $this->getOption('extra-libs'),
'EXTRA_LDFLAGS_PROGRAM' => "{$use_lld} -all-static",
]);

Expand All @@ -321,11 +333,11 @@ public function buildFpm(string $extra_libs, string $use_lld): void
$this->deployBinary(BUILD_TARGET_FPM);
}

public function buildEmbed(string $extra_libs, string $use_lld): void
public function buildEmbed(string $use_lld): void
{
$vars = SystemUtil::makeEnvVarString([
'EXTRA_CFLAGS' => '-g -Os -fno-ident ' . implode(' ', array_map(fn ($x) => "-Xcompiler {$x}", $this->tune_c_flags)),
'EXTRA_LIBS' => $extra_libs,
'EXTRA_LIBS' => $this->getOption('extra-libs'),
'EXTRA_LDFLAGS_PROGRAM' => "{$use_lld} -all-static",
]);

Expand Down
Loading