add micro php build

This commit is contained in:
crazywhalecc
2022-05-16 14:01:00 +08:00
parent 4cba2cb8c1
commit 74060cbf27
5 changed files with 73 additions and 7 deletions

View File

@@ -2,11 +2,12 @@ FROM alpine:latest
# define script basic information
# Version of this Dockerfile
ENV SCRIPT_VERSION=1.4.3
ENV SCRIPT_VERSION=1.5.0
# Download address uses backup address
ARG USE_BACKUP_ADDRESS
ARG COMPILE_PHP_VERSION
ARG COMPILE_MICRO
# (if downloading slowly, consider set it to yes)
ENV USE_BACKUP="${USE_BACKUP_ADDRESS}"
@@ -14,6 +15,8 @@ ENV USE_BACKUP="${USE_BACKUP_ADDRESS}"
# Version of some manually-installed package
ENV VER_PHP="${COMPILE_PHP_VERSION}"
ENV ENABLE_MICRO="${COMPILE_MICRO}"
# APK repositories mirror address, if u r not in China, consider set USE_BACKUP=yes to boost
ENV LINK_APK_REPO='mirrors.ustc.edu.cn'
ENV LINK_APK_REPO_BAK='dl-cdn.alpinelinux.org'
@@ -45,6 +48,8 @@ RUN apk add libevent libevent-dev libevent-static > /dev/null
RUN apk add sqlite sqlite-dev sqlite-libs sqlite-static > /dev/null
# php libzip dependencies
RUN apk add bzip2-dev bzip2-static bzip2
# php micro ffi dependencies
RUN apk add libffi libffi-dev
RUN mkdir /app
@@ -76,10 +81,15 @@ COPY check-extensions.sh /app/
COPY compile-php.sh /app/
RUN chmod +x ./check-extensions.sh && \
chmod +x ./compile-php.sh
chmod +x ./compile-php.sh && \
chmod +x ./compile-micro.sh
RUN echo "Checking and Compiling Dependencies ..."
RUN ./check-extensions.sh check_before_configure > /dev/null
RUN echo "Compiling PHP ..."
RUN ./compile-php.sh ${VER_PHP} > /dev/null 2>&1
RUN if [ "${ENABLE_MICRO}" = "yes" ]; then \
./compile-micro.sh ${VER_PHP} > /dev/null 2>&1 ; \
else \
./compile-php.sh ${VER_PHP} > /dev/null 2>&1 ; \
fi

View File

@@ -260,6 +260,7 @@ function check_after_configure() {
case $loop in
swoole)
sed -ie 's/swoole_clock_gettime(CLOCK_REALTIME/clock_gettime(CLOCK_REALTIME/g' "$php_dir/ext/swoole/include/swoole.h"
sed -ie 's/strcmp("cli", sapi_module.name) == 0/strcmp("cli", sapi_module.name) == 0 || strcmp("micro", sapi_module.name) == 0/g' "$php_dir/ext/swoole/ext-src/php_swoole.cc"
;;
esac
done

38
docker/compile-micro.sh Executable file
View File

@@ -0,0 +1,38 @@
#!/bin/sh
VER_PHP="$1"
self_dir=$(cd "$(dirname "$0")";pwd)
php_dir=$(find $self_dir/source -name "php-$VER_PHP" -type d | tail -n1)
function php_compile_args() {
_php_arg="--prefix=$self_dir/php-dist"
_php_arg="$_php_arg --disable-all"
_php_arg="$_php_arg --enable-shared=no"
_php_arg="$_php_arg --enable-static=yes"
_php_arg="$_php_arg --enable-inline-optimization"
_php_arg="$_php_arg --with-layout=GNU"
_php_arg="$_php_arg --with-pear=no"
_php_arg="$_php_arg --disable-cgi"
_php_arg="$_php_arg --disable-phpdbg"
_php_arg="$_php_arg --with-ffi"
_php_arg="$_php_arg --enable-micro"
_php_arg="$_php_arg $($self_dir/check-extensions.sh check_in_configure $1)"
echo $_php_arg
}
php_compile_args && sleep 1s
cd $php_dir && \
git clone https://github.com/dixyes/phpmicro.git --depth=1 sapi/micro && \
./buildconf --force && \
./configure LDFLAGS=-static $(php_compile_args $VER_PHP) && \
$self_dir/check-extensions.sh check_after_configure && \
sed -ie 's/-export-dynamic//g' "Makefile" && \
sed -ie 's/-o $(SAPI_CLI_PATH)/-all-static -o $(SAPI_CLI_PATH)/g' "Makefile" && \
sed -ie 's/-o $(SAPI_MICRO_PATH)/-all-static -o $(SAPI_MICRO_PATH)/g' "Makefile" && \
sed -ie 's/$(PHP_GLOBAL_OBJS) $(PHP_BINARY_OBJS) $(PHP_MICRO_OBJS)/$(PHP_GLOBAL_OBJS:.lo=.o) $(PHP_BINARY_OBJS:.lo=.o) $(PHP_MICRO_OBJS:.lo=.o)/g' "Makefile" && \
sed -ie 's/$(EXTRA_LIBS:-lresolv=-Wl,-Bstatic,-lresolv,-Bdynamic)/$(EXTRA_LIBS)/g' "Makefile" && \
make micro LDFLAGS="-static" -j$(cat /proc/cpuinfo | grep processor | wc -l)
#make install
#strip $self_dir/php-dist/bin/php

View File

@@ -2,7 +2,7 @@
# This script needs alpine linux system.
test "$VER_PHP" = "" && VER_PHP="7.4.28"
test "$VER_PHP" = "" && VER_PHP="8.1.6"
test "$USE_BACKUP" = "" && USE_BACKUP="no"
LINK_APK_REPO='mirrors.ustc.edu.cn'
@@ -35,8 +35,10 @@ apk add libevent libevent-dev libevent-static
apk add sqlite sqlite-dev sqlite-libs sqlite-static
# php libzip dependencies
apk add bzip2-dev bzip2-static bzip2
# php micro ffi dependencies
apk add libffi libffi-dev
chmod +x download.sh check-extensions.sh compile-php.sh
chmod +x download.sh check-extensions.sh compile-php.sh compile-micro.sh
./download.sh swoole ${USE_BACKUP} && \
./download.sh inotify ${USE_BACKUP} && \
@@ -49,5 +51,5 @@ chmod +x download.sh check-extensions.sh compile-php.sh
./download.sh libzip ${USE_BACKUP} && \
./download.sh php ${USE_BACKUP} ${VER_PHP} && \
./check-extensions.sh check_before_configure && \
./compile-php.sh ${VER_PHP}
./compile-micro.sh ${VER_PHP}