Skip to content

Commit

Permalink
Boom
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed May 12, 2023
1 parent 2552dc5 commit df6f763
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 225 deletions.
129 changes: 114 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,120 @@
FROM emscripten/emsdk:3.1.22
FROM emscripten/emsdk:3.1.35 as build_tool

RUN apt-get update && \
apt-get --no-install-recommends -y install \
build-essential \
automake \
autoconf \
libtool \
pkgconf \
apt-get --no-install-recommends -y install \
build-essential \
automake \
autoconf \
libtool \
pkgconf \
python3 \
bison \
flex \
make \
re2c \
gdb \
git \
bison \
flex \
make \
re2c \
gdb \
git \
libxml2 \
libxml2-dev \
pv \
pv \
re2c

SHELL ["/bin/bash", "-c"]
FROM build_tool AS libxml
ARG LIBXML2_TAG=v2.9.10
RUN git clone https://gitlab.gnome.org/GNOME/libxml2.git libxml2 \
--branch $LIBXML2_TAG \
--single-branch \
--depth 1
WORKDIR /src/libxml2
RUN ./autogen.sh
RUN emconfigure ./configure --prefix=/src/libxml2/build --enable-static --disable-shared --with-python=no --with-threads=no
RUN emmake make -j8
RUN emmake make install

FROM build_tool AS sqlite
RUN wget https://sqlite.org/2020/sqlite-amalgamation-3330000.zip \
&& unzip sqlite-amalgamation-3330000.zip \
&& rm sqlite-amalgamation-3330000.zip \
&& mv sqlite-amalgamation-3330000 sqlite
WORKDIR /src/sqlite
RUN emcc -Oz -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_DISABLE_LFS -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_THREADSAFE=0 -DSQLITE_ENABLE_NORMALIZE -c sqlite3.c -o sqlite3.o

FROM build_tool as php_src
ARG PHP_BRANCH=PHP-8.2.5
RUN git clone https://github.com/php/php-src.git php-src \
--branch $PHP_BRANCH \
--single-branch \
--depth 1

FROM php_src AS php-wasm
ARG WASM_ENVIRONMENT=web
ARG ASSERTIONS=0
ARG OPTIMIZE=-O2
ARG INITIAL_MEMORY=256mb
COPY ./source /src/source
COPY --from=libxml /src/libxml2/build/ /src/usr
COPY --from=sqlite /src/sqlite/sqlite3.o /src/usr/lib/
COPY --from=sqlite /src/sqlite/sqlite3.h /src/usr/include/sqlite3/
ENV LIBXML_LIBS "-L/src/usr/lib"
ENV LIBXML_CFLAGS "-I/src/usr/include/libxml2"
ENV SQLITE_CFLAGS "-I/src/usr/include/sqlite3"
ENV SQLITE_LIBS "-L/src/usr/lib"
WORKDIR /src/php-src
RUN ./buildconf --force \
&& emconfigure ./configure \
--enable-embed=static \
--with-layout=GNU \
--with-libxml \
--enable-xml \
--disable-cgi \
--disable-cli \
--disable-fiber-asm \
--disable-all \
--enable-session \
--enable-filter \
--enable-calendar \
--enable-dom \
--disable-rpath \
--disable-phpdbg \
--without-pear \
--with-valgrind=no \
--without-pcre-jit \
--enable-bcmath \
--enable-json \
--enable-ctype \
--enable-mbstring \
--disable-mbregex \
--enable-tokenizer \
--enable-simplexml \
--enable-pdo \
--with-pdo-sqlite \
--with-sqlite3
RUN emmake make -j8
# PHP7 outputs a libphp7 whereas php8 a libphp
RUN bash -c '[[ -f .libs/libphp7.la ]] && mv .libs/libphp7.la .libs/libphp.la && mv .libs/libphp7.a .libs/libphp.a && mv .libs/libphp7.lai .libs/libphp.lai || exit 0'
RUN emcc $OPTIMIZE \
-I . \
-I Zend \
-I main \
-I TSRM/ \
-c \
/src/source/pib_eval.c \
-o /src/pib_eval.o \
-s ERROR_ON_UNDEFINED_SYMBOLS=0
RUN mkdir /build && emcc $OPTIMIZE \
-o /build/php-$WASM_ENVIRONMENT.mjs \
--llvm-lto 2 \
-s EXPORTED_FUNCTIONS='["_pib_init", "_pib_destroy", "_pib_run", "_pib_exec", "_pib_refresh", "_php_embed_init", "_php_embed_shutdown", "_php_embed_shutdown", "_zend_eval_string"]' \
-s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "UTF8ToString", "lengthBytesUTF8", "FS"]' \
-s ENVIRONMENT=$WASM_ENVIRONMENT \
-s FORCE_FILESYSTEM=1 \
-s MAXIMUM_MEMORY=2gb \
-s INITIAL_MEMORY=$INITIAL_MEMORY \
-s ALLOW_MEMORY_GROWTH=1 \
-s ASSERTIONS=$ASSERTIONS \
-s ERROR_ON_UNDEFINED_SYMBOLS=0 \
-s MODULARIZE=1 \
-s INVOKE_RUN=0 \
-s LZ4=1 \
-lidbfs.js \
/src/pib_eval.o /src/usr/lib/sqlite3.o .libs/libphp.a /src/usr/lib/libxml2.a
180 changes: 0 additions & 180 deletions Makefile

This file was deleted.

61 changes: 31 additions & 30 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
<script src="./build/php-web.js"></script>
<script>
const NUM = 'number'
const STR = 'string'
<script type="module">
import Module from "./build/php-web.mjs";

Module({
onAbort(reason) {
console.error(`WASM aborted: ${reason}`)
},
print(data) {
if (data) {
console.log('stdout: ', data)
}
},
printErr(data) {
if (data) {
console.log('stderr: ', data)
}
},
})
.then(({ccall, FS, IDBFS}) => {
ccall('pib_init', NUM, [STR], []);

const phpVersion = ccall('pib_exec', STR, [STR], ['phpversion();']);

console.log('test', phpVersion)

const tt = ccall('pib_exec', STR, [STR], ['phpinfo();']);

console.log('test', tt)
})
const NUM = "number";
const STR = "string";
let body = "";
const show = () => {
window.document.body.innerHTML = body;
};
let timeout = null;

Module({
onAbort(reason) {
console.error(`WASM aborted: ${reason}`);
},
print(data) {
if (data) {
body += data;
clearTimeout(timeout);
timeout = setTimeout(() => show());
}
},
printErr(data) {
if (data) {
console.log("stderr: ", data);
}
},
}).then(({ ccall, FS, IDBFS }) => {
ccall("pib_init");
const phpVersion = ccall("pib_exec", STR, [STR], ["phpversion();"]);
console.log("php version", phpVersion);
ccall("pib_exec", STR, [STR], ["phpinfo();"]);
});
</script>

0 comments on commit df6f763

Please sign in to comment.