#![warn(missing_docs)]
#![allow(unused)]
mod error;
mod fetch;
mod source_constants;
use fetch::update_cache;
use std::path::{Path, PathBuf};
pub use error::Error;
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Source {
pub tag: &'static str,
pub sha256: &'static str,
}
#[allow(missing_docs)]
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum Arch {
Aarch64,
Ia32,
LoongArch64,
Riscv64,
X64,
}
impl Arch {
pub fn as_str(self) -> &'static str {
match self {
Self::Aarch64 => "aarch64",
Self::Ia32 => "ia32",
Self::LoongArch64 => "loongarch64",
Self::Riscv64 => "riscv64",
Self::X64 => "x64",
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[allow(missing_docs)]
pub enum FileType {
Code,
Vars,
Shell,
}
impl FileType {
pub fn as_str(self) -> &'static str {
match self {
Self::Code => "code.fd",
Self::Vars => "vars.fd",
Self::Shell => "shell.efi",
}
}
}
pub struct Prebuilt {
dir: PathBuf,
}
impl Prebuilt {
pub fn fetch<P: AsRef<Path>>(source: Source, prebuilt_dir: P) -> Result<Self, Error> {
let prebuilt_dir = prebuilt_dir.as_ref();
update_cache(source, prebuilt_dir)?;
Ok(Self {
dir: prebuilt_dir.to_owned(),
})
}
pub fn get_file(&self, arch: Arch, file_type: FileType) -> PathBuf {
self.dir.join(arch.as_str()).join(file_type.as_str())
}
}