Skip to content

Add Win32/WinRT type system distinction for windows-rdl #3871

Merged
kennykerr merged 18 commits intomasterfrom
rdl-mod
Feb 4, 2026
Merged

Add Win32/WinRT type system distinction for windows-rdl #3871
kennykerr merged 18 commits intomasterfrom
rdl-mod

Conversation

@kennykerr
Copy link
Copy Markdown
Collaborator

@kennykerr kennykerr commented Feb 4, 2026

Although RDL and windows-rs in general supports both Win32 and WinRT types and they share the same ECMA-335 format for metadata definitions, WinRT types are distinct and must be identifiable as they conform to the stricter type system understood by WinRT language projections. In ECMA-335 this is represented by the WindowsRuntime type attribute in the TypeDef table.

This update adds the ability (and requirement) that types are unambiguously defined as either WinRT or Win32. Eventually, I'll add validation to ensure that WinRT types only refer to other WinRT types, while Win32 types can refer to both WinRT and Win32 types as needed. For now, this is just a big upgrade to the RDL reader and writer to accommodate this distinction.

Each type must have either a winrt or win32 attribute as follows:

mod Test {
    #[winrt]
    struct A {}

    #[win32]
    #[repr(i32)]
    enum B {}
}

This will produce the following metadata:

.namespace Test
{
	.class public sequential ansi sealed windowsruntime Test.A
		extends [mscorlib]System.ValueType
	{
	}

	.class public auto ansi sealed Test.B
		extends [mscorlib]System.Enum
	{
		.field private specialname rtspecialname int32 value__
	}
}

Alternatively, types can inherit this attribute from the surrounding module for convenience:

#[win32]
mod Test {
    struct A {}
    
    #[repr(i32)]
    enum B {}
}

In this case, both types will be defined as Win32 types. This default can also be overriden:

#[win32]
mod Test {
    struct A {}

    #[winrt]
    #[repr(i32)]
    enum B {}
}

In this, A inherits the win32 attribute while B overrides this default.

This work builds on #3861.

@kennykerr kennykerr merged commit 5810657 into master Feb 4, 2026
32 checks passed
@kennykerr kennykerr deleted the rdl-mod branch February 4, 2026 18:43
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

Successfully merging this pull request may close these issues.

1 participant