2024-03-12 18:17:47 +02:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
use clap::ValueEnum;
|
|
|
|
|
2024-03-12 19:39:04 +02:00
|
|
|
#[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,
|
2024-10-10 18:06:54 +03:00
|
|
|
i686
|
2024-03-12 18:17:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct BuildEnv {
|
2024-03-12 19:39:04 +02:00
|
|
|
pub config: XTaskConfig,
|
2024-03-20 21:21:39 +02:00
|
|
|
pub verbose: bool,
|
2024-03-12 19:39:04 +02:00
|
|
|
|
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-03-12 18:17:47 +02:00
|
|
|
}
|
|
|
|
|
2024-03-12 19:39:04 +02:00
|
|
|
impl Default for ToolchainConfig {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self {
|
|
|
|
branch: "alnyan/yggdrasil-master".into(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-12 18:17:47 +02:00
|
|
|
impl BuildEnv {
|
2024-03-20 21:21:39 +02:00
|
|
|
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");
|
|
|
|
|
|
|
|
Self {
|
2024-03-12 19:39:04 +02:00
|
|
|
config,
|
2024-03-20 21:21:39 +02:00
|
|
|
verbose,
|
2024-03-12 19:39:04 +02:00
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-10-10 18:06:54 +03: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-10-10 18:06:54 +03: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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|