microsoft / igvm

MIT License
81 stars 17 forks source link

igvm_defs: build error without "unstable" feature #63

Closed osteffenrh closed 2 weeks ago

osteffenrh commented 1 month ago

cargo build of igvm_defs fails:

error[E0599]: no associated item named `SEV` found for struct `IgvmPlatformType` in the current scope
   --> src/lib.rs:383:5
    |
368 | #[open_enum]
    | ------------ associated item `SEV` not found for this struct
...
383 |     SEV = 0x04,
    |     ^^^ associated item not found in `IgvmPlatformType`

error[E0599]: no associated item named `SEV_ES` found for struct `IgvmPlatformType` in the current scope
   --> src/lib.rs:387:5
    |
368 | #[open_enum]
    | ------------ associated item `SEV_ES` not found for this struct
...
387 |     SEV_ES = 0x05,
    |     ^^^^^^ associated item not found in `IgvmPlatformType`

For more information about this error, try `rustc --explain E0599`.

If works, if the unstable feature is set: cargo build -F unstable

chris-oo commented 1 month ago

Interesting... let me take a look. What's curious is CI didn't catch this, so we probably need another update there to test building without this feature.

chris-oo commented 1 month ago

Aha it's because of how open_enum handles expansion... Let me see if i can submit a fix, i think it needs to propagate the corresponding cfgs to the debug impl...

// Recursive expansion of open_enum macro
// =======================================

#[allow(clippy::exhaustive_structs)]
#[doc = " Enum describing different isolation platforms for"]
#[doc = " [`IGVM_VHS_SUPPORTED_PLATFORM`] structures."]
#[doc = " cbindgen:prefix-with-name=true"]
#[doc = " cbindgen:rename-all=ScreamingSnakeCase"]
#[repr(transparent)]
#[derive(
    ::core::cmp::PartialEq, ::core::cmp::Eq, AsBytes, FromBytes, FromZeroes, Clone, Copy, Hash,
)]
pub struct IgvmPlatformType(pub u8);

#[allow(non_upper_case_globals)]
impl IgvmPlatformType {
    #[doc = " Native platform type without isolation."]
    pub const NATIVE: IgvmPlatformType = IgvmPlatformType(0);
    #[doc = " Platform type of Hyper-V\'s which supports VSM isolation."]
    pub const VSM_ISOLATION: IgvmPlatformType = IgvmPlatformType(1);
    #[doc = " AMD SEV-SNP."]
    pub const SEV_SNP: IgvmPlatformType = IgvmPlatformType(2);
    #[doc = " Intel TDX."]
    pub const TDX: IgvmPlatformType = IgvmPlatformType(3);
    #[doc = " AMD SEV."]
    #[cfg(feature = "unstable")]
    #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
    pub const SEV: IgvmPlatformType = IgvmPlatformType(4);
    #[doc = " AMD SEV-ES"]
    #[cfg(feature = "unstable")]
    #[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
    pub const SEV_ES: IgvmPlatformType = IgvmPlatformType(5);
}
impl ::core::fmt::Debug for IgvmPlatformType {
    fn fmt(&self, fmt: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        #![allow(unreachable_patterns)]
        let s = match *self {
            Self::NATIVE => "NATIVE",
            Self::VSM_ISOLATION => "VSM_ISOLATION",
            Self::SEV_SNP => "SEV_SNP",
            Self::TDX => "TDX",
            Self::SEV => "SEV",
            Self::SEV_ES => "SEV_ES",
            _ => {
                return fmt.debug_tuple("IgvmPlatformType").field(&self.0).finish();
            }
        };
        fmt.pad(s)
    }
}
chris-oo commented 1 month ago

I have a PR out in that repo for a fix, so once we have that merged we should be able to take it. Let me see also about fixing CI to test this as well.

chris-oo commented 2 weeks ago

upstream PR is merged, will find some time tomorrow to close this out and publish a new release, sorry about that!

stefano-garzarella commented 5 days ago

Thanks for fixing it! We would need a new release with the fix to finish the packaging of this crate for Fedora, do you have an estimation for a new release?