Skip to content

Commit dd72b32

Browse files
committed
Merge
1 parent a5d26d6 commit dd72b32

File tree

6 files changed

+50
-5
lines changed

6 files changed

+50
-5
lines changed

src/SPC/builder/LibraryBase.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,15 @@ public function patchBeforeMake(): bool
332332
return false;
333333
}
334334

335+
/**
336+
* Patch php-config after embed was built
337+
* Example: imap requires -lcrypt
338+
*/
339+
public function patchPhpConfig(): bool
340+
{
341+
return false;
342+
}
343+
335344
/**
336345
* Build this library.
337346
*

src/SPC/builder/extension/imap.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace SPC\builder\extension;
66

77
use SPC\builder\Extension;
8+
use SPC\builder\linux\SystemUtil;
89
use SPC\exception\WrongUsageException;
910
use SPC\store\FileSystem;
1011
use SPC\util\CustomExt;
@@ -41,4 +42,14 @@ public function getUnixConfigureArg(bool $shared = false): string
4142
}
4243
return $arg;
4344
}
45+
46+
public function patchBeforeMake(): bool
47+
{
48+
if (PHP_OS_FAMILY !== 'Linux' || SystemUtil::isMuslDist()) {
49+
return false;
50+
}
51+
$extra_libs = trim(getenv('SPC_EXTRA_LIBS') . ' -lcrypt');
52+
f_putenv('SPC_EXTRA_LIBS=' . $extra_libs);
53+
return true;
54+
}
4455
}

src/SPC/builder/linux/library/imap.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use SPC\exception\FileSystemException;
88
use SPC\exception\RuntimeException;
99
use SPC\store\FileSystem;
10+
use SPC\util\SPCTarget;
1011

1112
class imap extends LinuxLibraryBase
1213
{
@@ -34,6 +35,15 @@ public function patchBeforeBuild(): bool
3435
return true;
3536
}
3637

38+
public function patchPhpConfig(): bool
39+
{
40+
if (SPCTarget::getLibc() === 'glibc') {
41+
FileSystem::replaceFileRegex(BUILD_BIN_PATH . '/php-config', '/^libs="(.*)"$/m', 'libs="$1 -lcrypt"');
42+
return true;
43+
}
44+
return false;
45+
}
46+
3747
/**
3848
* @throws RuntimeException
3949
*/
@@ -44,16 +54,16 @@ protected function build(): void
4454
} else {
4555
$ssl_options = 'SSLTYPE=none';
4656
}
57+
$libcVer = SPCTarget::getLibcVersion();
58+
$extraLibs = $libcVer && version_compare($libcVer, '2.17', '<=') ? 'EXTRALDFLAGS="-ldl -lrt -lpthread"' : '';
4759
shell()->cd($this->source_dir)
4860
->exec('make clean')
4961
->exec('touch ip6')
5062
->exec('chmod +x tools/an')
5163
->exec('chmod +x tools/ua')
5264
->exec('chmod +x src/osdep/unix/drivers')
5365
->exec('chmod +x src/osdep/unix/mkauths')
54-
->exec(
55-
"yes | make slx {$ssl_options} EXTRACFLAGS='-fPIC -fpermissive'"
56-
);
66+
->exec("yes | make slx {$ssl_options} EXTRACFLAGS='-fPIC -fpermissive' {$extraLibs}");
5767
try {
5868
shell()
5969
->exec("cp -rf {$this->source_dir}/c-client/c-client.a " . BUILD_LIB_PATH . '/libc-client.a')

src/SPC/builder/unix/UnixBuilderBase.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,11 @@ protected function patchPhpScripts(): void
294294
$php_config_str = preg_replace('/(libs=")(.*?)\s*(-lstdc\+\+)\s*(.*?)"/', '$1$2 $4 $3"', $php_config_str);
295295
FileSystem::writeFile(BUILD_BIN_PATH . '/php-config', $php_config_str);
296296
}
297+
foreach ($this->getLibs() as $lib) {
298+
if ($lib->patchPhpConfig()) {
299+
logger()->debug("Library {$lib->getName()} patched php-config");
300+
}
301+
}
297302
}
298303

299304
/**

src/SPC/store/SourceManager.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public static function initSource(?array $sources = null, ?array $libs = null, ?
6666
$check = LockFile::getExtractPath($lock_name, SOURCE_PATH . '/' . $source);
6767
// $check = $lock[$lock_name]['move_path'] === null ? (SOURCE_PATH . '/' . $source) : (SOURCE_PATH . '/' . $lock[$lock_name]['move_path']);
6868
if (!is_dir($check)) {
69-
logger()->debug('Extracting source [' . $source . '] to ' . $check . ' ...');
69+
logger()->debug("Extracting source [{$source}] to {$check} ...");
7070
$filename = LockFile::getLockFullPath($lock_content);
7171
FileSystem::extractSource($source, $lock_content['source_type'], $filename, $check);
7272
LockFile::putLockSourceHash($lock_content, $check);
@@ -81,7 +81,14 @@ public static function initSource(?array $sources = null, ?array $libs = null, ?
8181

8282
// when source already extracted, detect if the extracted source hash is the same as the lock file one
8383
if (file_exists("{$check}/.spc-hash") && FileSystem::readFile("{$check}/.spc-hash") === $hash) {
84-
logger()->debug('Source [' . $source . '] already extracted in ' . $check . ', skip !');
84+
logger()->debug("Source [{$source}] already extracted in {$check}, skip !");
85+
continue;
86+
}
87+
88+
// ext imap was included in php < 8.4 which we should not extract,
89+
// but since it's not simple to compare php version, for now we just skip it
90+
if ($source === 'ext-imap') {
91+
logger()->debug("Source [ext-imap] already extracted in {$check}, skip !");
8592
continue;
8693
}
8794

src/SPC/util/SPCConfigUtil.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ private function getLibsString(array $libraries, bool $withDependencies = false)
145145
}
146146
}
147147
}
148+
if (in_array('imap', $libraries) && SPCTarget::getLibc() === 'glibc') {
149+
$short_name[] = '-lcrypt';
150+
}
148151
return implode(' ', $short_name);
149152
}
150153

0 commit comments

Comments
 (0)