diff --git a/Cargo.lock b/Cargo.lock index 9c47ae5..08292a3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -513,7 +513,7 @@ dependencies = [ [[package]] name = "epoxy-client" -version = "2.1.2" +version = "2.1.3" dependencies = [ "async-compression", "async-trait", diff --git a/README.md b/README.md index 99d4af8..12be662 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ See the [server readme](server/README.md). > [!IMPORTANT] > Building the client is only supported on Linux. -Make sure you have the `wasm32-unknown-unknown` rust target, the `rust-std` component, and the `wasm-bindgen`, `wasm-opt`, and `base64` binaries installed. +Make sure you have the `wasm32-unknown-unknown` rust target, the `rust-std` component, and the `wasm-bindgen`, `wasm-opt`, `jq`, and `base64` binaries installed. In the `client` directory: ``` diff --git a/client/Cargo.toml b/client/Cargo.toml index 0b44f82..25f929f 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "epoxy-client" -version = "2.1.2" +version = "2.1.3" edition = "2021" [lib] diff --git a/client/build.sh b/client/build.sh index 6470be4..531cd76 100755 --- a/client/build.sh +++ b/client/build.sh @@ -6,7 +6,13 @@ mkdir out/ || true rm -r pkg/ || true mkdir pkg/ -RUSTFLAGS='-C target-feature=+atomics,+bulk-memory -Zlocation-detail=none' cargo build --target wasm32-unknown-unknown -Z build-std=panic_abort,std -Z build-std-features=panic_immediate_abort,optimize_for_size --release "$@" +if [ "${MINIMAL:-0}" = "1" ]; then + CARGOFLAGS="--no-default-features" +else + CARGOFLAGS="" +fi + +RUSTFLAGS='-C target-feature=+atomics,+bulk-memory -Zlocation-detail=none' cargo build --target wasm32-unknown-unknown -Z build-std=panic_abort,std -Z build-std-features=panic_immediate_abort,optimize_for_size --release $CARGOFLAGS "$@" echo "[epx] cargo finished" wasm-bindgen --target web --out-dir out/ ../target/wasm32-unknown-unknown/release/epoxy_client.wasm echo "[epx] wasm-bindgen finished" @@ -23,6 +29,9 @@ echo "[epx] wasm-opt finished" # === js === +AUTOGENERATED_INFO_FUNC="export const info = { version: $(jq .version package.json), minimal: ${MINIMAL:-0}===1, release: ${RELEASE:=0}===1 };" +AUTOGENERATED_INFO_FUNC_TYPE="export const info = { version: string, minimal: boolean, release: boolean };"; + AUTOGENERATED_SOURCE=$(<"out/epoxy_client.js") AUTOGENERATED_SNIPPET_PATH=$(<"out/epoxy_client.js") @@ -52,11 +61,13 @@ AUTOGENERATED_SOURCE=${AUTOGENERATED_SOURCE//export $'{' initSync $'}\n'/} AUTOGENERATED_SOURCE=${AUTOGENERATED_SOURCE//return __wbg_finalize_init/__wbg_finalize_init} echo "$AUTOGENERATED_SOURCE" > pkg/epoxy.js +echo "$AUTOGENERATED_INFO_FUNC" >> pkg/epoxy.js WASM_BASE64=$(base64 -w0 out/epoxy_client_bg.wasm) AUTOGENERATED_SOURCE=${AUTOGENERATED_SOURCE//__wbg_init(input, maybe_memory) \{/__wbg_init(maybe_memory) \{$'\n'let input=\'data:application/wasm;base64,$WASM_BASE64\'} echo "$AUTOGENERATED_SOURCE" > pkg/epoxy-bundled.js +echo "$AUTOGENERATED_INFO_FUNC" >> pkg/epoxy-bundled.js # === types === @@ -66,12 +77,14 @@ AUTOGENERATED_TYPES=${AUTOGENERATED_TYPES//$'\n'export interface InitOutput*Init AUTOGENERATED_TYPES=${AUTOGENERATED_TYPES//Promise/Promise} echo "$AUTOGENERATED_TYPES" > pkg/epoxy.d.ts +echo "$AUTOGENERATED_INFO_FUNC_TYPE" >> pkg/epoxy.d.ts # remove useless comment AUTOGENERATED_TYPES=${AUTOGENERATED_TYPES//$'\n*' If $'`'module_or_path*$'}' module_or_path/} AUTOGENERATED_TYPES=${AUTOGENERATED_TYPES//module_or_path*, /} echo "$AUTOGENERATED_TYPES" > pkg/epoxy-bundled.d.ts +echo "$AUTOGENERATED_INFO_FUNC_TYPE" >> pkg/epoxy-bundled.d.ts cp out/epoxy_client_bg.wasm pkg/epoxy.wasm diff --git a/client/demo.js b/client/demo.js index 6b7c2a5..1ff9cd1 100644 --- a/client/demo.js +++ b/client/demo.js @@ -40,7 +40,7 @@ import initEpoxy, { EpoxyClient, EpoxyClientOptions, EpoxyHandlers, info as epox console.log(epoxy_client); // you can change the user agent and redirect limit in JS epoxy_client.redirect_limit = 15; - console.log(epoxyInfo()); + console.log(epoxyInfo); const test_mux = async (url) => { const t0 = performance.now(); diff --git a/client/package.json b/client/package.json index 45799ab..a38f540 100644 --- a/client/package.json +++ b/client/package.json @@ -1,6 +1,6 @@ { "name": "@mercuryworkshop/epoxy-tls", - "version": "2.1.2-1", + "version": "2.1.3-1", "description": "A wasm library for using raw encrypted tls/ssl/tcp/udp/https/websocket streams on the browser", "scripts": { "build": "./build.sh" diff --git a/client/publish.sh b/client/publish.sh index 31ba73a..90933df 100755 --- a/client/publish.sh +++ b/client/publish.sh @@ -9,5 +9,5 @@ rm -r full minimal || true cargo clean bash build.sh mv pkg full -bash build.sh --no-default-features +MINIMAL=1 bash build.sh mv pkg minimal diff --git a/client/src/lib.rs b/client/src/lib.rs index e876019..b9e7d64 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -43,20 +43,6 @@ mod utils; mod websocket; mod ws_wrapper; -#[wasm_bindgen] -pub fn info() -> Object { - let obj = Object::new(); - object_set(&obj, "version", env!("CARGO_PKG_VERSION").into()); - cfg_if! { - if #[cfg(feature = "full")] { - object_set(&obj, "minimal", false.into()); - } else { - object_set(&obj, "minimal", true.into()); - } - }; - obj -} - type HttpBody = http_body_util::Full; #[derive(Debug, Error)]