Skip to content

Commit 478bf0e

Browse files
committed
Merge branch 'build_native_php' into php-fpm
2 parents cd3acbd + ffb81ee commit 478bf0e

File tree

8 files changed

+120
-18
lines changed

8 files changed

+120
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,4 +343,5 @@ LICENSE
343343
swoole-cli-*
344344
php-cli-*
345345
php-fpm-*
346+
!sapi/patches
346347

docs/upgrade.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ php sync-source-code.php
1212
php sync-source-code.php --action run
1313

1414

15+
./bin/runtime/php -c ./bin/runtime/php.ini sync-source-code.php
16+
./bin/runtime/php -c ./bin/runtime/php.ini sync-source-code.php --action run
17+
1518
```
1619

1720
## 目录说明
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
From 2a15bd4c55d8d2f46d2e17d4f7e642a2387d6e01 Mon Sep 17 00:00:00 2001
2+
From: jingjingxyk <[email protected]>
3+
Date: Sun, 6 Oct 2024 18:59:27 +0800
4+
Subject: [PATCH] fix readline not work
5+
6+
---
7+
ext/readline/readline_cli.c | 19 ++-----------------
8+
1 file changed, 2 insertions(+), 17 deletions(-)
9+
10+
diff --git a/ext/readline/readline_cli.c b/ext/readline/readline_cli.c
11+
index 8bf5d23df..0adecf42a 100644
12+
--- a/ext/readline/readline_cli.c
13+
+++ b/ext/readline/readline_cli.c
14+
@@ -744,24 +744,9 @@ typedef cli_shell_callbacks_t *(__cdecl *get_cli_shell_callbacks)(void);
15+
} while(0)
16+
17+
#else
18+
-/*
19+
-#ifdef COMPILE_DL_READLINE
20+
-This dlsym() is always used as even the CGI SAPI is linked against "CLI"-only
21+
-extensions. If that is being changed dlsym() should only be used when building
22+
-this extension sharedto offer compatibility.
23+
-*/
24+
-#define GET_SHELL_CB(cb) \
25+
- do { \
26+
- (cb) = NULL; \
27+
- cli_shell_callbacks_t *(*get_callbacks)(void); \
28+
- get_callbacks = dlsym(RTLD_DEFAULT, "php_cli_get_shell_callbacks"); \
29+
- if (get_callbacks) { \
30+
- (cb) = get_callbacks(); \
31+
- } \
32+
- } while(0)
33+
-/*#else
34+
+
35+
#define GET_SHELL_CB(cb) (cb) = php_cli_get_shell_callbacks()
36+
-#endif*/
37+
+
38+
#endif
39+
40+
PHP_MINIT_FUNCTION(cli_readline)
41+
--
42+
2.46.2
43+

sapi/src/builder/extension/opcache.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@
1010
->withOptions('--enable-opcache')
1111
);
1212

13-
1413
// 扩展钩子 写法
1514
$p->withBeforeConfigureScript('opcache', function (Preprocessor $p) {
1615
$php_src_dir = $p->getPhpSrcDir();
17-
$cmd = "cd {$php_src_dir}/" . PHP_EOL;
16+
$cmd = <<<EOF
17+
cd {$php_src_dir}/ ;
18+
19+
EOF;
20+
1821
$cmd .= <<<'EOF'
1922
2023
cat > ext/opcache/php_opcache.h <<PHP_OPCACHE_H_EOF

sapi/src/builder/extension/readline.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,39 @@
1111
->withOptions('--with-readline=' . READLINE_PREFIX)
1212
->withDependentLibraries('ncurses', 'readline')
1313
);
14+
15+
16+
// 扩展钩子
17+
$p->withBeforeConfigureScript('readline', function (Preprocessor $p) {
18+
$workDir = $p->getWorkDir();
19+
$php_src = $p->getPhpSrcDir();
20+
$delim = " ";
21+
$cmd = <<<EOF
22+
cd {$php_src}/
23+
24+
# 获得行号
25+
# awk '/#ifdef COMPILE_DL_READLINE/ { print NR }' ext/readline/readline_cli.c
26+
# grep -n '#ifdef COMPILE_DL_READLINE' ext/readline/readline_cli.c | cut -d ':' -f 1
27+
# sed -n "/#ifdef COMPILE_DL_READLINE/=" ext/readline/readline_cli.c
28+
29+
grep -n '#ifdef COMPILE_DL_READLINE' ext/readline/readline_cli.c
30+
if [ $? = 0 ] ; then
31+
# 获得待删除 区间
32+
START_LINE_NUM=$(sed -n "/#ifdef COMPILE_DL_READLINE/=" ext/readline/readline_cli.c)
33+
START_LINE_NUM=$((\$START_LINE_NUM - 1))
34+
END_LINE_NUM=$(sed -n "/PHP_MINIT_FUNCTION(cli_readline)/=" ext/readline/readline_cli.c)
35+
END_LINE_NUM=$((\$END_LINE_NUM - 5))
36+
37+
sed -i.backup "\${START_LINE_NUM},\${END_LINE_NUM}d" ext/readline/readline_cli.c
38+
39+
REPLACE_LINE_NUM=$(sed -n "/#define GET_SHELL_CB(cb) (cb) = php_cli_get_shell_callbacks()/=" ext/readline/readline_cli.c)
40+
REPLACE_LINE_NUM=$((\$REPLACE_LINE_NUM + 1))
41+
42+
sed -i.backup "\${REPLACE_LINE_NUM} s/.*/ /" ext/readline/readline_cli.c
43+
44+
fi
45+
EOF;
46+
47+
return $cmd;
48+
});
1449
};

sapi/src/builder/library/php.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
test -d {$php_src} && rm -rf {$php_src}
2424
2525
cp -rf php {$php_src}
26+
echo "{$php_tag}" > {$php_src}/X-PHP-VERSION
27+
2628
rm -rf php
2729
cd {$build_dir}/
2830
EOF

sapi/src/template/make.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,12 @@
265265
}
266266

267267
make_config() {
268+
PHP_VERSION=<?= BUILD_PHP_VERSION; ?> ;
269+
if [ ! -f "<?= $this->phpSrcDir ?>/X-PHP-VERSION" ] ; then
270+
bash make.sh php ;
271+
fi
272+
test "${PHP_VERSION}" = "$(cat '<?= $this->phpSrcDir ?>/X-PHP-VERSION')" || bash make.sh php ;
273+
268274
cd <?= $this->phpSrcDir ?>/
269275
<?php if (in_array($this->buildType, ['dev'])) : ?>
270276
# dev 环境 过滤扩展,便于调试单个扩展编译
@@ -285,21 +291,21 @@
285291
<?php if ($this->getInputOption('with-swoole-cli-sfx')) : ?>
286292
PHP_VERSION=$(cat main/php_version.h | grep 'PHP_VERSION_ID' | grep -E -o "[0-9]+")
287293
if [[ $PHP_VERSION -lt 80000 ]] ; then
288-
echo "only support PHP >= 8.0 "
294+
echo "only support PHP >= 8.0 "
289295
else
290-
# 请把这个做成 patch https://github.com/swoole/swoole-cli/pull/55/files
291-
296+
# 请把这个做成 patch https://github.com/swoole/swoole-cli/pull/55/files
292297
fi
293-
<?php endif ;?>
298+
<?php endif; ?>
294299

295300
cd <?= $this->getPhpSrcDir() ?>/
296301
test -f ./configure && rm ./configure
297302
./buildconf --force
298303

299304
<?php if ($this->isMacos()) : ?>
300305
<?php if ($this->hasLibrary('pgsql')) : ?>
301-
sed -i.backup "s/ac_cv_func_explicit_bzero\" = xyes/ac_cv_func_explicit_bzero\" = x_fake_yes/" ./configure
302-
<?php endif;?>
306+
sed -i.backup "s/ac_cv_func_explicit_bzero\" = xyes/ac_cv_func_explicit_bzero\" = x_fake_yes/" ./configure
307+
test -f ./configure.backup && rm -f ./configure.backup
308+
<?php endif; ?>
303309
<?php endif; ?>
304310

305311
export_variables
@@ -317,7 +323,8 @@
317323

318324
<?php if ($this->isLinux()) : ?>
319325
sed -i.backup 's/-export-dynamic/-all-static/g' Makefile
320-
<?php endif ; ?>
326+
test -f Makefile.backup && rm -f Makefile.backup
327+
<?php endif; ?>
321328

322329
}
323330

sync-source-code.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
9696
sed -i.backup 's/ext_shared=yes/ext_shared=no/g' ext/opcache/config.m4
9797
sed -i.backup 's/shared,,/$ext_shared,,/g' ext/opcache/config.m4
98+
# sed -i 's/-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1/-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -DPHP_ENABLE_OPCACHE/g' ext/opcache/config.m4
9899
# echo '#include "php.h"\n\nextern zend_module_entry opcache_module_entry;\n#define phpext_opcache_ptr &opcache_module_entry\n' > ext/opcache/php_opcache.h
99100
cat > ext/opcache/php_opcache.h <<PHP_OPCACHE_H_EOF
100101
#include "php.h"
@@ -140,8 +141,8 @@
140141
# build
141142
cp -rf $SRC/build/ ./build
142143
143-
# TSRM
144-
cp -rf $SRC/TSRM/ ./TSRM
144+
# TSRM (more info: https://github.com/swoole/swoole-cli/commit/172c76445a631abb1b32fc2a721a2dd9d5a5fc0d)
145+
# cp -rf $SRC/TSRM/ ./TSRM
145146
146147
cp -f $SRC/configure.ac ./configure.ac
147148
cp -f $SRC/buildconf ./buildconf
@@ -153,22 +154,29 @@
153154
# 在sed命令中,常见的需要转义的字符有:\、/、$、&、.、*、[、]等
154155
# 反斜杠、正斜杠、美元符号、引用符号、点号、星号、方括号等
155156
156-
test -f main/main.c.backup && rm -f main/main.c.backup
157-
test -f ext/opcache/config.m4.backup && rm -f ext/opcache/config.m4.backup
158157
159158
160-
# fpm
161-
cp -rf $SRC/sapi/fpm/fpm ./sapi/cli/
159+
# fpm [Need to manually compare fpm_main.c]
160+
# cp -rf $SRC/sapi/fpm/fpm ./sapi/cli/
162161
sed -i.backup 's/int main(int argc, char \*argv\[\])/int fpm_main(int argc, char \*argv\[\])/g' ./sapi/cli/fpm/fpm_main.c
163-
sed -i.backup 's/{'-', 0, NULL}/{'P', 0, "fpm"},\n {'-', 0, NULL}/g' ./sapi/cli/fpm/fpm_main.c
164-
165-
162+
# sed -i.backup "s/{'-', 0, NULL}/{'P', 0, \"fpm\"},\n {'-', 0, NULL}/g" ./sapi/cli/fpm/fpm_main.c
166163
167164
# cli
168165
cp -rf $SRC/sapi/cli/ps_title.c ./sapi/cli
169166
cp -rf $SRC/sapi/cli/generate_mime_type_map.php ./sapi/cli
170167
cp -rf $SRC/sapi/cli/php.1.in ./sapi/cli
171168
169+
170+
# clean file
171+
test -f main/main.c.backup && rm -f main/main.c.backup
172+
test -f ext/opcache/config.m4.backup && rm -f ext/opcache/config.m4.backup
173+
test -f sapi/cli/fpm/fpm_main.c.backup && rm -f sapi/cli/fpm/fpm_main.c.backup
174+
175+
# ext readline_cli patch
176+
cp -f sapi/patches/0001-fix-readline-not-work.patch 0001-fix-readline-not-work.patch
177+
{ git apply --check 0001-fix-readline-not-work.patch ; } && { git apply 0001-fix-readline-not-work.patch ; }
178+
179+
172180
EOF;
173181

174182
echo PHP_EOL;

0 commit comments

Comments
 (0)