Update to 1.5.2 (Add protobuf support)

This commit is contained in:
crazywhalecc 2022-06-21 13:49:38 +08:00
parent 96bc62b2a9
commit 4c55f4a22b
7 changed files with 42 additions and 10 deletions

View File

@ -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 <https://github.com/dixyes/phpmicro>
> Special thanks: <https://github.com/dixyes/phpmicro>
## 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 | * | |

View File

@ -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` 可调整要下载的扩展和依赖库版本和链接。

View File

@ -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" ;;

View File

@ -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 <space> 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
}

View File

@ -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",

View File

@ -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
zip

View File

@ -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} && \