Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSPI support #1339

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions curltest/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env node

// import { NodePHP } from '@php-wasm/node';
import { NodePHP } from '../dist/packages/php-wasm/node/index.cjs';
import { rootCertificates } from 'tls';

const caBundlePath = new URL('ca-bundle.crt', (import.meta || {}).url).pathname;

NodePHP.load('8.0')
.then((php) => {
php.setPhpIniEntry('allow_url_fopen', '1');
php.setPhpIniEntry('disable_functions', '');
php.setPhpIniEntry('openssl.cafile', caBundlePath);
php.useHostFilesystem();
php.writeFile(caBundlePath, rootCertificates.join('\n'));

console.log('php.run');
return php.run({
code: `<?php
echo file_get_contents('https://wordpress.org');
`,
});
return php.cli(['php', ...process.argv.slice(2)]);
})
.then((result) => {
console.log('done!');
console.log(result.text);
})
.catch((e) => {
console.error(e);
});

/*
'php.wasm.__wrap_select',
'php.wasm.Curl_socket_check',
'php.wasm.Curl_is_connected',
'php.wasm.multi_runsingle',
'php.wasm.curl_multi_perform',
'php.wasm.easy_transfer',
'php.wasm.Curl_poll',
'php.wasm.Curl_multi_wait',
'php.wasm.curl_multi_poll',
'php.wasm.easy_perform',
'php.wasm.RAND_poll',
'php.wasm.rand_status',
'php.wasm.RAND_status',
'php.wasm.rand_enough',
'php.wasm.Curl_ossl_seed',
'php.wasm.zif_curl_multi_exec'
"php.wasm.ossl_connect_common",
"php.wasm.Curl_ossl_connect_nonblocking",
"php.wasm.Curl_ssl_connect_nonblocking",
"php.wasm.https_connecting",
"php.wasm.Curl_readwrite",
*/
6 changes: 6 additions & 0 deletions curltest/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "module",
"dependencies": {
"@php-wasm/node": "file:../dist/packages/php-wasm/node"
}
}
60 changes: 60 additions & 0 deletions curltest/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

// echo file_get_contents('https://wordpress.org');


// die();


function handle_for_url($url)
{
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_TCP_NODELAY, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYSTATUS, 0);

$streamVerboseHandle = fopen('php://stdout', 'w+');
curl_setopt($ch, CURLOPT_STDERR, $streamVerboseHandle);
return $ch;
}

// Single handle
$ch = handle_for_url('https://api.wordpress.org/stats/locale/1.0/');
$output = curl_exec($ch);
var_dump($output);

// Multi handle
$ch1 = handle_for_url('https://api.wordpress.org/stats/locale/1.0/');
$ch2 = handle_for_url('https://api.wordpress.org/stats/wordpress/1.0/');
$ch3 = handle_for_url('https://api.wordpress.org/stats/php/1.0/');

$mh = curl_multi_init();

curl_multi_add_handle($mh, $ch1);
curl_multi_add_handle($mh, $ch2);
curl_multi_add_handle($mh, $ch3);

$running = null;
do {
curl_multi_exec($mh, $running);
} while ($running);

$output1 = curl_multi_getcontent($ch1);
$output2 = curl_multi_getcontent($ch2);
$output3 = curl_multi_getcontent($ch3);

curl_multi_remove_handle($mh, $ch1);
curl_multi_remove_handle($mh, $ch2);
curl_multi_remove_handle($mh, $ch3);
curl_multi_close($mh);

var_dump($output1);
var_dump($output2);
var_dump($output3);
4 changes: 2 additions & 2 deletions packages/php-wasm/compile/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ libsqlite3: libsqlite3/dist/root/lib/lib/libsqlite3.a
libsqlite3/dist/root/lib/lib/libsqlite3.a: base-image libz
mkdir -p ./libsqlite3/dist/root/lib
docker build -f ./libsqlite3/Dockerfile -t playground-php-wasm:libsqlite3 . --progress=plain
docker cp $$(docker create playground-php-wasm:libsqlite3):/root/install/lib ./libsqlite3/dist/root/lib
docker cp $$(docker create playground-php-wasm:libsqlite3):/root/install/include ./libsqlite3/dist/root/lib
docker cp $$(docker create playground-php-wasm:libsqlite3):/root/lib/lib ./libsqlite3/dist/root/lib
docker cp $$(docker create playground-php-wasm:libsqlite3):/root/lib/include ./libsqlite3/dist/root/lib

libiconv: libiconv/dist/root/lib/lib/libiconv.a
libiconv/dist/root/lib/lib/libiconv.a: base-image libz
Expand Down
4 changes: 2 additions & 2 deletions packages/php-wasm/compile/base-image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ RUN set -euxo pipefail;\
# the build take forever on Apple Silicon.
RUN ln -s /usr/bin/python3 /usr/bin/python
RUN git clone https://github.com/emscripten-core/emsdk.git && \
./emsdk/emsdk install 3.1.43 && \
/root/emsdk/emsdk activate 3.1.43
./emsdk/emsdk install 3.1.58 && \
/root/emsdk/emsdk activate 3.1.58

RUN mkdir -p /root/lib/lib /root/lib/include /root/lib/share /root/lib/bin

Expand Down
1 change: 1 addition & 0 deletions packages/php-wasm/compile/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ const platformDefaults = {
},
['web-light']: {},
['web-kitchen-sink']: {
WITH_CURL: 'yes',
WITH_FILEINFO: 'yes',
WITH_ICONV: 'yes',
WITH_LIBXML: 'yes',
Expand Down
21 changes: 2 additions & 19 deletions packages/php-wasm/compile/libcurl/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,6 @@ RUN CPPFLAGS="-I/root/lib/include " \
--disable-threaded-resolver \
--with-zlib=/root/lib

RUN cp /root/emsdk/upstream/bin/wasm-ld /root/emsdk/upstream/bin/wasm-ld-original && \
echo $'#!/bin/bash\n\
if [[ " $@ " =~ " -o curl " ]]; then \n\
echo '' > /root/curl-7.69.1/src/curl; \n\
echo '' > /root/curl-7.69.1/curl; \n\
fi; \n\
/root/emsdk/upstream/bin/wasm-ld-original "$@" || true; \n\
exit 0; \n' > /root/emsdk/upstream/bin/wasm-ld && \
chmod a+x /root/emsdk/upstream/bin/wasm-ld


RUN source /root/emsdk/emsdk_env.sh && \
EMCC_SKIP="-lc -lz -lcurl -lssl " \
EMCC_FLAGS="-sSIDE_MODULE -Wl,--wrap=select " emmake make -i || true

RUN source /root/emsdk/emsdk_env.sh && \
EMCC_SKIP="-lc -lz -lcurl -lssl " \
EMCC_FLAGS="-sSIDE_MODULE -Wl,--wrap=select " emmake make install -i || true

RUN ls -R /root/lib
EMCC_SKIP="-lc -lz -lcurl -lssl " \
EMCC_FLAGS="-sSIDE_MODULE -Wl,--wrap=select -sSUPPORT_LONGJMP=wasm -fwasm-exceptions " emmake make || true
Loading
Loading