Add cfg(ktest) as a well-known configuration

This commit is contained in:
Zhang Junyang 2024-06-20 16:00:56 +00:00 committed by Tate, Hongliang Tian
parent ab1d931cb7
commit 8633893bb9
2 changed files with 9 additions and 0 deletions

View File

@ -209,6 +209,9 @@ fn build_kernel_elf(
// We do not really allow unwinding except for kernel testing. However, we need to specify
// this to show backtraces when panicking.
"-C panic=unwind",
// This is to let rustc know that "cfg(ktest)" is our well-known configuration.
// See the [Rust Blog](https://blog.rust-lang.org/2024/05/06/check-cfg.html) for details.
"--check-cfg cfg(ktest)",
]);
if matches!(arch, Arch::X86_64) {

View File

@ -24,6 +24,12 @@ pub fn execute_forwarded_command(subcommand: &str, args: &Vec<String>) -> ! {
cargo.arg("--target").arg(get_default_arch().triple());
}
cargo.args(args);
let env_rustflags = std::env::var("RUSTFLAGS").unwrap_or_default();
let rustflags = env_rustflags + " --check-cfg cfg(ktest)";
cargo.env("RUSTFLAGS", rustflags);
let status = cargo.status().expect("Failed to execute cargo");
std::process::exit(status.code().unwrap_or(1));
}