support latest emscripten and detect emcc version changes

This commit is contained in:
Allen Ding 2024-11-20 12:23:02 -08:00
parent 627fd15e4d
commit b2df01fd18
7 changed files with 30 additions and 11 deletions

View file

@ -52,10 +52,11 @@ git clone https://github.com/ading2210/libcurl.js --recursive
cd libcurl.js/client
./build.sh
```
Make sure you have emscripten v3.1.6, git, and the various C build tools installed. The only OS supported for building libcurl.js is Linux. On Debian-based systems, you can run the following command to install all the dependencies:
Make sure you have emscripten, git, and the various C build tools installed. The only OS supported for building libcurl.js is Linux. On Debian-based systems, you can run the following command to install all the dependencies:
```
sudo apt install make cmake emscripten autoconf automake libtool pkg-config wget xxd jq
```
Emscripten versions 3.1.6 and 3.1.72 have been tested and known to work.
The build script will generate `client/out/libcurl.js` as well as `client/out/libcurl.mjs`, which is an ES6 module. You can supply the following arguments to the build script to control the build:
- `release` - Use all optimizations.

View file

@ -18,6 +18,16 @@ MODULE_FILE="$OUT_DIR/emscripten_compiled.js"
COMPILED_FILE="$OUT_DIR/emscripten_compiled.wasm"
WASM_FILE="$OUT_DIR/libcurl.wasm"
#check last used emscripten version
CURRENT_EMCC_VER="$(emcc --version)"
LAST_EMCC_VER="$(cat "$BUILD_DIR/emcc_version.txt" || emcc --version)"
if [ ! "$CURRENT_EMCC_VER" = "$LAST_EMCC_VER" ]; then
echo "triggering a full rebuild since we're on a different emcc version"
rm -rf "$BUILD_DIR"
mkdir -p "$BUILD_DIR"
fi
emcc --version > "$BUILD_DIR/emcc_version.txt"
#read exported functions
EXPORTED_FUNCS=""
for func in $(cat exported_funcs.txt); do

View file

@ -3,4 +3,12 @@ var ?opts ?= ?undefined;
*/
var parts = addr.split("/");
if (!url.endsWith("/")) url += "/";
url += parts[0] + ":" + port;
url += parts[0] + ":" + port;
/* REPLACE
url ?= ?SOCKFS\.websocketArgs\[['"]url['"]\];
*/
var parts = addr.split("/");
url = Module.websocket.url;
if (!url.endsWith("/")) url += "/";
url += parts[0] + ":" + port;

View file

@ -1,16 +1,16 @@
/* REPLACE
var asm ?= ?createWasm\(\);
*/
if (isDataURI(wasmBinaryFile)) var asm = createWasm();
if (wasmBinaryFile && isDataURI(wasmBinaryFile)) var asm = createWasm();
else var asm = null;
/* REPLACE
var wasmExports ?= ?createWasm\(\);
*/
if (isDataURI(wasmBinaryFile)) var wasmExports = createWasm();
if (wasmBinaryFile && isDataURI(wasmBinaryFile)) var wasmExports = createWasm();
else var wasmExports = null;
/* REPLACE
run\(\);\n\n
*/
if (isDataURI(wasmBinaryFile)) run();
if (wasmBinaryFile && isDataURI(wasmBinaryFile)) run();

View file

@ -2,8 +2,3 @@
err\("__syscall_getsockname " ?\+ ?fd\);
*/
/* INSERT
function _emscripten_console_error\(str\) ?{
*/
if (UTF8ToString(str).endsWith("__syscall_setsockopt\\n")) return;

View file

@ -45,6 +45,8 @@ function set_websocket_url(url) {
websocket_url = url;
if (typeof Module.websocket === "undefined")
Module.websocket = {};
if (typeof SOCKFS.websocketArgs !== "undefined")
SOCKFS.websocketArgs.url = url;
Module.websocket.url = url;
if (!main_session && wasm_ready) {
setup_main_session();
@ -101,7 +103,7 @@ function load_wasm(url) {
if (wasm_ready) return;
//skip this if we are running in single file mode
if (!isDataURI(wasmBinaryFile)) {
if (!wasmBinaryFile || !isDataURI(wasmBinaryFile)) {
wasmBinaryFile = url;
createWasm();
run();

View file

@ -46,6 +46,9 @@ CURL* create_request(const char* url, int request_id, DataCallback data_callback
curl_easy_setopt(http_handle, CURLOPT_CAINFO_BLOB, cacert_blob);
curl_easy_setopt(http_handle, CURLOPT_BUFFERSIZE, 512*1024);
//emscripten doesn't support tcp nodelay anyways
curl_easy_setopt(http_handle, CURLOPT_TCP_NODELAY, 0L);
//callbacks to pass the response data back to js
curl_easy_setopt(http_handle, CURLOPT_WRITEFUNCTION, &write_function);
curl_easy_setopt(http_handle, CURLOPT_WRITEDATA, request_info);