agentmux_common/
srv_binary.rs1use std::path::{Path, PathBuf};
8
9pub const VERSION: &str = env!("CARGO_PKG_VERSION");
11
12pub const EXE_SUFFIX: &str = if cfg!(target_os = "windows") { ".exe" } else { "" };
14
15fn os_arch() -> (&'static str, &'static str) {
17 let arch = if cfg!(target_arch = "aarch64") { "arm64" } else { "x64" };
18 if cfg!(target_os = "macos") {
19 ("darwin", arch)
20 } else if cfg!(target_os = "linux") {
21 ("linux", arch)
22 } else {
23 ("windows", arch)
24 }
25}
26
27pub fn versioned_name(name: &str, exe_suffix: &str) -> String {
29 let (os, arch) = os_arch();
30 format!("{name}-{VERSION}-{os}.{arch}{exe_suffix}")
31}
32
33pub fn candidates(dirs: &[&Path], name: &str, exe_suffix: &str) -> Vec<PathBuf> {
36 dirs.iter()
37 .flat_map(|dir| [dir.join(versioned_name(name, exe_suffix)), dir.join(format!("{name}{exe_suffix}"))])
38 .collect()
39}
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44
45 #[test]
46 fn each_dir_gives_the_versioned_name_then_the_plain_one() {
47 let found = candidates(&[Path::new("a"), Path::new("b")], "agentmux-srv", ".exe");
48 assert_eq!(found.len(), 4);
49 assert_eq!(found[0], Path::new("a").join(versioned_name("agentmux-srv", ".exe")));
50 assert_eq!(found[1], Path::new("a").join("agentmux-srv.exe"));
51 assert_eq!(found[2], Path::new("b").join(versioned_name("agentmux-srv", ".exe")));
52 assert_eq!(found[3], Path::new("b").join("agentmux-srv.exe"));
53 }
54
55 #[test]
56 fn the_versioned_name_carries_version_os_and_arch() {
57 let n = versioned_name("agentmux-srv", "");
58 assert!(n.starts_with(&format!("agentmux-srv-{VERSION}-")), "{n}");
59 assert!(n.contains('.'), "{n}");
60 }
61}