Closed char101 closed 1 year ago
Hi @char101
What is the reason for the need for static build? Can PECL meet the demand?
Because it is supported by PHP.
https://www.php.net/manual/en/install.pecl.static.php
In my case I want to compile a static php binary so that it can be deployed along the application.
There is no fix required for this. I only put it here since other people who want to compile the extension statically might find it useful.
If you don't want to support the case of statically linking the extension please close the issue.
I think this benefit may be small.
Even if compiled statically, the binary file still depends on the external library, and you cannot directly copy the executable file and run it anywhere.
Or you have a way to solve this problem, if you don’t mind, I would love to know your working method, thank you.
The benefit of a static php binary is exactly that it does not depend on any shared library and can be just copied to and run in another machine. In fact I have just compiled a static php executable with this extension embedded statically.
mini:~/compile/php-static/dist-8.0.8$ ls -alh bin
total 28M
drwxr-xr-x 2 char char 4.0K Jul 29 14:38 .
drwxr-xr-x 10 char char 4.0K Jul 28 18:54 ..
lrwxrwxrwx 1 char char 9 Jul 29 14:28 phar -> phar.phar
-rwxr-xr-x 1 char char 15.0K Jul 29 14:28 phar.phar
-rwxr-xr-x 1 char char 32.1M Jul 29 14:38 php
-rwxr-xr-x 1 char char 3.2K Jul 29 14:28 php-config
-rwxr-xr-x 1 char char 4.5K Jul 29 14:28 phpize
mini:~/compile/php-static/dist-8.0.8$ file bin/php
bin/php: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped
mini:~/compile/php-static/dist-8.0.8$ ./bin/php -i | rg -i xls
Configure Command => './configure' '--prefix=/home/char/compile/php-static/dist-8.0.8' '--enable-re2c-cgoto' '--enable-fpm' '--disable-cgi' '--disable-ipv6' '--disable-phpdbg' '--with-openssl' '--with-pcre-jit' '--with-zlib' '--with-bz2' '--with-curl' '--enable-exif' '--enable-gd' '--with-jpeg' '--with-freetype''--with-ldap' '--enable-mbstring' '--with-mysqli' '--enable-pcntl' '--with-pdo-mysql' '--with-pdo-pgsql' '--with-pgsql' '--enable-soap' '--enable-sockets' '--with-zip' '--without-pear' '--enable-static' '--disable-shared' '--with-event-core' '--enable-redis' '--with-yaml' '--with-xlswriter'
xlswriter
xlswriter support => enabled
bundled libxlsxwriter version => 1.0.0
bundled libxlsxio version => 0.2.27
There is also this repository https://github.com/crazywhalecc/static-php-cli that provides a build script although I don't use it (I use my own build script).
Wow, this is great, are you interested in making your script public?
It is not a simple script, there are several alpine linux packages that need to be rebuild and there are some extensions that need to be modified.
@viest xlsWriter是一个非常好的项目,我们在我们的代码里广泛使用了xlsWriter。 swoole-cli 也是一个非常好的项目,便于项目部署和分发。代码上线时只需要部署一个 cli 文件,就包含了php环境以及数以万计的文件。 请问能否对兼容swoole-cli进行支持?
静态编译报错信息:
n file included from main/internal_functions_cli.c:57:
In file included from /work/php-src/ext/xlswriter/php_xlswriter.h:16:
In file included from /work/php-src/ext/xlswriter/include/xlswriter.h:34:
/work/php-src/ext/xlswriter/include/excel.h:48:1: warning: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
VTIFUL_STARTUP_FUNCTION(excel);
^
int
/work/php-src/ext/xlswriter/include/excel.h:48:25: error: a parameter list without types is only allowed in a function definition
VTIFUL_STARTUP_FUNCTION(excel);
^
In file included from main/internal_functions_cli.c:57:
In file included from /work/php-src/ext/xlswriter/php_xlswriter.h:16:
In file included from /work/php-src/ext/xlswriter/include/xlswriter.h:35:
/work/php-src/ext/xlswriter/include/validation.h:18:1: warning: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
VTIFUL_STARTUP_FUNCTION(validation);
^
int
/work/php-src/ext/xlswriter/include/validation.h:18:25: error: a parameter list without types is only allowed in a function definition
VTIFUL_STARTUP_FUNCTION(validation);
^
In file included from main/internal_functions_cli.c:57:
In file included from /work/php-src/ext/xlswriter/php_xlswriter.h:16:
In file included from /work/php-src/ext/xlswriter/include/xlswriter.h:36:
/work/php-src/ext/xlswriter/include/exception.h:18:1: warning: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
VTIFUL_STARTUP_FUNCTION(exception);
^
int
/work/php-src/ext/xlswriter/include/exception.h:18:25: error: a parameter list without types is only allowed in a function definition
VTIFUL_STARTUP_FUNCTION(exception);
^
In file included from main/internal_functions_cli.c:57:
In file included from /work/php-src/ext/xlswriter/php_xlswriter.h:16:
In file included from /work/php-src/ext/xlswriter/include/xlswriter.h:37:
/work/php-src/ext/xlswriter/include/format.h:18:1: warning: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
VTIFUL_STARTUP_FUNCTION(format);
^
int
/work/php-src/ext/xlswriter/include/format.h:18:25: error: a parameter list without types is only allowed in a function definition
VTIFUL_STARTUP_FUNCTION(format);
^
In file included from main/internal_functions_cli.c:57:
In file included from /work/php-src/ext/xlswriter/php_xlswriter.h:16:
In file included from /work/php-src/ext/xlswriter/include/xlswriter.h:38:
/work/php-src/ext/xlswriter/include/chart.h:18:1: warning: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
VTIFUL_STARTUP_FUNCTION(chart);
^
int
/work/php-src/ext/xlswriter/include/chart.h:18:25: error: a parameter list without types is only allowed in a function definition
VTIFUL_STARTUP_FUNCTION(chart);
^
In file included from main/internal_functions_cli.c:57:
In file included from /work/php-src/ext/xlswriter/php_xlswriter.h:16:
In file included from /work/php-src/ext/xlswriter/include/xlswriter.h:39:
/work/php-src/ext/xlswriter/include/rich_string.h:18:1: warning: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
VTIFUL_STARTUP_FUNCTION(rich_string);
^
int
/work/php-src/ext/xlswriter/include/rich_string.h:18:25: error: a parameter list without types is only allowed in a function definition
VTIFUL_STARTUP_FUNCTION(rich_string);
^
In file included from main/internal_functions_cli.c:57:
In file included from /work/php-src/ext/xlswriter/php_xlswriter.h:16:
In file included from /work/php-src/ext/xlswriter/include/xlswriter.h:43:
/work/php-src/ext/xlswriter/library/libxlsxio/include/xlsxio_read.h:92:67: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
DLL_EXPORT_XLSXIO const XLSXIOCHAR* xlsxioread_get_version_string ();
^
void
7 warnings and 6 errors generated.
make: *** [Makefile:2104: main/internal_functions_cli.lo] Error 1
静态编译命令:
git clone -b php-8.2.4 --depth=1 https://github.com/php/php-src.git
git clone -b v1.5.4 --depth=1 --recursive https://github.com/viest/php-ext-xlswriter.git
mv php-ext-xlswriter xlswriter
mv xlswriter php-src/ext/
cd php-src/
./buildconf --force
export CPPFLAGS=' -I/usr/libiconv/include -I/usr/bzip2/include -I/usr/zlib/include -I/usr/libxml2/include/libxml2 -I/usr/libiconv/include '
export LDFLAGS=' -L/usr/libiconv/lib -L/usr/bzip2/lib -L/usr/zlib/lib -L/usr/libxml2/lib -L/usr/libiconv/lib '
export LIBS=' -liconv -lbz2 -lz -lxml2 -liconv -lm -lstdc++'
./configure --prefix=/tmp/php-8.2.4 \
--disable-all \
--disable-cgi \
--disable-phpdbg \
--enable-shared=no \
--enable-static=yes \
--enable-cli \
--with-iconv=/usr/libiconv \
--with-bz2=/usr/bzip2 \
--enable-filter \
--enable-session \
--enable-tokenizer \
--enable-ctype \
--with-zlib --with-zlib-dir=/usr/zlib \
--enable-posix \
--enable-phar \
--enable-fileinfo \
--enable-xml --enable-simplexml --enable-xmlreader --enable-xmlwriter --enable-dom --with-libxml \
--with-xlswriter --enable-reader
export LDFLAGS="$LDFLAGS -all-static"
make -j $(nproc) cli
命令来自: https://github.com/jingjingxyk/swoole-cli/tree/build_native_php
Hi,
This extension cannot be statically built into php and can only be build using using phpize, because of several factors
$srcdir
should be$ext_srcdir
, and$builddir
should be$ext_builddir
$ext_srcdir
and$ext_builddir
are defined byPHP_NEW_EXTENSION
, before it we need to usePHP_EXT_SRCDIR
andPHP_EXT_BUILDDIR
macros.