Skip to content

Commit

Permalink
build: Add has_sev flags to test presence of SEV device
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Fanelli <[email protected]>
  • Loading branch information
tylerfanelli committed Jul 28, 2023
1 parent 9b7608e commit 4998c05
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
// SPDX-License-Identifier: Apache-2.0

use std::path::Path;
use std::{env, fs, io, process};
use std::{
env,
fs::{self, OpenOptions},
io,
path::Path,
process,
};

const COMMANDS: [&str; 1] = ["snphost"];

Expand All @@ -14,6 +19,10 @@ fn main() {
};
fs::create_dir_all(&outdir).unwrap();

if sev_rw() {
println!("cargo:rustc-cfg=has_sev");
}

for command in COMMANDS {
if let Err(err) = generate_man_page(&outdir, command) {
println!(
Expand Down Expand Up @@ -52,3 +61,11 @@ fn generate_man_page<P: AsRef<Path>>(outdir: P, command: &str) -> io::Result<()>
}
Ok(())
}

fn sev_rw() -> bool {
OpenOptions::new()
.read(true)
.write(true)
.open("/dev/sev")
.is_ok()
}

0 comments on commit 4998c05

Please sign in to comment.