92 lines
1.9 KiB
Rust
Raw Normal View History

2024-03-12 18:17:47 +02:00
use std::path::PathBuf;
use clap::ValueEnum;
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub enum Profile {
#[default]
Debug,
Release,
}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, ValueEnum)]
#[allow(non_camel_case_types)]
#[clap(rename_all = "verbatim")]
pub enum Arch {
#[default]
aarch64,
x86_64,
}
#[derive(Debug)]
pub struct BuildEnv {
pub profile: Profile,
pub arch: Arch,
pub host_triple: String,
pub workspace_root: PathBuf,
pub kernel_output_dir: PathBuf,
pub userspace_output_dir: PathBuf,
}
impl BuildEnv {
pub fn new(profile: Profile, arch: Arch, workspace_root: PathBuf) -> Self {
let kernel_output_dir =
workspace_root.join(format!("target/{}/{}", arch.kernel_triple(), profile.dir()));
let userspace_output_dir = workspace_root.join(format!(
"userspace/target/{}-unknown-yggdrasil/{}",
arch.name(),
profile.dir()
));
let host = env!("TARGET");
Self {
profile,
arch,
host_triple: host.into(),
workspace_root,
kernel_output_dir,
userspace_output_dir,
}
}
}
impl Profile {
pub fn dir(&self) -> &str {
match self {
Self::Debug => "debug",
Self::Release => "release",
}
}
pub fn name(&self) -> &str {
self.dir()
}
}
impl Arch {
pub fn kernel_triple(&self) -> &str {
match self {
Self::aarch64 => "aarch64-unknown-qemu",
Self::x86_64 => "x86_64-unknown-none",
}
}
pub fn user_triple(&self) -> &str {
match self {
Self::aarch64 => "aarch64-unknown-yggdrasil",
Self::x86_64 => "x86_64-unknown-yggdrasil",
}
}
pub fn name(&self) -> &str {
match self {
Self::aarch64 => "aarch64",
Self::x86_64 => "x86_64",
}
}
}