Skip to content

Commit

Permalink
Ship WASM builds of libjpeg-turbo and libwebp
Browse files Browse the repository at this point in the history
Related to #1381
and #1175.

Ships WASM builds og libjpeg and libwebp. This PR doesn't include them
in the PHP build yet, only ships pre-build wasm binaries. It might
require further tweaking before they can be included in the GD build.
  • Loading branch information
adamziel committed May 14, 2024
1 parent 0b05edf commit 0691e3a
Show file tree
Hide file tree
Showing 48 changed files with 7,302 additions and 1 deletion.
18 changes: 17 additions & 1 deletion packages/php-wasm/compile/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ libpng16/dist/root/lib/lib/libpng16.a: base-image libz
docker cp $$(docker create playground-php-wasm:libpng):/root/install/lib ./libpng16/dist/root/lib
docker cp $$(docker create playground-php-wasm:libpng):/root/install/include ./libpng16/dist/root/lib

libjpeg: libjpeg/dist/root/lib/lib/libjpeg.a
libjpeg/dist/root/lib/lib/libjpeg.a: base-image libz
mkdir -p ./libjpeg/dist/root/lib
docker build -f ./libjpeg/Dockerfile -t playground-php-wasm:libpng . --progress=plain
docker cp $$(docker create playground-php-wasm:libpng):/opt/libjpeg-turbo/lib32 ./libjpeg/dist/root/lib
docker cp $$(docker create playground-php-wasm:libpng):/opt/libjpeg-turbo/include ./libjpeg/dist/root/lib

libwebp: libwebp/dist/root/lib/lib/libwebp.a
libwebp/dist/root/lib/lib/libwebp.a: base-image libz
mkdir -p ./libwebp/dist/root/lib
docker build -f ./libwebp/Dockerfile -t playground-php-wasm:libpng .
docker cp $$(docker create playground-php-wasm:libpng):/root/install/lib ./libwebp/dist/root/lib
docker cp $$(docker create playground-php-wasm:libpng):/root/install/include ./libwebp/dist/root/lib

libxml2: libxml2/dist/root/lib/lib/libxml2.a
libxml2/dist/root/lib/lib/libxml2.a: base-image
mkdir -p ./libxml2/dist/root/lib
Expand Down Expand Up @@ -95,11 +109,13 @@ libcurl/dist/root/lib/lib/libcurl.a: base-image libz libopenssl
docker cp $$(docker create playground-php-wasm:libcurl):/root/curl-7.69.1/lib/.libs ./libcurl/dist/root/lib/lib
docker cp $$(docker create playground-php-wasm:libcurl):/root/curl-7.69.1/include/ ./libcurl/dist/root/lib

all: libz libzip libpng16 libxml2 libopenssl libsqlite3 libiconv libncurses libedit bison2.7 oniguruma libcurl
all: libz libzip libpng16 libjpeg libwebp libxml2 libopenssl libsqlite3 libiconv libncurses libedit bison2.7 oniguruma libcurl
clean:
rm -rf ./libz/dist
rm -rf ./libzip/dist
rm -rf ./libpng16/dist
rm -rf ./libjpeg/dist
rm -rf ./libwebp/dist
rm -rf ./libxml2/dist
rm -rf ./libopenssl/dist
rm -rf ./libsqlite3/dist
Expand Down
16 changes: 16 additions & 0 deletions packages/php-wasm/compile/libjpeg/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM playground-php-wasm:base

RUN mkdir -p /root/lib/include /root/lib/lib
COPY ./libz/dist/root/lib/include /root/lib/include
COPY ./libz/dist/root/lib/lib /root/lib/lib

RUN wget https://github.com/libjpeg-turbo/libjpeg-turbo/releases/download/3.0.3/libjpeg-turbo-3.0.3.tar.gz -O libjpeg.tar.gz
RUN tar -xzf libjpeg.tar.gz
WORKDIR /root/libjpeg-turbo-3.0.3
RUN ls -a
RUN source /root/emsdk/emsdk_env.sh && \
CPPFLAGS="-I/root/lib/include " \
LDFLAGS="-L/root/lib/lib " \
emcmake cmake -G"Unix Makefiles" -DCMAKE_PREFIX_PATH=/root/lib
RUN source /root/emsdk/emsdk_env.sh && EMCC_SKIP="-lc -lz" EMCC_FLAGS="-sSIDE_MODULE" emmake make
RUN source /root/emsdk/emsdk_env.sh && emmake make install
60 changes: 60 additions & 0 deletions packages/php-wasm/compile/libjpeg/dist/root/lib/include/jconfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* Version ID for the JPEG library.
* Might be useful for tests like "#if JPEG_LIB_VERSION >= 60".
*/
#define JPEG_LIB_VERSION 62

/* libjpeg-turbo version */
#define LIBJPEG_TURBO_VERSION 3.0.3

/* libjpeg-turbo version in integer form */
#define LIBJPEG_TURBO_VERSION_NUMBER 3000003

/* Support arithmetic encoding when using 8-bit samples */
#define C_ARITH_CODING_SUPPORTED 1

/* Support arithmetic decoding when using 8-bit samples */
#define D_ARITH_CODING_SUPPORTED 1

/* Support in-memory source/destination managers */
#define MEM_SRCDST_SUPPORTED 1

/* Use accelerated SIMD routines when using 8-bit samples */
/* #undef WITH_SIMD */

/* This version of libjpeg-turbo supports run-time selection of data precision,
* so BITS_IN_JSAMPLE is no longer used to specify the data precision at build
* time. However, some downstream software expects the macro to be defined.
* Since 12-bit data precision is an opt-in feature that requires explicitly
* calling 12-bit-specific libjpeg API functions and using 12-bit-specific data
* types, the unmodified portion of the libjpeg API still behaves as if it were
* built for 8-bit precision, and JSAMPLE is still literally an 8-bit data
* type. Thus, it is correct to define BITS_IN_JSAMPLE to 8 here.
*/
#ifndef BITS_IN_JSAMPLE
#define BITS_IN_JSAMPLE 8
#endif

#ifdef _WIN32

#undef RIGHT_SHIFT_IS_UNSIGNED

/* Define "boolean" as unsigned char, not int, per Windows custom */
#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
typedef unsigned char boolean;
#endif
#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */

/* Define "INT32" as int, not long, per Windows custom */
#if !(defined(_BASETSD_H_) || defined(_BASETSD_H)) /* don't conflict if basetsd.h already read */
typedef short INT16;
typedef signed int INT32;
#endif
#define XMD_H /* prevent jmorecfg.h from redefining it */

#else

/* Define if your (broken) compiler shifts signed values as if they were
unsigned. */
/* #undef RIGHT_SHIFT_IS_UNSIGNED */

#endif
Loading

0 comments on commit 0691e3a

Please sign in to comment.