From 64c6ae6bfc761e9c7d1a4d79b71d9571a763e57f Mon Sep 17 00:00:00 2001 From: Graham MacDonald Date: Wed, 25 Oct 2023 20:55:53 +0100 Subject: [PATCH] cargo check uses xtask Various build improvements: - Add support for `cargo xtask check` - Add .vscode/settings.json to have rust-analyzer use `cargo xtask check` - Minor code changes to fix build with latest nightly and remove some errors - Change aarch64 target to aarch64-unknown-none (from aarch64-unknown-none-softfloat) Signed-off-by: Graham MacDonald --- .gitignore | 1 - .vscode/settings.json | 9 ++++ README.md | 8 +++- aarch64/Cargo.toml | 2 +- aarch64/src/runtime.rs | 2 +- aarch64/src/trap.S | 1 + riscv64/src/sbi.rs | 2 +- rust-toolchain.toml | 2 +- x86_64/src/runtime.rs | 2 +- xtask/src/main.rs | 102 +++++++++++++++++++++++++++++++++++++++-- 10 files changed, 120 insertions(+), 11 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.gitignore b/.gitignore index ed1117f..ea8c4bf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ /target -.vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..83a9058 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,9 @@ +{ + "git.alwaysSignOff": true, + "rust-analyzer.check.overrideCommand": [ + "cargo", + "xtask", + "check", + "--json" + ] +} \ No newline at end of file diff --git a/README.md b/README.md index c78a8a0..a59eb49 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,12 @@ Right now, r9 is not self-hosting. `cargo xtask dist`, which `cargo xtask qemu` and `cargo xtask qemukvm` depend on, requires `llvm-objcopy`. -This is expected to live in the rust toolchain path. If -you get `No such file or directory (os error 2)` messages, +This is expected to live in the rust toolchain path. You can install by running: +``` +rustup component add llvm-tools +``` + +If you get `No such file or directory (os error 2)` messages, then install `llvm` separate from the rust toolchain and set: ``` OBJCOPY=$(which llvm-objcopy) cargo xtask qemukvm diff --git a/aarch64/Cargo.toml b/aarch64/Cargo.toml index 340fcda..ee51820 100644 --- a/aarch64/Cargo.toml +++ b/aarch64/Cargo.toml @@ -4,7 +4,7 @@ cargo-features = ["per-package-target"] name = "aarch64" version = "0.1.0" edition = "2021" -default-target = "aarch64-unknown-none-softfloat" +default-target = "aarch64-unknown-none" [dependencies] bitstruct = "0.1" diff --git a/aarch64/src/runtime.rs b/aarch64/src/runtime.rs index 331570e..f24a4a0 100644 --- a/aarch64/src/runtime.rs +++ b/aarch64/src/runtime.rs @@ -15,7 +15,7 @@ use port::mem::VirtRange; // - Use Console via println!() macro once available // - Add support for raspi4 #[panic_handler] -pub extern "C" fn panic(info: &PanicInfo) -> ! { +pub fn panic(info: &PanicInfo) -> ! { let mmio = rpi_mmio().expect("mmio base detect failed").to_virt(); let gpio_range = VirtRange::with_len(mmio + 0x200000, 0xb4); diff --git a/aarch64/src/trap.S b/aarch64/src/trap.S index 6dbdea9..0dee4c5 100644 --- a/aarch64/src/trap.S +++ b/aarch64/src/trap.S @@ -99,6 +99,7 @@ /// Each entry is 16 instructions/128 bytes. /// Ventry handles alignment of individual entries. .balign 2048 +.globl exception_vectors exception_vectors: // Current EL with SP0 ventry sync_invalid_el1t // Synchronous EL1t diff --git a/riscv64/src/sbi.rs b/riscv64/src/sbi.rs index 395ce76..db35524 100644 --- a/riscv64/src/sbi.rs +++ b/riscv64/src/sbi.rs @@ -2,7 +2,7 @@ //! //! Chapter 5: Legacy Extensions -#![cfg_attr(not(target_arch = "riscv64"), allow(dead_code))] +#![allow(dead_code)] const SBI_SET_TIMER: usize = 0; const SBI_CONSOLE_PUTCHAR: usize = 1; diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 5c471d8..6e48daf 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -2,7 +2,7 @@ channel = "nightly-2023-06-05" components = [ "rustfmt", "rust-src", "clippy", "llvm-tools" ] targets = [ - "aarch64-unknown-none-softfloat", + "aarch64-unknown-none", "riscv64imac-unknown-none-elf", "x86_64-unknown-none" ] diff --git a/x86_64/src/runtime.rs b/x86_64/src/runtime.rs index 592aba1..6535d47 100644 --- a/x86_64/src/runtime.rs +++ b/x86_64/src/runtime.rs @@ -6,7 +6,7 @@ use alloc::alloc::{GlobalAlloc, Layout}; use core::panic::PanicInfo; #[panic_handler] -pub extern "C" fn panic(_info: &PanicInfo) -> ! { +pub fn panic(_info: &PanicInfo) -> ! { #[allow(clippy::empty_loop)] loop {} } diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 0097244..b7a6f2c 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -35,6 +35,7 @@ impl fmt::Display for Arch { } } +// TODO This is becoming a bag of random fields - maybe turn into an enum struct BuildParams { arch: Arch, profile: Profile, @@ -42,11 +43,16 @@ struct BuildParams { wait_for_gdb: bool, config: Configuration, dump_dtb: String, + json_output: bool, } impl BuildParams { fn new(matches: &clap::ArgMatches) -> Self { - let profile = if matches.get_flag("release") { Profile::Release } else { Profile::Debug }; + let profile = if matches.try_contains_id("release").unwrap_or(false) { + Profile::Release + } else { + Profile::Debug + }; let verbose = matches.get_flag("verbose"); let arch = matches.try_get_one("arch").ok().flatten().unwrap_or(&Arch::X86_64); let wait_for_gdb = @@ -67,7 +73,9 @@ impl BuildParams { config_file )); - Self { arch: *arch, profile, verbose, wait_for_gdb, dump_dtb, config } + let json_output = matches.try_contains_id("json").unwrap_or(false); + + Self { arch: *arch, profile, verbose, wait_for_gdb, dump_dtb, config, json_output } } fn dir(&self) -> &'static str { @@ -164,6 +172,12 @@ fn main() { clap::arg!(--verbose "Print commands"), ]), ) + .subcommand( + clap::Command::new("check") + .about("Runs check") + .args(&[clap::arg!(--json "Output messages as json")]) + .args(&[clap::arg!(--verbose "Print commands")]), + ) .subcommand( clap::Command::new("qemu").about("Run r9 under QEMU").args(&[ clap::arg!(--release "Build a release version").conflicts_with("debug"), @@ -201,6 +215,7 @@ fn main() { Some(("dist", m)) => dist(&BuildParams::new(m)), Some(("test", m)) => test(&BuildParams::new(m)), Some(("clippy", m)) => clippy(&BuildParams::new(m)), + Some(("check", m)) => check(&BuildParams::new(m)), Some(("qemu", m)) => run(&BuildParams::new(m)), Some(("qemukvm", m)) => accelrun(&BuildParams::new(m)), Some(("clean", _)) => clean(), @@ -426,7 +441,88 @@ fn clippy(build_params: &BuildParams) -> Result<()> { } let status = annotated_status(&mut cmd)?; if !status.success() { - return Err("build kernel failed".into()); + return Err("clippy failed".into()); + } + Ok(()) +} + +fn check(build_params: &BuildParams) -> Result<()> { + let all_check_args = vec![ + vec!["check", "--package", "aarch64", "--bins"], + vec!["check", "--package", "x86_64", "--bins"], + vec!["check", "--package", "riscv64", "--bins"], + vec!["check", "--package", "port", "--lib"], + vec![ + "check", + "--package", + "aarch64", + "--tests", + "--benches", + "--target", + "aarch64-unknown-linux-gnu", + ], + vec![ + "check", + "--package", + "x86_64", + "--tests", + "--benches", + "--target", + "x86_64-unknown-linux-gnu", + ], + vec![ + "check", + "--package", + "riscv64", + "--tests", + "--benches", + "--target", + "riscv64gc-unknown-linux-gnu", + ], + vec![ + "check", + "--package", + "port", + "--tests", + "--benches", + "--target", + "aarch64-unknown-linux-gnu", + ], + vec![ + "check", + "--package", + "port", + "--tests", + "--benches", + "--target", + "x86_64-unknown-linux-gnu", + ], + vec![ + "check", + "--package", + "port", + "--tests", + "--benches", + "--target", + "riscv64gc-unknown-linux-gnu", + ], + ]; + + for check_args in all_check_args { + let mut cmd = Command::new(cargo()); + cmd.args(check_args); + if build_params.json_output { + cmd.arg("--message-format=json").arg("--quiet"); + } + cmd.current_dir(workspace()); + + if build_params.verbose { + println!("Executing {cmd:?}"); + } + let status = annotated_status(&mut cmd)?; + if !status.success() { + return Err("check failed".into()); + } } Ok(()) }