youyuanwu / msquic-tokio

MIT License
1 stars 0 forks source link

Native bitfield in winmd does not have rust bindings #1

Open youyuanwu opened 3 months ago

youyuanwu commented 3 months ago

given winmd:

public struct QUIC_SETTINGS
{
    [StructLayout(LayoutKind.Explicit)]
    public struct _Anonymous1_e__Union
    {
        public struct _IsSet_e__Struct
        {
            [NativeBitfield("MaxBytesPerKey", 0L, 1L)]
            [NativeBitfield("HandshakeIdleTimeoutMs", 1L, 1L)]
            public ulong _bitfield;
        }

        [FieldOffset(0)]
        public ulong IsSetFlags;

        [FieldOffset(0)]
        public _IsSet_e__Struct IsSet;
    }

    public _Anonymous1_e__Union Anonymous1;

    public ulong MaxBytesPerKey;

    public ulong HandshakeIdleTimeoutMs;
}

There is no NativeBitfield support in generated Rust:

#[repr(C)]
pub struct QUIC_SETTINGS {
    pub Anonymous1: QUIC_SETTINGS_0,
    pub MaxBytesPerKey: u64,
    pub HandshakeIdleTimeoutMs: u64
}
#[repr(C)]
pub union QUIC_SETTINGS_0 {
    pub IsSetFlags: u64,
    pub IsSet: QUIC_SETTINGS_0_0,
}
#[repr(C)]
pub struct QUIC_SETTINGS_0_0 {
    pub _bitfield: u64,
}

C code is like this that is used to generate winmd:

typedef struct QUIC_SETTINGS {

    union {
        uint64_t IsSetFlags;
        struct {
            uint64_t MaxBytesPerKey                         : 1;
            uint64_t HandshakeIdleTimeoutMs                 : 1;

        } IsSet;
    };

} QUIC_SETTINGS;

The intended use in c:

    // config
    QUIC_SETTINGS Settings = {0};
    Settings.MaxBytesPerKey                         = 1000;
    Settings.IsSet.MaxBytesPerKey                 = TRUE;
youyuanwu commented 3 months ago

Seems like windows-rs has already an open issue about this: https://github.com/microsoft/windows-rs/issues/2942