build: Ability to specify toolchain branch
This commit is contained in:
parent
a39d42a3eb
commit
c5699db3a5
2
xtask.toml
Normal file
2
xtask.toml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
[toolchain]
|
||||||
|
branch = "alnyan/v0.1.0"
|
@ -128,7 +128,7 @@ pub fn clean_all(env: &BuildEnv, clean_toolchain: bool) -> Result<(), Error> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build_toolchain(env: BuildEnv, branch: &str) -> Result<(), Error> {
|
pub fn build_toolchain(env: &BuildEnv, branch: &str) -> Result<(), Error> {
|
||||||
toolchain::fetch(&env, branch)?;
|
toolchain::fetch(env, branch)?;
|
||||||
toolchain::build(&env)
|
toolchain::build(env)
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,18 @@ use std::path::PathBuf;
|
|||||||
|
|
||||||
use clap::ValueEnum;
|
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)]
|
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, ValueEnum)]
|
||||||
pub enum Profile {
|
pub enum Profile {
|
||||||
#[default]
|
#[default]
|
||||||
@ -20,6 +32,8 @@ pub enum Arch {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct BuildEnv {
|
pub struct BuildEnv {
|
||||||
|
pub config: XTaskConfig,
|
||||||
|
|
||||||
pub profile: Profile,
|
pub profile: Profile,
|
||||||
pub arch: Arch,
|
pub arch: Arch,
|
||||||
pub host_triple: String,
|
pub host_triple: String,
|
||||||
@ -30,8 +44,16 @@ pub struct BuildEnv {
|
|||||||
pub userspace_output_dir: PathBuf,
|
pub userspace_output_dir: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for ToolchainConfig {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
branch: "alnyan/yggdrasil-master".into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl BuildEnv {
|
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 =
|
let kernel_output_dir =
|
||||||
workspace_root.join(format!("target/{}/{}", arch.kernel_triple(), profile.dir()));
|
workspace_root.join(format!("target/{}/{}", arch.kernel_triple(), profile.dir()));
|
||||||
let userspace_output_dir = workspace_root.join(format!(
|
let userspace_output_dir = workspace_root.join(format!(
|
||||||
@ -42,6 +64,8 @@ impl BuildEnv {
|
|||||||
let host = env!("TARGET");
|
let host = env!("TARGET");
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
|
config,
|
||||||
|
|
||||||
profile,
|
profile,
|
||||||
arch,
|
arch,
|
||||||
host_triple: host.into(),
|
host_triple: host.into(),
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
// #![deny(warnings)]
|
#![deny(warnings)]
|
||||||
|
|
||||||
use std::{
|
use std::{fs, path::PathBuf, process::ExitCode};
|
||||||
fs,
|
|
||||||
path::{Path, PathBuf},
|
|
||||||
process::ExitCode,
|
|
||||||
};
|
|
||||||
|
|
||||||
use build::CheckAction;
|
use build::CheckAction;
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
@ -40,6 +36,14 @@ struct Args {
|
|||||||
)]
|
)]
|
||||||
clean_userspace: bool,
|
clean_userspace: bool,
|
||||||
|
|
||||||
|
#[clap(
|
||||||
|
short = 'C',
|
||||||
|
long,
|
||||||
|
default_value = "xtask.toml",
|
||||||
|
help = "Configuration path"
|
||||||
|
)]
|
||||||
|
config_path: PathBuf,
|
||||||
|
|
||||||
#[clap(subcommand)]
|
#[clap(subcommand)]
|
||||||
action: Option<SubArgs>,
|
action: Option<SubArgs>,
|
||||||
}
|
}
|
||||||
@ -77,13 +81,7 @@ enum SubArgs {
|
|||||||
},
|
},
|
||||||
|
|
||||||
#[clap(about = "Build the Yggdrasil OS Rust toolchain")]
|
#[clap(about = "Build the Yggdrasil OS Rust toolchain")]
|
||||||
Toolchain {
|
Toolchain { branch: Option<String> },
|
||||||
#[clap(
|
|
||||||
default_value = "alnyan/yggdrasil-master",
|
|
||||||
help = "Use a specific toolchain repo branch"
|
|
||||||
)]
|
|
||||||
branch: String,
|
|
||||||
},
|
|
||||||
#[clap(about = "Print the host triple")]
|
#[clap(about = "Print the host triple")]
|
||||||
HostTriple,
|
HostTriple,
|
||||||
}
|
}
|
||||||
@ -97,7 +95,8 @@ fn run(args: Args) -> Result<(), Error> {
|
|||||||
} else {
|
} else {
|
||||||
Profile::Debug
|
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 { .. }) {
|
if args.clean_userspace && !matches!(&action, SubArgs::Clean { .. }) {
|
||||||
build::clean_userspace(&env)?;
|
build::clean_userspace(&env)?;
|
||||||
@ -111,7 +110,10 @@ fn run(args: Args) -> Result<(), Error> {
|
|||||||
SubArgs::Clean { toolchain } => build::clean_all(&env, toolchain),
|
SubArgs::Clean { toolchain } => build::clean_all(&env, toolchain),
|
||||||
// SubArgs::GitStatus => util::git_status_all(&env),
|
// SubArgs::GitStatus => util::git_status_all(&env),
|
||||||
SubArgs::Qemu { qemu, extra_args } => qemu::run(env, qemu, extra_args),
|
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 => {
|
SubArgs::HostTriple => {
|
||||||
println!("{}", env.host_triple);
|
println!("{}", env.host_triple);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user