idt/installers/
rust_analyzer.rs

1use std::path::Path;
2
3use ytil_sys::Arch;
4use ytil_sys::Os;
5use ytil_sys::SysInfo;
6
7use crate::downloaders::curl::CurlDownloaderOption;
8use crate::installers::Installer;
9use crate::installers::SystemDependent;
10
11pub struct RustAnalyzer<'a> {
12    pub bin_dir: &'a Path,
13    pub sys_info: &'a SysInfo,
14}
15
16impl SystemDependent for RustAnalyzer<'_> {
17    fn target_arch_and_os(&self) -> (&str, &str) {
18        let SysInfo { os, arch } = self.sys_info;
19        let os = match os {
20            Os::MacOs => "apple-darwin",
21            Os::Linux => "unknown-linux",
22        };
23        let arch = match arch {
24            Arch::Arm => "aarch64",
25            Arch::X86 => "x86_64",
26        };
27        (arch, os)
28    }
29}
30
31impl Installer for RustAnalyzer<'_> {
32    fn bin_name(&self) -> &'static str {
33        "rust-analyzer"
34    }
35
36    fn install(&self) -> color_eyre::Result<()> {
37        let (arch, os) = self.target_arch_and_os();
38
39        let target = crate::downloaders::curl::run(
40            &format!(
41                "https://github.com/rust-lang/{0}/releases/download/nightly/{0}-{arch}-{os}.gz",
42                self.bin_name()
43            ),
44            &CurlDownloaderOption::PipeIntoZcat {
45                dest_path: &self.bin_dir.join(self.bin_name()),
46            },
47        )?;
48
49        ytil_sys::file::chmod_x(target)?;
50
51        Ok(())
52    }
53}