mirror of
https://github.com/MercuryWorkshop/epoxy-tls.git
synced 2025-05-12 22:10: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]]
|
[[package]]
|
||||||
name = "epoxy-client"
|
name = "epoxy-client"
|
||||||
version = "2.1.2"
|
version = "2.1.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-compression",
|
"async-compression",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
|
|
@ -30,7 +30,7 @@ See the [server readme](server/README.md).
|
||||||
> [!IMPORTANT]
|
> [!IMPORTANT]
|
||||||
> Building the client is only supported on Linux.
|
> 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:
|
In the `client` directory:
|
||||||
```
|
```
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "epoxy-client"
|
name = "epoxy-client"
|
||||||
version = "2.1.2"
|
version = "2.1.3"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
|
|
|
@ -6,7 +6,13 @@ mkdir out/ || true
|
||||||
rm -r pkg/ || true
|
rm -r pkg/ || true
|
||||||
mkdir pkg/
|
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"
|
echo "[epx] cargo finished"
|
||||||
wasm-bindgen --target web --out-dir out/ ../target/wasm32-unknown-unknown/release/epoxy_client.wasm
|
wasm-bindgen --target web --out-dir out/ ../target/wasm32-unknown-unknown/release/epoxy_client.wasm
|
||||||
echo "[epx] wasm-bindgen finished"
|
echo "[epx] wasm-bindgen finished"
|
||||||
|
@ -23,6 +29,9 @@ echo "[epx] wasm-opt finished"
|
||||||
|
|
||||||
# === js ===
|
# === 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_SOURCE=$(<"out/epoxy_client.js")
|
||||||
|
|
||||||
AUTOGENERATED_SNIPPET_PATH=$(<"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}
|
AUTOGENERATED_SOURCE=${AUTOGENERATED_SOURCE//return __wbg_finalize_init/__wbg_finalize_init}
|
||||||
|
|
||||||
echo "$AUTOGENERATED_SOURCE" > pkg/epoxy.js
|
echo "$AUTOGENERATED_SOURCE" > pkg/epoxy.js
|
||||||
|
echo "$AUTOGENERATED_INFO_FUNC" >> pkg/epoxy.js
|
||||||
|
|
||||||
WASM_BASE64=$(base64 -w0 out/epoxy_client_bg.wasm)
|
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\'}
|
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_SOURCE" > pkg/epoxy-bundled.js
|
||||||
|
echo "$AUTOGENERATED_INFO_FUNC" >> pkg/epoxy-bundled.js
|
||||||
|
|
||||||
# === types ===
|
# === types ===
|
||||||
|
|
||||||
|
@ -66,12 +77,14 @@ AUTOGENERATED_TYPES=${AUTOGENERATED_TYPES//$'\n'export interface InitOutput*Init
|
||||||
AUTOGENERATED_TYPES=${AUTOGENERATED_TYPES//Promise<InitOutput>/Promise<void>}
|
AUTOGENERATED_TYPES=${AUTOGENERATED_TYPES//Promise<InitOutput>/Promise<void>}
|
||||||
|
|
||||||
echo "$AUTOGENERATED_TYPES" > pkg/epoxy.d.ts
|
echo "$AUTOGENERATED_TYPES" > pkg/epoxy.d.ts
|
||||||
|
echo "$AUTOGENERATED_INFO_FUNC_TYPE" >> pkg/epoxy.d.ts
|
||||||
|
|
||||||
# remove useless comment
|
# remove useless comment
|
||||||
AUTOGENERATED_TYPES=${AUTOGENERATED_TYPES//$'\n*' If $'`'module_or_path*$'}' module_or_path/}
|
AUTOGENERATED_TYPES=${AUTOGENERATED_TYPES//$'\n*' If $'`'module_or_path*$'}' module_or_path/}
|
||||||
AUTOGENERATED_TYPES=${AUTOGENERATED_TYPES//module_or_path*, /}
|
AUTOGENERATED_TYPES=${AUTOGENERATED_TYPES//module_or_path*, /}
|
||||||
|
|
||||||
echo "$AUTOGENERATED_TYPES" > pkg/epoxy-bundled.d.ts
|
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
|
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);
|
console.log(epoxy_client);
|
||||||
// you can change the user agent and redirect limit in JS
|
// you can change the user agent and redirect limit in JS
|
||||||
epoxy_client.redirect_limit = 15;
|
epoxy_client.redirect_limit = 15;
|
||||||
console.log(epoxyInfo());
|
console.log(epoxyInfo);
|
||||||
|
|
||||||
const test_mux = async (url) => {
|
const test_mux = async (url) => {
|
||||||
const t0 = performance.now();
|
const t0 = performance.now();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@mercuryworkshop/epoxy-tls",
|
"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",
|
"description": "A wasm library for using raw encrypted tls/ssl/tcp/udp/https/websocket streams on the browser",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "./build.sh"
|
"build": "./build.sh"
|
||||||
|
|
|
@ -9,5 +9,5 @@ rm -r full minimal || true
|
||||||
cargo clean
|
cargo clean
|
||||||
bash build.sh
|
bash build.sh
|
||||||
mv pkg full
|
mv pkg full
|
||||||
bash build.sh --no-default-features
|
MINIMAL=1 bash build.sh
|
||||||
mv pkg minimal
|
mv pkg minimal
|
||||||
|
|
|
@ -43,20 +43,6 @@ mod utils;
|
||||||
mod websocket;
|
mod websocket;
|
||||||
mod ws_wrapper;
|
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>;
|
type HttpBody = http_body_util::Full<Bytes>;
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue