Skip to content

Commit

Permalink
feat(xtask): migrate to clap
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kröning <[email protected]>
  • Loading branch information
mkroening committed Sep 1, 2023
1 parent 1fb60a8 commit 92484bf
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 122 deletions.
129 changes: 113 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"

[dependencies]
anyhow = "1.0"
clap = { version = "4", features = ["derive"] }
goblin = { version = "0.7", default-features = false, features = ["archive", "elf32", "elf64", "std"] }
llvm-tools = "0.1"
xflags = "0.3"
xshell = "0.2"
19 changes: 6 additions & 13 deletions xtask/src/arch.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
use std::str::FromStr;

use anyhow::anyhow;
use clap::ValueEnum;

#[derive(Clone, Copy, PartialEq, Eq, Debug)]
/// Target architecture.
#[derive(ValueEnum, Clone, Copy, PartialEq, Eq, Debug)]
#[value(rename_all = "snake_case")]
pub enum Arch {
/// x86-64
X86_64,
/// AArch64
Aarch64,
}

Expand Down Expand Up @@ -65,15 +70,3 @@ impl Arch {
}
}
}

impl FromStr for Arch {
type Err = anyhow::Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"x86_64" => Ok(Self::X86_64),
"aarch64" => Ok(Self::Aarch64),
s => Err(anyhow!("Unsupported arch: {s}")),
}
}
}
41 changes: 39 additions & 2 deletions xtask/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,49 @@ use std::ffi::OsStr;
use std::path::{Path, PathBuf};

use anyhow::Result;
use clap::Args;
use xshell::cmd;

use crate::arch::Arch;
use crate::archive::Archive;
use crate::flags;

impl flags::Build {
/// Build the kernel.
#[derive(Args)]
pub struct Build {
/// Build for the architecture.
#[arg(value_enum, long)]
pub arch: Arch,

/// Directory for all generated artifacts.
#[arg(long)]
pub target_dir: Option<PathBuf>,

/// Do not activate the `default` feature.
#[arg(long)]
pub no_default_features: bool,

/// Space or comma separated list of features to activate.
#[arg(long)]
pub features: Vec<String>,

/// Build artifacts in release mode, with optimizations.
#[arg(short, long)]
pub release: bool,

/// Build artifacts with the specified profile.
#[arg(long)]
pub profile: Option<String>,

/// Enable the `-Z instrument-mcount` flag.
#[arg(long)]
pub instrument_mcount: bool,

/// Enable the `-Z randomize-layout` flag.
#[arg(long)]
pub randomize_layout: bool,
}

impl Build {
pub fn run(self) -> Result<()> {
let sh = crate::sh()?;

Expand Down
8 changes: 6 additions & 2 deletions xtask/src/clippy.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use anyhow::Result;
use clap::Args;
use xshell::cmd;

use crate::arch::Arch;
use crate::flags;

impl flags::Clippy {
/// Run Clippy for all targets.
#[derive(Args)]
pub struct Clippy;

impl Clippy {
pub fn run(self) -> Result<()> {
let sh = crate::sh()?;

Expand Down
81 changes: 0 additions & 81 deletions xtask/src/flags.rs

This file was deleted.

Loading

0 comments on commit 92484bf

Please sign in to comment.