add a minimal build

This commit is contained in:
Toshit Chawda 2024-07-03 11:04:02 -07:00
parent b5263a06fa
commit 93e5812211
No known key found for this signature in database
GPG key ID: 91480ED99E2B3D9D
10 changed files with 151 additions and 99 deletions

2
.gitignore vendored
View file

@ -2,5 +2,7 @@
**/*.pem
client/pkg
client/out
client/full
client/minimal
.direnv
pnpm-lock.yaml

120
Cargo.lock generated
View file

@ -219,9 +219,9 @@ dependencies = [
[[package]]
name = "backtrace"
version = "0.3.72"
version = "0.3.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17c6a35df3749d2e8bb1b7b21a976d82b15548788d2735b9d82f329268f71a11"
checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a"
dependencies = [
"addr2line",
"cc",
@ -252,9 +252,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitflags"
version = "2.5.0"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1"
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
[[package]]
name = "block-buffer"
@ -306,9 +306,9 @@ checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9"
[[package]]
name = "cc"
version = "1.0.99"
version = "1.0.104"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695"
checksum = "74b6a57f98764a267ff415d50a25e6e166f3831a5071af4995296ea97d210490"
[[package]]
name = "certs-grabber"
@ -326,9 +326,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "4.5.7"
version = "4.5.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5db83dced34638ad474f39f250d7fea9598bdd239eaced1bdf45d597da0f433f"
checksum = "84b3edb18336f4df585bc9aa31dd99c036dfa5dc5e9a2939a722a188f3a8970d"
dependencies = [
"clap_builder",
"clap_derive",
@ -336,9 +336,9 @@ dependencies = [
[[package]]
name = "clap_builder"
version = "4.5.7"
version = "4.5.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7e204572485eb3fbf28f871612191521df159bc3e15a9f5064c66dba3a8c05f"
checksum = "c1c09dd5ada6c6c78075d6fd0da3f90d8080651e2d6cc8eb2f1aaa4034ced708"
dependencies = [
"anstream",
"anstyle",
@ -349,9 +349,9 @@ dependencies = [
[[package]]
name = "clap_derive"
version = "4.5.5"
version = "4.5.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c780290ccf4fb26629baa7a1081e68ced113f1d3ec302fa5948f1c381ebf06c6"
checksum = "2bac35c6dafb060fd4d275d9a4ffae97917c13a6327903a8be2153cd964f7085"
dependencies = [
"heck",
"proc-macro2",
@ -516,18 +516,19 @@ dependencies = [
[[package]]
name = "either"
version = "1.12.0"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b"
checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0"
[[package]]
name = "epoxy-client"
version = "2.0.2"
version = "2.0.3"
dependencies = [
"async-compression",
"async-trait",
"base64 0.22.1",
"bytes",
"cfg-if",
"event-listener",
"fastwebsockets",
"flume",
@ -536,7 +537,7 @@ dependencies = [
"getrandom",
"http 1.1.0",
"http-body-util",
"hyper 1.3.1",
"hyper 1.4.0",
"hyper-util-wasm",
"js-sys",
"pin-project-lite",
@ -565,7 +566,7 @@ dependencies = [
"fastwebsockets",
"futures-util",
"http-body-util",
"hyper 1.3.1",
"hyper 1.4.0",
"hyper-util",
"tokio",
"tokio-util",
@ -614,7 +615,7 @@ dependencies = [
"base64 0.21.7",
"bytes",
"http-body-util",
"hyper 1.3.1",
"hyper 1.4.0",
"hyper-util",
"pin-project",
"rand",
@ -952,9 +953,9 @@ dependencies = [
[[package]]
name = "httparse"
version = "1.9.3"
version = "1.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0e7a4dd27b9476dc40cb050d3632d3bba3a70ddbff012285f7f8559a1e7e545"
checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9"
[[package]]
name = "httpdate"
@ -994,9 +995,9 @@ dependencies = [
[[package]]
name = "hyper"
version = "1.3.1"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe575dd17d0862a9a33781c8c4696a55c320909004a67a00fb286ba8b1bc496d"
checksum = "c4fe55fb7a772d59a5ff1dfbff4fe0258d19b89fec4b233e75d35d5d2316badc"
dependencies = [
"bytes",
"futures-channel",
@ -1027,31 +1028,31 @@ dependencies = [
[[package]]
name = "hyper-util"
version = "0.1.5"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b875924a60b96e5d7b9ae7b066540b1dd1cbd90d1828f54c92e02a283351c56"
checksum = "3ab92f4f49ee4fb4f997c784b7a2e0fa70050211e0b6a287f898c3c9785ca956"
dependencies = [
"bytes",
"futures-util",
"http 1.1.0",
"http-body 1.0.0",
"hyper 1.3.1",
"hyper 1.4.0",
"pin-project-lite",
"tokio",
]
[[package]]
name = "hyper-util-wasm"
version = "0.1.3"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d75266d8a7846ac2878c0337387caeb96b75d7a2ebe58317611df0f8f0861ee"
checksum = "185e0d2e1af65e61860ad821d8ceafd38715f264f4abbed62456851ff5415e55"
dependencies = [
"bytes",
"futures-channel",
"futures-util",
"http 1.1.0",
"http-body 1.0.0",
"hyper 1.3.1",
"hyper 1.4.0",
"pin-project-lite",
"tower",
"tower-service",
@ -1123,9 +1124,9 @@ dependencies = [
[[package]]
name = "lazy_static"
version = "1.4.0"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]]
name = "libc"
@ -1151,9 +1152,9 @@ dependencies = [
[[package]]
name = "log"
version = "0.4.21"
version = "0.4.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c"
checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
[[package]]
name = "matchers"
@ -1172,9 +1173,9 @@ checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94"
[[package]]
name = "memchr"
version = "2.7.2"
version = "2.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d"
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]]
name = "mime"
@ -1190,9 +1191,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "miniz_oxide"
version = "0.7.3"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae"
checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08"
dependencies = [
"adler",
]
@ -1265,9 +1266,9 @@ dependencies = [
[[package]]
name = "object"
version = "0.35.0"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8ec7ab813848ba4522158d5517a6093db1ded27575b070f4177b8d12b41db5e"
checksum = "081b846d1d56ddfc18fdf1a922e4f6e07a11768ea1b92dec44e42b72712ccfce"
dependencies = [
"memchr",
]
@ -1284,7 +1285,7 @@ version = "0.10.64"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f"
dependencies = [
"bitflags 2.5.0",
"bitflags 2.6.0",
"cfg-if",
"foreign-types",
"libc",
@ -1403,9 +1404,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "proc-macro2"
version = "1.0.85"
version = "1.0.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23"
checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77"
dependencies = [
"unicode-ident",
]
@ -1483,11 +1484,11 @@ dependencies = [
[[package]]
name = "redox_syscall"
version = "0.5.1"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e"
checksum = "c82cf8cff14456045f55ec4241383baeff27af886adb72ffb2162f99911de0fd"
dependencies = [
"bitflags 2.5.0",
"bitflags 2.6.0",
]
[[package]]
@ -1570,7 +1571,7 @@ version = "0.38.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f"
dependencies = [
"bitflags 2.5.0",
"bitflags 2.6.0",
"errno",
"libc",
"linux-raw-sys",
@ -1579,9 +1580,9 @@ dependencies = [
[[package]]
name = "rustls"
version = "0.23.9"
version = "0.23.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a218f0f6d05669de4eabfb24f31ce802035c952429d037507b4a4a39f0e60c5b"
checksum = "05cff451f60db80f490f3c182b77c35260baace73209e9cdbbe526bfe3a4d402"
dependencies = [
"once_cell",
"ring",
@ -1602,9 +1603,9 @@ dependencies = [
[[package]]
name = "rustls-webpki"
version = "0.102.4"
version = "0.102.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff448f7e92e913c4b7d4c6d8e4540a1724b319b4152b8aef6d4cf8339712b33e"
checksum = "f9a6fccd794a42c2c105b513a2f62bc3fd8f3ba57a4593677ceb0bd035164d78"
dependencies = [
"ring",
"rustls-pki-types",
@ -1653,7 +1654,7 @@ version = "2.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0"
dependencies = [
"bitflags 2.5.0",
"bitflags 2.6.0",
"core-foundation",
"core-foundation-sys",
"libc",
@ -1704,9 +1705,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.117"
version = "1.0.120"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3"
checksum = "4e0d21c9a8cae1235ad58a00c11cb40d4b1e5c784f1ef2c537876ed6ffd8b7c5"
dependencies = [
"itoa",
"ryu",
@ -1760,7 +1761,7 @@ dependencies = [
"futures",
"http-body-util",
"humantime",
"hyper 1.3.1",
"hyper 1.4.0",
"simple_moving_average",
"tokio",
"tokio-native-tls",
@ -1819,15 +1820,15 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "subtle"
version = "2.5.0"
version = "2.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc"
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]]
name = "syn"
version = "2.0.66"
version = "2.0.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5"
checksum = "901fa70d88b9d6c98022e23b4136f9f3e54e4662c3bc1bd1d84a42a9a0f0c1e9"
dependencies = [
"proc-macro2",
"quote",
@ -2032,7 +2033,6 @@ version = "0.1.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef"
dependencies = [
"log",
"pin-project-lite",
"tracing-attributes",
"tracing-core",
@ -2268,9 +2268,9 @@ dependencies = [
[[package]]
name = "webpki-roots"
version = "0.26.2"
version = "0.26.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c452ad30530b54a4d8e71952716a212b08efd0f3562baa66c29a618b07da7c3"
checksum = "bd7c23921eeb1713a4e851530e9b9756e4fb0e89978582942612524cf09f01cd"
dependencies = [
"rustls-pki-types",
]

View file

@ -1,3 +1,2 @@
[profile.release]
opt-level = 'z'
debug = false

View file

@ -4,3 +4,4 @@ serve.py
src
tests
test.sh
.cargo

View file

@ -1,22 +1,23 @@
[package]
name = "epoxy-client"
version = "2.0.2"
version = "2.0.3"
edition = "2021"
[lib]
crate-type = ["cdylib"]
[dependencies]
async-compression = { version = "0.4.11", features = ["futures-io", "gzip", "brotli"] }
async-compression = { version = "0.4.11", features = ["futures-io", "gzip", "brotli"], optional = true }
async-trait = "0.1.80"
base64 = "0.22.1"
base64 = { version = "0.22.1", optional = true }
bytes = "1.6.0"
cfg-if = "1.0.0"
event-listener = "5.3.1"
fastwebsockets = { version = "0.7.2", features = ["unstable-split"] }
fastwebsockets = { version = "0.7.2", features = ["unstable-split"], optional = true }
flume = "0.11.0"
futures-rustls = { version = "0.26.0", default-features = false, features = ["tls12", "ring"] }
futures-util = { version = "0.3.30", features = ["sink"] }
getrandom = { version = "0.2.15", features = ["js"] }
getrandom = { version = "0.2.15", features = ["js", "std"], optional = true }
http = "1.1.0"
http-body-util = "0.1.2"
hyper = "1.3.1"
@ -42,3 +43,7 @@ features = ["wasm32_unknown_unknown_js"]
# update whenever rustls updates
version = "1.4.1"
features = ["web"]
[features]
default = ["full"]
full = ["fastwebsockets", "base64", "async-compression", "getrandom"]

View file

@ -6,7 +6,7 @@ mkdir out/ || true
rm -r pkg/ || true
mkdir pkg/
RUSTFLAGS='-C target-feature=+atomics,+bulk-memory,+simd128' cargo build --target wasm32-unknown-unknown -Z build-std=panic_abort,std --release
RUSTFLAGS='-C target-feature=+atomics,+bulk-memory,+simd128' cargo build --target wasm32-unknown-unknown -Z build-std=panic_abort,std --release "$@"
echo "[epx] cargo finished"
wasm-bindgen --weak-refs --target no-modules --no-modules-global epoxy --out-dir out/ ../target/wasm32-unknown-unknown/release/epoxy_client.wasm
echo "[epx] wasm-bindgen finished"

View file

@ -182,7 +182,7 @@ onmessage = async (msg) => {
);
let ws = await epoxy_client.connect_websocket(
handlers,
"ws://localhost:5000",
"wss://echo.websocket.events",
[],
{ "x-header": "abc" },
);

View file

@ -1,6 +1,6 @@
{
"name": "@mercuryworkshop/epoxy-tls",
"version": "2.0.2-1",
"version": "2.0.3-1",
"description": "A wasm library for using raw encrypted tls/ssl/https/websocket streams on the browser",
"scripts": {
"build": "./build.sh"

11
client/publish.sh Executable file
View file

@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -euo pipefail
shopt -s inherit_errexit
rm -r full minimal || true
cargo clean
bash build.sh
mv pkg full
bash build.sh --no-default-features
mv pkg minimal

View file

@ -1,9 +1,13 @@
#![feature(let_chains, impl_trait_in_assoc_type)]
use std::{str::FromStr, sync::Arc};
#[cfg(feature = "full")]
use async_compression::futures::bufread as async_comp;
use bytes::Bytes;
use futures_util::{future::Either, TryStreamExt};
use cfg_if::cfg_if;
use futures_util::TryStreamExt;
#[cfg(feature = "full")]
use futures_util::future::Either;
use http::{
header::{InvalidHeaderName, InvalidHeaderValue},
method::InvalidMethod,
@ -12,6 +16,7 @@ use http::{
};
use hyper::{body::Incoming, Uri};
use hyper_util_wasm::client::legacy::Client;
#[cfg(feature = "full")]
use io_stream::{EpoxyIoStream, EpoxyUdpStream};
use js_sys::{Array, Function, Object, Reflect};
use stream_provider::{StreamProvider, StreamProviderService};
@ -23,13 +28,17 @@ use utils::{
use wasm_bindgen::prelude::*;
use wasm_streams::ReadableStream;
use web_sys::ResponseInit;
#[cfg(feature = "full")]
use websocket::EpoxyWebSocket;
#[cfg(feature = "full")]
use wisp_mux::StreamType;
#[cfg(feature = "full")]
mod io_stream;
mod stream_provider;
mod tokioio;
mod utils;
#[cfg(feature = "full")]
mod websocket;
mod ws_wrapper;
@ -51,8 +60,10 @@ pub enum EpoxyError {
Hyper(#[from] hyper::Error),
#[error("HTTP ToStr: {0:?}")]
ToStr(#[from] http::header::ToStrError),
#[cfg(feature = "full")]
#[error("Getrandom: {0:?}")]
GetRandom(#[from] getrandom::Error),
#[cfg(feature = "full")]
#[error("Fastwebsockets: {0:?}")]
FastWebSockets(#[from] fastwebsockets::WebSocketError),
@ -134,6 +145,7 @@ enum EpoxyResponse {
Redirect((Response<Incoming>, http::Request<HttpBody>)),
}
#[cfg(feature = "full")]
enum EpoxyCompression {
Brotli,
Gzip,
@ -178,6 +190,7 @@ pub struct EpoxyHandlers {
pub onmessage: Function,
}
#[cfg(feature = "full")]
#[wasm_bindgen]
impl EpoxyHandlers {
#[wasm_bindgen(constructor)]
@ -240,6 +253,7 @@ impl EpoxyClient {
self.stream_provider.replace_client().await
}
#[cfg(feature = "full")]
pub async fn connect_websocket(
&self,
handlers: EpoxyHandlers,
@ -250,6 +264,7 @@ impl EpoxyClient {
EpoxyWebSocket::connect(self, handlers, url, protocols, headers, &self.user_agent).await
}
#[cfg(feature = "full")]
pub async fn connect_tcp(
&self,
handlers: EpoxyHandlers,
@ -273,6 +288,7 @@ impl EpoxyClient {
}
}
#[cfg(feature = "full")]
pub async fn connect_tls(
&self,
handlers: EpoxyHandlers,
@ -296,6 +312,7 @@ impl EpoxyClient {
}
}
#[cfg(feature = "full")]
pub async fn connect_udp(
&self,
handlers: EpoxyHandlers,
@ -433,7 +450,13 @@ impl EpoxyClient {
.headers_mut()
.ok_or(EpoxyError::InvalidRequest)?;
cfg_if! {
if #[cfg(feature = "full")] {
headers_map.insert("Accept-Encoding", HeaderValue::from_static("gzip, br"));
} else {
headers_map.insert("Accept-Encoding", HeaderValue::from_static("identity"));
}
}
headers_map.insert("Connection", HeaderValue::from_static("keep-alive"));
headers_map.insert("User-Agent", HeaderValue::from_str(&self.user_agent)?);
headers_map.insert("Host", HeaderValue::from_str(host)?);
@ -480,6 +503,8 @@ impl EpoxyClient {
.status(response.status().as_u16())
.status_text(response.status().canonical_reason().unwrap_or_default());
cfg_if! {
if #[cfg(feature = "full")] {
let response_stream = if !is_null_body(response.status().as_u16()) {
let compression = match response
.headers()
@ -508,6 +533,15 @@ impl EpoxyClient {
} else {
None
};
} else {
let response_stream = if !is_null_body(response.status().as_u16()) {
let response_body = IncomingBody::new(response.into_body()).into_async_read();
Some(ReadableStream::from_async_read(response_body, 1024).into_raw())
} else {
None
};
}
}
let resp = web_sys::Response::new_with_opt_readable_stream_and_init(
response_stream.as_ref(),