-
Notifications
You must be signed in to change notification settings - Fork 31
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
swoole扩展怎么编译进去 #1
Comments
像一般的扩展in-tree构建一样,你可以这么来构建带某个扩展的micro.sfx: Like common extension in-tree build, you can build micro.sfx with some extension: # 在php源码目录 / at php source dir
# clone swoole to ext/swoole / clone swoole到ext/swoole
git clone --depth 1 --branch <你喜欢的ref> https://github.com/swoole/swoole-src ext/myext
# 重新生成configure / regenerate configure
./buildconf --force
# congfigure
./configure <args like "--disable-cli --enable-micro"> --enable-<扩展名比如swoole>
# make
make -j`nproc` 注意的是,可能一些非官方扩展对in-tree构建的支持不是很好,你可能需要稍微修改一下它的源代码 Note here, some non-offical extensions may not compatible with in-tree build, you may need to patch its source. 特别的,对于swoole,多个swoole版本在in-tree构建时会以各种方式出错 As for swoole, variant swoole versions may error in in-tree build. 同时 swoole需要c++,这意味着你需要编译glibc或者libcpp,这将大大增加micro的大小 |
好的,谢谢, |
我试着编译了 swoole 4.6.2 I tried built with swoole 4.6.2 确实,swoole需要一些patch才能in-tree编译,我使用了这些patch: Indeed, swoole need some patches to in-tree build, the patches I used: nonghttp.patch我单独编译并连接了nghttp,因此需要将swoole的nghttp代码删除: I build and linked in nghttp, so I need remove nghttp codes in swoole: diff --git a/config.m4 b/config.m4
index 8193d9d69..56de650fb 100644
--- a/config.m4
+++ b/config.m4
@@ -597,7 +597,7 @@ if test "$PHP_SWOOLE" != "no"; then
thirdparty/hiredis/read.c \
thirdparty/hiredis/sds.c"
- swoole_source_file="$swoole_source_file \
+ NOswoole_source_file="$swoole_source_file \
thirdparty/nghttp2/nghttp2_hd.c \
thirdparty/nghttp2/nghttp2_rcbuf.c \
thirdparty/nghttp2/nghttp2_helper.c \ clang.patchswoole直接修改了clang编译时的CFLAGS,导致php代码无法正常编译, 我也使用了clang swoole modified CFLAGS instantly when using clang, this cause php codes cannot compile normally diff --git a/config.m4 b/config.m4
index 8193d9d69..5ccd58891 100644
--- a/config.m4
+++ b/config.m4
@@ -279,10 +279,6 @@ AC_COMPILE_IFELSE([
)
AC_MSG_RESULT([$CLANG])
-if test "$CLANG" = "yes"; then
- CFLAGS="$CFLAGS -std=gnu89"
-fi
-
AC_CANONICAL_HOST
if test "$PHP_SWOOLE" != "no"; then config_h.patchin-tree编译时不使用config.h而是main/php_config.h,这导致HAVE_CONFIG_H预定义宏无法正常生效 when in-tree building, generated header is main/php_config.h not config.h, this causes HAVE_CONFIG_H macro not work ( copied from my config.m4 for swow... diff --git a/config.m4 b/config.m4
index 8193d9d69..1a9d1c846 100644
--- a/config.m4
+++ b/config.m4
@@ -286,6 +286,13 @@ fi
AC_CANONICAL_HOST
if test "$PHP_SWOOLE" != "no"; then
+dnl solve in-tree build config.h problem
+dnl just make a fake config.h before all things
+PHP_ADD_BUILD_DIR(PHP_EXT_DIR(swoole)"/build", 1)
+cat > PHP_EXT_DIR(swoole)/build/config.h << EOF
+#include "php_config.h"
+EOF
+INCLUDES="-I. -I"PHP_EXT_DIR(swoole)"/build ${INCLUDES}"
AC_CHECK_LIB(c, accept4, AC_DEFINE(HAVE_ACCEPT4, 1, [have accept4]))
AC_CHECK_LIB(c, signalfd, AC_DEFINE(HAVE_SIGNALFD, 1, [have signalfd]))
@@ -682,7 +689,7 @@ if test "$PHP_SWOOLE" != "no"; then
AC_DEFINE(SW_USE_ASM_CONTEXT, 1, [use boost asm context])
fi
- PHP_NEW_EXTENSION(swoole, $swoole_source_file, $ext_shared,,$EXTRA_CFLAGS, cxx)
+ PHP_NEW_EXTENSION(swoole, $swoole_source_file, $ext_shared,,"$EXTRA_CFLAGS -DHAVE_CONFIG_H", cxx)
PHP_ADD_INCLUDE([$ext_srcdir])
PHP_ADD_INCLUDE([$ext_srcdir/include])
除此之外,swoole的php_swoole.h没有出现在扩展根目录,这导致configure无法正常找到定义,你还需要在扩展根目录放置任意名称(比如"php_swoole_for_configure.h")的头文件,内容如下 Otherwise, swoole's php_swoole.h is not located in extension root dir, this cause configure cannot locate module definations, you need put a header at extension root dir with any name (like "php_swoole_for_configure.h") with content: extern zend_module_entry swoole_module_entry;
#define phpext_swoole_ptr &swoole_module_entry
|
[root@SwLocal api]# php api.php [root@SwLocal api]# |
看来是做了硬编码的SAPI检查,加了个patch Seems there's some hardcoden checks, add a patch diff --git a/ext-src/php_swoole.cc b/ext-src/php_swoole.cc
index d98127733..89ab4380c 100644
--- a/ext-src/php_swoole.cc
+++ b/ext-src/php_swoole.cc
@@ -722,7 +722,7 @@ PHP_MINIT_FUNCTION(swoole) {
}
swoole_init();
- if (strcmp("cli", sapi_module.name) == 0 || strcmp("phpdbg", sapi_module.name) == 0) {
+ if (strcmp("cli", sapi_module.name) == 0 || strcmp("phpdbg", sapi_module.name) == 0 || strcmp("micro", sapi_module.name) == 0 ) {
SWOOLE_G(cli) = 1;
}
|
谢谢。目前可以了,能搞一个Windows版本的吗? |
Swoole不支持windows,如果需要windows版,考虑Swow替代 |
整一个撒, |
WARNING swoole_timer_free: timer is not available |
哥,redis扩展也没有弄好呀 |
试试这个 https://github.com/dixyes/build-my-own-phpmicro/releases/tag/20210218030458-a4f6aaf 最近么的电脑,稍晚点再考虑phpredis里lzf zstd lz4之类的依赖 |
Fatal error: Uncaught Error: Call to undefined function Jobs\curl_init() in phar |
搞不来c++,不然我自己搞了 |
redis好了, |
(讲道理我的这俩项目里一行C++都没有 curl整上了,做解析静态库依赖花了点时间。 至于swoole的弃用,你需要适配下swoole的api。 https://github.com/dixyes/build-my-own-phpmicro/releases/tag/20210220061013-a4f6aaf |
怎么设置php.ini里面内容?? |
|
我按照你的步骤执行 在php源码目录下patch -p1 api/micro/patches/disable_huge_page.patch 到是可以执行后面得步骤,,但是我编译出来的micro.sfx,结果感觉是我当前php环境,并不是我下载得源码php8.0版本得环境,我有点蒙了 |
swoole扩展怎么编译进去
The text was updated successfully, but these errors were encountered: