hyperv_secure_boot_templates/lib.rs
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4#![expect(missing_docs)]
5#![forbid(unsafe_code)]
6
7//! A basic "resource" crate which contains hard-coded Hyper-V Secure Boot
8//! Template JSON files which can be embedded directly into a final binary.
9//!
10//! This crate should not include any `cfg(target_arch)` or `cfg(guest_arch)`
11//! gates! Unused templates should be stripped from the final binary by the
12//! linker.
13
14macro_rules! include_templates {
15 (
16 $(($fn_name:ident, $path:literal),)*
17 ) => {
18 $(
19 pub fn $fn_name() -> firmware_uefi_custom_vars::CustomVars {
20 // DEVNOTE: in the future, it may be interesting to explore
21 // parsing the JSON at compile time, and then "baking" the
22 // parsed templates into the binary as a `const` value, instead
23 // of baking in the JSON and doing this extra "useless" parsing
24 // + validation at runtime.
25 //
26 // While it's unlikely this would save all that much code space
27 // in the final bin (given that much of the parsing + validation
28 // code is shared between both templates and user custom uefi
29 // JSON files), it may result in a nice .rodata size decrease.
30 hyperv_uefi_custom_vars_json::load_template_from_json(include_bytes!(concat!(env!("OUT_DIR"), "/", $path))).unwrap()
31 }
32 )*
33
34 #[cfg(test)]
35 mod test {
36 $(
37 #[test]
38 fn $fn_name() {
39 super::$fn_name();
40 }
41 )*
42 }
43
44 };
45}
46
47pub mod aarch64 {
48 include_templates! {
49 (microsoft_windows, "aarch64/MicrosoftWindows_Template.json"),
50 (microsoft_uefi_ca, "aarch64/MicrosoftUEFICertificateAuthority_Template.json"),
51 }
52}
53
54pub mod x64 {
55 include_templates! {
56 (microsoft_windows, "x64/MicrosoftWindows_Template.json"),
57 (microsoft_uefi_ca, "x64/MicrosoftUEFICertificateAuthority_Template.json"),
58 }
59}