Skip to content

Commit

Permalink
Merge pull request #3 from soyuka/fixphp81
Browse files Browse the repository at this point in the history
fix: include sqlite3 properly
  • Loading branch information
soyuka committed Sep 30, 2022
2 parents c3cdc70 + c2925d6 commit 2552dc5
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 183 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM emscripten/emsdk:2.0.10
FROM emscripten/emsdk:3.1.22
RUN apt-get update && \
apt-get --no-install-recommends -y install \
build-essential \
Expand Down
39 changes: 22 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,22 @@ OPTIMIZE ?=-O2
RELEASE_SUFFIX ?=

DOCKER_IMAGE ?=soyuka/php-emscripten-builder:latest
PHP_BRANCH ?=PHP-8.0.0
PHP_BRANCH ?=PHP-8.1.10
LIBXML2_TAG ?=v2.9.10

DOCKER_ENV=docker run --rm \
-v $(CURDIR):/src \
-e INITIAL_MEMORY=${INITIAL_MEMORY} \
-e LIBXML_LIBS="-L/src/lib/lib" \
-e LIBXML_CFLAGS="-I/src/lib/include/libxml2" \
-e SQLITE_CFLAGS="-I/src/third_party/sqlite-src" \
-e SQLITE_LIBS="-L/src/third_party/sqlite-src" \
-e SQLITE_CFLAGS="-I/src/lib/include/sqlite3" \
-e SQLITE_LIBS="-L/src/lib/lib" \
-e PRELOAD_ASSETS='${PRELOAD_ASSETS}' \
-e ENVIRONMENT=${ENVIRONMENT}

DOCKER_RUN =${DOCKER_ENV} ${DOCKER_IMAGE}
DOCKER_RUN_IN_PHP =${DOCKER_ENV} -w /src/third_party/php-src/ ${DOCKER_IMAGE}
DOCKER_RUN_IN_SQLITE =${DOCKER_ENV} -w /src/third_party/sqlite-src/ ${DOCKER_IMAGE}
DOCKER_RUN_IN_LIBXML =${DOCKER_ENV} -w /src/third_party/libxml2/ ${DOCKER_IMAGE}

.PHONY: clean build pull
Expand All @@ -32,21 +33,26 @@ all: lib/pib_eval.o php-web.wasm

########### Collect & patch the source code. ###########

third_party/sqlite-src/sqlite3.c:
third_party/sqlite-src:
mkdir -p third_party
wget https://sqlite.org/2020/sqlite-amalgamation-3330000.zip
${DOCKER_RUN} unzip sqlite-amalgamation-3330000.zip
${DOCKER_RUN} rm sqlite-amalgamation-3330000.zip
${DOCKER_RUN} mv sqlite-amalgamation-3330000 third_party/sqlite-src

third_party/php-src/patched: third_party/sqlite-src/sqlite3.c
third_party/sqlite-src/sqlite3.o: third_party/sqlite-src
${DOCKER_RUN_IN_SQLITE} 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
${DOCKER_RUN} mkdir -p /src/lib/include/sqlite3
${DOCKER_RUN} cp -v third_party/sqlite-src/sqlite3.h /src/lib/include/sqlite3/sqlite3.h
${DOCKER_RUN} cp -v third_party/sqlite-src/sqlite3.o /src/lib/lib/sqlite3.o

third_party/php-src/patched:
${DOCKER_RUN} git clone https://github.com/php/php-src.git third_party/php-src \
--branch ${PHP_BRANCH} \
--single-branch \
--depth 1
${DOCKER_RUN} cp -v third_party/sqlite-src/sqlite3.h third_party/php-src/main/sqlite3.h
${DOCKER_RUN} cp -v third_party/sqlite-src/sqlite3.c third_party/php-src/main/sqlite3.c
${DOCKER_RUN} git apply --directory=third_party/php-src --no-index patch/${PHP_BRANCH}.patch
${DOCKER_RUN_IN_PHP} sed -i -s 's/headers_sent) = 1/headers_sent) = 0/' sapi/embed/php_embed.c
${DOCKER_RUN_IN_PHP} sed -i -s 's/no_headers = 1/no_headers = 0/' sapi/embed/php_embed.c
${DOCKER_RUN} touch third_party/php-src/patched

third_party/libxml2/README:
Expand All @@ -64,7 +70,7 @@ third_party/libxml2/configure: third_party/libxml2/README

########### Build the objects. ###########

third_party/php-src/configure: third_party/php-src/patched third_party/libxml2/configure
third_party/php-src/configure: third_party/php-src/patched third_party/libxml2/configure third_party/sqlite-src/sqlite3.o
mkdir -p build
${DOCKER_RUN_IN_PHP} bash -c "./buildconf --force && emconfigure ./configure \
--enable-embed=static \
Expand All @@ -73,14 +79,12 @@ third_party/php-src/configure: third_party/php-src/patched third_party/libxml2/c
--enable-xml \
--disable-cgi \
--disable-cli \
--disable-fiber-asm \
--disable-all \
--with-sqlite3 \
--enable-session \
--enable-filter \
--enable-calendar \
--enable-dom \
--enable-pdo \
--with-pdo-sqlite \
--disable-rpath \
--disable-phpdbg \
--without-pear \
Expand All @@ -93,9 +97,12 @@ third_party/php-src/configure: third_party/php-src/patched third_party/libxml2/c
--disable-mbregex \
--enable-tokenizer \
--enable-simplexml \
--enable-pdo \
--with-pdo-sqlite \
--with-sqlite3 \
"

lib/libphp.a: third_party/php-src/configure third_party/php-src/patched third_party/sqlite-src/sqlite3.c
lib/libphp.a: third_party/php-src/configure third_party/php-src/patched
${DOCKER_RUN_IN_PHP} emmake make -j8
# PHP7 outputs a libphp7 whereas php8 a libphp
${DOCKER_RUN_IN_PHP} 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'
Expand All @@ -107,12 +114,10 @@ lib/pib_eval.o: lib/libphp.a source/pib_eval.c
-I Zend \
-I main \
-I TSRM/ \
-I /src/third_party/libxml2 \
-I /src/third_party/sqlite-src \
-c \
/src/source/pib_eval.c \
-o /src/lib/pib_eval.o \
-s ERROR_ON_UNDEFINED_SYMBOLS=0
-s ERROR_ON_UNDEFINED_SYMBOLS=0

########### Build the final files. ###########

Expand All @@ -131,7 +136,7 @@ FINAL_BUILD=${DOCKER_RUN_IN_PHP} emcc ${OPTIMIZE} \
-s MODULARIZE=1 \
-s INVOKE_RUN=0 \
-lidbfs.js \
/src/lib/pib_eval.o /src/lib/libphp.a /src/lib/lib/libxml2.a
/src/lib/pib_eval.o /src/lib/lib/sqlite3.o /src/lib/libphp.a /src/lib/lib/libxml2.a

php-web.wasm: ENVIRONMENT=web
php-web.wasm: lib/libphp.a lib/pib_eval.o
Expand Down
33 changes: 33 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<script src="./build/php-web.js"></script>
<script>
const NUM = 'number'
const STR = 'string'

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)
})

</script>
55 changes: 0 additions & 55 deletions patch/PHP-7.4.patch

This file was deleted.

55 changes: 0 additions & 55 deletions patch/PHP-8.0.0.patch

This file was deleted.

55 changes: 0 additions & 55 deletions patch/master.patch

This file was deleted.

0 comments on commit 2552dc5

Please sign in to comment.