Skip to content

Commit

Permalink
cargo check uses xtask
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
gmacd committed Oct 25, 2023
1 parent 617e6bc commit a0352ef
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 11 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/target
.vscode/settings.json
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"git.alwaysSignOff": true,
"rust-analyzer.check.overrideCommand": [
"cargo",
"xtask",
"check",
"--json"
]
}
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion aarch64/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion aarch64/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions aarch64/src/trap.S
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion riscv64/src/sbi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
2 changes: 1 addition & 1 deletion x86_64/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
}
Expand Down
102 changes: 99 additions & 3 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,24 @@ 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,
verbose: bool,
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 =
Expand All @@ -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 {
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(())
}
Expand Down

0 comments on commit a0352ef

Please sign in to comment.