diff --git a/Cargo.lock b/Cargo.lock index e3a41f9e10..3a6806275e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -664,7 +664,7 @@ dependencies = [ "candle-nn", "candle-transformers", "cudarc", - "expanduser", + "dirs 6.0.0", "filesys", "futures 0.3.29", "hf-hub 0.3.2", @@ -673,12 +673,12 @@ dependencies = [ "log", "memory_caching", "once_cell", - "openssl", "rand 0.8.5", "reqwest 0.12.12", "serde", "serde_json", "serde_yaml", + "serial_test", "tauri", "tauri-build", "tauri-plugin-log", @@ -739,12 +739,6 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "76a2e8124351fda1ef8aaaa3bbd7ebbcb486bbcd4225aca0aa0d84bb2db8fecb" -[[package]] -name = "arrayvec" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" - [[package]] name = "arrayvec" version = "0.7.6" @@ -1028,7 +1022,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6678909d8c5d46a42abcf571271e15fdbc0a225e3646cf23762cd415046c78bf" dependencies = [ "anyhow", - "arrayvec 0.7.6", + "arrayvec", "log", "nom", "num-rational", @@ -1041,7 +1035,7 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e335041290c43101ca215eed6f43ec437eb5a42125573f600fc3fa42b9bddd62" dependencies = [ - "arrayvec 0.7.6", + "arrayvec", ] [[package]] @@ -1311,17 +1305,6 @@ dependencies = [ "wyz", ] -[[package]] -name = "blake2b_simd" -version = "0.5.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afa748e348ad3be8263be728124b24a24f268266f6f5d58af9d75f6a40b5c587" -dependencies = [ - "arrayref", - "arrayvec 0.5.2", - "constant_time_eq 0.1.5", -] - [[package]] name = "blake2b_simd" version = "1.0.2" @@ -1329,7 +1312,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23285ad32269793932e830392f2fe2f83e26488fd3ec778883a93c8323735780" dependencies = [ "arrayref", - "arrayvec 0.7.6", + "arrayvec", "constant_time_eq 0.3.0", ] @@ -2857,19 +2840,6 @@ dependencies = [ "syn 2.0.87", ] -[[package]] -name = "dashmap" -version = "5.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" -dependencies = [ - "cfg-if 1.0.0", - "hashbrown 0.14.5", - "lock_api 0.4.12", - "once_cell", - "parking_lot_core 0.9.10", -] - [[package]] name = "dasp_sample" version = "0.11.0" @@ -3212,17 +3182,6 @@ dependencies = [ "dirs-sys 0.4.1", ] -[[package]] -name = "dirs" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fd78930633bd1c6e35c4b42b1df7b0cbc6bc191146e512bb3bedf243fcc3901" -dependencies = [ - "libc", - "redox_users 0.3.5", - "winapi 0.3.9", -] - [[package]] name = "dirs" version = "5.0.1" @@ -3873,17 +3832,6 @@ version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" -[[package]] -name = "expanduser" -version = "1.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14e0b79235da57db6b6c2beed9af6e5de867d63a973ae3e91910ddc33ba40bc0" -dependencies = [ - "dirs 1.0.5", - "lazy_static", - "pwd", -] - [[package]] name = "exr" version = "1.73.0" @@ -5918,7 +5866,7 @@ checksum = "50ae7e0018905a795d6f2a60ac32a547490abdd8df509906a8c6171e6d861711" dependencies = [ "anyhow", "binstring", - "blake2b_simd 1.0.2", + "blake2b_simd", "coarsetime", "ct-codecs", "ed25519-compact", @@ -6883,7 +6831,7 @@ dependencies = [ "actix-rt", "ahash 0.8.11", "anstream", - "arrayvec 0.7.6", + "arrayvec", "base64 0.21.7", "base64 0.22.1", "base64ct", @@ -8660,16 +8608,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "pwd" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72c71c0c79b9701efe4e1e4b563b2016dd4ee789eb99badcb09d61ac4b92e4a2" -dependencies = [ - "libc", - "thiserror 1.0.63", -] - [[package]] name = "pyo3" version = "0.22.6" @@ -8995,7 +8933,7 @@ checksum = "cd87ce80a7665b1cce111f8a16c1f3929f6547ce91ade6addf4ec86a8dda5ce9" dependencies = [ "arbitrary", "arg_enum_proc_macro", - "arrayvec 0.7.6", + "arrayvec", "av1-grain", "bitstream-io", "built", @@ -9224,17 +9162,6 @@ dependencies = [ "bitflags 2.5.0", ] -[[package]] -name = "redox_users" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d" -dependencies = [ - "getrandom 0.1.16", - "redox_syscall 0.1.57", - "rust-argon2", -] - [[package]] name = "redox_users" version = "0.4.6" @@ -9521,18 +9448,6 @@ dependencies = [ "realfft", ] -[[package]] -name = "rust-argon2" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b18820d944b33caa75a71378964ac46f58517c92b6ae5f762636247c09e78fb" -dependencies = [ - "base64 0.13.1", - "blake2b_simd 0.5.11", - "constant_time_eq 0.1.5", - "crossbeam-utils 0.8.20", -] - [[package]] name = "rust-embed" version = "8.0.0" @@ -9618,7 +9533,7 @@ version = "1.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b082d80e3e3cc52b2ed634388d436fe1f4de6af5786cc2de9ba9737527bdf555" dependencies = [ - "arrayvec 0.7.6", + "arrayvec", "borsh", "bytes 1.10.0", "num-traits", @@ -9836,6 +9751,15 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "scc" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea091f6cac2595aa38993f04f4ee692ed43757035c36e67c180b6828356385b1" +dependencies = [ + "sdd", +] + [[package]] name = "schannel" version = "0.1.23" @@ -9925,6 +9849,12 @@ dependencies = [ "untrusted", ] +[[package]] +name = "sdd" +version = "3.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "584e070911c7017da6cb2eb0788d09f43d789029b5877d3e5ecc8acf86ceee21" + [[package]] name = "seahash" version = "4.1.0" @@ -10245,23 +10175,23 @@ dependencies = [ [[package]] name = "serial_test" -version = "3.0.0" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "953ad9342b3aaca7cb43c45c097dd008d4907070394bd0751a0aa8817e5a018d" +checksum = "1b258109f244e1d6891bf1053a55d63a5cd4f8f4c30cf9a1280989f80e7a1fa9" dependencies = [ - "dashmap", "futures 0.3.29", - "lazy_static", "log", + "once_cell", "parking_lot 0.12.2", + "scc", "serial_test_derive", ] [[package]] name = "serial_test_derive" -version = "3.0.0" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b93fb4adc70021ac1b47f7d45e8cc4169baaa7ea58483bc5b721d19a26202212" +checksum = "5d69265a08751de7844521fd15003ae0a888e035773ba05695c5c759a6f89eef" dependencies = [ "proc-macro2", "quote", @@ -11309,7 +11239,7 @@ name = "symphonia-core" version = "0.5.0" source = "git+https://github.com/pdeljanov/Symphonia.git?rev=e1a70095c4409478c1ded499fb8dd4afa540fb90#e1a70095c4409478c1ded499fb8dd4afa540fb90" dependencies = [ - "arrayvec 0.7.6", + "arrayvec", "bitflags 1.3.2", "bytemuck", "lazy_static", @@ -11322,7 +11252,7 @@ version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "798306779e3dc7d5231bd5691f5a813496dc79d3f56bf82e25789f2094e022c3" dependencies = [ - "arrayvec 0.7.6", + "arrayvec", "bitflags 1.3.2", "bytemuck", "lazy_static", diff --git a/crates/desktop/src-tauri/Cargo.toml b/crates/desktop/src-tauri/Cargo.toml index f0650c2353..42a7ad4d74 100644 --- a/crates/desktop/src-tauri/Cargo.toml +++ b/crates/desktop/src-tauri/Cargo.toml @@ -27,21 +27,22 @@ memory_caching = { path = "../../lib/caching/memory_caching" } cudarc = "0.13.7" # External +#openssl = { version = "0.10", features = ["vendored"] } anyhow = "1.0" base64 = "0.22.1" bytes = "1.10" candle-core = { path = "../../vendor/candle/candle-core", features = ["cuda"] } candle-nn = { path = "../../vendor/candle/candle-nn", features = ["cuda"] } candle-transformers = { path = "../../vendor/candle/candle-transformers", features = ["cuda"] } -expanduser = "1.2.2" +dirs = "6.0.0" futures = "0.3" hf-hub = "0.3.2" image = "0.25.5" log = "0.4" once_cell = "1.20.3" -openssl = { version = "0.10", features = ["vendored"] } rand = "0.8.5" -reqwest = { version = "0.12.12", features = ["stream"] } +# NB(bt,2025-03-10): default-features = false on Windows while I debug openssl / rustls +reqwest = { version = "0.12.12", features = ["stream"], default-features = false } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" serde_yaml = "0.9" @@ -55,10 +56,18 @@ tokio-util = { version = "0.7", features = ["codec"] } [features] default = ["cuda"] -cuda = ["candle-core/cuda", "candle-nn/cuda", "candle-transformers/cuda", "candle-transformers/flash-attn", "candle-core/cudnn"] +cuda = [ + "candle-core/cuda", + "candle-nn/cuda", + "candle-transformers/cuda", +# NB(bt,2025-03-10): Building without Flash attention on Windows for now to bypass linker issues +# "candle-transformers/flash-attn", +# "candle-core/cudnn" +] [dev-dependencies] libloading = "0.8.6" +serial_test = "3.2.0" [profile.dev] incremental = true # Compile your binary in smaller steps. diff --git a/crates/desktop/src-tauri/src/state/app_config.rs b/crates/desktop/src-tauri/src/state/app_config.rs index bbec6c266e..896962daeb 100644 --- a/crates/desktop/src-tauri/src/state/app_config.rs +++ b/crates/desktop/src-tauri/src/state/app_config.rs @@ -4,7 +4,6 @@ use crate::state::os_platform::OsPlatform; use crate::state::yaml_config::YamlConfig; use candle_core::{DType, Device}; use candle_transformers::models::stable_diffusion::StableDiffusionConfig; -use expanduser::expanduser; use filesys::recursively_find_file_by_name::recursively_find_file_by_name; use hf_hub::api::sync::Api; use log::info; diff --git a/crates/desktop/src-tauri/src/state/app_dir.rs b/crates/desktop/src-tauri/src/state/app_dir.rs index 24a690dbec..000c59c6a4 100644 --- a/crates/desktop/src-tauri/src/state/app_dir.rs +++ b/crates/desktop/src-tauri/src/state/app_dir.rs @@ -1,9 +1,9 @@ +use crate::ml::model_type::ModelType; +use crate::state::expanduser::expanduser; use crate::state::os_platform::OsPlatform; -use expanduser::expanduser; use std::path::{Path, PathBuf}; use tempdir::TempDir; use tempfile::{Builder, NamedTempFile}; -use crate::ml::model_type::ModelType; const ASSETS_SUBDIRECTORY : &str = "assets"; const WEIGHTS_SUBDIRECTORY : &str = "weights"; diff --git a/crates/desktop/src-tauri/src/state/expanduser.rs b/crates/desktop/src-tauri/src/state/expanduser.rs new file mode 100644 index 0000000000..788d3c259b --- /dev/null +++ b/crates/desktop/src-tauri/src/state/expanduser.rs @@ -0,0 +1,73 @@ +use once_cell::sync::Lazy; +use std::io; +use std::path::{PathBuf, MAIN_SEPARATOR}; + +static PREFIX: Lazy = Lazy::new(|| format!("~{}", MAIN_SEPARATOR)); + +/// The "expanduser" crate doesn't compile on Windows, so we replace its functionality slightly +pub fn expanduser>(path: P) -> io::Result { + + Ok(match path.as_ref() { + // matches an exact "~" + s if s == "~" => { + home_dir()? + }, + // matches paths that start with `~/` + s if s.starts_with(&*PREFIX) => { + let home = home_dir()?; + home.join(&s[2..]) + }, + // // matches paths that start with `~` but not `~/`, might be a `~username/` path + // s if s.starts_with("~") => { + // let mut parts = s[1..].splitn(2, MAIN_SEPARATOR); + // let user = parts.next() + // .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "malformed path"))?; + // let user = Passwd::from_name(&user) + // .map_err(|_| io::Error::new(io::ErrorKind::Other, "error searching for user"))? + // .ok_or_else(|| io::Error::new(io::ErrorKind::Other, format!("user '{}', does not exist", &user)))?; + // if let Some(ref path) = parts.next() { + // PathBuf::from(user.dir).join(&path) + // } else { + // PathBuf::from(user.dir) + // } + // }, + // nothing to expand, just make a PathBuf + s => PathBuf::from(s) + }) +} + +pub fn home_dir() -> io::Result { + dirs::home_dir() + .ok_or_else(|| io::Error::new(io::ErrorKind::Other, "no home directory is set")) +} + +#[cfg(test)] +mod tests { + use crate::state::expanduser::expanduser; + use std::env; + use std::path::PathBuf; + + #[test] + #[serial_test::serial] + fn test_success() { + let old_home = env::var("HOME").expect("no home dir set"); + let new_home = "/home/foo"; + env::set_var("HOME", new_home); + let path = expanduser("~/path/to/directory"); + env::set_var("HOME", old_home); + assert_eq!(path.expect("io error"), PathBuf::from("/home/foo/path/to/directory")); + } + + #[test] + #[serial_test::serial] + fn test_only_tilde() { + let old_home = env::var("HOME").expect("no home dir set"); + let new_home = "/home/foo"; + env::set_var("HOME", new_home); + let pathstr = "~"; + let path = expanduser(pathstr); + env::set_var("HOME", old_home); + assert_eq!(path.expect("io error"), PathBuf::from("/home/foo")); + } + +} \ No newline at end of file diff --git a/crates/desktop/src-tauri/src/state/mod.rs b/crates/desktop/src-tauri/src/state/mod.rs index 9bfb21afea..6038017250 100644 --- a/crates/desktop/src-tauri/src/state/mod.rs +++ b/crates/desktop/src-tauri/src/state/mod.rs @@ -1,4 +1,5 @@ pub mod app_config; pub mod app_dir; pub mod os_platform; -pub mod yaml_config; \ No newline at end of file +pub mod yaml_config; +pub mod expanduser; \ No newline at end of file