diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-07-09 08:27:57 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-07-09 08:27:57 +0900 |
| commit | 925f7f4a11341fb950f4f6cd6390187b780ba419 (patch) | |
| tree | 78d1e1717234675da5e9ce36b6d3408cef586085 /examples | |
| parent | 61d6fdffb161c8b4130eb4982f021fbc0c77c445 (diff) | |
| download | php-waddiwasi-925f7f4a11341fb950f4f6cd6390187b780ba419.tar.gz php-waddiwasi-925f7f4a11341fb950f4f6cd6390187b780ba419.tar.zst php-waddiwasi-925f7f4a11341fb950f4f6cd6390187b780ba419.zip | |
feat: add examples/compile-php-to-wasm
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/compile-php-to-wasm/Dockerfile | 65 | ||||
| -rw-r--r-- | examples/compile-php-to-wasm/php-wasm.c | 22 | ||||
| -rw-r--r-- | examples/compile-php-to-wasm/php-wasm.js (renamed from examples/php-on-wasm/php-wasm.mjs) | 22 | ||||
| -rwxr-xr-x | examples/compile-php-to-wasm/php-wasm.wasm | bin | 0 -> 4862431 bytes | |||
| -rw-r--r-- | examples/php-on-wasm/php-wasm.php | 2 | ||||
| l---------[-rwxr-xr-x] | examples/php-on-wasm/php-wasm.wasm | bin | 4863136 -> 36 bytes | |||
| -rw-r--r-- | examples/rubyvm-on-php-on-wasm/php-wasm.php | 2 | ||||
| l---------[-rwxr-xr-x] | examples/rubyvm-on-php-on-wasm/php-wasm.wasm | bin | 4863136 -> 36 bytes |
8 files changed, 100 insertions, 13 deletions
diff --git a/examples/compile-php-to-wasm/Dockerfile b/examples/compile-php-to-wasm/Dockerfile new file mode 100644 index 0000000..1bdef61 --- /dev/null +++ b/examples/compile-php-to-wasm/Dockerfile @@ -0,0 +1,65 @@ +FROM emscripten/emsdk:3.1.46 + +RUN git clone --depth=1 --branch=php-8.2.10 https://github.com/php/php-src + +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + autoconf \ + bison \ + pkg-config \ + re2c \ + && \ + : + +RUN cd php-src && \ + ./buildconf --force && \ + emconfigure ./configure \ + --disable-all \ + --disable-mbregex \ + --disable-fiber-asm \ + --disable-cli \ + --disable-cgi \ + --disable-phpdbg \ + --enable-embed=static \ + --enable-mbstring \ + --without-iconv \ + --without-libxml \ + --without-pcre-jit \ + --without-pdo-sqlite \ + --without-sqlite3 \ + && \ + EMCC_CFLAGS='-s ERROR_ON_UNDEFINED_SYMBOLS=0' emmake make -j$(nproc) && \ + mv libs/libphp.a .. && \ + make clean && \ + git clean -fd && \ + : + +COPY php-wasm.c /src/ + +RUN cd php-src && \ + emcc \ + -c \ + -o php-wasm.o \ + -I . \ + -I TSRM \ + -I Zend \ + -I main \ + ../php-wasm.c \ + && \ + mv php-wasm.o .. && \ + make clean && \ + git clean -fd && \ + : + +RUN emcc \ + -s ENVIRONMENT=node \ + -s ERROR_ON_UNDEFINED_SYMBOLS=0 \ + -s EXPORTED_RUNTIME_METHODS='["ccall"]' \ + -s EXPORT_ES6=1 \ + -s INITIAL_MEMORY=16777216 \ + -s INVOKE_RUN=0 \ + -s MODULARIZE=1 \ + -o php-wasm.js \ + php-wasm.o \ + libphp.a \ + ; diff --git a/examples/compile-php-to-wasm/php-wasm.c b/examples/compile-php-to-wasm/php-wasm.c new file mode 100644 index 0000000..9c71ca1 --- /dev/null +++ b/examples/compile-php-to-wasm/php-wasm.c @@ -0,0 +1,22 @@ +#include <stdio.h> +#include <emscripten.h> +#include <Zend/zend_execute.h> +#include <sapi/embed/php_embed.h> + +int EMSCRIPTEN_KEEPALIVE php_wasm_run(const char* code) { + zend_result result; + + int argc = 1; + char* argv[] = { "php.wasm", NULL }; + + PHP_EMBED_START_BLOCK(argc, argv); + + result = zend_eval_string_ex(code, NULL, "php.wasm code", 1); + + PHP_EMBED_END_BLOCK(); + + fflush(stdout); + fflush(stderr); + + return result == SUCCESS ? 0 : 1; +} diff --git a/examples/php-on-wasm/php-wasm.mjs b/examples/compile-php-to-wasm/php-wasm.js index 8477416..92ba924 100644 --- a/examples/php-on-wasm/php-wasm.mjs +++ b/examples/compile-php-to-wasm/php-wasm.js @@ -7746,17 +7746,6 @@ function invoke_v(index) { } } -function invoke_iiii(index,a1,a2,a3) { - var sp = stackSave(); - try { - return getWasmTableEntry(index)(a1,a2,a3); - } catch(e) { - stackRestore(sp); - if (e !== e+0) throw e; - _setThrew(1, 0); - } -} - function invoke_ii(index,a1) { var sp = stackSave(); try { @@ -7823,6 +7812,17 @@ function invoke_iiiiiii(index,a1,a2,a3,a4,a5,a6) { } } +function invoke_iiii(index,a1,a2,a3) { + var sp = stackSave(); + try { + return getWasmTableEntry(index)(a1,a2,a3); + } catch(e) { + stackRestore(sp); + if (e !== e+0) throw e; + _setThrew(1, 0); + } +} + function invoke_viiii(index,a1,a2,a3,a4) { var sp = stackSave(); try { diff --git a/examples/compile-php-to-wasm/php-wasm.wasm b/examples/compile-php-to-wasm/php-wasm.wasm Binary files differnew file mode 100755 index 0000000..cf5ca85 --- /dev/null +++ b/examples/compile-php-to-wasm/php-wasm.wasm diff --git a/examples/php-on-wasm/php-wasm.php b/examples/php-on-wasm/php-wasm.php index 809af69..96625b8 100644 --- a/examples/php-on-wasm/php-wasm.php +++ b/examples/php-on-wasm/php-wasm.php @@ -35,7 +35,6 @@ $hostFuncs = [ makeHostFunc('(i32, i32, i32) -> (i32)', hostFunc__env__invoke_iii(...)), makeHostFunc('(i32, i32, i32, i32, i32) -> (i32)', hostFunc__env__invoke_iiiii(...)), makeHostFunc('(i32) -> ()', hostFunc__env__invoke_v(...)), - makeHostFunc('(i32, i32, i32, i32) -> (i32)', hostFunc__env__invoke_iiii(...)), makeHostFunc('(i32, i32) -> (i32)', hostFunc__env__invoke_ii(...)), makeHostFunc('() -> ()', hostFunc__env__abort(...)), makeHostFunc('(i32) -> ()', hostFunc__env__exit(...)), @@ -44,6 +43,7 @@ $hostFuncs = [ makeHostFunc('(i32, i32) -> ()', hostFunc__env__invoke_vi(...)), makeHostFunc('(i32) -> (i32)', hostFunc__env__invoke_i(...)), makeHostFunc('(i32, i32, i32, i32, i32, i32, i32) -> (i32)', hostFunc__env__invoke_iiiiiii(...)), + makeHostFunc('(i32, i32, i32, i32) -> (i32)', hostFunc__env__invoke_iiii(...)), makeHostFunc('(i32, i32, i32, i32) -> ()', hostFunc__env____assert_fail(...)), makeHostFunc('(i32, i32, i32, i32, i32) -> ()', hostFunc__env__invoke_viiii(...)), makeHostFunc('(i32, i32, i32, i32, i32, i32) -> ()', hostFunc__env__invoke_viiiii(...)), diff --git a/examples/php-on-wasm/php-wasm.wasm b/examples/php-on-wasm/php-wasm.wasm Binary files differindex 8e91021..4f254d7 100755..120000 --- a/examples/php-on-wasm/php-wasm.wasm +++ b/examples/php-on-wasm/php-wasm.wasm diff --git a/examples/rubyvm-on-php-on-wasm/php-wasm.php b/examples/rubyvm-on-php-on-wasm/php-wasm.php index 61fe691..1efb89f 100644 --- a/examples/rubyvm-on-php-on-wasm/php-wasm.php +++ b/examples/rubyvm-on-php-on-wasm/php-wasm.php @@ -36,7 +36,6 @@ $hostFuncs = [ makeHostFunc('(i32, i32, i32) -> (i32)', hostFunc__env__invoke_iii(...)), makeHostFunc('(i32, i32, i32, i32, i32) -> (i32)', hostFunc__env__invoke_iiiii(...)), makeHostFunc('(i32) -> ()', hostFunc__env__invoke_v(...)), - makeHostFunc('(i32, i32, i32, i32) -> (i32)', hostFunc__env__invoke_iiii(...)), makeHostFunc('(i32, i32) -> (i32)', hostFunc__env__invoke_ii(...)), makeHostFunc('() -> ()', hostFunc__env__abort(...)), makeHostFunc('(i32) -> ()', hostFunc__env__exit(...)), @@ -45,6 +44,7 @@ $hostFuncs = [ makeHostFunc('(i32, i32) -> ()', hostFunc__env__invoke_vi(...)), makeHostFunc('(i32) -> (i32)', hostFunc__env__invoke_i(...)), makeHostFunc('(i32, i32, i32, i32, i32, i32, i32) -> (i32)', hostFunc__env__invoke_iiiiiii(...)), + makeHostFunc('(i32, i32, i32, i32) -> (i32)', hostFunc__env__invoke_iiii(...)), makeHostFunc('(i32, i32, i32, i32) -> ()', hostFunc__env____assert_fail(...)), makeHostFunc('(i32, i32, i32, i32, i32) -> ()', hostFunc__env__invoke_viiii(...)), makeHostFunc('(i32, i32, i32, i32, i32, i32) -> ()', hostFunc__env__invoke_viiiii(...)), diff --git a/examples/rubyvm-on-php-on-wasm/php-wasm.wasm b/examples/rubyvm-on-php-on-wasm/php-wasm.wasm Binary files differindex 8e91021..4f254d7 100755..120000 --- a/examples/rubyvm-on-php-on-wasm/php-wasm.wasm +++ b/examples/rubyvm-on-php-on-wasm/php-wasm.wasm |
