Skip to content

Commit

Permalink
feat: add configuration args
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Dec 9, 2023
1 parent bab81bc commit b264188
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
15 changes: 10 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,18 @@ 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.10
ARG PHP_BRANCH=PHP-8.3.0
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 JAVASCRIPT_EXTENSION=mjs
ARG EXPORT_NAME=createPhpModule
ARG MODULARIZE=1
ARG EXPORT_ES6=1
ARG ASSERTIONS=0
ARG OPTIMIZE=-O1
# TODO: find a way to keep this, it can't be empty if defined...
Expand Down Expand Up @@ -84,6 +88,7 @@ RUN cd /src/php-src && ./buildconf --force \
--enable-ctype \
--enable-mbstring \
--disable-mbregex \
--with-config-file-scan-dir=/src/php \
--enable-tokenizer \
--enable-simplexml \
--enable-pdo \
Expand All @@ -103,7 +108,7 @@ RUN cd /src/php-src && emcc $OPTIMIZE \
-o /src/phpw.o \
-s ERROR_ON_UNDEFINED_SYMBOLS=0
RUN mkdir /build && cd /src/php-src && emcc $OPTIMIZE \
-o /build/php-$WASM_ENVIRONMENT.mjs \
-o /build/php-$WASM_ENVIRONMENT.$JAVASCRIPT_EXTENSION \
--llvm-lto 2 \
-s EXPORTED_FUNCTIONS='["_phpw", "_phpw_flush", "_phpw_exec", "_phpw_run", "_chdir", "_setenv", "_php_embed_init", "_php_embed_shutdown", "_zend_eval_string"]' \
-s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "UTF8ToString", "lengthBytesUTF8", "FS"]' \
Expand All @@ -114,11 +119,11 @@ RUN mkdir /build && cd /src/php-src && emcc $OPTIMIZE \
-s ALLOW_MEMORY_GROWTH=1 \
-s ASSERTIONS=$ASSERTIONS \
-s ERROR_ON_UNDEFINED_SYMBOLS=0 \
-s MODULARIZE=1 \
-s MODULARIZE=$MODULARIZE \
-s INVOKE_RUN=0 \
-s LZ4=1 \
-s EXPORT_ES6=1 \
-s EXPORT_NAME=createPhpModule \
-s EXPORT_ES6=$EXPORT_ES6 \
-s EXPORT_NAME=$EXPORT_NAME \
# -s DECLARE_ASM_MODULE_EXPORTS=0 \
-lidbfs.js \
/src/phpw.o /src/usr/lib/sqlite3.o .libs/libphp.a /src/usr/lib/libxml2.a
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,24 @@ The module we export in this image is called `createPhpModule`.

Use this as template to build PHP with emscripten. At build these arguments are available:

```
```console
LIBXML2_TAG=v2.9.10
PHP_BRANCH=PHP-8.2.9
PHP_BRANCH=PHP-8.3.0
```

The next args are used for [emcc options](https://github.com/soyuka/php-wasm/blob/513f284e1ba8f26d66e08a97291f484b3dd7de1b/Dockerfile#L108) `-sOPTION`
see [settings.js](https://github.com/emscripten-core/emscripten/blob/9bdb310b89472a0f4d64f36e4a79273d8dc7fa98/src/settings.js#L633).
In fact it's even easier for you to set them directly in [the Dockerfile](https://github.com/soyuka/php-wasm/blob/513f284e1ba8f26d66e08a97291f484b3dd7de1b/Dockerfile#L108).

```
```console
WASM_ENVIRONMENT=web
ASSERTIONS=0
OPTIMIZE=-O2
INITIAL_MEMORY=256mb
JAVASCRIPT_EXTENSION=mjs # change by js if needed
MODULARIZE=1
EXPORT_ES6=1
EXPORT_NAME=createPhpModule
```

### Preload data
Expand Down

0 comments on commit b264188

Please sign in to comment.