diff --git a/.github/workflows/release-ci.yml b/.github/workflows/release-ci.yml index 378d7279..1b9e38a2 100644 --- a/.github/workflows/release-ci.yml +++ b/.github/workflows/release-ci.yml @@ -39,6 +39,14 @@ jobs: working-directory: rustmail_panel run: trunk build --release --dist ../rustmail/static --config Trunk.toml + - name: Optimize WASM + run: | + cargo install wasm-opt --locked + for f in rustmail/static/*.wasm; do + wasm-opt -Oz "$f" -o "$f.tmp" + mv "$f.tmp" "$f" + done + - name: Build Rust backend run: cargo build --verbose -p rustmail @@ -100,6 +108,15 @@ jobs: working-directory: rustmail_panel run: trunk build --release --dist ../rustmail/static --config Trunk.toml + - name: Optimize WASM + run: | + cargo install wasm-opt --locked + for f in rustmail/static/*.wasm; do + wasm-opt -Oz "$f" -o "$f.tmp" + mv "$f.tmp" "$f" + done + shell: bash + - name: Verify static files were created run: ls rustmail/static shell: bash diff --git a/Cargo.lock b/Cargo.lock index aa7ac5a0..2f87b5d4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,21 @@ dependencies = [ "memchr", ] +[[package]] +name = "alloc-no-stdlib" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc7bb162ec39d46ab1ca8c77bf72e890535becd1751bb45f64c597edb4c8c6b3" + +[[package]] +name = "alloc-stdlib" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94fb8275041c72129eb51b7d0322c29b8387a0386127718b096429201a5d6ece" +dependencies = [ + "alloc-no-stdlib", +] + [[package]] name = "allocator-api2" version = "0.2.21" @@ -60,6 +75,19 @@ dependencies = [ "serde", ] +[[package]] +name = "async-compression" +version = "0.4.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93c1f86859c1af3d514fa19e8323147ff10ea98684e6c7b307912509f50e67b2" +dependencies = [ + "compression-codecs", + "compression-core", + "futures-core", + "pin-project-lite", + "tokio", +] + [[package]] name = "async-lock" version = "3.4.1" @@ -234,6 +262,27 @@ version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfa8873f51c92e232f9bac4065cddef41b714152812bfc5f7672ba16d6ef8cd9" +[[package]] +name = "brotli" +version = "8.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bd8b9603c7aa97359dbd97ecf258968c95f3adddd6db2f7e7a5bef101c84560" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", + "brotli-decompressor", +] + +[[package]] +name = "brotli-decompressor" +version = "5.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "874bb8112abecc98cbd6d81ea4fa7e94fb9449648c93cc89aa40c81c24d7de03" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", +] + [[package]] name = "bumpalo" version = "3.17.0" @@ -340,6 +389,24 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "compression-codecs" +version = "0.4.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "680dc087785c5230f8e8843e2e57ac7c1c90488b6a91b88caa265410568f441b" +dependencies = [ + "brotli", + "compression-core", + "flate2", + "memchr", +] + +[[package]] +name = "compression-core" +version = "0.4.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75984efb6ed102a0d42db99afb6c1948f0380d1d91808d5529916e6c08b49d8d" + [[package]] name = "concurrent-queue" version = "2.5.0" @@ -2820,6 +2887,7 @@ dependencies = [ "subtle", "tokio", "toml", + "tower-http", "urlencoding", "uuid", ] @@ -3851,17 +3919,21 @@ dependencies = [ [[package]] name = "tower-http" -version = "0.6.6" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adc82fd73de2a9722ac5da747f12383d2bfdb93591ee6c58486e0097890f05f2" +checksum = "9cf146f99d442e8e68e585f5d798ccd3cad9a7835b917e09728880a862706456" dependencies = [ + "async-compression", "bitflags 2.9.1", "bytes", + "futures-core", "futures-util", "http 1.3.1", "http-body 1.0.1", "iri-string", "pin-project-lite", + "tokio", + "tokio-util", "tower", "tower-layer", "tower-service", diff --git a/rustmail/Cargo.toml b/rustmail/Cargo.toml index 7b8ff515..5daa841b 100644 --- a/rustmail/Cargo.toml +++ b/rustmail/Cargo.toml @@ -27,6 +27,7 @@ subtle = "2.6.1" sha2 = "0.10.8" hex = "0.4.3" moka = { version = "0.12", features = ["future"] } +tower-http = { version = "0.6.7", features = ["compression-gzip", "compression-br"] } [dependencies.uuid] version = "1.18.1" diff --git a/rustmail/src/main.rs b/rustmail/src/main.rs index 2fc9bbc0..2491e352 100644 --- a/rustmail/src/main.rs +++ b/rustmail/src/main.rs @@ -6,6 +6,7 @@ use rust_embed::RustEmbed; use std::borrow::Cow; use std::net::SocketAddr; use tokio::signal; +use tower_http::compression::CompressionLayer; mod api; mod bot; @@ -85,7 +86,8 @@ async fn main() { let server_task = tokio::spawn(async move { let app = create_api_router(bot_state_clone) .route("/", axum::routing::get(static_handler)) - .route("/{*path}", axum::routing::get(static_handler)); + .route("/{*path}", axum::routing::get(static_handler)) + .layer(CompressionLayer::new()); let bind_address = config .bot