1
0
Fork 0
mirror of https://github.com/VSadov/Satori.git synced 2025-06-09 09:34:49 +09:00

Basic infrastructure to enable DllImportGenerator (#52486)

This commit is contained in:
Elinor Fung 2021-05-10 12:48:18 -07:00 committed by GitHub
parent 74cafe71de
commit 757002794e
Signed by: github
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 116 additions and 1 deletions

View file

@ -9,6 +9,7 @@
<Import Project="Sdk.targets" Sdk="Microsoft.DotNet.Arcade.Sdk" />
<Import Project="$(RepositoryEngineeringDir)liveBuilds.targets" />
<Import Project="$(RepositoryEngineeringDir)generators.targets" />
<Import Project="$(RepositoryEngineeringDir)python.targets" />
<PropertyGroup>

View file

@ -19,6 +19,8 @@
<add key="dotnet6-transport" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6-transport/nuget/v3/index.json" />
<!-- Used for the Rich Navigation indexing task -->
<add key="richnav" value="https://pkgs.dev.azure.com/azure-public/vside/_packaging/vs-buildservices/nuget/v3/index.json" />
<!-- Used for DllImportGenerator -->
<add key="dotnet-experimental" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-experimental/nuget/v3/index.json" />
</packageSources>
<disabledPackageSources>
<clear />

View file

@ -168,6 +168,8 @@
<runtimewinx64MicrosoftNETCoreRuntimeMonoLLVMToolsVersion>9.0.1-alpha.1.21253.1</runtimewinx64MicrosoftNETCoreRuntimeMonoLLVMToolsVersion>
<runtimeosx1012x64MicrosoftNETCoreRuntimeMonoLLVMSdkVersion>9.0.1-alpha.1.21253.1</runtimeosx1012x64MicrosoftNETCoreRuntimeMonoLLVMSdkVersion>
<runtimeosx1012x64MicrosoftNETCoreRuntimeMonoLLVMToolsVersion>9.0.1-alpha.1.21253.1</runtimeosx1012x64MicrosoftNETCoreRuntimeMonoLLVMToolsVersion>
<!-- Experimental -->
<MicrosoftInteropDllImportGeneratorVersion>1.0.0-alpha.21258.2</MicrosoftInteropDllImportGeneratorVersion>
</PropertyGroup>
<!-- Override isolated build dependency versions with versions from Repo API. -->
<Import Project="$(DotNetPackageVersionPropsPath)" Condition="'$(DotNetPackageVersionPropsPath)' != ''" />

35
eng/generators.targets Normal file
View file

@ -0,0 +1,35 @@
<Project InitialTargets="ConfigureGenerators">
<Target Name="ConfigureGenerators"
DependsOnTargets="ConfigureDllImportGenerator" />
<!-- Microsoft.Interop.DllImportGenerator -->
<Target Name="ConfigureDllImportGenerator" DependsOnTargets="EnableDllImportGeneratorForNetCoreApp">
<PropertyGroup Condition="'$(EnableDllImportGenerator)' == 'true'">
<DllImportGenerator_UseMarshalType>true</DllImportGenerator_UseMarshalType>
</PropertyGroup>
<ItemGroup Condition="'$(EnableDllImportGenerator)' == 'true' and $([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">
<PackageReference Include="Microsoft.Interop.DllImportGenerator" Version="$(MicrosoftInteropDllImportGeneratorVersion)" PrivateAssets="all" />
<!-- For testing purposes, compile sources files with attributes directly into the project.
This is mimicking the case where the source generator always generates the attributes. -->
<Compile Include="$(LibrariesProjectRoot)Common/src/System/Runtime/InteropServices/GeneratedDllImportAttribute.cs" />
<Compile Include="$(LibrariesProjectRoot)Common/src/System/Runtime/InteropServices/GeneratedMarshallingAttribute.cs" />
</ItemGroup>
</Target>
<Target Name="EnableDllImportGeneratorForNetCoreApp"
Condition="'$(EnableDllImportGenerator)' == ''
and ('$(IsNetCoreAppSrc)' == 'true' or '$(MSBuildProjectName)' == 'System.Private.CoreLib')
and '$(MSBuildProjectExtension)' == '.csproj'">
<PropertyGroup>
<!-- Enable DllImportGenerator by default for System.Private.CoreLib -->
<EnableDllImportGenerator Condition="'$(MSBuildProjectName)' == 'System.Private.CoreLib'">true</EnableDllImportGenerator>
<!-- Enable DllImportGenerator by default for NETCoreApp libraries that reference either System.Runtime.InteropServices or System.Private.CoreLib -->
<EnableDllImportGenerator Condition="'@(Reference)' != '' and @(Reference->AnyHaveMetadataValue('Identity', 'System.Runtime.InteropServices'))">true</EnableDllImportGenerator>
<EnableDllImportGenerator Condition="'@(ProjectReference)' != '' and @(ProjectReference->AnyHaveMetadataValue('Identity', '$(CoreLibProject)'))">true</EnableDllImportGenerator>
</PropertyGroup>
</Target>
</Project>

View file

@ -0,0 +1,34 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#nullable enable
//
// Types in this file are used for generated p/invokes (docs/design/features/source-generator-pinvokes.md).
// See the DllImportGenerator experiment in https://github.com/dotnet/runtimelab.
//
namespace System.Runtime.InteropServices
{
/// <summary>
/// Indicates that method will be generated at compile time and invoke into an unmanaged library entry point
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
internal sealed class GeneratedDllImportAttribute : Attribute
{
public bool BestFitMapping { get; set; }
public CallingConvention CallingConvention { get; set; }
public CharSet CharSet { get; set; }
public string? EntryPoint { get; set; }
public bool ExactSpelling { get; set; }
public bool PreserveSig { get; set; }
public bool SetLastError { get; set; }
public bool ThrowOnUnmappableChar { get; set; }
public GeneratedDllImportAttribute(string dllName)
{
this.Value = dllName;
}
public string Value { get; private set; }
}
}

View file

@ -0,0 +1,41 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//
// Types in this file are used for generated p/invokes (docs/design/features/source-generator-pinvokes.md).
// See the DllImportGenerator experiment in https://github.com/dotnet/runtimelab.
//
namespace System.Runtime.InteropServices
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)]
internal class GeneratedMarshallingAttribute : Attribute
{
}
[AttributeUsage(AttributeTargets.Struct)]
internal class BlittableTypeAttribute : Attribute
{
}
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class)]
internal class NativeMarshallingAttribute : Attribute
{
public NativeMarshallingAttribute(Type nativeType)
{
NativeType = nativeType;
}
public Type NativeType { get; }
}
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.Field)]
internal class MarshalUsingAttribute : Attribute
{
public MarshalUsingAttribute(Type nativeType)
{
NativeType = nativeType;
}
public Type NativeType { get; }
}
}