From 4c55f4a22be0b2e130af023ef7593bcefa78314a Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Tue, 21 Jun 2022 13:49:38 +0800 Subject: [PATCH] Update to 1.5.2 (Add protobuf support) --- README-en.md | 7 ++++--- README.md | 8 +++++--- docker/check-extensions.sh | 16 ++++++++++++++-- docker/compile-php.sh | 8 +++++++- docker/config.json | 5 +++++ docker/extensions.txt | 7 ++++++- docker/fast-compiler.sh | 1 + 7 files changed, 42 insertions(+), 10 deletions(-) diff --git a/README-en.md b/README-en.md index 2cb2cf9a..00a77f8c 100755 --- a/README-en.md +++ b/README-en.md @@ -3,7 +3,7 @@ Compile A Statically Linked PHP With Swoole and other Extensions. BTW, It's only for CLI mode. -[![version](https://img.shields.io/badge/version-1.6.0-green.svg)]() +[![version](https://img.shields.io/badge/version-1.5.2-green.svg)]() ![Build Actions](https://github.com/crazywhalecc/static-php-cli/actions/workflows/build-php.yml/badge.svg) ## Compilation Requirements @@ -46,7 +46,7 @@ cat micro.sfx code.php > single-app && chmod +x single-app # If packing phar into a static binary, just change code.php to your phar path. ``` -> Thanks +> Special thanks: ## Compiling @@ -81,7 +81,7 @@ export USE_BACKUP="yes" ``` To customize PHP extensions, edit `docker/extensions.txt` file, and rules below: -- Use `#` as comment, to mark not install +- Use `^` as deselect, to mark not install. Use `#` as comments. - extensions name uses lower case, and default file contains all supported extensions, if u need other extensions, consider write an Issue ## Supported PHP extensions @@ -114,6 +114,7 @@ To customize PHP extensions, edit `docker/extensions.txt` file, and rules below: | | pdo_pgsql | * | | | yes | phar | * | | | yes | posix | * | | +| yes, not compiled | protobuf | * | Not compiled and enabled as default | | yes | readline | * | Not support `./php -a` | | yes | redis | * | | | yes | shmop | * | | diff --git a/README.md b/README.md index b54cfcdb..481f462f 100755 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Compile A Statically Linked PHP With Swoole and other Extensions. [English READM 注:只能编译 CLI 模式,暂不支持 CGI 和 FPM 模式 -[![版本](https://img.shields.io/badge/script--version-1.6.0-green.svg)]() +[![版本](https://img.shields.io/badge/script--version-1.5.2-green.svg)]() [![License](https://img.shields.io/badge/License-MIT-blue.svg)]() ![Build Actions](https://github.com/crazywhalecc/static-php-cli/actions/workflows/build-php.yml/badge.svg) @@ -87,7 +87,7 @@ export VER_PHP="8.1.7" ``` 如果要选择安装的扩展,可以修改 `docker/extensions.txt` 文件,具体规则如下: -- 文件内使用 `#` 可以注释,表示不安装 +- 文件内使用 `^` 可以表示默认不安装该扩展,`#` 开头可以编写注释 - 扩展名一律使用小写,目前默认状态下文件内所列的扩展为支持的扩展,其他扩展暂不支持,如有需求请提 Issue 添加 ## 支持的扩展表 @@ -120,6 +120,7 @@ export VER_PHP="8.1.7" | | pdo_pgsql | * | | | yes, enabled | phar | * | | | yes, enabled | posix | * | | +| yes, not enabled | protobuf | * | 默认不编译 | | yes, enabled | readline | * | 不支持 `./php -a` | | yes, enabled | redis | * | 从 pecl 或镜像站下载的源码 | | yes, enabled | shmop | * | | @@ -143,13 +144,14 @@ export VER_PHP="8.1.7" > > `参数2`: `8.1.7` 是你要编译的 PHP 版本。 > -> `参数3`: `all` 代表你要编译所有支持的扩展,不询问。 +> `参数3`: `all` 代表你要编译所有非反选的扩展,不询问。 > > `参数4`: `/dist/` 是你编译后输出二进制 PHP 和 micro 的文件夹 > > 基本例子: `docker run --rm -v $(pwd)/dist:/dist/ -it static-php build-php original 8.1.7 all /dist/` - `docker/extensions.txt` 指定要编译安装的扩展。 +- `docker/extensions.txt` 中,`^` 开头的扩展名为反选,反选的扩展将出现在编译的扩展列表中,但默认不选中。 - `docker/compile-php.sh` 中的 `php_compile_args` 函数来调整 PHP 编译参数。 - `docker/check-extensions.sh` 中的 `check_in_configure` 函数可调整 PHP 扩展编译的参数。 - `docker/config.json` 可调整要下载的扩展和依赖库版本和链接。 diff --git a/docker/check-extensions.sh b/docker/check-extensions.sh index a9bdd519..b60d90f5 100755 --- a/docker/check-extensions.sh +++ b/docker/check-extensions.sh @@ -20,7 +20,7 @@ function do_copy_extension() { } function check_before_configure() { - list=$(cat "$EXT_LIST_FILE" | grep -v "^#" | grep -v "^$") + list=$(cat "$EXT_LIST_FILE" | grep -v "^#" | grep -v "^$" | grep -v "^\^") xml_sign="no" for loop in $list do @@ -44,6 +44,17 @@ function check_before_configure() { pdo_sqlite) ;; phar) ;; posix) ;; + protobuf) + do_copy_extension protobuf + echo '#ifndef PHP_PROTOBUF_H' >> $php_dir/ext/protobuf/php_protobuf.h && \ + echo '# define PHP_PROTOBUF_H' >> $php_dir/ext/protobuf/php_protobuf.h && \ + echo '#ifdef HAVE_CONFIG_H' >> $php_dir/ext/protobuf/php_protobuf.h && \ + echo '# include "config.h"' >> $php_dir/ext/protobuf/php_protobuf.h && \ + echo '#endif' >> $php_dir/ext/protobuf/php_protobuf.h && \ + echo 'extern zend_module_entry protobuf_module_entry;' >> $php_dir/ext/protobuf/php_protobuf.h && \ + echo '# define phpext_protobuf_ptr &protobuf_module_entry' >> $php_dir/ext/protobuf/php_protobuf.h && \ + echo '#endif' >> $php_dir/ext/protobuf/php_protobuf.h + ;; readline) if [ ! -d "/nom" ]; then mkdir /nom @@ -76,7 +87,7 @@ function check_before_configure() { function check_in_configure() { php_configure="" - list=$(cat "$EXT_LIST_FILE" | sed 's/#.*//g' | sed -e 's/[ ]*$//g' | grep -v "^\s*$") + list=$(cat "$EXT_LIST_FILE" | sed 's/#.*//g' | sed 's/\^.*//g' | sed -e 's/[ ]*$//g' | grep -v "^\s*$") for loop in $list do case $loop in @@ -122,6 +133,7 @@ function check_in_configure() { pdo_mysql) php_configure="$php_configure --with-pdo-mysql=mysqlnd" ;; phar) php_configure="$php_configure --enable-phar" ;; posix) php_configure="$php_configure --enable-posix" ;; + protobuf) php_configure="$php_configure --enable-protobuf" ;; readline) php_configure="$php_configure --with-readline" ;; redis) php_configure="$php_configure --enable-redis --disable-redis-session" ;; shmop) php_configure="$php_configure --enable-shmop" ;; diff --git a/docker/compile-php.sh b/docker/compile-php.sh index 7a1d808e..479df03f 100755 --- a/docker/compile-php.sh +++ b/docker/compile-php.sh @@ -8,7 +8,13 @@ function generate_ext_dialog_cmd() { echo -n "dialog --backtitle \"static-php-cli Compile Options\" --checklist \"Please select the extension you don't want to compile.\n\nNOTE: Use to select or deselect items\n\n** Default is compiling all **\" 24 60 20 " > $self_dir/.ask_cmd.sh for loop in $list do - echo -n "$loop '$loop Extension' on " >> $self_dir/.ask_cmd.sh + case $loop in + ^*) + loop=$(echo ${loop:1} | xargs) + echo -n "$loop '$loop Extension' off " >> $self_dir/.ask_cmd.sh + ;; + *) echo -n "$loop '$loop Extension' on " >> $self_dir/.ask_cmd.sh ;; + esac done echo "2>$self_dir/extensions_install.txt" >> $self_dir/.ask_cmd.sh } diff --git a/docker/config.json b/docker/config.json index 7796a2e7..f76ed57a 100755 --- a/docker/config.json +++ b/docker/config.json @@ -3,6 +3,11 @@ "link": "http://mirrors.zhamao.xin/php/php-{version}.tar.gz", "link_2": "https://www.php.net/distributions/php-{version}.tar.gz" }, + "protobuf": { + "version": "3.21.1", + "link": "http://mirrors.zhamao.xin/pecl/protobuf-{version}.tgz", + "link_2": "https://pecl.php.net/get/protobuf-{version}.tgz" + }, "swoole": { "version": "4.8.9", "link": "http://mirrors.zhamao.xin/pecl/swoole-{version}.tgz", diff --git a/docker/extensions.txt b/docker/extensions.txt index 80180457..776c5706 100755 --- a/docker/extensions.txt +++ b/docker/extensions.txt @@ -1,3 +1,7 @@ +# Start with '#' is comments +# Start with '^' is deselecting extensions, which is not installed as default +# Each line just leave the extension name or ^ character + bcmath calendar ctype @@ -23,6 +27,7 @@ pdo_mysql pdo_sqlite phar posix +^protobuf readline redis shmop @@ -36,4 +41,4 @@ xml xmlreader xmlwriter zlib -zip \ No newline at end of file +zip diff --git a/docker/fast-compiler.sh b/docker/fast-compiler.sh index a1f54f06..0f7db733 100755 --- a/docker/fast-compiler.sh +++ b/docker/fast-compiler.sh @@ -54,6 +54,7 @@ $self_dir/download.sh swoole ${USE_BACKUP} && \ $self_dir/download.sh redis ${USE_BACKUP} && \ $self_dir/download.sh libxml2 ${USE_BACKUP} && \ $self_dir/download.sh xz ${USE_BACKUP} && \ + $self_dir/download.sh protobuf ${USE_BACKUP} && \ $self_dir/download.sh curl ${USE_BACKUP} && \ $self_dir/download.sh libzip ${USE_BACKUP} && \ $self_dir/download-git.sh dixyes/phpmicro phpmicro ${USE_BACKUP} && \