Skip to content

Commit

Permalink
Remove libxml from the default web PHP build (configurable with an en…
Browse files Browse the repository at this point in the history
…v variable)
  • Loading branch information
adamziel committed Oct 14, 2022
1 parent cbabb77 commit db0a477
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 25 deletions.
2 changes: 1 addition & 1 deletion dist-web/php-web.js

Large diffs are not rendered by default.

Binary file modified dist-web/php-web.wasm
Binary file not shown.
49 changes: 30 additions & 19 deletions wasm-build/php/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ ARG VRZNO_FLAG="--disable-vrzno"
ENV VRZNO_FLAG ${VRZNO_FLAG}
ARG PHP_VERSION=8.0.24
ENV PHP_VERSION ${PHP_VERSION}
ARG WITH_LIBXML=no
ENV WITH_LIBXML ${WITH_LIBXML}

WORKDIR /root
RUN mkdir lib
Expand All @@ -14,8 +16,8 @@ RUN set -euxo pipefail;\
apt-get --no-install-recommends -y install \
build-essential \
automake-1.15 \
libxml2-dev \
autoconf \
libxml2-dev \
libtool \
pkgconf \
bison \
Expand Down Expand Up @@ -45,7 +47,6 @@ RUN git clone https://github.com/php/php-src.git php-src \
&& cp php-src/Zend/bench.php php-src/preload/Zend \
&& touch php-src/patched


# Get and patch Sqlite3
COPY ./docker-build-files/sqlite3-wasm.patch /root/
RUN set -euxo pipefail;\
Expand All @@ -64,34 +65,37 @@ RUN git clone https://github.com/seanmorris/vrzno.git php-src/ext/vrzno \
--depth 1

# Get and build Libxml2
RUN env GIT_SSL_NO_VERIFY=true git clone https://gitlab.gnome.org/GNOME/libxml2.git libxml2 \
RUN if [ "$WITH_LIBXML" = "yes" ]; \
then env GIT_SSL_NO_VERIFY=true git clone https://gitlab.gnome.org/GNOME/libxml2.git libxml2 \
--branch v2.9.10 \
--single-branch \
--depth 1;

RUN cd libxml2 && ./autogen.sh
RUN cd libxml2 && emconfigure ./configure --with-http=no --with-ftp=no --with-python=no --with-threads=no --enable-shared=no --prefix=/root/lib/
RUN cd libxml2 && emmake make
RUN cd libxml2 && emmake make install
--depth 1 && \
cd libxml2 && \
./autogen.sh && \
emconfigure ./configure --with-http=no --with-ftp=no --with-python=no --with-threads=no --enable-shared=no --prefix=/root/lib/ &&\
emmake make && \
emmake make install; \
fi

# Build the patched PHP
RUN cd php-src/ && PKG_CONFIG_PATH=$PKG_CONFIG_PATH ./buildconf --force

# RUN ls /root/lib/lib/; sleep 50
RUN if [ "$WITH_LIBXML" = "yes" ]; \
then export LIBXML_FLAGS=(--with-libxml --enable-dom --enable-xml --enable-simplexml); \
else export LIBXML_FLAGS=(--without-libxml --disable-dom --disable-xml --disable-simplexml); \
fi

RUN cd php-src/ && PKG_CONFIG_PATH=$PKG_CONFIG_PATH emconfigure ./configure \
PKG_CONFIG_PATH=$PKG_CONFIG_PATH \
--enable-embed=static \
--with-layout=GNU \
--with-libxml \
--disable-cgi \
--disable-cli \
--disable-all \
--with-sqlite3 \
--enable-session \
--enable-filter \
--enable-calendar \
--enable-dom \
--enable-pdo \
--with-pdo-sqlite \
--disable-rpath \
Expand All @@ -105,28 +109,35 @@ RUN cd php-src/ && PKG_CONFIG_PATH=$PKG_CONFIG_PATH emconfigure ./configure \
--enable-mbstring \
--disable-mbregex \
--enable-tokenizer \
$VRZNO_FLAG \
--enable-xml \
--enable-simplexml \
"${LIBXML_FLAGS[@]}" \
$VRZNO_FLAG \
--with-gd


RUN cd php-src/ && emmake make -j8

RUN cp -v php-src/.libs/libphp.la /root/lib/libphp7.la
RUN cp -v php-src/.libs/libphp.a /root/lib//libphp7.a
RUN cp -v php-src/.libs/libphp.a /root/lib/libphp7.a

COPY ./docker-build-files/pib_eval.c /root/

RUN if [ "$WITH_LIBXML" = "yes" ]; \
then export LIBXML_EMCC_FLAGS=(-I /root/libxml2); \
else export LIBXML_EMCC_FLAGS=""; \
fi

RUN if [ "$VRZNO_FLAG" = "--enable-vrzno" ]; \
then export DEFINES='-DWITH_VRZNO=1'; \
else export DEFINES=''; \
fi && \
cd php-src/ && \
fi

RUN cd php-src/ && \
emcc -Oz \
-I . \
-I Zend \
-I main \
-I TSRM/ \
-I /root/libxml2 \
"${LIBXML_EMCC_FLAGS[@]}" \
$DEFINES \
/root/pib_eval.c \
-o /root/lib/pib_eval.o;
14 changes: 12 additions & 2 deletions wasm-build/php/node-build-wasm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,19 @@ else
EXTRA_EXPORTED_FUNCTIONS=""
fi

WITH_LIBXML="yes" # Hardcoded for now, flip to "no" to disable libxml.

EXPORTED_FUNCTIONS='["_pib_init", "_pib_destroy", "_pib_run", "_pib_exec" "_pib_refresh", "_main", "_php_embed_init", "_php_embed_shutdown", "_php_embed_shutdown", "_zend_eval_string" '$EXTRA_EXPORTED_FUNCTIONS']'

docker build . --tag=wasm-wordpress-php-builder --build-arg PHP_VERSION=$PHP_VERSION --build-arg VRZNO_FLAG="$VRZNO_FLAG"
docker build . --tag=wasm-wordpress-php-builder \
--build-arg PHP_VERSION=$PHP_VERSION \
--build-arg VRZNO_FLAG="$VRZNO_FLAG" \
--build-arg WITH_LIBXML="$WITH_LIBXML"

if [ "$WITH_LIBXML" = "yes" ]; \
then export LIBXML="/root/lib/lib/libxml2.a"; \
else export LIBXML=""; \
fi

docker run \
-v `pwd`/preload:/preload \
Expand All @@ -34,7 +44,7 @@ docker run \
-s MODULARIZE=1 \
-s INVOKE_RUN=0 \
-s USE_ZLIB=1 \
/root/lib/pib_eval.o /root/lib/libphp7.a /root/lib/lib/libxml2.a \
/root/lib/pib_eval.o /root/lib/libphp7.a $LIBXML \
-lnodefs.js \
--pre-js /preload/node-pre.js \
-s ENVIRONMENT=node
Expand Down
14 changes: 12 additions & 2 deletions wasm-build/php/web-build-wasm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,19 @@ else
EXTRA_EXPORTED_FUNCTIONS=""
fi

WITH_LIBXML="no" # Hardcoded for now, flip to "yes" to enable libxml.

EXPORTED_FUNCTIONS='["_pib_init", "_pib_destroy", "_pib_run", "_pib_exec" "_pib_refresh", "_main", "_php_embed_init", "_php_embed_shutdown", "_php_embed_shutdown", "_zend_eval_string" '$EXTRA_EXPORTED_FUNCTIONS']'

docker build . --tag=wasm-wordpress-php-builder --build-arg PHP_VERSION=$PHP_VERSION --build-arg VRZNO_FLAG="$VRZNO_FLAG"
docker build . --tag=wasm-wordpress-php-builder \
--build-arg PHP_VERSION=$PHP_VERSION \
--build-arg VRZNO_FLAG="$VRZNO_FLAG" \
--build-arg WITH_LIBXML="$WITH_LIBXML"

if [ "$WITH_LIBXML" = "yes" ]; \
then export LIBXML="/root/lib/lib/libxml2.a"; \
else export LIBXML=""; \
fi

# Build the PHP wasm binary
docker run \
Expand All @@ -35,7 +45,7 @@ docker run \
-s MODULARIZE=1 \
-s INVOKE_RUN=0 \
-s USE_ZLIB=1 \
/root/lib/pib_eval.o /root/lib/libphp7.a /root/lib/lib/libxml2.a \
/root/lib/pib_eval.o /root/lib/libphp7.a $LIBXML \
--pre-js /preload/php-web-pre-script.js \
-s ENVIRONMENT=web \
-s FORCE_FILESYSTEM=1
Expand Down
2 changes: 1 addition & 1 deletion wasm-build/php/web-publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ root_dir=../..
dest_dir=$root_dir/dist-web

cp ./docker-output/php* $dest_dir/
cp $root_dir/src/shared/etc/php.ini $dest_dir/etc/
cp $root_dir/src/web/etc/php.ini $dest_dir/etc/

0 comments on commit db0a477

Please sign in to comment.