Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native bitfield in winmd does not have rust bindings #1

Open
youyuanwu opened this issue Apr 19, 2024 · 1 comment
Open

Native bitfield in winmd does not have rust bindings #1

youyuanwu opened this issue Apr 19, 2024 · 1 comment

Comments

@youyuanwu
Copy link
Owner

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
Copy link
Owner Author

Seems like windows-rs has already an open issue about this:
microsoft/windows-rs#2942

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant