116 lines
2.4 KiB
Rust
Raw Normal View History

2024-03-12 18:17:47 +02:00
use std::path::PathBuf;
use clap::ValueEnum;
#[derive(Debug, serde::Deserialize)]
#[serde(default)]
pub struct ToolchainConfig {
pub branch: String,
}
#[derive(Debug, Default, serde::Deserialize)]
#[serde(default)]
pub struct XTaskConfig {
pub toolchain: ToolchainConfig,
}
2024-03-12 18:17:47 +02:00
#[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 config: XTaskConfig,
2024-03-12 18:17:47 +02:00
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 Default for ToolchainConfig {
fn default() -> Self {
Self {
branch: "alnyan/yggdrasil-master".into(),
}
}
}
2024-03-12 18:17:47 +02:00
impl BuildEnv {
pub fn new(config: XTaskConfig, profile: Profile, arch: Arch, workspace_root: PathBuf) -> Self {
2024-03-12 18:17:47 +02:00
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 {
config,
2024-03-12 18:17:47 +02:00
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",
}
}
}