Skip to content

Commit 9af3b74

Browse files
authored
Merge pull request #792 from crazywhalecc/fix/ext-imap-extraction
Skip re-extract ext-imap source
2 parents a5d26d6 + a5cd5fc commit 9af3b74

File tree

8 files changed

+62
-17
lines changed

8 files changed

+62
-17
lines changed

bin/spc-alpine-docker

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set -e
44

55
# This file is using docker to run commands
6-
SPC_DOCKER_VERSION=v4
6+
SPC_DOCKER_VERSION=v5
77

88
# Detect docker can run
99
if ! which docker >/dev/null; then
@@ -53,9 +53,9 @@ aarch64|arm64)
5353
exit 1
5454
;;
5555
esac
56-
# if ALPINE_FROM is not set, use alpine:edge
56+
# if ALPINE_FROM is not set, use alpine:3.21
5757
if [ -z "$ALPINE_FROM" ]; then
58-
ALPINE_FROM=alpine:edge
58+
ALPINE_FROM=alpine:3.21
5959
fi
6060
if [ "$SPC_USE_ARCH" != "$CURRENT_ARCH" ]; then
6161
echo "* Using different arch needs to setup qemu-static for docker !"
@@ -64,7 +64,7 @@ if [ "$SPC_USE_ARCH" != "$CURRENT_ARCH" ]; then
6464
$DOCKER_EXECUTABLE run --rm --privileged multiarch/qemu-user-static:register --reset > /dev/null
6565
fi
6666
else
67-
ALPINE_FROM=alpine:edge
67+
ALPINE_FROM=alpine:3.21
6868
fi
6969

7070
if [ "$SPC_USE_MIRROR" = "yes" ]; then

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

src/globals/test-extensions.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@
2323
$test_os = [
2424
// 'macos-13', // bin/spc for x86_64
2525
// 'macos-14', // bin/spc for arm64
26-
'macos-15', // bin/spc for arm64
26+
// 'macos-15', // bin/spc for arm64
2727
'ubuntu-latest', // bin/spc-alpine-docker for x86_64
28-
'ubuntu-22.04', // bin/spc-gnu-docker for x86_64
29-
'ubuntu-24.04', // bin/spc for x86_64
28+
// 'ubuntu-22.04', // bin/spc-gnu-docker for x86_64
29+
// 'ubuntu-24.04', // bin/spc for x86_64
3030
// 'ubuntu-22.04-arm', // bin/spc-gnu-docker for arm64
3131
// 'ubuntu-24.04-arm', // bin/spc for arm64
3232
// 'windows-latest', // .\bin\spc.ps1
3333
];
3434

3535
// whether enable thread safe
36-
$zts = true;
36+
$zts = false;
3737

3838
$no_strip = false;
3939

@@ -44,17 +44,17 @@
4444
$frankenphp = false;
4545

4646
// prefer downloading pre-built packages to speed up the build process
47-
$prefer_pre_built = true;
47+
$prefer_pre_built = false;
4848

4949
// If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`).
5050
$extensions = match (PHP_OS_FAMILY) {
51-
'Linux', 'Darwin' => 'curl',
51+
'Linux', 'Darwin' => 'imap,swoole',
5252
'Windows' => 'intl',
5353
};
5454

5555
// If you want to test shared extensions, add them below (comma separated, example `bcmath,openssl`).
5656
$shared_extensions = match (PHP_OS_FAMILY) {
57-
'Linux' => 'uv',
57+
'Linux' => '',
5858
'Darwin' => '',
5959
'Windows' => '',
6060
};
@@ -72,7 +72,7 @@
7272
// You can use `common`, `bulk`, `minimal` or `none`.
7373
// note: combination is only available for *nix platform. Windows must use `none` combination
7474
$base_combination = match (PHP_OS_FAMILY) {
75-
'Linux', 'Darwin' => 'common',
75+
'Linux', 'Darwin' => 'minimal',
7676
'Windows' => 'none',
7777
};
7878

0 commit comments

Comments
 (0)