mirror of
https://github.com/MercuryWorkshop/epoxy-tls.git
synced 2025-05-12 14:00:01 -04:00
move info from a wasm function to an object
This commit is contained in:
parent
6fbe1248c3
commit
80b68f1cee
8 changed files with 20 additions and 21 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -513,7 +513,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "epoxy-client"
|
||||
version = "2.1.2"
|
||||
version = "2.1.3"
|
||||
dependencies = [
|
||||
"async-compression",
|
||||
"async-trait",
|
||||
|
|
|
@ -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:
|
||||
```
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "epoxy-client"
|
||||
version = "2.1.2"
|
||||
version = "2.1.3"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
|
|
|
@ -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<InitOutput>/Promise<void>}
|
||||
|
||||
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
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<Bytes>;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue