diff --git a/.github/workflows/demo.yml b/.github/workflows/demo.yml new file mode 100644 index 000000000..092979b11 --- /dev/null +++ b/.github/workflows/demo.yml @@ -0,0 +1,60 @@ +# Simple workflow for deploying static content to GitHub Pages +name: Deploy static content to Pages + +on: + # Runs on pushes targeting the default branch + push: + branches: ["main"] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: read + pages: write + id-token: write + +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. +concurrency: + group: "pages" + cancel-in-progress: true + +jobs: + # Single deploy job since we're just deploying + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - + name: Build PHP WASM + uses: docker/build-push-action@v5 + with: + context: . + push: false + tags: soyuka/php-wasm:latest + cache-from: type=gha + cache-to: type=gha,mode=max + - name: Setup Pages + uses: actions/configure-pages@v3 + - name: Build website + working-directory: demo + run: | + docker create --name=php-wasm soyuka/php-wasm:latest + mkdir -p public/ dist/ + docker cp php-wasm:/build/php-web.mjs ./dist + docker cp php-wasm:/build/php-web.wasm ./public + docker run -v $(pwd)/src:/src -v $(pwd)/public:/public -v $(pwd)/dist:/dist php-wasm python3 /emsdk/upstream/emscripten/tools/file_packager.py /public/php-web.data --use-preload-cache --lz4 --preload "/src" --js-output=/dist/php-web.data.js --no-node --exclude '*/.*' --export-name=createPhpModule + sed '/--pre-js/r dist/php-web.data.js' dist/php-web.mjs > public/php-web.mjs + - name: Upload artifact + uses: actions/upload-pages-artifact@v2 + with: + path: 'demo/public' + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v2 diff --git a/Dockerfile b/Dockerfile index bfc4c0d1e..05b84f685 100644 --- a/Dockerfile +++ b/Dockerfile @@ -40,7 +40,7 @@ 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.9 +ARG PHP_BRANCH=PHP-8.2.10 RUN git clone https://github.com/php/php-src.git php-src \ --branch $PHP_BRANCH \ --single-branch \ @@ -49,7 +49,7 @@ RUN git clone https://github.com/php/php-src.git php-src \ FROM php_src AS php-wasm ARG WASM_ENVIRONMENT=web ARG ASSERTIONS=0 -ARG OPTIMIZE=-O2 +ARG OPTIMIZE=-O1 # TODO: find a way to keep this, it can't be empty if defined... # ARG PRE_JS= ARG INITIAL_MEMORY=256mb @@ -60,8 +60,7 @@ 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 \ +RUN cd /src/php-src && ./buildconf --force \ && emconfigure ./configure \ --enable-embed=static \ --with-layout=GNU \ @@ -90,11 +89,11 @@ RUN ./buildconf --force \ --enable-pdo \ --with-pdo-sqlite \ --with-sqlite3 -RUN emmake make -j8 +RUN cd /src/php-src && 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 cd /src/php-src && 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' COPY ./source /src/source -RUN emcc $OPTIMIZE \ +RUN cd /src/php-src && emcc $OPTIMIZE \ -I . \ -I Zend \ -I main \ @@ -103,7 +102,7 @@ RUN emcc $OPTIMIZE \ /src/source/phpw.c \ -o /src/phpw.o \ -s ERROR_ON_UNDEFINED_SYMBOLS=0 -RUN mkdir /build && emcc $OPTIMIZE \ +RUN mkdir /build && cd /src/php-src && emcc $OPTIMIZE \ -o /build/php-$WASM_ENVIRONMENT.mjs \ --llvm-lto 2 \ -s EXPORTED_FUNCTIONS='["_phpw", "_phpw_flush", "_phpw_exec", "_phpw_run", "_chdir", "_setenv", "_php_embed_init", "_php_embed_shutdown", "_zend_eval_string"]' \ @@ -123,3 +122,4 @@ RUN mkdir /build && emcc $OPTIMIZE \ # -s DECLARE_ASM_MODULE_EXPORTS=0 \ -lidbfs.js \ /src/phpw.o /src/usr/lib/sqlite3.o .libs/libphp.a /src/usr/lib/libxml2.a +RUN rm -r /src/* diff --git a/demo/.gitignore b/demo/.gitignore index ddb38e888..de3b0dc5b 100644 --- a/demo/.gitignore +++ b/demo/.gitignore @@ -1,3 +1,4 @@ dist/ -public/ -!public/index.html +public/php-web.mjs +public/php-web.data +public/php-web.wasm diff --git a/demo/public/index.html b/demo/public/index.html index 8f6a4a890..ae5901d4f 100644 --- a/demo/public/index.html +++ b/demo/public/index.html @@ -1,24 +1,43 @@ - + +
+ diff --git a/demo/src/index.php b/demo/src/index.php index 83f154933..61ace196d 100644 --- a/demo/src/index.php +++ b/demo/src/index.php @@ -1,3 +1,2 @@