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

Open
wants to merge 7 commits into
base: staging/2.3
Choose a base branch
from
Open
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
17 changes: 15 additions & 2 deletions build/AzurePipelineTemplates/CsWinRT-Benchmarks-Steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,23 @@ steps:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;

dotnet new globaljson --sdk-version "$($env:NET8_SDK_VERSION)"

&([scriptblock]::Create((Invoke-WebRequest -UseBasicParsing 'https://dot.net/v1/dotnet-install.ps1'))) -Version "$($env:NET8_SDK_VERSION)" -Architecture "x64" -AzureFeed "$($env:NET5_SDK_FEED)"

# Install .NET 9 SDK
- task: PowerShell@2
displayName: Install .NET 9 SDK
inputs:
targetType: inline
failOnStderr: true
script: |
Write-Host ##vso[task.setvariable variable=PATH;]${env:LocalAppData}\Microsoft\dotnet;${env:PATH};

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;

dotnet new globaljson --sdk-version "$($env:NET9_SDK_VERSION)"

&([scriptblock]::Create((Invoke-WebRequest -UseBasicParsing 'https://dot.net/v1/dotnet-install.ps1'))) -Version "$($env:NET9_SDK_VERSION)" -Architecture "x64" -AzureFeed "$($env:NET5_SDK_FEED)"

# Verify .NET SDK
- task: CmdLine@2
displayName: Verify .NET SDK
Expand Down
28 changes: 26 additions & 2 deletions build/AzurePipelineTemplates/CsWinRT-Build-Steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,23 @@ steps:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;

dotnet new globaljson --sdk-version "$($env:NET8_SDK_VERSION)"

&([scriptblock]::Create((Invoke-WebRequest -UseBasicParsing 'https://dot.net/v1/dotnet-install.ps1'))) -Version "$($env:NET8_SDK_VERSION)" -Architecture "x64" -AzureFeed "$($env:NET5_SDK_FEED)"

# Install .NET 9 SDK
- task: PowerShell@2
displayName: Install .NET 9 SDK
inputs:
targetType: inline
failOnStderr: true
script: |
Write-Host ##vso[task.setvariable variable=PATH;]${env:LocalAppData}\Microsoft\dotnet;${env:PATH};

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;

dotnet new globaljson --sdk-version "$($env:NET9_SDK_VERSION)"

&([scriptblock]::Create((Invoke-WebRequest -UseBasicParsing 'https://dot.net/v1/dotnet-install.ps1'))) -Version "$($env:NET9_SDK_VERSION)" -Architecture "x64" -AzureFeed "$($env:NET5_SDK_FEED)"

# Verify .NET SDK
- task: CmdLine@2
displayName: Verify .NET SDK
Expand Down Expand Up @@ -287,6 +300,17 @@ steps:
WinRT.Runtime.pdb
TargetFolder: $(Build.ArtifactStagingDirectory)\release_net8.0

# Stage Net9.0
- task: CopyFiles@2
displayName: Stage Net9.0
condition: and(succeeded(), eq(variables['BuildPlatform'], 'x86'), eq(variables['BuildConfiguration'], 'release'))
inputs:
SourceFolder: $(Build.SourcesDirectory)\src\WinRT.Runtime\bin\$(BuildConfiguration)\net9.0
Contents: |
WinRT.Runtime.dll
WinRT.Runtime.pdb
TargetFolder: $(Build.ArtifactStagingDirectory)\release_net9.0

# Stage WinRT.Host.Shim
- task: CopyFiles@2
displayName: Stage WinRT.Host.Shim
Expand Down
5 changes: 5 additions & 0 deletions build/AzurePipelineTemplates/CsWinRT-BuildAndTest-Stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ stages:
condition: and(succeeded(), eq(variables['BuildPlatform'], 'x86'), eq(variables['BuildConfiguration'], 'release'))
targetPath: $(Build.ArtifactStagingDirectory)\release_net8.0
artifactName: net8.0
- output: pipelineArtifact
displayName: 'Publish Net9.0'
condition: and(succeeded(), eq(variables['BuildPlatform'], 'x86'), eq(variables['BuildConfiguration'], 'release'))
targetPath: $(Build.ArtifactStagingDirectory)\release_net9.0
artifactName: net9.0

- job: Benchmarks
displayName: Run Benchmarks
Expand Down
11 changes: 10 additions & 1 deletion build/AzurePipelineTemplates/CsWinRT-PublishToNuget-Stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ stages:
itemPattern: ''
targetPath: $(Build.SourcesDirectory)\net8.0

# Download Net8.0
- task: DownloadPipelineArtifact@2
displayName: 'Download Net9.0'
inputs:
artifactName: net9.0
itemPattern: ''
targetPath: $(Build.SourcesDirectory)\net9.0

# Stage Binaries
- task: CmdLine@2
displayName: Stage Binaries
Expand Down Expand Up @@ -93,6 +101,7 @@ stages:
netstandard2.0\WinRT.SourceGenerator.dll
net8.0\WinRT.Host.Shim.dll
net8.0\WinRT.Runtime.dll
net9.0\WinRT.Runtime.dll
release_x64\WinRT.Host.dll
release_x64\WinRT.Host.dll.mui
release_x86\WinRT.Host.dll
Expand Down Expand Up @@ -221,7 +230,7 @@ stages:
command: pack
searchPatternPack: nuget/Microsoft.Windows.CsWinRT.nuspec
configurationToPack: Release
buildProperties: cswinrt_nuget_version=$(NugetVersion);cswinrt_exe=$(Build.SourcesDirectory)\cswinrt.exe;interop_winmd=$(Build.SourcesDirectory)\WinRT.Interop.winmd;netstandard2_runtime=$(Build.SourcesDirectory)\netstandard2.0\WinRT.Runtime.dll;net8_runtime=$(Build.SourcesDirectory)\net8.0\WinRT.Runtime.dll;source_generator=$(Build.SourcesDirectory)\netstandard2.0\WinRT.SourceGenerator.dll;winrt_shim=$(Build.SourcesDirectory)\net8.0\WinRT.Host.Shim.dll;winrt_host_x86=$(Build.SourcesDirectory)\release_x86\WinRT.Host.dll;winrt_host_x64=$(Build.SourcesDirectory)\release_x64\WinRT.Host.dll;winrt_host_arm64=$(Build.SourcesDirectory)\release_arm64\WinRT.Host.dll;winrt_host_resource_x86=$(Build.SourcesDirectory)\release_x86\WinRT.Host.dll.mui;winrt_host_resource_x64=$(Build.SourcesDirectory)\release_x64\WinRT.Host.dll.mui;winrt_host_resource_arm64=$(Build.SourcesDirectory)\release_arm64\WinRT.Host.dll.mui;guid_patch=$(Build.SourcesDirectory)\net8.0\IIDOptimizer\*.*
buildProperties: cswinrt_nuget_version=$(NugetVersion);cswinrt_exe=$(Build.SourcesDirectory)\cswinrt.exe;interop_winmd=$(Build.SourcesDirectory)\WinRT.Interop.winmd;netstandard2_runtime=$(Build.SourcesDirectory)\netstandard2.0\WinRT.Runtime.dll;net8_runtime=$(Build.SourcesDirectory)\net8.0\WinRT.Runtime.dll;net9_runtime=$(Build.SourcesDirectory)\net9.0\WinRT.Runtime.dll;source_generator=$(Build.SourcesDirectory)\netstandard2.0\WinRT.SourceGenerator.dll;winrt_shim=$(Build.SourcesDirectory)\net8.0\WinRT.Host.Shim.dll;winrt_host_x86=$(Build.SourcesDirectory)\release_x86\WinRT.Host.dll;winrt_host_x64=$(Build.SourcesDirectory)\release_x64\WinRT.Host.dll;winrt_host_arm64=$(Build.SourcesDirectory)\release_arm64\WinRT.Host.dll;winrt_host_resource_x86=$(Build.SourcesDirectory)\release_x86\WinRT.Host.dll.mui;winrt_host_resource_x64=$(Build.SourcesDirectory)\release_x64\WinRT.Host.dll.mui;winrt_host_resource_arm64=$(Build.SourcesDirectory)\release_arm64\WinRT.Host.dll.mui;guid_patch=$(Build.SourcesDirectory)\net8.0\IIDOptimizer\*.*

- task: NuGetCommand@2
displayName: NuGet pack
Expand Down
4 changes: 4 additions & 0 deletions build/AzurePipelineTemplates/CsWinRT-Variables.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ variables:
value: 'https://dotnetcli.blob.core.windows.net/dotnet'
- name: Net8.SDK.Version
value: '8.0.303'
- name: Net9.SDK.Version
value: '9.0.100'
- name: NoSamples
value: 'false'

Expand All @@ -26,6 +28,8 @@ variables:
value: $[coalesce(variables.RunGCStress, 'false')]
- name: _DotNetRuntimeVersion
value: $[coalesce(variables.DotNetRuntimeVersion, '8.0.303')]
- name: _DotNet9RuntimeVersion
value: $[coalesce(variables.DotNet9RuntimeVersion, '9.0.100')]
- name: _WindowsSdkVersionSuffix
value: $[coalesce(variables.WindowsSdkPackageVersionSuffix, '25')]
- name: _PublishCsWinMD
Expand Down
8 changes: 6 additions & 2 deletions nuget/Microsoft.Windows.CsWinRT.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<projectUrl>https://github.com/microsoft/cswinrt</projectUrl>
<dependencies>
<group targetFramework=".NET8.0" />
<group targetFramework=".NET9.0" />
</dependencies>
</metadata>
<files>
Expand All @@ -31,11 +32,13 @@
<file src="$interop_winmd$" target="metadata"/>
<file src="readme.txt"/>
<file src="$net8_runtime$" target="lib\net8.0\"/>
<file src="$net9_runtime$" target="lib\net9.0\"/>
<file src="$source_generator$" target="analyzers\dotnet\cs\"/>
<file src="$winrt_host_x64$" target ="hosting\x64\native"/>
<file src="$winrt_host_x86$" target ="hosting\x86\native"/>
<file src="$winrt_host_arm64$" target ="hosting\arm64\native"/>
<file src="$winrt_shim$" target ="lib\net8.0\"/>
<file src="$winrt_shim$" target ="lib\net9.0\"/>

<!-- Localized resources for error strings
The paths here leads to a folder of folders,
Expand All @@ -44,11 +47,12 @@
<file src="..\src\Authoring\WinRT.Host\MUI\**" target ="hosting\x64\native"/>
<file src="..\src\Authoring\WinRT.Host\MUI\**" target ="hosting\x86\native"/>
<file src="..\src\Authoring\WinRT.Host\MUI\**" target ="hosting\arm64\native"/>
<file src="$winrt_host_resource_x64$" target ="hosting\x64\native\en-US"/>
<file src="$winrt_host_resource_x86$" target ="hosting\x86\native\en-US"/>
<file src="$winrt_host_resource_x64$" target ="hosting\x64\native\en-US"/>
<file src="$winrt_host_resource_x86$" target ="hosting\x86\native\en-US"/>
<file src="$winrt_host_resource_arm64$" target ="hosting\arm64\native\en-US"/>

<file src="..\src\WinRT.Runtime\ResX\**" target ="lib\net8.0\"/>
<file src="..\src\WinRT.Runtime\ResX\**" target ="lib\net9.0\"/>
<file src="..\src\Authoring\WinRT.SourceGenerator\ResX\**" target ="analyzers\dotnet\cs\"/>

<!-- Add the WinRT.Runtime sources to the pkg for embedded scenarios -->
Expand Down
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;net8.0</AppBuildTFMs>
<AppBuildTFMs Condition="'$(CIBuildReason)' == 'CI'">netcoreapp3.1;net8.0</AppBuildTFMs>
<LibBuildTFMs>netstandard2.0;net8.0</LibBuildTFMs>
<LibBuildTFMs>netstandard2.0;net8.0;net9.0</LibBuildTFMs>
<LibBuildTFMs Condition="'$(CIBuildReason)' == 'CI'">netstandard2.0;net8.0</LibBuildTFMs>
<LibBuildTFMsNoNetStandard>net8.0</LibBuildTFMsNoNetStandard>
<LibBuildTFMsNoNetStandard>net8.0;net9.0</LibBuildTFMsNoNetStandard>
<LibBuildTFMsNoNetStandard Condition="'$(CIBuildReason)' == 'CI'">net8.0</LibBuildTFMsNoNetStandard>
<TestsBuildTFMs>net8.0-windows10.0.19041.0</TestsBuildTFMs>
<TestsBuildTFMs Condition="'$(CIBuildReason)' == 'CI'">net8.0-windows10.0.19041.0</TestsBuildTFMs>
Expand Down
2 changes: 2 additions & 0 deletions src/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

<ItemGroup>
<FrameworkReference Remove="Microsoft.Windows.SDK.NET.Ref" />
<FrameworkReference Remove="Microsoft.Windows.SDK.NET.Ref.Windows" />
<FrameworkReference Remove="Microsoft.Windows.SDK.NET.Ref.Xaml" />
</ItemGroup>

<Import Condition="'$(MSBuildProjectExtension)' == '.csproj' and '$(SimulateCsWinRTNugetReference)' == 'true'" Project="..\nuget\Microsoft.Windows.CsWinRT.targets" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
</ItemGroup>
<ItemGroup>
<FrameworkReference Remove="Microsoft.Windows.SDK.NET.Ref" />
<FrameworkReference Remove="Microsoft.Windows.SDK.NET.Ref.Windows" />
<FrameworkReference Remove="Microsoft.Windows.SDK.NET.Ref.Xaml" />
<RuntimeHostConfigurationOption Include="System.Runtime.Loader.UseRidGraph" Value="true" />
</ItemGroup>
<ItemGroup>
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 @@ -1092,7 +1092,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 @@ -1108,7 +1108,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 @@ -1140,7 +1145,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 @@ -1158,10 +1163,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 @@ -1171,7 +1186,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 @@ -1184,10 +1199,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 @@ -1196,7 +1221,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 @@ -1213,7 +1238,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 @@ -1237,7 +1267,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 @@ -1254,7 +1284,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 @@ -1278,18 +1313,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 @@ -300,6 +300,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 @@ -1299,6 +1300,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
Loading
Loading