diff --git a/README.md b/README.md index e73c278..2ef5d7e 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/client/build.sh b/client/build.sh index a6b5dc1..0cda2a6 100755 --- a/client/build.sh +++ b/client/build.sh @@ -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 diff --git a/client/fragments/force_wsproxy.js b/client/fragments/force_wsproxy.js index 81554bc..d65e701 100644 --- a/client/fragments/force_wsproxy.js +++ b/client/fragments/force_wsproxy.js @@ -3,4 +3,12 @@ var ?opts ?= ?undefined; */ var parts = addr.split("/"); if (!url.endsWith("/")) url += "/"; -url += parts[0] + ":" + port; \ No newline at end of file +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; diff --git a/client/fragments/load_later.js b/client/fragments/load_later.js index 2fb25b4..183a7c6 100644 --- a/client/fragments/load_later.js +++ b/client/fragments/load_later.js @@ -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(); \ No newline at end of file +if (wasmBinaryFile && isDataURI(wasmBinaryFile)) run(); \ No newline at end of file diff --git a/client/fragments/silence_socket.js b/client/fragments/silence_socket.js index de7bf00..1eac179 100644 --- a/client/fragments/silence_socket.js +++ b/client/fragments/silence_socket.js @@ -2,8 +2,3 @@ err\("__syscall_getsockname " ?\+ ?fd\); */ - -/* INSERT -function _emscripten_console_error\(str\) ?{ -*/ -if (UTF8ToString(str).endsWith("__syscall_setsockopt\\n")) return; \ No newline at end of file diff --git a/client/javascript/main.js b/client/javascript/main.js index bc8d50e..c8a0bf0 100644 --- a/client/javascript/main.js +++ b/client/javascript/main.js @@ -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(); diff --git a/client/libcurl/request.c b/client/libcurl/request.c index b9e6f51..2b1a56b 100644 --- a/client/libcurl/request.c +++ b/client/libcurl/request.c @@ -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);