Skip to content

Skip re-extract ext-imap source #792

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
9 changes: 9 additions & 0 deletions src/SPC/builder/LibraryBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,15 @@ public function patchBeforeMake(): bool
return false;
}

/**
* Patch php-config after embed was built
* Example: imagemagick requires -lgomp, imap requires -lcrypt
*/
public function patchPhpConfig(): bool
{
return false;
}

/**
* Build this library.
*
Expand Down
11 changes: 11 additions & 0 deletions src/SPC/builder/extension/imap.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace SPC\builder\extension;

use SPC\builder\Extension;
use SPC\builder\linux\SystemUtil;
use SPC\exception\WrongUsageException;
use SPC\store\FileSystem;
use SPC\util\CustomExt;
Expand Down Expand Up @@ -41,4 +42,14 @@ public function getUnixConfigureArg(bool $shared = false): string
}
return $arg;
}

public function patchBeforeMake(): bool
{
if (PHP_OS_FAMILY !== 'Linux' || SystemUtil::isMuslDist()) {
return false;
}
$extra_libs = trim(getenv('SPC_EXTRA_LIBS') . ' -lcrypt');
f_putenv('SPC_EXTRA_LIBS=' . $extra_libs);
return true;
}
}
11 changes: 11 additions & 0 deletions src/SPC/builder/linux/library/imagemagick.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace SPC\builder\linux\library;

use SPC\store\FileSystem;

/**
* a template library class for unix
*/
Expand All @@ -12,4 +14,13 @@ class imagemagick extends LinuxLibraryBase
use \SPC\builder\unix\library\imagemagick;

public const NAME = 'imagemagick';

public function patchPhpConfig(): bool
{
if (getenv('SPC_LIBC') !== 'glibc' || !str_contains(getenv('CC'), 'devtoolset-10')) {
FileSystem::replaceFileRegex(BUILD_BIN_PATH . '/php-config', '/^libs="(.*)"$/m', 'libs="$1 -lgomp"');
return true;
}
return false;
}
}
15 changes: 12 additions & 3 deletions src/SPC/builder/linux/library/imap.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace SPC\builder\linux\library;

use SPC\builder\linux\SystemUtil;
use SPC\exception\FileSystemException;
use SPC\exception\RuntimeException;
use SPC\store\FileSystem;
Expand Down Expand Up @@ -34,6 +35,15 @@ public function patchBeforeBuild(): bool
return true;
}

public function patchPhpConfig(): bool
{
if (getenv('SPC_LIBC') === 'glibc') {
FileSystem::replaceFileRegex(BUILD_BIN_PATH . '/php-config', '/^libs="(.*)"$/m', 'libs="$1 -lcrypt"');
return true;
}
return false;
}

/**
* @throws RuntimeException
*/
Expand All @@ -44,16 +54,15 @@ protected function build(): void
} else {
$ssl_options = 'SSLTYPE=none';
}
$extraLibs = SystemUtil::getLibcVersionIfExists() <= '2.17' ? 'EXTRALDFLAGS="-ldl -lrt -lpthread"' : '';
shell()->cd($this->source_dir)
->exec('make clean')
->exec('touch ip6')
->exec('chmod +x tools/an')
->exec('chmod +x tools/ua')
->exec('chmod +x src/osdep/unix/drivers')
->exec('chmod +x src/osdep/unix/mkauths')
->exec(
"yes | make slx {$ssl_options} EXTRACFLAGS='-fPIC -fpermissive'"
);
->exec("yes | make slx {$ssl_options} EXTRACFLAGS='-fPIC -fpermissive' {$extraLibs}");
try {
shell()
->exec("cp -rf {$this->source_dir}/c-client/c-client.a " . BUILD_LIB_PATH . '/libc-client.a')
Expand Down
5 changes: 5 additions & 0 deletions src/SPC/builder/unix/UnixBuilderBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,11 @@ protected function patchPhpScripts(): void
$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);
}
foreach ($this->getLibs() as $lib) {
if ($lib->patchPhpConfig()) {
logger()->debug("Library {$lib->getName()} patched php-config");
}
}
}

/**
Expand Down
11 changes: 9 additions & 2 deletions src/SPC/store/SourceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static function initSource(?array $sources = null, ?array $libs = null, ?
$check = LockFile::getExtractPath($lock_name, SOURCE_PATH . '/' . $source);
// $check = $lock[$lock_name]['move_path'] === null ? (SOURCE_PATH . '/' . $source) : (SOURCE_PATH . '/' . $lock[$lock_name]['move_path']);
if (!is_dir($check)) {
logger()->debug('Extracting source [' . $source . '] to ' . $check . ' ...');
logger()->debug("Extracting source [{$source}] to {$check} ...");
$filename = LockFile::getLockFullPath($lock_content);
FileSystem::extractSource($source, $lock_content['source_type'], $filename, $check);
LockFile::putLockSourceHash($lock_content, $check);
Expand All @@ -81,7 +81,14 @@ public static function initSource(?array $sources = null, ?array $libs = null, ?

// when source already extracted, detect if the extracted source hash is the same as the lock file one
if (file_exists("{$check}/.spc-hash") && FileSystem::readFile("{$check}/.spc-hash") === $hash) {
logger()->debug('Source [' . $source . '] already extracted in ' . $check . ', skip !');
logger()->debug("Source [{$source}] already extracted in {$check}, skip !");
continue;
}

// ext imap was included in php < 8.4 which we should not extract,
// but since it's not simple to compare php version, for now we just skip it
if ($source === 'ext-imap') {
logger()->debug("Source [ext-imap] already extracted in {$check}, skip !");
continue;
}

Expand Down
3 changes: 3 additions & 0 deletions src/SPC/util/SPCConfigUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ private function getLibsString(array $libraries, bool $withDependencies = false)
if (in_array('imagemagick', $libraries) && PHP_OS_FAMILY === 'Linux' && !(getenv('SPC_LIBC') === 'glibc' && str_contains(getenv('CC'), 'devtoolset-10'))) {
$short_name[] = '-lgomp';
}
if (in_array('imap', $libraries) && PHP_OS_FAMILY === 'Linux' && getenv('SPC_LIBC') === 'glibc') {
$short_name[] = '-lcrypt';
}
return implode(' ', $short_name);
}

Expand Down
12 changes: 6 additions & 6 deletions src/globals/test-extensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
$test_os = [
// 'macos-13',
// 'macos-14',
// 'macos-15',
// 'ubuntu-latest',
'macos-15',
'ubuntu-latest',
// 'ubuntu-22.04',
// 'ubuntu-24.04',
'ubuntu-22.04-arm',
Expand All @@ -33,7 +33,7 @@
];

// whether enable thread safe
$zts = true;
$zts = false;

$no_strip = false;

Expand All @@ -48,13 +48,13 @@

// If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`).
$extensions = match (PHP_OS_FAMILY) {
'Linux', 'Darwin' => 'apcu,ast,bcmath,calendar,ctype,curl,dba,dom,exif,fileinfo,filter,iconv,libxml,mbregex,mbstring,opcache,openssl,pcntl,phar,posix,readline,session,simplexml,sockets,sodium,tokenizer,xml,xmlreader,xmlwriter,zip,zlib',
'Linux', 'Darwin' => 'openssl',
'Windows' => 'xlswriter,openssl',
};

// If you want to test shared extensions, add them below (comma separated, example `bcmath,openssl`).
$shared_extensions = match (PHP_OS_FAMILY) {
'Linux' => 'uv',
'Linux' => '',
'Darwin' => '',
'Windows' => '',
};
Expand All @@ -72,7 +72,7 @@
// 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',
};

Expand Down
Loading