131 lines
2.8 KiB
Rust

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,
}
#[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,
i686
}
#[derive(Debug)]
pub struct BuildEnv {
pub config: XTaskConfig,
pub verbose: bool,
pub profile: Profile,
pub arch: Arch,
pub host_triple: String,
pub workspace_root: PathBuf,
pub kernel_output_dir: PathBuf,
pub userspace_output_dir: PathBuf,
pub kernel_symbol_file: PathBuf,
}
impl Default for ToolchainConfig {
fn default() -> Self {
Self {
branch: "alnyan/yggdrasil-master".into(),
}
}
}
impl BuildEnv {
pub fn new(
config: XTaskConfig,
verbose: bool,
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 kernel_symbol_file = kernel_output_dir.join("symbols.dat");
let host = env!("TARGET");
Self {
config,
verbose,
profile,
arch,
host_triple: host.into(),
workspace_root,
kernel_symbol_file,
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",
Self::i686 => "i686-unknown-none"
}
}
pub fn user_triple(&self) -> &str {
match self {
Self::aarch64 => "aarch64-unknown-yggdrasil",
Self::x86_64 => "x86_64-unknown-yggdrasil",
Self::i686 => "i686-unknown-yggdrasil"
}
}
pub fn name(&self) -> &str {
match self {
Self::aarch64 => "aarch64",
Self::x86_64 => "x86_64",
Self::i686 => "i686",
}
}
}