Browse Source

build(deps): use ring-only rustls for reqwest to skip aws-lc-sys

- Cargo.toml: build reqwest with rustls-no-provider and add rustls with
  the ring provider; enable the qrcode svg feature; drop lto and
  codegen-units from the release profile.
- Cargo.lock: remove aws-lc-rs, aws-lc-sys, quinn and related crates.
- src/ai.rs: install the ring crypto provider before building the HTTP
  client; rename vision.md references to VISION.md.
softword 4 days ago
parent
commit
04186be216
3 changed files with 15 additions and 165 deletions
  1. 1 156
      Cargo.lock
  2. 6 6
      Cargo.toml
  3. 8 3
      src/ai.rs

+ 1 - 156
Cargo.lock

@@ -113,29 +113,6 @@ version = "1.5.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
 
-[[package]]
-name = "aws-lc-rs"
-version = "1.18.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "faac5829c2b74c28f830747e7818ccfb684261b5f48a1118b1e2a13d36dfab13"
-dependencies = [
- "aws-lc-sys",
- "zeroize",
-]
-
-[[package]]
-name = "aws-lc-sys"
-version = "0.46.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f1622d8446a2d4b2ce0c7eefc73dd43a99779028d5ee5c2dd8073a658ba8a2bc"
-dependencies = [
- "cc",
- "cmake",
- "dunce",
- "fs_extra",
- "pkg-config",
-]
-
 [[package]]
 name = "base64"
 version = "0.22.1"
@@ -330,8 +307,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "877bf67ac8e52449eb2f9e98a344ea163beb70dd1f9eebe3cc5357dcfeaee4df"
 dependencies = [
  "find-msvc-tools",
- "jobserver",
- "libc",
  "shlex",
 ]
 
@@ -387,15 +362,6 @@ dependencies = [
  "inout",
 ]
 
-[[package]]
-name = "cmake"
-version = "0.1.58"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c0f78a02292a74a88ac736019ab962ece0bc380e3f977bf72e376c5d78ff0678"
-dependencies = [
- "cc",
-]
-
 [[package]]
 name = "cmov"
 version = "0.5.4"
@@ -842,12 +808,6 @@ dependencies = [
  "syn 2.0.119",
 ]
 
-[[package]]
-name = "dunce"
-version = "1.0.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813"
-
 [[package]]
 name = "either"
 version = "1.19.0"
@@ -989,12 +949,6 @@ dependencies = [
  "percent-encoding",
 ]
 
-[[package]]
-name = "fs_extra"
-version = "1.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c"
-
 [[package]]
 name = "futures"
 version = "0.3.34"
@@ -1088,10 +1042,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0"
 dependencies = [
  "cfg-if",
- "js-sys",
  "libc",
  "wasi",
- "wasm-bindgen",
 ]
 
 [[package]]
@@ -1556,16 +1508,6 @@ dependencies = [
  "syn 2.0.119",
 ]
 
-[[package]]
-name = "jobserver"
-version = "0.1.35"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1c00acbd29eabad4a2392fa0e921c874934dbbf4194312ad20f04a0ed67a3cb3"
-dependencies = [
- "getrandom 0.4.3",
- "libc",
-]
-
 [[package]]
 name = "js-sys"
 version = "0.3.106"
@@ -1683,12 +1625,6 @@ dependencies = [
  "hashbrown 0.17.1",
 ]
 
-[[package]]
-name = "lru-slab"
-version = "0.1.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4050469837a6ff301cd14c1f8f24f88549e6d548f24f64e2148eb0f72cebc51f"
-
 [[package]]
 name = "mac_address"
 version = "1.2.1"
@@ -2115,63 +2051,6 @@ version = "0.14.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "d68782463e408eb1e668cf6152704bd856c78c5b6417adaee3203d8f4c1fc9ec"
 
-[[package]]
-name = "quinn"
-version = "0.11.12"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4051e23e9185c255a7e33ef59cdbca87a22d359052eecd22fc6b901fb37d9d11"
-dependencies = [
- "bytes",
- "cfg_aliases",
- "pin-project-lite",
- "quinn-proto",
- "quinn-udp",
- "rustc-hash",
- "rustls",
- "socket2",
- "thiserror 2.0.21",
- "tokio",
- "tracing",
- "web-time",
-]
-
-[[package]]
-name = "quinn-proto"
-version = "0.11.19"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0e750cca55fe4f0439a15d0bb529da9651e79993e8e72c61a899a36d462befbe"
-dependencies = [
- "aws-lc-rs",
- "bytes",
- "getrandom 0.4.3",
- "lru-slab",
- "rand 0.10.3",
- "rand_pcg",
- "ring",
- "rustc-hash",
- "rustls",
- "rustls-pki-types",
- "slab",
- "thiserror 2.0.21",
- "tinyvec",
- "tracing",
- "web-time",
-]
-
-[[package]]
-name = "quinn-udp"
-version = "0.5.16"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "af66907df18639dcf4db56ca65490cabc4b27a97dbadd96f2926cca73298f016"
-dependencies = [
- "cfg_aliases",
- "libc",
- "once_cell",
- "socket2",
- "tracing",
- "windows-sys 0.61.2",
-]
-
 [[package]]
 name = "quote"
 version = "1.0.47"
@@ -2236,15 +2115,6 @@ version = "0.10.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69"
 
-[[package]]
-name = "rand_pcg"
-version = "0.10.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "caa0f4137e1c0a72f4c651489402276c8e8e1cf081f3b0ba156d2cbeef09e86a"
-dependencies = [
- "rand_core 0.10.1",
-]
-
 [[package]]
 name = "ratatui"
 version = "0.30.2"
@@ -2413,7 +2283,6 @@ dependencies = [
  "log",
  "percent-encoding",
  "pin-project-lite",
- "quinn",
  "rustls",
  "rustls-pki-types",
  "rustls-platform-verifier",
@@ -2470,12 +2339,6 @@ dependencies = [
  "sqlite-wasm-rs",
 ]
 
-[[package]]
-name = "rustc-hash"
-version = "2.1.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d"
-
 [[package]]
 name = "rustc_version"
 version = "0.4.1"
@@ -2504,7 +2367,6 @@ version = "0.23.46"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "48e13bd8c0e9365c43cfa5c9e8f9ad49d3c8444926c9aac819e0e4dc503c8fdf"
 dependencies = [
- "aws-lc-rs",
  "log",
  "once_cell",
  "ring",
@@ -2532,7 +2394,6 @@ version = "1.15.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "2f4925028c7eb5d1fcdaf196971378ed9d2c1c4efc7dc5d011256f76c99c0a96"
 dependencies = [
- "web-time",
  "zeroize",
 ]
 
@@ -2569,7 +2430,6 @@ version = "0.103.15"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "f3c3cf1d8b1e7d4927e2d154c3fcb02979afb9939629c62cd9048d4f07b60ac2"
 dependencies = [
- "aws-lc-rs",
  "ring",
  "rustls-pki-types",
  "untrusted",
@@ -3142,12 +3002,6 @@ dependencies = [
  "zerovec",
 ]
 
-[[package]]
-name = "tinyvec"
-version = "1.13.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fd3ca314f692efd6c868f8408f53fe444634a845f96c028b97d35f6a1f79f0ee"
-
 [[package]]
 name = "tokio"
 version = "1.53.3"
@@ -3764,16 +3618,6 @@ dependencies = [
  "wasm-bindgen",
 ]
 
-[[package]]
-name = "web-time"
-version = "1.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb"
-dependencies = [
- "js-sys",
- "wasm-bindgen",
-]
-
 [[package]]
 name = "webpki-root-certs"
 version = "1.0.9"
@@ -3876,6 +3720,7 @@ dependencies = [
  "ratatui",
  "reqwest",
  "rusqlite",
+ "rustls",
  "serde",
  "serde_json",
  "tiny_http",

+ 6 - 6
Cargo.toml

@@ -10,14 +10,18 @@ publish = false
 whatsapp-rust = { version = "0.7", default-features = false, features = ["sqlite-storage", "tokio-transport", "tokio-runtime", "ureq-client", "tokio-native", "signal"] }
 tokio = { version = "1", features = ["macros", "rt-multi-thread", "sync", "time"] }
 ratatui = "0.30"
-reqwest = { version = "0.13", default-features = false, features = ["json", "rustls"] }
+# rustls-no-provider + ring: avoids aws-lc-sys, a large C build that dominates cross-compile time.
+reqwest = { version = "0.13", default-features = false, features = ["json", "rustls-no-provider"] }
+# Crypto provider installed at startup for reqwest (ring is already built for whatsapp-rust).
+rustls = { version = "0.23", default-features = false, features = ["ring", "std", "tls12"] }
 # rusqlite 0.39 -> libsqlite3-sys 0.37, same as diesel 2.3 pulled by whatsapp-rust-sqlite-storage (links = "sqlite3").
 rusqlite = { version = "0.39", features = ["bundled"] }
 serde = { version = "1", features = ["derive"] }
 serde_json = "1"
 toml = "1.1.8"
 anyhow = "1"
-qrcode = { version = "0.14", default-features = false }
+# svg: QR code of the web panel pairing screen (no extra dependencies).
+qrcode = { version = "0.14", default-features = false, features = ["svg"] }
 dirs = "7"
 base64 = "0.23"
 chrono = { version = "0.4", default-features = false, features = ["clock", "std"] }
@@ -27,10 +31,6 @@ tiny_http = "0.12"
 [profile.release]
 # Remove symbols and debug info from the binary.
 strip = true
-# Cross-crate link-time optimization: drops unused code and shrinks the binary.
-lto = true
-# Single codegen unit: better optimization and smaller size, slower release builds.
-codegen-units = 1
 
 [lints.rust]
 # MSVC link.exe prints an informational "Creazione della libreria ... wh.lib/wh.exp" line because the binary exports symbols; it is not actionable.

+ 8 - 3
src/ai.rs

@@ -19,7 +19,7 @@ pub const MAX_IMAGE_BYTES: usize = 5 * 1024 * 1024;
 const MISSING_VISION_MODEL_MESSAGE: &str = "modello vision non configurato";
 const EMPTY_IMAGE_MESSAGE: &str = "immagine vuota";
 const EMPTY_REPLY_MESSAGE: &str = "risposta del servizio AI vuota";
-/// Request sent with an image to obtain its description when `vision.md` is missing or blank.
+/// Request sent with an image to obtain its description when `VISION.md` is missing or blank.
 const DEFAULT_IMAGE_DESCRIPTION_REQUEST: &str = "Descrivi in modo oggettivo e conciso, in italiano, il contenuto di questa immagine: soggetti, azioni, testo leggibile e contesto. Rispondi solo con la descrizione.";
 const TEXT_PART_TYPE: &str = "text";
 const IMAGE_PART_TYPE: &str = "image_url";
@@ -94,7 +94,7 @@ pub struct AiClient {
     api_key: String,
     model: String,
     vision_model: Option<String>,
-    /// Request sent with each image to describe it: `vision.md`, else `DEFAULT_IMAGE_DESCRIPTION_REQUEST`.
+    /// Request sent with each image to describe it: `VISION.md`, else `DEFAULT_IMAGE_DESCRIPTION_REQUEST`.
     description_request: String,
     /// File receiving one record per request; `None` when `ai_log` is disabled.
     log_path: Option<PathBuf>,
@@ -165,12 +165,17 @@ impl AiClient {
     /// Inputs: `config` (API key, base URL and model are read from it).
     /// Output: the client, or an error if the API key is missing or the HTTP
     /// client cannot be built.
-    /// Side effects: none (no network traffic until `complete` is called).
+    /// Side effects: installs the ring rustls crypto provider process-wide if none is installed
+    /// (no network traffic until `complete` is called).
     pub fn new(config: &Config) -> anyhow::Result<AiClient> {
         let api_key = config
             .openai_api_key
             .clone()
             .ok_or_else(|| anyhow!(MISSING_API_KEY_MESSAGE))?;
+
+        // reqwest is built without a crypto provider (`rustls-no-provider`), so one must be
+        // installed first; `Err` only means one is already installed, and reqwest then uses it.
+        let _ = rustls::crypto::ring::default_provider().install_default();
         let http = reqwest::Client::builder()
             .timeout(Duration::from_secs(REQUEST_TIMEOUT_SECONDS))
             .build()