Skip to content

Commit db0a477

Browse files
committed
Remove libxml from the default web PHP build (configurable with an env variable)
1 parent cbabb77 commit db0a477

File tree

6 files changed

+56
-25
lines changed

6 files changed

+56
-25
lines changed

dist-web/php-web.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist-web/php-web.wasm

-1.21 MB
Binary file not shown.

wasm-build/php/Dockerfile

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ ARG VRZNO_FLAG="--disable-vrzno"
44
ENV VRZNO_FLAG ${VRZNO_FLAG}
55
ARG PHP_VERSION=8.0.24
66
ENV PHP_VERSION ${PHP_VERSION}
7+
ARG WITH_LIBXML=no
8+
ENV WITH_LIBXML ${WITH_LIBXML}
79

810
WORKDIR /root
911
RUN mkdir lib
@@ -14,8 +16,8 @@ RUN set -euxo pipefail;\
1416
apt-get --no-install-recommends -y install \
1517
build-essential \
1618
automake-1.15 \
17-
libxml2-dev \
1819
autoconf \
20+
libxml2-dev \
1921
libtool \
2022
pkgconf \
2123
bison \
@@ -45,7 +47,6 @@ RUN git clone https://github.com/php/php-src.git php-src \
4547
&& cp php-src/Zend/bench.php php-src/preload/Zend \
4648
&& touch php-src/patched
4749

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

6667
# Get and build Libxml2
67-
RUN env GIT_SSL_NO_VERIFY=true git clone https://gitlab.gnome.org/GNOME/libxml2.git libxml2 \
68+
RUN if [ "$WITH_LIBXML" = "yes" ]; \
69+
then env GIT_SSL_NO_VERIFY=true git clone https://gitlab.gnome.org/GNOME/libxml2.git libxml2 \
6870
--branch v2.9.10 \
6971
--single-branch \
70-
--depth 1;
71-
72-
RUN cd libxml2 && ./autogen.sh
73-
RUN cd libxml2 && emconfigure ./configure --with-http=no --with-ftp=no --with-python=no --with-threads=no --enable-shared=no --prefix=/root/lib/
74-
RUN cd libxml2 && emmake make
75-
RUN cd libxml2 && emmake make install
72+
--depth 1 && \
73+
cd libxml2 && \
74+
./autogen.sh && \
75+
emconfigure ./configure --with-http=no --with-ftp=no --with-python=no --with-threads=no --enable-shared=no --prefix=/root/lib/ &&\
76+
emmake make && \
77+
emmake make install; \
78+
fi
7679

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

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

8288
RUN cd php-src/ && PKG_CONFIG_PATH=$PKG_CONFIG_PATH emconfigure ./configure \
8389
PKG_CONFIG_PATH=$PKG_CONFIG_PATH \
8490
--enable-embed=static \
8591
--with-layout=GNU \
86-
--with-libxml \
8792
--disable-cgi \
8893
--disable-cli \
8994
--disable-all \
9095
--with-sqlite3 \
9196
--enable-session \
9297
--enable-filter \
9398
--enable-calendar \
94-
--enable-dom \
9599
--enable-pdo \
96100
--with-pdo-sqlite \
97101
--disable-rpath \
@@ -105,28 +109,35 @@ RUN cd php-src/ && PKG_CONFIG_PATH=$PKG_CONFIG_PATH emconfigure ./configure \
105109
--enable-mbstring \
106110
--disable-mbregex \
107111
--enable-tokenizer \
108-
$VRZNO_FLAG \
109-
--enable-xml \
110-
--enable-simplexml \
112+
"${LIBXML_FLAGS[@]}" \
113+
$VRZNO_FLAG \
111114
--with-gd
112115

116+
113117
RUN cd php-src/ && emmake make -j8
114118

115119
RUN cp -v php-src/.libs/libphp.la /root/lib/libphp7.la
116-
RUN cp -v php-src/.libs/libphp.a /root/lib//libphp7.a
120+
RUN cp -v php-src/.libs/libphp.a /root/lib/libphp7.a
117121

118122
COPY ./docker-build-files/pib_eval.c /root/
123+
124+
RUN if [ "$WITH_LIBXML" = "yes" ]; \
125+
then export LIBXML_EMCC_FLAGS=(-I /root/libxml2); \
126+
else export LIBXML_EMCC_FLAGS=""; \
127+
fi
128+
119129
RUN if [ "$VRZNO_FLAG" = "--enable-vrzno" ]; \
120130
then export DEFINES='-DWITH_VRZNO=1'; \
121131
else export DEFINES=''; \
122-
fi && \
123-
cd php-src/ && \
132+
fi
133+
134+
RUN cd php-src/ && \
124135
emcc -Oz \
125136
-I . \
126137
-I Zend \
127138
-I main \
128139
-I TSRM/ \
129-
-I /root/libxml2 \
140+
"${LIBXML_EMCC_FLAGS[@]}" \
130141
$DEFINES \
131142
/root/pib_eval.c \
132143
-o /root/lib/pib_eval.o;

wasm-build/php/node-build-wasm.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,19 @@ else
1212
EXTRA_EXPORTED_FUNCTIONS=""
1313
fi
1414

15+
WITH_LIBXML="yes" # Hardcoded for now, flip to "no" to disable libxml.
16+
1517
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']'
1618

17-
docker build . --tag=wasm-wordpress-php-builder --build-arg PHP_VERSION=$PHP_VERSION --build-arg VRZNO_FLAG="$VRZNO_FLAG"
19+
docker build . --tag=wasm-wordpress-php-builder \
20+
--build-arg PHP_VERSION=$PHP_VERSION \
21+
--build-arg VRZNO_FLAG="$VRZNO_FLAG" \
22+
--build-arg WITH_LIBXML="$WITH_LIBXML"
23+
24+
if [ "$WITH_LIBXML" = "yes" ]; \
25+
then export LIBXML="/root/lib/lib/libxml2.a"; \
26+
else export LIBXML=""; \
27+
fi
1828

1929
docker run \
2030
-v `pwd`/preload:/preload \
@@ -34,7 +44,7 @@ docker run \
3444
-s MODULARIZE=1 \
3545
-s INVOKE_RUN=0 \
3646
-s USE_ZLIB=1 \
37-
/root/lib/pib_eval.o /root/lib/libphp7.a /root/lib/lib/libxml2.a \
47+
/root/lib/pib_eval.o /root/lib/libphp7.a $LIBXML \
3848
-lnodefs.js \
3949
--pre-js /preload/node-pre.js \
4050
-s ENVIRONMENT=node

wasm-build/php/web-build-wasm.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,19 @@ else
1212
EXTRA_EXPORTED_FUNCTIONS=""
1313
fi
1414

15+
WITH_LIBXML="no" # Hardcoded for now, flip to "yes" to enable libxml.
16+
1517
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']'
1618

17-
docker build . --tag=wasm-wordpress-php-builder --build-arg PHP_VERSION=$PHP_VERSION --build-arg VRZNO_FLAG="$VRZNO_FLAG"
19+
docker build . --tag=wasm-wordpress-php-builder \
20+
--build-arg PHP_VERSION=$PHP_VERSION \
21+
--build-arg VRZNO_FLAG="$VRZNO_FLAG" \
22+
--build-arg WITH_LIBXML="$WITH_LIBXML"
23+
24+
if [ "$WITH_LIBXML" = "yes" ]; \
25+
then export LIBXML="/root/lib/lib/libxml2.a"; \
26+
else export LIBXML=""; \
27+
fi
1828

1929
# Build the PHP wasm binary
2030
docker run \
@@ -35,7 +45,7 @@ docker run \
3545
-s MODULARIZE=1 \
3646
-s INVOKE_RUN=0 \
3747
-s USE_ZLIB=1 \
38-
/root/lib/pib_eval.o /root/lib/libphp7.a /root/lib/lib/libxml2.a \
48+
/root/lib/pib_eval.o /root/lib/libphp7.a $LIBXML \
3949
--pre-js /preload/php-web-pre-script.js \
4050
-s ENVIRONMENT=web \
4151
-s FORCE_FILESYSTEM=1

wasm-build/php/web-publish.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ root_dir=../..
66
dest_dir=$root_dir/dist-web
77

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

0 commit comments

Comments
 (0)