diff --git a/xtask.toml b/xtask.toml new file mode 100644 index 00000000..ceabe64a --- /dev/null +++ b/xtask.toml @@ -0,0 +1,2 @@ +[toolchain] +branch = "alnyan/v0.1.0" diff --git a/xtask/src/build/mod.rs b/xtask/src/build/mod.rs index 228ec300..f74e1268 100644 --- a/xtask/src/build/mod.rs +++ b/xtask/src/build/mod.rs @@ -128,7 +128,7 @@ pub fn clean_all(env: &BuildEnv, clean_toolchain: bool) -> Result<(), Error> { Ok(()) } -pub fn build_toolchain(env: BuildEnv, branch: &str) -> Result<(), Error> { - toolchain::fetch(&env, branch)?; - toolchain::build(&env) +pub fn build_toolchain(env: &BuildEnv, branch: &str) -> Result<(), Error> { + toolchain::fetch(env, branch)?; + toolchain::build(env) } diff --git a/xtask/src/env.rs b/xtask/src/env.rs index b1229e83..79761ac1 100644 --- a/xtask/src/env.rs +++ b/xtask/src/env.rs @@ -2,6 +2,18 @@ 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] @@ -20,6 +32,8 @@ pub enum Arch { #[derive(Debug)] pub struct BuildEnv { + pub config: XTaskConfig, + pub profile: Profile, pub arch: Arch, pub host_triple: String, @@ -30,8 +44,16 @@ pub struct BuildEnv { pub userspace_output_dir: PathBuf, } +impl Default for ToolchainConfig { + fn default() -> Self { + Self { + branch: "alnyan/yggdrasil-master".into(), + } + } +} + impl BuildEnv { - pub fn new(profile: Profile, arch: Arch, workspace_root: PathBuf) -> Self { + pub fn new(config: XTaskConfig, 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!( @@ -42,6 +64,8 @@ impl BuildEnv { let host = env!("TARGET"); Self { + config, + profile, arch, host_triple: host.into(), diff --git a/xtask/src/main.rs b/xtask/src/main.rs index f32ffdbd..b985501e 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -1,10 +1,6 @@ -// #![deny(warnings)] +#![deny(warnings)] -use std::{ - fs, - path::{Path, PathBuf}, - process::ExitCode, -}; +use std::{fs, path::PathBuf, process::ExitCode}; use build::CheckAction; use clap::{Parser, Subcommand}; @@ -40,6 +36,14 @@ struct Args { )] clean_userspace: bool, + #[clap( + short = 'C', + long, + default_value = "xtask.toml", + help = "Configuration path" + )] + config_path: PathBuf, + #[clap(subcommand)] action: Option, } @@ -77,13 +81,7 @@ enum SubArgs { }, #[clap(about = "Build the Yggdrasil OS Rust toolchain")] - Toolchain { - #[clap( - default_value = "alnyan/yggdrasil-master", - help = "Use a specific toolchain repo branch" - )] - branch: String, - }, + Toolchain { branch: Option }, #[clap(about = "Print the host triple")] HostTriple, } @@ -97,7 +95,8 @@ fn run(args: Args) -> Result<(), Error> { } else { Profile::Debug }; - let env = env::BuildEnv::new(profile, args.arch, workspace_root); + let config = toml::from_str(&fs::read_to_string(args.config_path)?)?; + let env = env::BuildEnv::new(config, profile, args.arch, workspace_root); if args.clean_userspace && !matches!(&action, SubArgs::Clean { .. }) { build::clean_userspace(&env)?; @@ -111,7 +110,10 @@ fn run(args: Args) -> Result<(), Error> { SubArgs::Clean { toolchain } => build::clean_all(&env, toolchain), // SubArgs::GitStatus => util::git_status_all(&env), SubArgs::Qemu { qemu, extra_args } => qemu::run(env, qemu, extra_args), - SubArgs::Toolchain { branch } => build::build_toolchain(env, &branch), + SubArgs::Toolchain { branch } => { + let branch = branch.as_ref().unwrap_or(&env.config.toolchain.branch); + build::build_toolchain(&env, branch) + } SubArgs::HostTriple => { println!("{}", env.host_triple); Ok(())