use std::io::stdin; use anyhow::{Error, Ok}; use clap::Parser; #[derive(clap::Parser, Debug)] // #[clap(version = clap::crate_version!(), author = clap::crate_authors!("\n"))] /// Hello Remember this is a feature enum Command { Run { #[clap(long, short)] debug: bool, #[clap(long, short)] profile: bool, #[clap(long, short, arg_enum)] machine: Option, }, Doc { #[clap(long, short, arg_enum)] machine: Option, }, Mount { #[clap(long, short)] path: Option, }, Unmount { #[clap(long, short)] path: Option, }, MakeFS {}, } #[derive(clap::ArgEnum, Debug, Clone)] enum MachineType { X86, Riscv, Arm, } fn main() -> anyhow::Result<()> { let args = Command::parse(); match args { Command::Run { debug, profile, machine, } => { let _dir = xshell::pushd("./ableos"); let debug_log: &[&str] = match debug { true => &["-D", "debug.log"], false => &[], }; match machine.unwrap_or(MachineType::X86) { MachineType::X86 => { // export RUSTFLAGS=\"-Cforce-unwind-tables -Clink-arg=-Wl,eh_frame.ld\" && xshell::cmd!("cargo run --release -- -D debug.log").run()?; if profile { xshell::cmd!("python qprofiler.py --path=qmp-sock --filename=target/x86_64-ableos/release/ableos").run()?; } } MachineType::Arm => { xshell::cmd!("cargo build --release --target=json_targets/aarch64-ableos.json") .run()?; #[rustfmt::skip] xshell::cmd!( "qemu-system-aarch64 -machine virt -m 1024M -cpu cortex-a53 -kernel target/aarch64-ableos/release/ableos -device virtio-keyboard " ).run()?; } MachineType::Riscv => { xshell::cmd!("cargo build --release --target=riscv64gc-unknown-none-elf") .run()?; #[rustfmt::skip] xshell::cmd!( "qemu-system-riscv64 -machine virt -cpu rv64 -smp 8 -m 128M -bios src/arch/riscv/firmwear/opensbi-riscv64-generic-fw_jump.bin -kernel target/riscv64gc-unknown-none-elf/release/ableos " // -serial stdio ).run()?; } } } Command::Doc { machine } => { let _dir = xshell::pushd("./ableos"); match machine.unwrap_or(MachineType::X86) { MachineType::X86 => { xshell::cmd!("cargo doc --open").run()?; } MachineType::Arm => { xshell::cmd!("cargo doc --open --target=json_targets/aarch64-ableos.json") .run()?; } MachineType::Riscv => { xshell::cmd!("cargo doc --open --target=riscv64gc-unknown-none-elf").run()?; } } } Command::Mount { path } => { let path = path.unwrap_or_else(|| "./userland/root_fs/mnt".to_string()); xshell::cmd!("sudo mount userland/root_fs/ext2.img {path}").run()?; } Command::Unmount { path } => { let path = path.unwrap_or_else(|| "./userland/root_fs/mnt".to_string()); xshell::cmd!("sudo umount {path}").run()?; } Command::MakeFS {} => match make_fs() { Result::Ok(_) => {} Err(err) => println!("{}", err), }, } Ok(()) } pub fn make_fs() -> Result<(), Error> { xshell::cmd!("sh repbuild/assets/mkfs.sh").run()?; println!("Make changes in root_fs"); let mut input = String::new(); println!("Press enter when ready:"); stdin().read_line(&mut input).unwrap(); // build // xshell::cmd!("rm -rf root").run()?; Ok(()) } pub fn make_user(user: String) -> Result<(), Error> { xshell::mkdir_p(user)?; Ok(()) }