From fc6423ad44dceecd04ebc9d36f899f141bfad864 Mon Sep 17 00:00:00 2001 From: Arkitu Date: Sun, 10 Aug 2025 03:14:11 +0200 Subject: [PATCH] clean + minify --- Cargo.lock | 86 ------------------------------------------ Cargo.toml | 6 --- build.rs | 2 +- src/apps/index.html | 9 +---- src/apps/index.rs | 22 ++++++++++- src/apps/mod.rs | 6 --- src/apps/ttt.html | 1 - src/apps/ttt.js | 7 ---- src/apps/ttt.rs | 88 ++++++++----------------------------------- src/dhcp.rs | 6 +-- src/lib.rs | 8 ++-- src/main.rs | 24 ------------ src/socket.rs | 28 +------------- src/socket/ws.rs | 26 ++++++------- static/index.min.html | 1 + static/ttt.min.html | 1 + static/ttt.min.js | 1 + 17 files changed, 61 insertions(+), 261 deletions(-) create mode 100644 static/index.min.html create mode 100644 static/ttt.min.html create mode 100644 static/ttt.min.js diff --git a/Cargo.lock b/Cargo.lock index 9ba2abc..6f1fa0e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -290,48 +290,6 @@ version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f578e8e2c440e7297e008bb5486a3a8a194775224bbc23729b0dbdfaeebf162e" -[[package]] -name = "defmt" -version = "0.3.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86f6162c53f659f65d00619fe31f14556a6e9f8752ccc4a41bd177ffcf3d6130" -dependencies = [ - "bitflags 1.3.2", - "defmt-macros", -] - -[[package]] -name = "defmt-macros" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d135dd939bad62d7490b0002602d35b358dce5fd9233a709d3c1ef467d4bde6" -dependencies = [ - "defmt-parser", - "proc-macro-error2", - "proc-macro2", - "quote", - "syn 2.0.100", -] - -[[package]] -name = "defmt-parser" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3983b127f13995e68c1e29071e5d115cd96f215ccb5e6812e3728cd6f92653b3" -dependencies = [ - "thiserror", -] - -[[package]] -name = "defmt-rtt" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab697b3dbbc1750b7c8b821aa6f6e7f2480b47a99bc057a2ed7b170ebef0c51" -dependencies = [ - "critical-section", - "defmt", -] - [[package]] name = "dhcparse" version = "1.0.0" @@ -399,7 +357,6 @@ source = "git+https://github.com/embassy-rs/embassy#cae954a87ec3c5ece520b6a44168 dependencies = [ "cortex-m", "critical-section", - "defmt", "document-features", "embassy-executor-macros", ] @@ -427,7 +384,6 @@ source = "git+https://github.com/embassy-rs/embassy#cae954a87ec3c5ece520b6a44168 dependencies = [ "cortex-m", "critical-section", - "defmt", "num-traits", ] @@ -436,7 +392,6 @@ name = "embassy-net" version = "0.7.0" source = "git+https://github.com/embassy-rs/embassy#cae954a87ec3c5ece520b6a44168b36e79f3f86a" dependencies = [ - "defmt", "document-features", "embassy-net-driver", "embassy-sync", @@ -452,9 +407,6 @@ dependencies = [ name = "embassy-net-driver" version = "0.2.0" source = "git+https://github.com/embassy-rs/embassy#cae954a87ec3c5ece520b6a44168b36e79f3f86a" -dependencies = [ - "defmt", -] [[package]] name = "embassy-net-driver-channel" @@ -476,7 +428,6 @@ dependencies = [ "cortex-m", "cortex-m-rt", "critical-section", - "defmt", "document-features", "embassy-embedded-hal", "embassy-futures", @@ -567,9 +518,6 @@ dependencies = [ name = "embassy-usb-driver" version = "0.1.0" source = "git+https://github.com/embassy-rs/embassy#cae954a87ec3c5ece520b6a44168b36e79f3f86a" -dependencies = [ - "defmt", -] [[package]] name = "embassy-usb-logger" @@ -834,7 +782,6 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" dependencies = [ - "defmt", "hash32", "serde", "stable_deref_trait", @@ -1031,15 +978,6 @@ version = "1.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d75b0bedcc4fe52caa0e03d9f1151a323e4aa5e2d78ba3580400cd3c9e2bc4bc" -[[package]] -name = "panic-probe" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4047d9235d1423d66cc97da7d07eddb54d4f154d6c13805c6d0793956f4f25b0" -dependencies = [ - "cortex-m", -] - [[package]] name = "parking_lot" version = "0.12.3" @@ -1109,8 +1047,6 @@ dependencies = [ "cortex-m-rt", "cyw43", "cyw43-pio", - "defmt", - "defmt-rtt", "dhcparse", "dnsparse", "embassy-executor", @@ -1122,7 +1058,6 @@ dependencies = [ "embedded-io-async", "heapless", "log", - "panic-probe", "percent-encoding", "portable-atomic", "rand_core", @@ -1494,7 +1429,6 @@ dependencies = [ "bitflags 1.3.2", "byteorder", "cfg-if", - "defmt", "heapless", "managed", ] @@ -1583,26 +1517,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "thiserror" -version = "2.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "2.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.100", -] - [[package]] name = "typenum" version = "1.18.0" diff --git a/Cargo.toml b/Cargo.toml index 858f77a..e2f829a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,14 +16,12 @@ default = ["dhcp", "dns", "ttt"] [dependencies] embassy-executor = { git = "https://github.com/embassy-rs/embassy", features = [ - "defmt", "nightly", "arch-cortex-m", "executor-thread", "executor-interrupt", ] } embassy-rp = { git = "https://github.com/embassy-rs/embassy", features = [ - "defmt", "unstable-pac", "rp2040", "time-driver", @@ -32,7 +30,6 @@ embassy-rp = { git = "https://github.com/embassy-rs/embassy", features = [ embassy-time = { git = "https://github.com/embassy-rs/embassy" } embassy-usb-logger = { git = "https://github.com/embassy-rs/embassy" } embassy-net = { git = "https://github.com/embassy-rs/embassy", features = [ - "defmt", "proto-ipv4", "tcp", "udp", @@ -43,9 +40,6 @@ cyw43-pio = { git = "https://github.com/embassy-rs/embassy" } cyw43 = { git = "https://github.com/embassy-rs/embassy" } embedded-io-async = "*" -defmt = "*" -defmt-rtt = "*" -panic-probe = "*" cortex-m = { version = "*", features = ["inline-asm"] } cortex-m-rt = "*" static_cell = "*" diff --git a/build.rs b/build.rs index 3f915f9..113c72e 100644 --- a/build.rs +++ b/build.rs @@ -32,5 +32,5 @@ fn main() { println!("cargo:rustc-link-arg-bins=--nmagic"); println!("cargo:rustc-link-arg-bins=-Tlink.x"); println!("cargo:rustc-link-arg-bins=-Tlink-rp.x"); - println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); + // println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); } diff --git a/src/apps/index.html b/src/apps/index.html index 8a081da..96ee3f6 100644 --- a/src/apps/index.html +++ b/src/apps/index.html @@ -1,15 +1,10 @@ - - -

Apps

diff --git a/src/apps/index.rs b/src/apps/index.rs index 1e18da5..4f767ae 100644 --- a/src/apps/index.rs +++ b/src/apps/index.rs @@ -23,7 +23,18 @@ impl App for IndexApp { "/" | "/index" | "/index.html" => ( HttpResCode::Ok, "html", - Some(include_str!("./index.html").into()), + #[cfg(debug_assertions)] + Some(include_str!("index.html").into()), + #[cfg(not(debug_assertions))] + Some(include_str!("../../static/index.min.html").into()), + ), + "/htmx.js" => ( + HttpResCode::Ok, + "javascript", + #[cfg(debug_assertions)] + Some(include_str!("../../static/htmx.js").into()), + #[cfg(not(debug_assertions))] + Some(include_str!("../../static/htmx.min.js").into()), ), path => { let (path, args) = path.split_once('?').unwrap_or((path, "")); @@ -39,7 +50,11 @@ impl App for IndexApp { let Some(team) = team else { return (HttpResCode::BadRequest, "", None); }; + #[cfg(debug_assertions)] let html = include_str!("ttt.html"); + #[cfg(not(debug_assertions))] + let html = include_str!("../../static/ttt.min.html"); + let mut content = Vec::new(); let r: Result<(), &str> = try { let (html1, html2) = html.split_once("/ttt.js").ok_or("")?; @@ -60,8 +75,11 @@ impl App for IndexApp { let r: Result<(), &str> = try { content.push("const team = ")?; content.push(team)?; - content.push(";\n")?; + content.push(";")?; + #[cfg(debug_assertions)] content.push(include_str!("ttt.js"))?; + #[cfg(not(debug_assertions))] + content.push(include_str!("../../static/ttt.min.js"))?; }; unwrap(r).await; (HttpResCode::Ok, "javascript", Some(Content(content))) diff --git a/src/apps/mod.rs b/src/apps/mod.rs index fc6413b..98e1e0d 100644 --- a/src/apps/mod.rs +++ b/src/apps/mod.rs @@ -31,12 +31,6 @@ pub trait App { pub struct Content<'a>(pub Vec<&'a str, 8>); -// pub enum Content<'a> { -// Str(&'a str), -// /// Return the number of bytes written -// /// (fn that writes content, length) -// Fn(fn(&mut [u8]) -> usize, usize), -// } impl<'a> From<&'a str> for Content<'a> { fn from(value: &'a str) -> Self { let mut v = Vec::new(); diff --git a/src/apps/ttt.html b/src/apps/ttt.html index f49d4f7..cfcdf1d 100644 --- a/src/apps/ttt.html +++ b/src/apps/ttt.html @@ -1,6 +1,5 @@ -

TicTacToe

diff --git a/static/ttt.min.js b/static/ttt.min.js new file mode 100644 index 0000000..c89d8d2 --- /dev/null +++ b/static/ttt.min.js @@ -0,0 +1 @@ +if(0!=team&&1!=team)throw"team is not 0 or 1! team="+team;const teams=[{name:"blue",color:"dodgerblue",port:"8080"},{name:"red",color:"firebrick",port:"8081"}];document.getElementById("team").innerHTML='Team : '+teams[team].name+"";const ws=new WebSocket("ws://192.254.0.2:"+teams[team].port+"/"+teams[team].name);ws.onmessage=e=>{if("string"==typeof e.data){let t=JSON.parse(e.data),n=[];for(let e=0;e<9;e++){let a,r=t.board[e];a=t.turn==team&&null===r?"button":"div";let m=document.createElement(a);m.classList.add("cell"),"button"===a&&m.addEventListener("click",(t=>{ws.send(new Uint8Array([e]))})),m.setAttribute("team",r),n.push(m)}document.getElementById("grid").replaceChildren(...n),null==t.turn?null==t.winner?document.getElementById("winner").innerHTML="Draw!":document.getElementById("winner").innerHTML='Winner : '+teams[t.winner].name+"":document.getElementById("winner").innerHTML=""}};