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::BaseTemplate {
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 firmware_uefi_custom_vars::BaseTemplate {
31 json: include_bytes!(concat!(env!("OUT_DIR"), "/", $path)).to_vec().into(),
32 }
33 }
34 )*
35
36 #[cfg(test)]
37 mod test {
38 $(
39 #[test]
40 fn $fn_name() {
41 let template = super::$fn_name();
42 hyperv_uefi_custom_vars_json::parse_template_json(
43 template.json.as_bytes()
44 ).unwrap();
45 }
46 )*
47 }
48
49 };
50}
51
52pub mod aarch64 {
53 include_templates! {
54 (microsoft_windows, "aarch64/MicrosoftWindows_Template.json"),
55 (microsoft_uefi_ca, "aarch64/MicrosoftUEFI_Template.json"),
56 }
57}
58
59pub mod x64 {
60 include_templates! {
61 (microsoft_windows, "x64/MicrosoftWindows_Template.json"),
62 (microsoft_uefi_ca, "x64/MicrosoftUEFI_Template.json"),
63 }
64}