194 lines
4.2 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, serde::Deserialize)]
#[serde(default)]
pub struct BuildComponents {
pub libc: bool,
// Depends on .libc
pub libcxx: bool,
}
#[derive(Debug, Default, serde::Deserialize)]
#[serde(default)]
pub struct AArch64TargetConfig {
pub components: BuildComponents,
}
#[derive(Debug, Default, serde::Deserialize)]
#[serde(default)]
pub struct X86_64TargetConfig {
pub components: BuildComponents,
}
#[derive(Debug, Default, serde::Deserialize)]
#[serde(default)]
pub struct I686TargetConfig {
pub components: BuildComponents,
}
#[derive(Debug, Default, serde::Deserialize)]
#[serde(default)]
pub struct TargetConfig {
pub aarch64: AArch64TargetConfig,
pub x86_64: X86_64TargetConfig,
pub i686: I686TargetConfig,
}
#[derive(Debug, Default, serde::Deserialize)]
#[serde(default)]
pub struct XTaskConfig {
pub toolchain: ToolchainConfig,
pub target: TargetConfig,
}
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,
2024-11-11 23:50:38 +02:00
i686,
2024-03-12 18:17:47 +02:00
}
#[derive(Debug)]
pub struct BuildEnv {
pub config: XTaskConfig,
pub verbose: bool,
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,
2024-04-01 17:23:12 +03:00
pub kernel_symbol_file: PathBuf,
2024-11-11 23:50:38 +02:00
pub llvm_sysroot: PathBuf,
2024-03-12 18:17:47 +02:00
}
impl Default for ToolchainConfig {
fn default() -> Self {
Self {
branch: "alnyan/yggdrasil-1.84.0".into(),
}
}
}
impl Default for BuildComponents {
fn default() -> Self {
Self {
libc: true,
libcxx: true,
}
}
}
2024-03-12 18:17:47 +02:00
impl BuildEnv {
pub fn new(
config: XTaskConfig,
verbose: bool,
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()
));
2024-04-01 17:23:12 +03:00
let kernel_symbol_file = kernel_output_dir.join("symbols.dat");
2024-03-12 18:17:47 +02:00
let host = env!("TARGET");
2024-11-11 23:50:38 +02:00
let llvm_sysroot = workspace_root.join(format!(
"toolchain-c/sysroot/{}-unknown-yggdrasil",
arch.name()
));
2024-03-12 18:17:47 +02:00
Self {
config,
verbose,
2024-03-12 18:17:47 +02:00
profile,
arch,
host_triple: host.into(),
workspace_root,
2024-04-01 17:23:12 +03:00
kernel_symbol_file,
2024-03-12 18:17:47 +02:00
kernel_output_dir,
userspace_output_dir,
2024-11-11 23:50:38 +02:00
llvm_sysroot,
2024-03-12 18:17:47 +02:00
}
}
}
2024-11-18 20:59:29 +02:00
impl XTaskConfig {
pub fn components(&self, env: &BuildEnv) -> &BuildComponents {
match env.arch {
Arch::aarch64 => &self.target.aarch64.components,
Arch::x86_64 => &self.target.x86_64.components,
Arch::i686 => &self.target.i686.components,
}
}
}
2024-03-12 18:17:47 +02:00
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",
2024-11-11 23:50:38 +02:00
Self::i686 => "i686-unknown-none",
2024-03-12 18:17:47 +02:00
}
}
pub fn user_triple(&self) -> &str {
match self {
Self::aarch64 => "aarch64-unknown-yggdrasil",
Self::x86_64 => "x86_64-unknown-yggdrasil",
2024-11-11 23:50:38 +02:00
Self::i686 => "i686-unknown-yggdrasil",
2024-03-12 18:17:47 +02:00
}
}
pub fn name(&self) -> &str {
match self {
Self::aarch64 => "aarch64",
Self::x86_64 => "x86_64",
2024-10-10 18:06:54 +03:00
Self::i686 => "i686",
2024-03-12 18:17:47 +02:00
}
}
}