-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hook up DllImportGenerator to the libraries build (excluding solution…
… file regeneration). Move System.Runtime.InteropServices unit tests to a subdirectory.
- Loading branch information
1 parent
fc18f4d
commit 4cfb51f
Showing
211 changed files
with
212 additions
and
377 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,77 @@ | ||
<Project InitialTargets="ConfigureGenerators"> | ||
<Project> | ||
|
||
<PropertyGroup> | ||
<EnableDllImportGenerator Condition="'$(EnableDllImportGenerator)' == '' | ||
and '$(MSBuildProjectName)' == 'System.Private.CoreLib'">true</EnableDllImportGenerator> | ||
<SetDllImportGeneratorConstants>false</SetDllImportGeneratorConstants> | ||
<IncludeDllImportGeneratorSources Condition="'$(IncludeDllImportGeneratorSources)' == ''">true</IncludeDllImportGeneratorSources> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<EnabledGenerators Include="DllImportGenerator" Condition="'$(EnableDllImportGenerator)' == 'true'" /> | ||
<!-- If the current project is not System.Private.CoreLib, we enable the DllImportGenerator source generator | ||
when the project is a C# source project that either: | ||
- references System.Private.CoreLib, or | ||
- references the following assemblies: | ||
- System.Runtime.InteropServices | ||
- System.Runtime.CompilerServices.Unsafe | ||
- System.Memory --> | ||
<EnabledGenerators Include="DllImportGenerator" | ||
Condition="'$(EnableDllImportGenerator)' == '' | ||
and '$(IsFrameworkSupportFacade)' != 'true' | ||
and '$(IsNetCoreAppSrc)' == 'true' | ||
and '$(MSBuildProjectExtension)' == '.csproj' | ||
and ( | ||
('@(Reference)' != '' | ||
and @(Reference->AnyHaveMetadataValue('Identity', 'System.Runtime.InteropServices')) | ||
and @(Reference->AnyHaveMetadataValue('Identity', 'System.Runtime.CompilerServices.Unsafe')) | ||
and @(Reference->AnyHaveMetadataValue('Identity', 'System.Memory'))) | ||
or ('@(ProjectReference)' != '' | ||
and @(ProjectReference->AnyHaveMetadataValue('Identity', '$(CoreLibProject)'))))" /> | ||
</ItemGroup> | ||
|
||
<!-- Use this complex ItemGroup-based filtering to add the ProjectReference to make sure dotnet/runtime stays compatible with NuGet Static Graph Restore. --> | ||
<ItemGroup Condition="'@(EnabledGenerators)' != '' | ||
and @(EnabledGenerators->AnyHaveMetadataValue('Identity', 'DllImportGenerator')) | ||
and '$(IncludeDllImportGeneratorSources)' == 'true'"> | ||
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> | ||
<Compile Include="$(LibrariesProjectRoot)Common/src/System/Runtime/InteropServices/GeneratedDllImportAttribute.cs" /> | ||
<Compile Include="$(LibrariesProjectRoot)Common/src/System/Runtime/InteropServices/GeneratedMarshallingAttribute.cs" /> | ||
<Compile Include="$(LibrariesProjectRoot)Common/src/System/Runtime/InteropServices/ArrayMarshaller.cs" /> | ||
</ItemGroup> | ||
|
||
<Target Name="ConfigureGenerators" | ||
DependsOnTargets="ConfigureDllImportGenerator" /> | ||
DependsOnTargets="ConfigureDllImportGenerator" | ||
BeforeTargets="CoreCompile" /> | ||
|
||
<!-- Microsoft.Interop.DllImportGenerator --> | ||
<Target Name="ConfigureDllImportGenerator" DependsOnTargets="EnableDllImportGeneratorForNetCoreApp"> | ||
<PropertyGroup Condition="'$(EnableDllImportGenerator)' == 'true'"> | ||
<Target Name="ConfigureDllImportGenerator" | ||
Condition="'@(EnabledGenerators)' != '' and @(EnabledGenerators->AnyHaveMetadataValue('Identity', 'DllImportGenerator'))" | ||
DependsOnTargets="ResolveReferences" | ||
BeforeTargets="GenerateMSBuildEditorConfigFileShouldRun"> | ||
<PropertyGroup> | ||
<DllImportGenerator_UseMarshalType>true</DllImportGenerator_UseMarshalType> | ||
</PropertyGroup> | ||
<!-- Projects that directly reference System.Private.CoreLib are typically low level enough that they don't reference | ||
System.Runtime.CompilerServices.Unsafe, so we use the Unsafe type defined in CoreLib (Internal.Runtime.CompilerServices.Unsafe) for these projects. --> | ||
<PropertyGroup Condition="'$(MSBuildProjectName)' == 'System.Private.CoreLib' or | ||
('@(ProjectReference)' != '' and @(ProjectReference->AnyHaveMetadataValue('Identity', '$(CoreLibProject)')))"> | ||
<DllImportGenerator_UseInternalUnsafeType>true</DllImportGenerator_UseInternalUnsafeType> | ||
<DefineConstants>$(DefineConstants);DLLIMPORTGENERATOR_INTERNALUNSAFE</DefineConstants> | ||
</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" /> | ||
<Compile Include="$(LibrariesProjectRoot)Common/src/System/Runtime/InteropServices/ArrayMarshaller.cs" /> | ||
</ItemGroup> | ||
</Target> | ||
<MSBuild Projects="$(LibrariesProjectRoot)System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.csproj"> | ||
<Output TaskParameter="TargetOutputs" PropertyName="DllImportGeneratorOutputPath" /> | ||
</MSBuild> | ||
|
||
<Target Name="EnableDllImportGeneratorForNetCoreApp" | ||
Condition="'$(EnableDllImportGenerator)' == '' | ||
and '$(IsFrameworkSupportFacade)' != 'true' | ||
and ('$(IsNetCoreAppSrc)' == 'true' or '$(MSBuildProjectName)' == 'System.Private.CoreLib') | ||
and '$(MSBuildProjectExtension)' == '.csproj'"> | ||
<!-- We add the copy of Microsoft.Interop.SourceGeneration.dll that lives next to Microsoft.Interop.DllImportGenerator.dll | ||
to work around https://github.com/dotnet/roslyn/issues/56442 --> | ||
<ItemGroup> | ||
<Analyzer Include="$([MSBuild]::NormalizePath('$([System.IO.Path]::GetDirectoryName('$(DllImportGeneratorOutputPath)'))', 'Microsoft.Interop.SourceGeneration.dll'))" /> | ||
</ItemGroup> | ||
<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')) | ||
and @(Reference->AnyHaveMetadataValue('Identity', 'System.Runtime.CompilerServices.Unsafe')) | ||
and @(Reference->AnyHaveMetadataValue('Identity', 'System.Memory'))">true</EnableDllImportGenerator> | ||
<EnableDllImportGenerator Condition="'@(ProjectReference)' != '' and @(ProjectReference->AnyHaveMetadataValue('Identity', '$(CoreLibProject)'))">true</EnableDllImportGenerator> | ||
<DefineConstants>$(DefineConstants);DLLIMPORTGENERATOR_ENABLED</DefineConstants> | ||
</PropertyGroup> | ||
</Target> | ||
|
||
<Import Project="$(LibrariesProjectRoot)System.Runtime.InteropServices/gen/DllImportGenerator/Microsoft.Interop.DllImportGenerator.props" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/libraries/System.Runtime.InteropServices/gen/Directory.Build.props
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project> | ||
<Import Project="..\Directory.Build.props" /> | ||
<PropertyGroup> | ||
<IsShipping>false</IsShipping> | ||
<IsPackable>false</IsPackable> | ||
<!-- We manually enable DllImportGenerator for projects in this folder as part of testing. --> | ||
<EnableDllImportGenerator>false</EnableDllImportGenerator> | ||
<EnableDefaultItems>true</EnableDefaultItems> | ||
<CLSCompliant>false</CLSCompliant> | ||
<ILLinkTrimAssembly>false</ILLinkTrimAssembly> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.