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

Add .NET 9 target for WinRT.Runtime.dll #1843

Draft
wants to merge 3 commits into
base: staging/2.2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
<IsTargetFrameworkNet8OrGreater Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) >= 8">true</IsTargetFrameworkNet8OrGreater>
<AppBuildTFMs>netcoreapp3.1;net6.0</AppBuildTFMs>
<AppBuildTFMs Condition="'$(CIBuildReason)' == 'CI'">netcoreapp3.1;net6.0;net8.0</AppBuildTFMs>
<LibBuildTFMs>netstandard2.0;net6.0;net8.0</LibBuildTFMs>
<LibBuildTFMs>netstandard2.0;net6.0;net8.0;net9.0</LibBuildTFMs>
<LibBuildTFMs Condition="'$(CIBuildReason)' == 'CI'">netstandard2.0;net6.0;net8.0</LibBuildTFMs>
<LibBuildTFMsNoNetStandard>net6.0;net8.0</LibBuildTFMsNoNetStandard>
<LibBuildTFMsNoNetStandard>net6.0;net8.0;net9.0</LibBuildTFMsNoNetStandard>
<LibBuildTFMsNoNetStandard Condition="'$(CIBuildReason)' == 'CI'">net6.0;net8.0</LibBuildTFMsNoNetStandard>
<TestsBuildTFMs>net6.0-windows10.0.19041.0;net8.0-windows10.0.19041.0</TestsBuildTFMs>
<TestsBuildTFMs Condition="'$(CIBuildReason)' == 'CI'">net6.0-windows10.0.19041.0</TestsBuildTFMs>
Expand Down
75 changes: 60 additions & 15 deletions src/WinRT.Runtime/Marshalers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ public void Dispose()

public static new unsafe MarshalerArray CreateMarshalerArray(T[] array)
{
#if NET
#if NET && !NET9_0_OR_GREATER
if (!RuntimeFeature.IsDynamicCodeCompiled)
{
throw new NotSupportedException($"Cannot handle array marshalling for non blittable type '{typeof(T)}'.");
Expand All @@ -1093,7 +1093,12 @@ public void Dispose()
{
int length = array.Length;
#pragma warning disable IL3050 // https://github.com/dotnet/runtime/issues/97273
var abi_element_size = Marshal.SizeOf(AbiType);
var abi_element_size =
#if NET9_0_OR_GREATER
RuntimeHelpers.SizeOf(AbiType.TypeHandle);
#else
Marshal.SizeOf(AbiType);
#endif
#pragma warning restore IL3050
var byte_length = length * abi_element_size;
m._array = Marshal.AllocCoTaskMem(byte_length);
Expand Down Expand Up @@ -1125,7 +1130,7 @@ public void Dispose()

public static new unsafe T[] FromAbiArray(object box)
{
#if NET
#if NET && !NET9_0_OR_GREATER
if (!RuntimeFeature.IsDynamicCodeCompiled)
{
throw new NotSupportedException($"Cannot handle array marshalling for non blittable type '{typeof(T)}'.");
Expand All @@ -1143,10 +1148,20 @@ public void Dispose()
var array = new T[abi.length];
var data = (byte*)abi.data.ToPointer();
#pragma warning disable IL3050 // https://github.com/dotnet/runtime/issues/97273
var abi_element_size = Marshal.SizeOf(AbiType);
var abi_element_size =
#if NET9_0_OR_GREATER
RuntimeHelpers.SizeOf(AbiType.TypeHandle);
#else
Marshal.SizeOf(AbiType);
#endif
for (int i = 0; i < abi.length; i++)
{
var abi_element = Marshal.PtrToStructure((IntPtr)data, AbiType);
var abi_element =
#if NET9_0_OR_GREATER
RuntimeHelpers.Box(ref *data, AbiType.TypeHandle);
#else
Marshal.PtrToStructure((IntPtr)data, AbiType);
#endif
#pragma warning restore IL3050
array[i] = Marshaler<T>.FromAbi(abi_element);
data += abi_element_size;
Expand All @@ -1156,7 +1171,7 @@ public void Dispose()

public static unsafe void CopyAbiArray(T[] array, object box)
{
#if NET
#if NET && !NET9_0_OR_GREATER
if (!RuntimeFeature.IsDynamicCodeCompiled)
{
throw new NotSupportedException($"Cannot handle array marshalling for non blittable type '{typeof(T)}'.");
Expand All @@ -1169,10 +1184,20 @@ public static unsafe void CopyAbiArray(T[] array, object box)
}
var data = (byte*)abi.data.ToPointer();
#pragma warning disable IL3050 // https://github.com/dotnet/runtime/issues/97273
var abi_element_size = Marshal.SizeOf(AbiType);
var abi_element_size =
#if NET9_0_OR_GREATER
RuntimeHelpers.SizeOf(AbiType.TypeHandle);
#else
Marshal.SizeOf(AbiType);
#endif
for (int i = 0; i < abi.length; i++)
{
var abi_element = Marshal.PtrToStructure((IntPtr)data, AbiType);
var abi_element =
#if NET9_0_OR_GREATER
RuntimeHelpers.Box(ref *data, AbiType.TypeHandle);
#else
Marshal.PtrToStructure((IntPtr)data, AbiType);
#endif
#pragma warning restore IL3050
array[i] = Marshaler<T>.FromAbi(abi_element);
data += abi_element_size;
Expand All @@ -1181,7 +1206,7 @@ public static unsafe void CopyAbiArray(T[] array, object box)

public static new unsafe (int length, IntPtr data) FromManagedArray(T[] array)
{
#if NET
#if NET && !NET9_0_OR_GREATER
if (!RuntimeFeature.IsDynamicCodeCompiled)
{
throw new NotSupportedException($"Cannot handle array marshalling for non blittable type '{typeof(T)}'.");
Expand All @@ -1198,7 +1223,12 @@ public static unsafe void CopyAbiArray(T[] array, object box)
{
int length = array.Length;
#pragma warning disable IL3050 // https://github.com/dotnet/runtime/issues/97273
var abi_element_size = Marshal.SizeOf(AbiType);
var abi_element_size =
#if NET9_0_OR_GREATER
RuntimeHelpers.SizeOf(AbiType.TypeHandle);
#else
Marshal.SizeOf(AbiType);
#endif
#pragma warning restore IL3050
var byte_length = length * abi_element_size;
data = Marshal.AllocCoTaskMem(byte_length);
Expand All @@ -1222,7 +1252,7 @@ public static unsafe void CopyAbiArray(T[] array, object box)

public static unsafe void CopyManagedArray(T[] array, IntPtr data)
{
#if NET
#if NET && !NET9_0_OR_GREATER
if (!RuntimeFeature.IsDynamicCodeCompiled)
{
throw new NotSupportedException($"Cannot handle array marshalling for non blittable type '{typeof(T)}'.");
Expand All @@ -1239,7 +1269,12 @@ public static unsafe void CopyManagedArray(T[] array, IntPtr data)
{
int length = array.Length;
#pragma warning disable IL3050 // https://github.com/dotnet/runtime/issues/97273
var abi_element_size = Marshal.SizeOf(AbiType);
var abi_element_size =
#if NET9_0_OR_GREATER
RuntimeHelpers.SizeOf(AbiType.TypeHandle);
#else
Marshal.SizeOf(AbiType);
#endif
#pragma warning restore IL3050
var byte_length = length * abi_element_size;
var bytes = (byte*)data.ToPointer();
Expand All @@ -1263,18 +1298,28 @@ public static unsafe void CopyManagedArray(T[] array, IntPtr data)

public static unsafe void DisposeAbiArrayElements((int length, IntPtr data) abi)
{
#if NET
#if NET && !NET9_0_OR_GREATER
if (!RuntimeFeature.IsDynamicCodeCompiled)
{
throw new NotSupportedException($"Cannot handle array marshalling for non blittable type '{typeof(T)}'.");
}
#endif
var data = (byte*)abi.data.ToPointer();
#pragma warning disable IL3050 // https://github.com/dotnet/runtime/issues/97273
var abi_element_size = Marshal.SizeOf(AbiType);
var abi_element_size =
#if NET9_0_OR_GREATER
RuntimeHelpers.SizeOf(AbiType.TypeHandle);
#else
Marshal.SizeOf(AbiType);
#endif
for (int i = 0; i < abi.length; i++)
{
var abi_element = Marshal.PtrToStructure((IntPtr)data, AbiType);
var abi_element =
#if NET9_0_OR_GREATER
RuntimeHelpers.Box(ref *data, AbiType.TypeHandle);
#else
Marshal.PtrToStructure((IntPtr)data, AbiType);
#endif
#pragma warning restore IL3050
Marshaler<T>.DisposeAbi(abi_element);
data += abi_element_size;
Expand Down
2 changes: 2 additions & 0 deletions src/WinRT.Runtime/Projections/IDictionary.net5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ unsafe static IDictionaryMethods()
#endif
#if NET
[UnconditionalSuppressMessage("Trimming", "IL2080", Justification = AttributeMessages.AbiTypesNeverHaveConstructors)]
[UnconditionalSuppressMessage("Trimming", "IL2081", Justification = AttributeMessages.AbiTypesNeverHaveConstructors)]
#endif
[MethodImpl(MethodImplOptions.NoInlining)]
static void InitRcwHelperFallbackIfNeeded()
Expand Down Expand Up @@ -1261,6 +1262,7 @@ static IDictionary()
#endif
#if NET
[UnconditionalSuppressMessage("Trimming", "IL2080", Justification = AttributeMessages.AbiTypesNeverHaveConstructors)]
[UnconditionalSuppressMessage("Trimming", "IL2081", Justification = AttributeMessages.AbiTypesNeverHaveConstructors)]
#endif
[MethodImpl(MethodImplOptions.NoInlining)]
static void InitFallbackCCWVTableIfNeeded()
Expand Down
3 changes: 3 additions & 0 deletions src/WinRT.Runtime/Projections/IEnumerable.net5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ static IEnumerable()
#endif
#if NET
[UnconditionalSuppressMessage("Trimming", "IL2080", Justification = AttributeMessages.AbiTypesNeverHaveConstructors)]
[UnconditionalSuppressMessage("Trimming", "IL2081", Justification = AttributeMessages.AbiTypesNeverHaveConstructors)]
#endif
[MethodImpl(MethodImplOptions.NoInlining)]
static void InitFallbackCCWVTableIfNeeded()
Expand Down Expand Up @@ -554,6 +555,7 @@ unsafe static IEnumeratorMethods()
#endif
#if NET
[UnconditionalSuppressMessage("Trimming", "IL2080", Justification = AttributeMessages.AbiTypesNeverHaveConstructors)]
[UnconditionalSuppressMessage("Trimming", "IL2081", Justification = AttributeMessages.AbiTypesNeverHaveConstructors)]
#endif
[MethodImpl(MethodImplOptions.NoInlining)]
static void InitRcwHelperFallbackIfNeeded()
Expand Down Expand Up @@ -1110,6 +1112,7 @@ static IEnumerator()
#endif
#if NET
[UnconditionalSuppressMessage("Trimming", "IL2080", Justification = AttributeMessages.AbiTypesNeverHaveConstructors)]
[UnconditionalSuppressMessage("Trimming", "IL2081", Justification = AttributeMessages.AbiTypesNeverHaveConstructors)]
#endif
[MethodImpl(MethodImplOptions.NoInlining)]
static void InitFallbackCCWVTableIfNeeded()
Expand Down
2 changes: 2 additions & 0 deletions src/WinRT.Runtime/Projections/IList.net5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ unsafe static IListMethods()
#endif
#if NET
[UnconditionalSuppressMessage("Trimming", "IL2080", Justification = AttributeMessages.AbiTypesNeverHaveConstructors)]
[UnconditionalSuppressMessage("Trimming", "IL2081", Justification = AttributeMessages.AbiTypesNeverHaveConstructors)]
#endif
[MethodImpl(MethodImplOptions.NoInlining)]
static void InitRcwHelperFallbackIfNeeded()
Expand Down Expand Up @@ -1366,6 +1367,7 @@ static IList()
#endif
#if NET
[UnconditionalSuppressMessage("Trimming", "IL2080", Justification = AttributeMessages.AbiTypesNeverHaveConstructors)]
[UnconditionalSuppressMessage("Trimming", "IL2081", Justification = AttributeMessages.AbiTypesNeverHaveConstructors)]
#endif
[MethodImpl(MethodImplOptions.NoInlining)]
static void InitFallbackCCWVTableIfNeeded()
Expand Down
2 changes: 2 additions & 0 deletions src/WinRT.Runtime/Projections/IReadOnlyDictionary.net5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ unsafe static IReadOnlyDictionaryMethods()
#endif
#if NET
[UnconditionalSuppressMessage("Trimming", "IL2080", Justification = AttributeMessages.AbiTypesNeverHaveConstructors)]
[UnconditionalSuppressMessage("Trimming", "IL2081", Justification = AttributeMessages.AbiTypesNeverHaveConstructors)]
#endif
[MethodImpl(MethodImplOptions.NoInlining)]
static void InitRcwHelperFallbackIfNeeded()
Expand Down Expand Up @@ -1092,6 +1093,7 @@ static IReadOnlyDictionary()
#endif
#if NET
[UnconditionalSuppressMessage("Trimming", "IL2080", Justification = AttributeMessages.AbiTypesNeverHaveConstructors)]
[UnconditionalSuppressMessage("Trimming", "IL2081", Justification = AttributeMessages.AbiTypesNeverHaveConstructors)]
#endif
[MethodImpl(MethodImplOptions.NoInlining)]
static void InitFallbackCCWVTableIfNeeded()
Expand Down
2 changes: 2 additions & 0 deletions src/WinRT.Runtime/Projections/IReadOnlyList.net5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ internal static unsafe bool EnsureInitialized()
#endif
#if NET
[UnconditionalSuppressMessage("Trimming", "IL2080", Justification = AttributeMessages.AbiTypesNeverHaveConstructors)]
[UnconditionalSuppressMessage("Trimming", "IL2081", Justification = AttributeMessages.AbiTypesNeverHaveConstructors)]
#endif
[MethodImpl(MethodImplOptions.NoInlining)]
static void InitRcwHelperFallbackIfNeeded()
Expand Down Expand Up @@ -645,6 +646,7 @@ static IReadOnlyList()
#endif
#if NET
[UnconditionalSuppressMessage("Trimming", "IL2080", Justification = AttributeMessages.AbiTypesNeverHaveConstructors)]
[UnconditionalSuppressMessage("Trimming", "IL2081", Justification = AttributeMessages.AbiTypesNeverHaveConstructors)]
#endif
[MethodImpl(MethodImplOptions.NoInlining)]
static void InitFallbackCCWVTableIfNeeded()
Expand Down
2 changes: 2 additions & 0 deletions src/WinRT.Runtime/Projections/KeyValuePair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ internal static unsafe bool EnsureInitialized()
#endif
#if NET
[UnconditionalSuppressMessage("Trimming", "IL2080", Justification = AttributeMessages.AbiTypesNeverHaveConstructors)]
[UnconditionalSuppressMessage("Trimming", "IL2081", Justification = AttributeMessages.AbiTypesNeverHaveConstructors)]
#endif
[MethodImpl(MethodImplOptions.NoInlining)]
static void InitRcwHelperFallbackIfNeeded()
Expand Down Expand Up @@ -396,6 +397,7 @@ static KeyValuePair()
#endif
#if NET
[UnconditionalSuppressMessage("Trimming", "IL2080", Justification = AttributeMessages.AbiTypesNeverHaveConstructors)]
[UnconditionalSuppressMessage("Trimming", "IL2081", Justification = AttributeMessages.AbiTypesNeverHaveConstructors)]
#endif
[MethodImpl(MethodImplOptions.NoInlining)]
static void InitFallbackCCWVTableIfNeeded()
Expand Down
3 changes: 3 additions & 0 deletions src/WinRT.Runtime/WinRT.Runtime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
<!-- Set remote for source link. -->
<AdoMirrorBuild Condition="'$(AdoMirrorBuild)' == ''">false</AdoMirrorBuild>
<GitRepositoryRemoteName Condition="$(AdoMirrorBuild)">github</GitRepositoryRemoteName>

<!-- Suppress warnings for using 'ref' as 'in', to simplify multi-targeting -->
<NoWarn>$(NoWarn);CS9191</NoWarn>
</PropertyGroup>

<!-- NativeAOT specific options, only starting from .NET 8 -->
Expand Down