Code Monkey home page Code Monkey logo

swoole-cli's Issues

下载依赖库 使用镜像地址

php prepare.php \
--with-build-type=dev \
--with-dependency-graph=1 \
+apcu +ds +inotify \
--without-docker=1 \
--with-download-mirror-url=https://swoole-cli.jingjingxyk.com/

提示: 构建依赖库解决依赖的3种办法

办法一: 直接指定依赖库所在目录 。例如(--with-openssl=/usr/openssl)

办法二: 使用 pkg-config

办法三: 上述两种办法混用,大部分情况是(办法一)比(办法二)优先级高

为啥会混用,因为一部分库未提供 pkg-config 配置。 比如bzip2 ,iconv ,libgif

例子:构建 curl

            package_name='zlib openssl libcares libbrotlicommon libbrotlidec libbrotlienc libzstd libnghttp2 libidn2'
            CPPFLAGS="$(pkg-config  --cflags-only-I  --static $package_name)" \
            LDFLAGS="$(pkg-config   --libs-only-L    --static $package_name)" \
            LIBS="$(pkg-config      --libs-only-l    --static $package_name)" \
            ./configure --prefix=/usr/curl  \
            --enable-static \
            --disable-shared \
            --without-librtmp \
            --disable-ldap \
            --disable-rtsp \
            --enable-http \
            --enable-alt-svc \
            --enable-hsts \
            --enable-http-auth \
            --enable-mime \
            --enable-cookies \
            --enable-doh \
            --enable-threaded-resolver \
            --enable-ipv6 \
            --enable-proxy  \
            --enable-websockets \
            --enable-get-easy-options \
            --enable-file \
            --enable-mqtt \
            --enable-unix-sockets  \
            --enable-progress-meter \
            --enable-optimize \
            --with-zlib=/usr/zlib \
            --with-openssl=/usr/openssl \
            --enable-ares=/usr/cares \
            --with-default-ssl-backend=openssl \
            --with-libidn2 \
            --with-nghttp2 \
            --without-ngtcp2 \
            --without-nghttp3 

cygwin64 编译本项目时,需要删除 main/main.c 文件中的2行代码,才能链接通过,不知道怎么解决这个问题

链接阶段找不到 结构体 zend_extension_entry

main/main.c 需要删除的行是: 2263,2264 行

	/* start Zend extensions */
	extern zend_extension ;
	# zend_register_extension(&zend_extension_entry, NULL);
	# zend_startup_extensions();

错误信息:

image

删除两行代码以后,可以编译通过

test -f main/main.c.backup ||  sed -i.backup '2263,2264d' main/main.c

截图 2023-02-13 18-57-41

configure:31121: error: Unable to locate gmp.h

version: v5.0.1 / current main

command:
./make.sh config

configure:27873: $? = 0
configure:30163: checking for GNU gettext support
configure:30200: result: no
configure:30892: checking for GNU MP support
configure:30929: result: yes
configure:31121: error: Unable to locate gmp.h

使用依赖库镜像地址

使用依赖库镜像地址

方式一:

php prepare.php   +ds +inotify +apcu +protobuf --with-download-mirror-url=https://swoole-cli.jingjingxyk.com

方式二:

执行这个脚本, 原理: 自动下载 https://swoole-cli.jingjingxyk.com/all-archive.zip

sh sapi/download-box/download-box-get-archive-from-server.sh

方式三:

借助容器分发

sh sapi/download-box/download-box-get-archive-from-container.sh
# 容器分发原理介绍
container_id=$(docker create $IMAGE) # returns container ID
docker cp $container_id:/usr/share/nginx/html/extensions extensions
docker cp $container_id:/usr/share/nginx/html/libraries libraries
docker rm $container_id

构建依赖库镜像参考: https://github.com/swoole/swoole-cli/tree/main/sapi/download-box

curl 启用nghttp2时出现 multiple definition of `nghttp2_strerror'; 函数多重定义

multiple definition of `nghttp2_strerror'; 函数多重定义

与这里出现冲突 https://github.com/swoole/swoole-src/blob/master/thirdparty/nghttp2/nghttp2_helper.c

/usr/bin/ld: /usr/nghttp2/lib/libnghttp2.a(nghttp2_helper.o): in function `nghttp2_strerror':
/work/thirdparty/nghttp2/lib/nghttp2_helper.c:254: multiple definition of `nghttp2_strerror'; ext/swoole/thirdparty/nghttp2/nghttp2_helper.o:/work/ext/swoole/thirdparty/nghttp2/nghttp2_helper.c:35: first defined here
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:295: bin/swoole-cli] Error 1

image

为了能直观的看到依赖关系,这个版本没有跟随主仓库,把构建安装依赖库的过程放到conf.d目录

主仓库依赖库安装顺序 查看

# 查看依赖库和依赖库安装顺序
 ./make.sh list-library 

# 查看各库 pkg-config 配置信息
./make.sh pkg-check

有兴趣的同志可以看参考以下:https://github.com/jingjingxyk/swoole-cli/pull/31/files

各依赖库构建过程放到:library_install_builder.php文件

库或者扩展的依赖关系简述: 用注释写在这个文件里library_builder.php

该版本与主仓库版本的差异

因为不能直观的看到依赖关系,因此诞生这个版本

image

image
image
image
image

提示: macOS 链接时libxslt 需要添加 -framework CoreFoundation -framework SystemConfiguration 原因所在

macOS 反复验证:
发现 依赖库libxslt 默认启用 --with-python --with-crypto --with-profiler --with-plugins --with-debugger
其中 crypto 依赖 libunistring 、libgcrypt 进一步依赖 -framework SystemConfiguration

根源: -lintl -Wl,-framework -Wl,CoreFoundation

gettext库包含intl
coreutils库包含libunistring

解决办法:

    ./configure \
    --prefix={$libxslt_prefix} \
    --enable-static=yes \
    --enable-shared=no \
    --with-libxml-libs-prefix={$libxml2_prefix} \
    --without-python \
    --without-crypto \
    --without-profiler \
    --without-plugins \
    --without-debugger

解决以后,链接参数就可以不需要

-framework CoreFoundation -framework SystemConfiguration 

静态编译libpq,libffi参考

静态编译libpq源代码

function install_pgsql(Preprocessor $p)
{
    $p->addLibrary(
        (new Library('pgsql'))
            ->withHomePage('https://www.postgresql.org/')
            ->withLicense('https://www.postgresql.org/about/licence/', Library::LICENSE_SPEC)
            ->withUrl('https://ftp.postgresql.org/pub/source/v15.1/postgresql-15.1.tar.gz')
            //https://www.postgresql.org/docs/devel/installation.html
            //https://www.postgresql.org/docs/devel/install-make.html#INSTALL-PROCEDURE-MAKE
            ->withManual('https://www.postgresql.org/docs/')
            ->withCleanBuildDirectory()
            ->withScriptBeforeConfigure(
                '
               test -d /usr/pgsql && rm -rf /usr/pgsql
            '
            )
            ->withConfigure(
                '
            ./configure --help
            
            sed -i.backup "s/invokes exit\'; exit 1;/invokes exit\';/"  src/interfaces/libpq/Makefile
  
            # 替换指定行内容
            sed -i.backup "102c all: all-lib" src/interfaces/libpq/Makefile
           
            # export CPPFLAGS="-static -fPIE -fPIC -O2 -Wall "
            # export CFLAGS="-static -fPIE -fPIC -O2 -Wall "
            
            export CPPFLAGS=$(pkg-config  --cflags --static  icu-uc icu-io icu-i18n readline libxml-2.0)
            export LIBS=$(pkg-config  --libs --static   icu-uc icu-io icu-i18n readline libxml-2.0)
          
         
            ./configure  --prefix=/usr/pgsql \
            --enable-coverage=no \
            --with-ssl=openssl  \
            --with-readline \
            --with-icu \
            --without-ldap \
            --with-libxml  \
            --with-libxslt \
            --with-includes="/usr/openssl/include/:/usr/libxml2/include/:/usr/libxslt/include:/usr/readline/include/readline:/usr/icu/include:/usr/zlib/include:/usr/include" \
            --with-libraries="/usr/openssl/lib:/usr/libxml2/lib/:/usr/libxslt/lib/:/usr/readline/lib:/usr/icu/lib:/usr/zlib/lib:/usr/lib"

            make -C src/include install 
            result_code=$?
            [[ $result_code -ne 0 ]] && echo "[make FAILURE]" && exit $result_code;
            
            make -C  src/bin/pg_config install
            result_code=$?
            [[ $result_code -ne 0 ]] && echo "[make FAILURE]" && exit $result_code;
            
            
            make -C  src/common -j $cpu_nums all 
            make -C  src/common install 
            result_code=$?
            [[ $result_code -ne 0 ]] && echo "[make FAILURE]" && exit $result_code;
            
            make -C  src/port -j $cpu_nums all 
            make -C  src/port install 
            result_code=$?
            [[ $result_code -ne 0 ]] && echo "[make FAILURE]" && exit $result_code;
                        
            make -C  src/backend/libpq -j $cpu_nums all 
            make -C  src/backend/libpq install 
            result_code=$?
            [[ $result_code -ne 0 ]] && echo "[make FAILURE]" && exit $result_code;
                        
            make -C src/interfaces/ecpg   -j $cpu_nums all-pgtypeslib-recurse all-ecpglib-recurse all-compatlib-recurse all-preproc-recurse
            make -C src/interfaces/ecpg  install-pgtypeslib-recurse install-ecpglib-recurse install-compatlib-recurse install-preproc-recurse
            result_code=$?
            [[ $result_code -ne 0 ]] && echo "[make FAILURE]" && exit $result_code;
                        
            # 静态编译 src/interfaces/libpq/Makefile  有静态配置  参考: all-static-lib
            
            make -C src/interfaces/libpq  -j $cpu_nums # soname=true
            make -C src/interfaces/libpq  install 
            result_code=$?
            [[ $result_code -ne 0 ]] && echo "[make FAILURE]" && exit $result_code;
                        
            rm -rf /usr/pgsql/lib/*.so.*
            rm -rf /usr/pgsql/lib/*.so
            return 0 

            '
            )
            ->withPkgName('libpq')
            ->withPkgConfig('/usr/pgsql/lib/pkgconfig')
            ->withLdflags('-L/usr/pgsql/lib/')
            ->withBinPath('/usr/pgsql/bin/')
    );
}

静态编译libffi

function install_libffi($p)
{
    $p->addLibrary(
        (new Library('libffi'))
            ->withHomePage('https://sourceware.org/libffi/')
            ->withLicense('http://github.com/libffi/libffi/blob/master/LICENSE', Library::LICENSE_BSD)
            ->withUrl('https://github.com/libffi/libffi/releases/download/v3.4.4/libffi-3.4.4.tar.gz')
            ->withFile('libffi-3.4.4.tar.gz')
            ->withPrefix('/usr/libffi/')
            ->withScriptBeforeConfigure(
                'test -d /usr/libffi && rm -rf /usr/libffi'
            )
            ->withConfigure(
                '
            ./configure --help ;
            ./configure \
            --prefix=/usr/libffi \
            --enable-shared=no \
            --enable-static=yes 
            '
            )
            ->withPkgName('libffi')
            ->withPkgConfig('/usr/libffi/lib/pkgconfig')
            ->withLdflags('-L/usr/libffi/lib/')
            ->withBinPath('/usr/libffi/bin/')
    //->withSkipInstall()
    //->disablePkgName()
    //->disableDefaultPkgConfig()
    //->disableDefaultLdflags()
    );
}

使用 curl 代替 wget 下载软件,支持 socks5 代理

由于 wget 仅支持 http 代理,不支持 socks5 代理,导致无法使用代理。需要替换为 curl,curl 同时支持两种代理方式。

export http_proxy=socks5h://127.0.0.1:1080
export https_proxy=socks5h://127.0.0.1:1080

执行 make clean 时会删除 thirdparty 中的目标文件

如题,待解决

考虑借鉴 phpbrew ,创建一个 $HOME/.swoole-cli/ 目录,存储下载、构建以及目标文件

  • $HOME/.swoole-cli/source:源代码包,替换当前的 pool/libpool/ext
  • $HOME/.swoole-cli/build:构建时文件,替换当前的 thirdparty 目录
  • $HOME/.swoole-cli/library:在 macOS 系统下替换 /usr 目录

macos 下避开被 /usr 目录替换

if ($p->getOsType() == 'macos') {
    $p->addEndCallback(function () use ($p) {
        $header=<<<'EOF'
export PATH=/opt/homebrew/bin/:/usr/local/bin/:$PATH
EOF;
        $command= file_get_contents(__DIR__ . '/make.sh');
        $command=$header.PHP_EOL.$command;
        file_put_contents(__DIR__ . '/make.sh',$command);
    });

}

$p->addEndCallback(function () use ($p) {
    $header=<<<'EOF'
#!/bin/env sh
set -uex
PKG_CONFIG_PATH='/usr/lib/pkgconfig'
test -d /usr/lib64/pkgconfig && PKG_CONFIG_PATH="/usr/lib64/pkgconfig:$PKG_CONFIG_PATH" ;
test -d /usr/local/lib64/pkgconfig && PKG_CONFIG_PATH="/usr/local/lib64/pkgconfig:$PKG_CONFIG_PATH" ;

cpu_nums=`nproc 2> /dev/null || sysctl -n hw.ncpu`
# `grep "processor" /proc/cpuinfo | sort -u | wc -l`

EOF;
    $command= file_get_contents(__DIR__ . '/make.sh');
    $command=$header.PHP_EOL.$command;
    file_put_contents(__DIR__ . '/make.sh',$command);
});

image

image

image

TODO: 使用 Github Action 自动构建,并自动上传到平台

使用 Github Action 自动构建,并上传发布:

发布

  • Github swoole-src releases
  • Gitee swoole-src releases
  • Github swoole-clireleases
  • Gitee swoole-cli releases
  • 腾讯云 OSSswoole.com/download 页面)

平台

  • Linux x86-64
  • Linux arm64
  • macOS x86-64
  • macOS arm64
  • Windows x86-64 cygwin

Enable c-ares support, require c-ares library

按照make.sh中的指令进行安装完成

cd /work/thirdparty
    echo "build cares"
    mkdir -p /work/thirdparty/cares && \
    tar --strip-components=1 -C /work/thirdparty/cares -xf /work/pool/lib/c-ares-1.18.1.tar.gz  && \
    cd cares && \
    echo  "./configure --prefix=/usr --enable-static --disable-shared"
        ./configure --prefix=/usr --enable-static --disable-shared && \
        make -j 8   && \
    make install
    cd -

安装完成

list.3 ares_strerror.3 ares_timeout.3 ares_version.3 '/usr/share/man/man3'
make[2]: Leaving directory '/work/c-ares-1.18.1/docs'
make[1]: Leaving directory '/work/c-ares-1.18.1/docs'
Making install in test
make[1]: Entering directory '/work/c-ares-1.18.1/test'
make[2]: Entering directory '/work/c-ares-1.18.1/test'
make[2]: Nothing to be done for 'install-exec-am'.
make[2]: Nothing to be done for 'install-data-am'.
make[2]: Leaving directory '/work/c-ares-1.18.1/test'
make[1]: Leaving directory '/work/c-ares-1.18.1/test'
make[1]: Entering directory '/work/c-ares-1.18.1'
make[2]: Entering directory '/work/c-ares-1.18.1'
make[2]: Nothing to be done for 'install-exec-am'.
 ./install-sh -c -d '/usr/lib/pkgconfig'
 /usr/bin/install -c -m 644 libcares.pc '/usr/lib/pkgconfig'
make[2]: Leaving directory '/work/c-ares-1.18.1'
make[1]: Leaving directory '/work/c-ares-1.18.1'

执行make.sh build报以下异常

/work/swoole-cli/ext/swoole/ext-src/php_swoole_private.h:85:2: error: "Enable c-ares support, require c-ares library"
#error "Enable c-ares support, require c-ares library"
 ^
In file included from /work/swoole-cli/ext/swoole/ext-src/php_swoole_cxx.cc:1:
In file included from /work/swoole-cli/ext/swoole/ext-src/php_swoole_cxx.h:19:
/work/swoole-cli/ext/swoole/ext-src/php_swoole_private.h:85:2: error: "Enable c-ares support, require c-ares library"
#error "Enable c-ares support, require c-ares library"
 ^
/work/swoole-cli/ext/swoole/ext-src/php_swoole.cc:55:10: fatal error: 'ares.h' file not found
#include <ares.h>
         ^~~~~~~~
In file included from /work/swoole-cli/ext/swoole/ext-src/swoole_admin_server.cc:17:
In file included from /work/swoole-cli/ext/swoole/ext-src/php_swoole_server.h:21:
In file included from /work/swoole-cli/ext/swoole/ext-src/php_swoole_cxx.h:19:
/work/swoole-cli/ext/swoole/ext-src/php_swoole_private.h:85:2: error: "Enable c-ares support, require c-ares library"
#error "Enable c-ares support, require c-ares library"
 ^
2 errors generated.
make: *** [Makefile:1898: ext/swoole/ext-src/php_swoole.lo] Error 1
make: *** Waiting for unfinished jobs....
In file included from /work/swoole-cli/ext/swoole/ext-src/swoole_async_coro.cc:17:
In file included from /work/swoole-cli/ext/swoole/ext-src/php_swoole_cxx.h:19:
/work/swoole-cli/ext/swoole/ext-src/php_swoole_private.h:85:2: error: "Enable c-ares support, require c-ares library"
#error "Enable c-ares support, require c-ares library"
 ^
In file included from /work/swoole-cli/ext/swoole/ext-src/swoole_atomic.cc:17:
/work/swoole-cli/ext/swoole/ext-src/php_swoole_private.h:85:2: error: "Enable c-ares support, require c-ares library"
#error "Enable c-ares support, require c-ares library"
 ^
In file included from /work/swoole-cli/ext/swoole/ext-src/swoole_channel_coro.cc:20:
In file included from /work/swoole-cli/ext/swoole/ext-src/php_swoole_cxx.h:19:
/work/swoole-cli/ext/swoole/ext-src/php_swoole_private.h:85:2: error: "Enable c-ares support, require c-ares library"
#error "Enable c-ares support, require c-ares library"
 ^
1 error generated.
make: *** [Makefile:1910: ext/swoole/ext-src/swoole_atomic.lo] Error 1
1 error generated.
make: *** [Makefile:1901: ext/swoole/ext-src/php_swoole_cxx.lo] Error 1
In file included from /work/swoole-cli/ext/swoole/ext-src/swoole_client_coro.cc:17:
In file included from /work/swoole-cli/ext/swoole/ext-src/php_swoole_cxx.h:19:
/work/swoole-cli/ext/swoole/ext-src/php_swoole_private.h:85:2: error: "Enable c-ares support, require c-ares library"
#error "Enable c-ares support, require c-ares library"
 ^
In file included from /work/swoole-cli/ext/swoole/ext-src/swoole_client.cc:17:
In file included from /work/swoole-cli/ext/swoole/ext-src/php_swoole_cxx.h:19:
/work/swoole-cli/ext/swoole/ext-src/php_swoole_private.h:85:2: error: "Enable c-ares support, require c-ares library"
#error "Enable c-ares support, require c-ares library"

请问为什么xlswriter被删除了?

@jingjingxyk 请问为什么xlswriter被删除了?您一般使用什么方案来解决xls读写文件的?我们之前使用 PHPExcel ,但是速度慢,所以就换了。您下线掉 xlswriter 是因为有更好的选择吗?

brotli编译链接时出现找不到函数,解决办法

通过查阅文档和反复实践,确认了原因和解决办法
原因所在:

 'mv ' . BROTLI_PREFIX . '/lib/libbrotlicommon-static.a ' . BROTLI_PREFIX . '/lib/libbrotli.a',

image

解决办法:

'cp ' . BROTLI_PREFIX . '/lib/libbrotlicommon-static.a ' . BROTLI_PREFIX . '/lib/libbrotli.a',
'mv ' . BROTLI_PREFIX . '/lib/libbrotlicommon-static.a ' . BROTLI_PREFIX . '/lib/libbrotlicommon.a',

image

最终解决:#36

image

@matyhtf

不修改本仓库源码前提下,添加内置扩展 ffi 、pdo_pgsql、pgsql 参考

自己新增内置扩展,同时又不修改本仓库源代码
install_php_internal_extensions

function ($p)
{

    $workDir = $p->getWorkDir();
    $p->addLibrary(
        (new Library('php_internal_extensions'))
            ->withHomePage('https://www.php.net/')
            ->withLicense('https://github.com/php/php-src/blob/master/LICENSE', Library::LICENSE_PHP)
            ->withUrl('https://github.com/php/php-src/archive/refs/tags/php-8.1.12.tar.gz')
            ->withFile('php-8.1.12.tar.gz')
            ->withManual('https://www.php.net/docs.php')
            ->withLabel('php_internal_extension')
            ->withCleanBuildDirectory()
            ->withScriptBeforeConfigure(
                "
                    test -d {$workDir}/ext/ffi && rm -rf {$workDir}/ext/ffi
                    cp -rf  ext/ffi {$workDir}/ext/
                    
                    test -d {$workDir}/ext/pdo_pgsql && rm -rf {$workDir}/ext/pdo_pgsql
                    cp -rf  ext/pdo_pgsql {$workDir}/ext/
                    
                    test -d {$workDir}/ext/pgsql && rm -rf {$workDir}/ext/pgsql
                    cp -rf  ext/pgsql {$workDir}/ext/
                "
            )
            ->withConfigure('return 0')
            ->disablePkgName()
            ->disableDefaultPkgConfig()
            ->disableDefaultLdflags()
            ->withSkipBuildLicense()

    );

}

openssl 证书路径

macOS 下会指向 ~/.swoole_cli/openssl/ssl ,linux 会指向 /usr/openssl/ssl

用户需要创建软连接,可在编译 openssl 时指定证书路径,直接使用操作系统的证书

提示:macOS 上启用opcache 建议添加 --disable-opcache-jit 参数

起因:
macOS 上启用opcache ,发现启用JIT 时,编译通过不了。进一步查看,发现会自动依赖库 capstone 、dynasm 等

#if defined(HAVE_DISASM) || defined(HAVE_GDB) || defined(HAVE_OPROFILE) || defined(HAVE_PERFTOOLS) || defined(HAVE_VTUNE)



另外一种解决办法是 卸载本机的 capstone dynasm 库

web ui 助力按需编译

web ui (雏形 暂只启用前端页面页面) : https://swoole-cli-ui.jingjingxyk.com/

缘由: swoole/swoole-src#4636

视频: https://www.bilibili.com/video/BV1Eb4y1n7xE/
视频节点: 0:58:34
视频节点: 1:02:44
视频节点: 1:05:34

swoole-cli 实验分支 experiment
借助 swoole-cli 项目提供的依赖库,编译器PHP其他版本 ,使用这个分支 build_native_php

其他:
借助依赖库 micro 二进制版本 build_native_php_sfx_micro
php-7.3.33
php-7.4.33

完整步骤:

bash sapi/quickstart/setup-php-runtime.sh --mirror china

bash sapi/quickstart/linux/run-alpine-3.16-container-full.sh

# 进入容器
bash sapi/quickstart/linux/connection-swoole-cli-alpine.sh


sh sapi/quickstart/linux/alpine-3.16-init.sh --mirror china

composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/

composer update --no-dev  --optimize-autoloader

php prepare.php --with-global-prefix=/usr --with-download-mirror-url=https://swoole-cli.jingjingxyk.com/ +protobuf

# bash make.sh all-library  (这步省略,因为已经通过容器技术提前构建好依赖库,并打包到容器中,运行容器已经包含依赖库)
bash make.sh config
bash make.sh build

bash make.sh archive

扩展依赖库 关系图

鼠标右键新标签页打开图片 图片上的链接是可以点击的,点击自动跳转到指定代码仓库
生成命令

php prepare.php --with-build-type=dev --with-dependency-graph=1 +ds +apcu +protobuf 生成graphvi z 模板文件
sh sapi/scripts/generate-dependency-graph.sh 生成svg 和 pdf

ext-dependency-graph

macOS 连接阶段抛出 warning

clang: warning: argument unused during compilation: '-fno-ident' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-all-static' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-fno-ident' [-Wunused-command-line-argument]

这些参数是无效的

解决macos curl configure 检测不通过 参考

文档 doc-macos.md

## curl configure 检测不通过
修改 `ext/curl/config.m4` ,去掉 `HAVE_CURL` 检测

依据上述文档的提示:写如下功能

function install_php_internal_extension_curl_patch(Preprocessor $p)
{
    $workDir=$p->getWorkDir();
    $command = '';

    if(is_file("{$workDir}/ext/curl/config.m4.backup")){
        $originFileHash=md5(file_get_contents("{$workDir}/ext/curl/config.m4"));
        $backupFileHash=md5(file_get_contents("{$workDir}/ext/curl/config.m4.backup"));
        if($originFileHash == $backupFileHash){
            $command =<<<EOF
           test -f {$workDir}/ext/curl/config.m4.backup && rm -f {$workDir}/ext/curl/config.m4.backup
           test -f {$workDir}/ext/curl/config.m4.backup ||  sed -i.backup '75,82d' {$workDir}/ext/curl/config.m4
EOF;
        }
    } else {
        $command =<<<EOF
           test -f {$workDir}/ext/curl/config.m4.backup ||  sed -i.backup '75,82d' {$workDir}/ext/curl/config.m4
EOF;
    }

    $p->addLibrary(
    (new Library('patch_php_internal_extension_curl'))
        ->withHomePage('https://www.php.net/')
        ->withLicense('https://github.com/php/php-src/blob/master/LICENSE', Library::LICENSE_PHP)
        ->withUrl('https://github.com/php/php-src/archive/refs/tags/php-8.1.12.tar.gz')
        ->withManual('https://www.php.net/docs.php')
        ->withLabel('php_extension_patch')
        ->withScriptBeforeConfigure($command)
        ->withConfigure('return 0 ')
        ->disableDefaultPkgConfig()
        ->disableDefaultLdflags()
        ->disablePkgName()
    );
}

cygwin 编译预览--编译swoole-cli一次 耗时 30分钟左右

缘由: 反复尝试 github action windows-latest 环境,发现编译始终不通过

解决办法: 用一台全新的服务器来编译测试 ,找到问题所在。

阿里云按量付费服务器 4核16G windows 2022 数据中心版 服务器成本:3元RMB左右

安装 cygwin setup-x86_64.exe依赖,花费半小时左右 (有情提醒: 提前准备好安装包等,可以节省时间)

提前准备脚本如下: (备注 ^ 是windows cmd 换行符)

setup-x86_64.exe  --no-desktop --no-shortcuts --no-startmenu --quiet-mode    -s https://mirrors.ustc.edu.cn/cygwin/  -P git,curl,wget,tar,libtool,re2c,bison,gcc-g++,autoconf,automake,openssl,libpcre2-devel,libssl-devel,libcurl-devel,libxml2-devel,libxslt-devel,libgmp-devel,ImageMagick,libpng-devel,libjpeg-devel,libfreetype-devel,libwebp-devel,libsqlite3-devel,zlib-devel,libbz2-devel,liblz4-devel,liblzma-devel,libzip-devel,libicu-devel,libonig-devel,libcares-devel,libsodium-devel,libyaml-devel,libMagick-devel,libzstd-devel,libbrotli-devel,libreadline-devel,libintl-devel,libpq-devel,libssh2-devel,libidn2-devel,gettext-devel,coreutils


发现问题所在: 因github runner 已经内置了msys 环境, cygwin 如果不安装 make ,默认引用的是 mingw-make。需要cygwin 安装 make 解决问题 。另外还有需要创建目录 mkdir -p bin/.libs

image
mkdir -p bin/.libs

image
image

swoole-cli windows 版,如何解决 /cygdrive/c/ 路径不存在问题,是不是必须安装cygwin 环境?

配置系统变量PATH 以后,是可以使用的

# 设置软连接

mklink  "C:\Users\biubiu\Downloads\swoole-cli-v5.0.1-cygwin64\bin\php.exe"  "C:\Users\biubiu\Downloads\swoole-cli-v5.0.1-cygwin64\bin\swoole-cli.exe" 

swoole-cli -v
php -v

get_dir.php

<?php

echo __DIR__;
php get_dir.php

但是当使用魔术变量 __DIR__ 时,返回的路径不存在

image

操作系统是不是还必须安装 cygwin

安装cygwin

setup-x86_64.exe -B -O -s http://cygwin.mirror.constant.com

cygwin 是否有版本要求?

借助本项目构建的依赖库,编译PHP其他版本--例子PHP7.4 ,PHP 8.20

比如:php 7.4 、 php 8.20

第一步:运行已经构建好依赖库的容器:

这两个容器镜像都是一样的,区别是:容器镜像的生成过程不同
前者通过 docker commit 生成
后者通过 Dockerfile 分步构建生成

#!/bin/env sh 
__DIR__=$(
  cd "$(dirname "$0")"
  pwd
)

image=phpswoole/swoole-cli-builder:1.6

image=registry.cn-beijing.aliyuncs.com/jingjingxyk-public/app:build-swoole-cli-build-dependencies-alpine-edge-20230226T074232Z


docker run --rm --name  swoole-cli-build-dev-all-dependencies-container -d -v ${__DIR__}:/work -w /work $image tail -f /dev/null

第二步:静态编译PHP

这三个分支,选择自己需要的,他们之间变化并不大哈。自己修改PHP 版本就行
build_native_php
build_php_8.2
build_php_7.4
build_php_7.3 需要更换为GCC 、glibc

步骤也没变

php prepare.php  
sh make.sh all_library
sh make.sh php_src   # 这一步执行下载PHP 源码,并把需要的扩展的源码拷贝到 PHP源码目录
sh amke.sh config 
sh make.sh build 
sh make.sh archive

每天都在关注,提一个想法

一直在关注cli的更新情况,希望可以支持把hyperf框架打包的phar包直接编译进cli,这样分发出去只要给一个文件就够了

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.