Skip to content

Commit

Permalink
Remove --disable-all configuration option in PHP compile process (#…
Browse files Browse the repository at this point in the history
…1132)

Based on #1127. This PR enables FileInfo and Posix extensions in PHP
previously disabled by `--disable-all`.

## What problem is it solving?

It allows the use of `new finfo()`. Previously, the following error
occurred :

```
node node_modules/.bin/cli test.php

> Fatal error: Uncaught Error: Class "finfo" not found in /mho22/works/php-wasm-issue/test.php:3
> Stack trace:
> #0 {main}
>   thrown in /mho22/works/php-wasm-issue/test.php on line 3
```

## Testing Instructions

1. `mkdir php-wasm-issue && cd php-wasm-issue` 

2. `npm install @php-wasm/cli`

3. `touch test.php` :

```php
<?php

$finfo = new finfo( FILEINFO_MIME );

echo json_encode( $finfo );
```

4. `node node_modules/.bin/cli test.php`
  • Loading branch information
mho22 authored Mar 28, 2024
1 parent 3f9291f commit 0b38914
Show file tree
Hide file tree
Showing 57 changed files with 44 additions and 31 deletions.
3 changes: 2 additions & 1 deletion packages/php-wasm/compile/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ const platformDefaults = {
},
['web-light']: {},
['web-kitchen-sink']: {
WITH_FILEINFO: 'yes',
WITH_ICONV: 'yes',
WITH_LIBXML: 'yes',
WITH_LIBPNG: 'yes',
Expand All @@ -126,10 +127,10 @@ const platformDefaults = {
WITH_OPENSSL: 'yes',
},
node: {
WITH_FILEINFO: 'yes',
WITH_ICONV: 'yes',
WITH_LIBXML: 'yes',
WITH_LIBPNG: 'yes',
WITH_ICONV: 'yes',
WITH_MBSTRING: 'yes',
WITH_MBREGEX: 'yes',
WITH_CLI_SAPI: 'yes',
Expand Down
16 changes: 14 additions & 2 deletions packages/php-wasm/compile/php/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ RUN if [ "$WITH_LIBXML" = "yes" ]; \
/root/replace.sh 's/xmlHashScan\(ht, itemHashScanner, iter\);/xmlHashScan(ht, (xmlHashScanner)itemHashScanner, iter);/g' /root/php-src/ext/dom/dom_iterators.c; \
fi; \
else \
echo -n ' --disable-libxml --without-libxml --disable-dom --disable-xml --disable-simplexml --disable-xmlwriter' >> /root/.php-configure-flags; \
echo -n ' --disable-libxml --without-libxml --disable-dom --disable-xml --disable-simplexml --disable-xmlreader --disable-xmlwriter' >> /root/.php-configure-flags; \
fi

# Add sqlite3 if needed
Expand All @@ -168,11 +168,22 @@ RUN if [ "$WITH_OPENSSL" = "yes" ]; \
echo -n ' -lssl -lcrypto ' >> /root/.emcc-php-wasm-flags; \
fi;

# Remove fileinfo if needed
RUN if [ ! "$WITH_FILEINFO" = "yes" ]; \
then \
# light bundle should compile without fileinfo and libmagic
echo -n ' --disable-fileinfo' >> /root/.php-configure-flags; \
fi;

# Add iconv if needed
RUN if [ "$WITH_ICONV" = "yes" ]; \
then \
echo -n ' --with-iconv=/root/lib ' >> /root/.php-configure-flags; \
echo -n ' /root/lib/lib/libiconv.a' >> /root/.emcc-php-wasm-sources; \
# PHP >= 8.0 posix is no longer supported.
# PHP ≤= 7.4 posix is supported.
else \
echo -n ' --without-iconv ' >> /root/.php-configure-flags; \
fi;

# Add mbstring if needed
Expand Down Expand Up @@ -240,7 +251,8 @@ RUN source /root/emsdk/emsdk_env.sh && \
--enable-embed=static \
--with-layout=GNU \
--disable-cgi \
--disable-all \
--disable-opcache \
--disable-posix \
--enable-hash \
--enable-static=yes \
--enable-shared=no \
Expand Down
Loading

0 comments on commit 0b38914

Please sign in to comment.