Skip to content

Commit 487c6da

Browse files
authored
switch readline to libedit (#919)
2 parents c5ae719 + e942b13 commit 487c6da

File tree

14 files changed

+117
-57
lines changed

14 files changed

+117
-57
lines changed

config/env.ini

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ SPC_MICRO_PATCHES=cli_checks,disable_huge_page
105105
SPC_CMD_PREFIX_PHP_BUILDCONF="./buildconf --force"
106106
; configure command
107107
SPC_CMD_PREFIX_PHP_CONFIGURE="./configure --prefix= --with-valgrind=no --disable-shared --enable-static --disable-all --disable-phpdbg --with-pic"
108-
; make command
109-
SPC_CMD_PREFIX_PHP_MAKE="make -j${SPC_CONCURRENCY}"
110108

111109
; *** default build vars for building php ***
112110
; embed type for php, static (libphp.a) or shared (libphp.so)
@@ -139,8 +137,6 @@ SPC_MICRO_PATCHES=cli_checks,macos_iconv
139137
SPC_CMD_PREFIX_PHP_BUILDCONF="./buildconf --force"
140138
; configure command
141139
SPC_CMD_PREFIX_PHP_CONFIGURE="./configure --prefix= --with-valgrind=no --enable-shared=no --enable-static=yes --disable-all --disable-phpdbg"
142-
; make command
143-
SPC_CMD_PREFIX_PHP_MAKE="make -j${SPC_CONCURRENCY}"
144140

145141
; *** default build vars for building php ***
146142
; embed type for php, static (libphp.a) or shared (libphp.dylib)

config/ext.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@
687687
"type": "builtin",
688688
"arg-type": "with-path",
689689
"lib-depends": [
690-
"readline"
690+
"libedit"
691691
],
692692
"target": [
693693
"static"

config/lib.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,15 @@
345345
],
346346
"cpp-library": true
347347
},
348+
"libedit": {
349+
"source": "libedit",
350+
"static-libs-unix": [
351+
"libedit.a"
352+
],
353+
"lib-depends": [
354+
"ncurses"
355+
]
356+
},
348357
"libevent": {
349358
"source": "libevent",
350359
"static-libs-unix": [

config/source.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,16 @@
498498
"path": "COPYING"
499499
}
500500
},
501+
"libedit": {
502+
"type": "filelist",
503+
"url": "https://thrysoee.dk/editline/",
504+
"regex": "/href=\"(?<file>libedit-(?<version>[^\"]+)\\.tar\\.gz)\"/",
505+
"provide-pre-built": true,
506+
"license": {
507+
"type": "file",
508+
"path": "COPYING"
509+
}
510+
},
501511
"libevent": {
502512
"type": "ghrel",
503513
"repo": "libevent/libevent",
@@ -546,7 +556,7 @@
546556
"provide-pre-built": true,
547557
"license": {
548558
"type": "file",
549-
"path": "COPYING"
559+
"path": "COPYING.LIB"
550560
}
551561
},
552562
"libiconv-win": {

src/SPC/builder/Extension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ public function runCliCheckUnix(): void
305305
// Run compile check if build target is cli
306306
// If you need to run some check, overwrite this or add your assert in src/globals/ext-tests/{extension_name}.php
307307
$sharedExtensions = $this->getSharedExtensionLoadString();
308-
[$ret, $out] = shell()->execWithResult(BUILD_BIN_PATH . '/php -n' . $sharedExtensions . ' --ri "' . $this->getDistName() . '"');
308+
[$ret] = shell()->execWithResult(BUILD_BIN_PATH . '/php -n' . $sharedExtensions . ' --ri "' . $this->getDistName() . '"');
309309
if ($ret !== 0) {
310310
throw new ValidationException(
311311
"extension {$this->getName()} failed compile check: php-cli returned {$ret}",
@@ -335,7 +335,7 @@ public function runCliCheckWindows(): void
335335
{
336336
// Run compile check if build target is cli
337337
// If you need to run some check, overwrite this or add your assert in src/globals/ext-tests/{extension_name}.php
338-
[$ret] = cmd()->execWithResult(BUILD_ROOT_PATH . '/bin/php.exe -n --ri "' . $this->getDistName() . '"', false);
338+
[$ret] = cmd()->execWithResult(BUILD_BIN_PATH . '/php.exe -n --ri "' . $this->getDistName() . '"', false);
339339
if ($ret !== 0) {
340340
throw new ValidationException("extension {$this->getName()} failed compile check: php-cli returned {$ret}", validation_module: "Extension {$this->getName()} sanity check");
341341
}

src/SPC/builder/extension/readline.php

Lines changed: 11 additions & 6 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\exception\ValidationException;
89
use SPC\store\FileSystem;
910
use SPC\util\CustomExt;
1011

@@ -23,12 +24,7 @@ public function patchBeforeConfigure(): bool
2324

2425
public function getUnixConfigureArg(bool $shared = false): string
2526
{
26-
$enable = '--without-libedit --with-readline=' . BUILD_ROOT_PATH;
27-
if ($this->builder->getPHPVersionID() < 84000) {
28-
// the check uses `char rl_pending_input()` instead of `extern int rl_pending_input`, which makes LTO fail
29-
$enable .= ' ac_cv_lib_readline_rl_pending_input=yes';
30-
}
31-
return $enable;
27+
return '--with-libedit --without-readline';
3228
}
3329

3430
public function buildUnixShared(): void
@@ -39,4 +35,13 @@ public function buildUnixShared(): void
3935
}
4036
parent::buildUnixShared();
4137
}
38+
39+
public function runCliCheckUnix(): void
40+
{
41+
parent::runCliCheckUnix();
42+
[$ret, $out] = shell()->execWithResult('printf "exit\n" | ' . BUILD_BIN_PATH . '/php -a');
43+
if ($ret !== 0 || !str_contains(implode("\n", $out), 'Interactive shell')) {
44+
throw new ValidationException("readline extension failed sanity check. Code: {$ret}, output: " . implode("\n", $out));
45+
}
46+
}
4247
}

src/SPC/builder/linux/LinuxBuilder.php

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,19 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
107107

108108
$this->seekPhpSrcLogFileOnException(fn () => shell()->cd(SOURCE_PATH . '/php-src')->exec(
109109
$php_configure_env . ' ' .
110-
getenv('SPC_CMD_PREFIX_PHP_CONFIGURE') . ' ' .
111-
($enableCli ? '--enable-cli ' : '--disable-cli ') .
112-
($enableFpm ? '--enable-fpm ' . ($this->getLib('libacl') !== null ? '--with-fpm-acl ' : '') : '--disable-fpm ') .
113-
($enableEmbed ? "--enable-embed={$embed_type} " : '--disable-embed ') .
114-
($enableMicro ? '--enable-micro=all-static ' : '--disable-micro ') .
115-
($enableCgi ? '--enable-cgi ' : '--disable-cgi ') .
116-
$config_file_path .
117-
$config_file_scan_dir .
118-
$json_74 .
119-
$zts .
120-
$maxExecutionTimers .
121-
"{$phpvars} " .
122-
$this->makeStaticExtensionArgs() . ' '
110+
getenv('SPC_CMD_PREFIX_PHP_CONFIGURE') . ' ' .
111+
($enableCli ? '--enable-cli ' : '--disable-cli ') .
112+
($enableFpm ? '--enable-fpm ' . ($this->getLib('libacl') !== null ? '--with-fpm-acl ' : '') : '--disable-fpm ') .
113+
($enableEmbed ? "--enable-embed={$embed_type} " : '--disable-embed ') .
114+
($enableMicro ? '--enable-micro=all-static ' : '--disable-micro ') .
115+
($enableCgi ? '--enable-cgi ' : '--disable-cgi ') .
116+
$config_file_path .
117+
$config_file_scan_dir .
118+
$json_74 .
119+
$zts .
120+
$maxExecutionTimers .
121+
$phpvars . ' ' .
122+
$this->makeStaticExtensionArgs() . ' '
123123
));
124124

125125
$this->emitPatchPoint('before-php-make');
@@ -179,16 +179,17 @@ public function testPHP(int $build_target = BUILD_TARGET_NONE)
179179
*/
180180
protected function buildCli(): void
181181
{
182-
if ($this->getExt('readline')) {
182+
if ($this->getExt('readline') && SPCTarget::isStatic()) {
183183
SourcePatcher::patchFile('musl_static_readline.patch', SOURCE_PATH . '/php-src');
184184
}
185+
185186
$vars = SystemUtil::makeEnvVarString($this->getMakeExtraVars());
186-
$SPC_CMD_PREFIX_PHP_MAKE = getenv('SPC_CMD_PREFIX_PHP_MAKE') ?: 'make';
187+
$concurrency = getenv('SPC_CONCURRENCY') ? '-j' . getenv('SPC_CONCURRENCY') : '';
187188
shell()->cd(SOURCE_PATH . '/php-src')
188189
->exec('sed -i "s|//lib|/lib|g" Makefile')
189-
->exec("{$SPC_CMD_PREFIX_PHP_MAKE} {$vars} cli");
190+
->exec("make {$concurrency} {$vars} cli");
190191

191-
if ($this->getExt('readline')) {
192+
if ($this->getExt('readline') && SPCTarget::isStatic()) {
192193
SourcePatcher::patchFile('musl_static_readline.patch', SOURCE_PATH . '/php-src', true);
193194
}
194195

@@ -206,10 +207,10 @@ protected function buildCli(): void
206207
protected function buildCgi(): void
207208
{
208209
$vars = SystemUtil::makeEnvVarString($this->getMakeExtraVars());
209-
$SPC_CMD_PREFIX_PHP_MAKE = getenv('SPC_CMD_PREFIX_PHP_MAKE') ?: 'make';
210+
$concurrency = getenv('SPC_CONCURRENCY') ? '-j' . getenv('SPC_CONCURRENCY') : '';
210211
shell()->cd(SOURCE_PATH . '/php-src')
211212
->exec('sed -i "s|//lib|/lib|g" Makefile')
212-
->exec("{$SPC_CMD_PREFIX_PHP_MAKE} {$vars} cgi");
213+
->exec("make {$concurrency} {$vars} cgi");
213214

214215
if (!$this->getOption('no-strip', false)) {
215216
shell()->cd(SOURCE_PATH . '/php-src/sapi/cgi')->exec('strip --strip-unneeded php-cgi');
@@ -241,11 +242,11 @@ protected function buildMicro(): void
241242
// patch fake cli for micro
242243
$vars['EXTRA_CFLAGS'] .= $enable_fake_cli;
243244
$vars = SystemUtil::makeEnvVarString($vars);
244-
$SPC_CMD_PREFIX_PHP_MAKE = getenv('SPC_CMD_PREFIX_PHP_MAKE') ?: 'make';
245+
$concurrency = getenv('SPC_CONCURRENCY') ? '-j' . getenv('SPC_CONCURRENCY') : '';
245246

246247
shell()->cd(SOURCE_PATH . '/php-src')
247248
->exec('sed -i "s|//lib|/lib|g" Makefile')
248-
->exec("{$SPC_CMD_PREFIX_PHP_MAKE} {$vars} micro");
249+
->exec("make {$concurrency} {$vars} micro");
249250

250251
$this->processMicroUPX();
251252

@@ -262,10 +263,10 @@ protected function buildMicro(): void
262263
protected function buildFpm(): void
263264
{
264265
$vars = SystemUtil::makeEnvVarString($this->getMakeExtraVars());
265-
$SPC_CMD_PREFIX_PHP_MAKE = getenv('SPC_CMD_PREFIX_PHP_MAKE') ?: 'make';
266+
$concurrency = getenv('SPC_CONCURRENCY') ? '-j' . getenv('SPC_CONCURRENCY') : '';
266267
shell()->cd(SOURCE_PATH . '/php-src')
267268
->exec('sed -i "s|//lib|/lib|g" Makefile')
268-
->exec("{$SPC_CMD_PREFIX_PHP_MAKE} {$vars} fpm");
269+
->exec("make {$concurrency} {$vars} fpm");
269270

270271
if (!$this->getOption('no-strip', false)) {
271272
shell()->cd(SOURCE_PATH . '/php-src/sapi/fpm')->exec('strip --strip-unneeded php-fpm');
@@ -283,11 +284,11 @@ protected function buildFpm(): void
283284
protected function buildEmbed(): void
284285
{
285286
$vars = SystemUtil::makeEnvVarString($this->getMakeExtraVars());
286-
287+
$concurrency = getenv('SPC_CONCURRENCY') ? '-j' . getenv('SPC_CONCURRENCY') : '';
287288
shell()->cd(SOURCE_PATH . '/php-src')
288289
->exec('sed -i "s|//lib|/lib|g" Makefile')
289290
->exec('sed -i "s|^EXTENSION_DIR = .*|EXTENSION_DIR = /' . basename(BUILD_MODULES_PATH) . '|" Makefile')
290-
->exec(getenv('SPC_CMD_PREFIX_PHP_MAKE') . ' INSTALL_ROOT=' . BUILD_ROOT_PATH . " {$vars} install");
291+
->exec("make {$concurrency} INSTALL_ROOT=" . BUILD_ROOT_PATH . " {$vars} install");
291292

292293
$ldflags = getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS') ?: '';
293294
$libDir = BUILD_LIB_PATH;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SPC\builder\linux\library;
6+
7+
class libedit extends LinuxLibraryBase
8+
{
9+
use \SPC\builder\unix\library\libedit;
10+
11+
public const NAME = 'libedit';
12+
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
namespace SPC\builder\linux\library;
66

7-
/**
8-
* gmp is a template library class for unix
9-
*/
107
class readline extends LinuxLibraryBase
118
{
129
use \SPC\builder\unix\library\readline;

src/SPC/builder/macos/MacOSBuilder.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ protected function buildCli(): void
186186
$vars = SystemUtil::makeEnvVarString($this->getMakeExtraVars());
187187

188188
$shell = shell()->cd(SOURCE_PATH . '/php-src');
189-
$SPC_CMD_PREFIX_PHP_MAKE = getenv('SPC_CMD_PREFIX_PHP_MAKE') ?: 'make';
190-
$shell->exec("{$SPC_CMD_PREFIX_PHP_MAKE} {$vars} cli");
189+
$concurrency = getenv('SPC_CONCURRENCY') ? '-j' . getenv('SPC_CONCURRENCY') : '';
190+
$shell->exec("make {$concurrency} {$vars} cli");
191191
if (!$this->getOption('no-strip', false)) {
192192
$shell->exec('dsymutil -f sapi/cli/php')->exec('strip -S sapi/cli/php');
193193
}
@@ -199,8 +199,8 @@ protected function buildCgi(): void
199199
$vars = SystemUtil::makeEnvVarString($this->getMakeExtraVars());
200200

201201
$shell = shell()->cd(SOURCE_PATH . '/php-src');
202-
$SPC_CMD_PREFIX_PHP_MAKE = getenv('SPC_CMD_PREFIX_PHP_MAKE') ?: 'make';
203-
$shell->exec("{$SPC_CMD_PREFIX_PHP_MAKE} {$vars} cgi");
202+
$concurrency = getenv('SPC_CONCURRENCY') ? '-j' . getenv('SPC_CONCURRENCY') : '';
203+
$shell->exec("make {$concurrency} {$vars} cgi");
204204
if (!$this->getOption('no-strip', false)) {
205205
$shell->exec('dsymutil -f sapi/cgi/php-cgi')->exec('strip -S sapi/cgi/php-cgi');
206206
}
@@ -229,7 +229,8 @@ protected function buildMicro(): void
229229

230230
$shell = shell()->cd(SOURCE_PATH . '/php-src');
231231
// build
232-
$shell->exec(getenv('SPC_CMD_PREFIX_PHP_MAKE') . " {$vars} micro");
232+
$concurrency = getenv('SPC_CONCURRENCY') ? '-j' . getenv('SPC_CONCURRENCY') : '';
233+
$shell->exec("make {$concurrency} {$vars} micro");
233234
// strip
234235
if (!$this->getOption('no-strip', false)) {
235236
$shell->exec('dsymutil -f sapi/micro/micro.sfx')->exec('strip -S sapi/micro/micro.sfx');
@@ -250,7 +251,8 @@ protected function buildFpm(): void
250251
$vars = SystemUtil::makeEnvVarString($this->getMakeExtraVars());
251252

252253
$shell = shell()->cd(SOURCE_PATH . '/php-src');
253-
$shell->exec(getenv('SPC_CMD_PREFIX_PHP_MAKE') . " {$vars} fpm");
254+
$concurrency = getenv('SPC_CONCURRENCY') ? '-j' . getenv('SPC_CONCURRENCY') : '';
255+
$shell->exec("make {$concurrency} {$vars} fpm");
254256
if (!$this->getOption('no-strip', false)) {
255257
$shell->exec('dsymutil -f sapi/fpm/php-fpm')->exec('strip -S sapi/fpm/php-fpm');
256258
}
@@ -263,9 +265,9 @@ protected function buildFpm(): void
263265
protected function buildEmbed(): void
264266
{
265267
$vars = SystemUtil::makeEnvVarString($this->getMakeExtraVars());
266-
268+
$concurrency = getenv('SPC_CONCURRENCY') ? '-j' . getenv('SPC_CONCURRENCY') : '';
267269
shell()->cd(SOURCE_PATH . '/php-src')
268-
->exec(getenv('SPC_CMD_PREFIX_PHP_MAKE') . ' INSTALL_ROOT=' . BUILD_ROOT_PATH . " {$vars} install");
270+
->exec("make {$concurrency} INSTALL_ROOT=" . BUILD_ROOT_PATH . " {$vars} install");
269271

270272
if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'static') {
271273
$AR = getenv('AR') ?: 'ar';

0 commit comments

Comments
 (0)