tensor_eigen/commands/
eigen.rs1use anyhow::{bail, Result};
2use std::env;
3use std::path::PathBuf;
4use std::process::Command;
5
6pub fn update_eigen() -> Result<()> {
7 let (os, arch) = detect_os_and_arch()?;
8 let url = get_download_url(os, arch)?;
9 let cargo_bin = get_cargo_bin()?;
10 let eigen_path = cargo_bin.join("eigen");
11
12 println!("Downloading Eigen binary for {}/{}", os, arch);
13 let status = Command::new("curl")
14 .args(["-L", "-o", eigen_path.to_str().unwrap(), &url])
15 .status()?;
16
17 if !status.success() {
18 bail!("Failed to download Eigen binary");
19 }
20
21 println!("Making Eigen binary executable");
22 let status = Command::new("chmod")
23 .args(["+x", eigen_path.to_str().unwrap()])
24 .status()?;
25
26 if !status.success() {
27 bail!("Failed to make Eigen binary executable");
28 }
29
30 println!(
31 "Eigen update completed successfully. Installed to: {:?}",
32 eigen_path
33 );
34
35 Ok(())
36}
37
38fn detect_os_and_arch() -> Result<(&'static str, &'static str)> {
39 let os = env::consts::OS;
40 let arch = env::consts::ARCH;
41
42 match (os, arch) {
43 ("macos", "aarch64") => Ok(("macos", "arm64")),
44 ("macos", "x86_64") => Ok(("macos", "x86_64")),
45 ("linux", "x86_64") => Ok(("linux", "x86_64")),
46 _ => bail!("Unsupported OS/architecture combination: {}/{}", os, arch),
47 }
48}
49
50fn get_download_url(os: &str, arch: &str) -> Result<String> {
51 let base_url = "https://github.com/tensor-foundation/eigen/releases/latest/download";
52 let filename = format!("eigen-{}-{}", os, arch);
53 Ok(format!("{}/{}", base_url, filename))
54}
55
56fn get_cargo_bin() -> Result<PathBuf> {
57 let home = env::var("HOME").expect("HOME environment variable not set");
58 let cargo_bin = PathBuf::from(home).join(".cargo").join("bin");
59
60 if !cargo_bin.exists() {
61 bail!("Cargo bin directory not found: {:?}", cargo_bin);
62 }
63
64 Ok(cargo_bin)
65}