Skip to content

Commit 3fd0315

Browse files
mho22adamzielMHO
authored
Curl extension for the Node.js build of PHP.wasm (#1273)
Ships the Node.js version of PHP built with `--with-libcurl` option to support the curl extension. It also changes two nuances in the overall PHP build process: * It replaces the `select(2)` function using `-Wl,--wrap=select` emcc option instead of patching PHP source code – this enables supporting asynchronous `select(2)` in curl without additional patches. * Brings the `__wrap_select` implementation more in line with `select(2)`, add support for `POLLERR`. * Adds support for polling file descriptors that represent neither child processes nor streams in `poll(2)` – that's because `libcurl` polls `/dev/urandom`. Builds on top of and supersedes #1133 ## Debugging Asyncify problems The [typical way of resolving Asyncify crashes](https://wordpress.github.io/wordpress-playground/architecture/wasm-asyncify/) didn't work during the work on this PR. Functions didn't come up in the error messages and even raw stack traces. The reasons are unclear. [The JSPI build of PHP](#1339) was more helpful as it enabled logging the current stack trace in all the asynchronous calls, which quickly revealed all the missing `ASYNCIFY_ONLY` functions. This is the way to debug any future issues until we fully migrate to JSPI. ## Testing Instructions Confirm the CI checks pass. This PR ships a few new tests specifically targeting networking with curl. ## Related resources * #85 * #1093 --------- Co-authored-by: Adam Zieliński <[email protected]> Co-authored-by: MHO <[email protected]>
1 parent cf118a4 commit 3fd0315

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+10680
-2470
lines changed

packages/php-wasm/compile/Makefile

+16-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ libzip/dist/1.9.2/root/lib/lib/libzip.a: base-image libz
2828
libpng16: libpng16/dist/root/lib/lib/libpng16.a
2929
libpng16/dist/root/lib/lib/libpng16.a: base-image libz
3030
mkdir -p ./libpng16/dist/root/lib
31-
docker build -f ./libpng16/Dockerfile -t playground-php-wasm:libpng .
31+
docker build -f ./libpng16/Dockerfile -t playground-php-wasm:libpng .
3232
docker cp $$(docker create playground-php-wasm:libpng):/root/install/lib ./libpng16/dist/root/lib
3333
docker cp $$(docker create playground-php-wasm:libpng):/root/install/include ./libpng16/dist/root/lib
3434

@@ -88,7 +88,21 @@ oniguruma/dist/root/lib/lib/libonig.a: base-image
8888
docker cp $$(docker create playground-php-wasm:oniguruma):/root/lib/lib ./oniguruma/dist/root/lib/
8989
docker cp $$(docker create playground-php-wasm:oniguruma):/root/lib/include ./oniguruma/dist/root/lib
9090

91-
all: libz libzip libpng16 libxml2 libopenssl libsqlite3 libiconv libncurses libedit bison2.7 oniguruma
91+
libcurl: libcurl/dist/root/lib/lib/libcurl.a
92+
libcurl/dist/root/lib/lib/libcurl.a: base-image libz libopenssl
93+
mkdir -p ./libcurl/dist/root/lib
94+
docker build -f ./libcurl/Dockerfile -t playground-php-wasm:libcurl . --progress=plain
95+
docker cp $$(docker create playground-php-wasm:libcurl):/root/curl-7.69.1/lib/.libs ./libcurl/dist/root/lib/lib
96+
docker cp $$(docker create playground-php-wasm:libcurl):/root/curl-7.69.1/include/ ./libcurl/dist/root/lib
97+
98+
libcurl7.15: libcurl7.15/dist/root/lib/lib/libcurl.a
99+
libcurl7.15/dist/root/lib/lib/libcurl.a: base-image libz libopenssl
100+
mkdir -p ./libcurl7.15/dist/root/lib
101+
docker build -f ./libcurl7.15/Dockerfile -t playground-php-wasm:libcurl7.15 . --progress=plain
102+
docker cp $$(docker create playground-php-wasm:libcurl):/root/curl-7.15.5/lib/.libs ./libcurl7.15/dist/root/lib/lib
103+
docker cp $$(docker create playground-php-wasm:libcurl):/root/curl-7.15.5/include/ ./libcurl7.15/dist/root/lib
104+
105+
all: libz libzip libpng16 libxml2 libopenssl libsqlite3 libiconv libncurses libedit bison2.7 oniguruma libcurl libcurl7.15
92106
clean:
93107
rm -rf ./libz/dist
94108
rm -rf ./libzip/dist

packages/php-wasm/compile/build.js

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ const platformDefaults = {
132132
WITH_OPENSSL: 'yes',
133133
},
134134
node: {
135+
WITH_CURL: 'yes',
135136
WITH_FILEINFO: 'yes',
136137
WITH_ICONV: 'yes',
137138
WITH_LIBXML: 'yes',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
FROM playground-php-wasm:base
2+
3+
RUN mkdir -p /root/lib/include /root/lib/lib
4+
COPY ./libz/dist/root/lib/include /root/lib/include
5+
COPY ./libz/dist/root/lib/lib /root/lib/lib
6+
COPY ./libopenssl/dist/root/lib/include /root/lib/include
7+
COPY ./libopenssl/dist/root/lib/lib /root/lib/lib
8+
9+
ARG CURL_VERSION="curl-7.69.1"
10+
11+
RUN /root/copy-lib.sh lib-libz
12+
RUN set -euxo pipefail && \
13+
source /root/emsdk/emsdk_env.sh && \
14+
wget https://curl.haxx.se/download/$CURL_VERSION.tar.gz && \
15+
tar xf $CURL_VERSION.tar.gz
16+
17+
WORKDIR /root/$CURL_VERSION
18+
19+
RUN CPPFLAGS="-I/root/lib/include " \
20+
LDFLAGS="-L/root/lib/lib " \
21+
PKG_CONFIG_PATH=$PKG_CONFIG_PATH \
22+
source /root/emsdk/emsdk_env.sh && \
23+
emconfigure ./configure \
24+
--build i386-pc-linux-gnu \
25+
--target wasm32-unknown-emscripten \
26+
--prefix=/root/lib/ \
27+
--disable-shared \
28+
--enable-static \
29+
--with-ssl \
30+
--with-openssl=/root/lib \
31+
--enable-https \
32+
--enable-http \
33+
--disable-pop3 \
34+
--disable-imap \
35+
--disable-smb \
36+
--disable-smtp \
37+
--disable-telnet \
38+
--disable-gopher \
39+
--disable-ftp \
40+
--disable-ftps \
41+
--disable-rtsp \
42+
--disable-tftp \
43+
--disable-pthreads \
44+
--disable-threaded-resolver \
45+
--with-zlib=/root/lib
46+
47+
RUN cp /root/emsdk/upstream/bin/wasm-ld /root/emsdk/upstream/bin/wasm-ld-original && \
48+
echo $'#!/bin/bash\n\
49+
if [[ " $@ " =~ " -o curl " ]]; then \n\
50+
echo '' > /root/curl-7.69.1/src/curl; \n\
51+
echo '' > /root/curl-7.69.1/curl; \n\
52+
fi; \n\
53+
/root/emsdk/upstream/bin/wasm-ld-original "$@" || true; \n\
54+
exit 0; \n' > /root/emsdk/upstream/bin/wasm-ld && \
55+
chmod a+x /root/emsdk/upstream/bin/wasm-ld
56+
57+
58+
RUN source /root/emsdk/emsdk_env.sh && \
59+
EMCC_SKIP="-lc -lz -lcurl -lssl " \
60+
EMCC_FLAGS="-sSIDE_MODULE -Wl,--wrap=select " emmake make -i || true
61+
62+
RUN source /root/emsdk/emsdk_env.sh && \
63+
EMCC_SKIP="-lc -lz -lcurl -lssl " \
64+
EMCC_FLAGS="-sSIDE_MODULE -Wl,--wrap=select " emmake make install -i || true
65+
66+
RUN ls -R /root/lib

0 commit comments

Comments
 (0)