Skip to content

Commit 2dff7cd

Browse files
authored
Dllimport generator build and test fixes (#59658)
1 parent d81945e commit 2dff7cd

File tree

21 files changed

+206
-26
lines changed

21 files changed

+206
-26
lines changed

eng/Versions.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
<XunitPerformanceApiPackageVersion>1.0.0-beta-build0015</XunitPerformanceApiPackageVersion>
145145
<MicrosoftDiagnosticsToolsRuntimeClientVersion>1.0.4-preview6.19326.1</MicrosoftDiagnosticsToolsRuntimeClientVersion>
146146
<MicrosoftDiagnosticsNETCoreClientVersion>0.2.61701</MicrosoftDiagnosticsNETCoreClientVersion>
147-
<DNNEVersion>1.0.23</DNNEVersion>
147+
<DNNEVersion>1.0.26</DNNEVersion>
148148
<!--
149149
These are used as reference assemblies only, so they must not take a ProdCon/source-build
150150
version. Insert "RefOnly" to avoid assignment via PVP.

eng/generators.targets

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
<ItemGroup Condition="'@(EnabledGenerators)' != ''
3434
and @(EnabledGenerators->AnyHaveMetadataValue('Identity', 'DllImportGenerator'))
3535
and '$(IncludeDllImportGeneratorSources)' == 'true'">
36-
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
37-
<Compile Include="$(LibrariesProjectRoot)Common/src/System/Runtime/InteropServices/GeneratedDllImportAttribute.cs" />
38-
<Compile Include="$(LibrariesProjectRoot)Common/src/System/Runtime/InteropServices/GeneratedMarshallingAttribute.cs" />
39-
<Compile Include="$(LibrariesProjectRoot)Common/src/System/Runtime/InteropServices/ArrayMarshaller.cs" />
36+
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices\gen\DllImportGenerator\DllImportGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
37+
<Compile Include="$(LibrariesProjectRoot)Common\src\System\Runtime\InteropServices\GeneratedDllImportAttribute.cs" />
38+
<Compile Include="$(LibrariesProjectRoot)Common\src\System\Runtime\InteropServices\GeneratedMarshallingAttribute.cs" />
39+
<Compile Include="$(LibrariesProjectRoot)Common\src\System\Runtime\InteropServices\ArrayMarshaller.cs" />
4040
</ItemGroup>
4141

4242
<Target Name="ConfigureGenerators"
@@ -59,7 +59,7 @@
5959
<DefineConstants>$(DefineConstants);DLLIMPORTGENERATOR_INTERNALUNSAFE</DefineConstants>
6060
</PropertyGroup>
6161

62-
<MSBuild Projects="$(LibrariesProjectRoot)System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.csproj"
62+
<MSBuild Projects="$(LibrariesProjectRoot)System.Runtime.InteropServices\gen\DllImportGenerator\DllImportGenerator.csproj"
6363
RemoveProperties="TargetFramework">
6464
<Output TaskParameter="TargetOutputs" PropertyName="DllImportGeneratorOutputPath" />
6565
</MSBuild>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Output the toolchain information required to create a command line that builds with the right rootfs as XML
2+
3+
set (ADDED_COMPILE_OPTIONS)
4+
if (CMAKE_SCRIPT_MODE_FILE)
5+
# add_compile_options and add_definitions can't be used in scripts,
6+
# so override the implementations to append to a local property
7+
macro(add_compile_options)
8+
list(APPEND ADDED_COMPILE_OPTIONS ${ARGV})
9+
endmacro()
10+
macro(add_definitions)
11+
list(APPEND ADDED_COMPILE_OPTIONS ${ARGV})
12+
endmacro()
13+
endif()
14+
15+
include(${CMAKE_CURRENT_LIST_DIR}/../common/cross/toolchain.cmake)
16+
17+
message("<toolchain-info>")
18+
message("<target-triple>${TOOLCHAIN}</target-triple>")
19+
message("<linker-args>${CMAKE_SHARED_LINKER_FLAGS_INIT}</linker-args>")
20+
message("<compiler-args>${ADDED_COMPILE_OPTIONS}</compiler-args>")
21+
message("</toolchain-info>")

src/libraries/Common/src/Interop/Windows/Kernel32/Interop.CloseHandle.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@ internal static partial class Interop
88
{
99
internal static partial class Kernel32
1010
{
11-
#if DLLIMPORTGENERATOR_ENABLED
12-
[GeneratedDllImport(Libraries.Kernel32, SetLastError = true)]
13-
internal static partial bool CloseHandle(IntPtr handle);
14-
#else
11+
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
12+
// Disabled since CloseHandle is a QCall in some scenarios and DllImportGenerator doesn't support QCalls.
1513
[DllImport(Libraries.Kernel32, SetLastError = true)]
1614
internal static extern bool CloseHandle(IntPtr handle);
17-
#endif
1815
}
1916
}

src/libraries/Common/src/Interop/Windows/Kernel32/Interop.FormatMessage.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,18 @@ internal static partial class Kernel32
1515
private const int FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100;
1616
private const int ERROR_INSUFFICIENT_BUFFER = 0x7A;
1717

18-
#if DLLIMPORTGENERATOR_ENABLED
19-
[GeneratedDllImport(Libraries.Kernel32, EntryPoint = "FormatMessageW", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
20-
private static unsafe partial int FormatMessage(
21-
#else
18+
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
19+
// Disabled since FormatMessage is a QCall in some scenarios and DllImportGenerator doesn't support QCalls.
2220
[DllImport(Libraries.Kernel32, EntryPoint = "FormatMessageW", BestFitMapping = true, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
2321
private static extern unsafe int FormatMessage(
24-
#endif
2522
int dwFlags,
2623
IntPtr lpSource,
2724
uint dwMessageId,
2825
int dwLanguageId,
2926
void* lpBuffer,
3027
int nSize,
3128
IntPtr arguments);
29+
#pragma warning restore DLLIMPORTGENANALYZER015
3230

3331
/// <summary>
3432
/// Returns a string message for the specified Win32 error code.

src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetFullPathNameW.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ internal static partial class Kernel32
1616
internal static partial uint GetFullPathNameW(
1717
#else
1818
[DllImport(Libraries.Kernel32, BestFitMapping = false, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
19-
internal static extern uint GetFullPathNameW(
2019
#endif
20+
internal static extern uint GetFullPathNameW(
2121
ref char lpFileName,
2222
uint nBufferLength,
2323
ref char lpBuffer,

src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetLongPathNameW.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ internal static partial class Kernel32
1515
internal static partial uint GetLongPathNameW(
1616
#else
1717
[DllImport(Libraries.Kernel32, BestFitMapping = false, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
18-
internal static extern uint GetLongPathNameW(
1918
#endif
19+
internal static extern uint GetLongPathNameW(
2020
ref char lpszShortPath,
2121
ref char lpszLongPath,
2222
uint cchBuffer);
23+
2324
}
2425
}

src/libraries/System.IO.Compression.ZipFile/tests/System.IO.Compression.ZipFile.Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3+
<EnableDllImportGenerator>true</EnableDllImportGenerator>
4+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
35
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser</TargetFrameworks>
46
</PropertyGroup>
57
<ItemGroup>

src/libraries/System.IO.FileSystem/tests/DisabledFileLockingTests/System.IO.FileSystem.DisabledFileLocking.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<PropertyGroup>
33
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
44
<IncludeRemoteExecutor>true</IncludeRemoteExecutor>
5+
<EnableDllImportGenerator>true</EnableDllImportGenerator>
56
<!-- file locking can't be disabled on Windows -->
67
<TargetFrameworks>$(NetCoreAppCurrent)-Unix</TargetFrameworks>
78

src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
88
<IncludeRemoteExecutor>true</IncludeRemoteExecutor>
99
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Linux;$(NetCoreAppCurrent)-Browser;$(NetCoreAppCurrent)-OSX</TargetFrameworks>
10+
<EnableDllImportGenerator>true</EnableDllImportGenerator>
1011
</PropertyGroup>
1112

1213
<ItemGroup>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Xunit;
5+
6+
// We build the libraries tests in CI once per target OS+Arch+Configuration, but we share it between runtime test runs.
7+
// As a result, we need to exclude the Mono run here since we build the tests once for CoreCLR and Mono for desktop test runs.
8+
// We should switch this to another mechanism in the future so we don't submit a work item of this assembly that skips every test
9+
// for Mono-on-Desktop-Platforms test runs.
10+
[assembly:ActiveIssue("https://github.com/dotnet/runtime/issues/59815", TestRuntimes.Mono)]

src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/DllImportGenerator.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
3+
<TargetFrameworks>$(NetCoreAppCurrent)</TargetFrameworks>
44
<IsPackable>false</IsPackable>
55
<LangVersion>Preview</LangVersion>
66
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/FunctionPointerTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ partial class NativeExportsNE
1313
{
1414
public partial class FunctionPointer
1515
{
16-
[GeneratedDllImport(NativeExportsNE_Binary, EntryPoint = "invoke_callback_after_gc")]
16+
[GeneratedDllImport(NativeExportsNE_Binary, EntryPoint = "invoke_managed_callback_after_gc")]
1717
public static unsafe partial void InvokeAfterGC(delegate* <void> cb);
1818

1919
[GeneratedDllImport(NativeExportsNE_Binary, EntryPoint = "invoke_callback_after_gc")]
@@ -22,7 +22,7 @@ public partial class FunctionPointer
2222
[GeneratedDllImport(NativeExportsNE_Binary, EntryPoint = "invoke_callback_after_gc")]
2323
public static unsafe partial void InvokeAfterGC(delegate* unmanaged[Stdcall]<void> cb);
2424

25-
[GeneratedDllImport(NativeExportsNE_Binary, EntryPoint = "invoke_callback_blittable_args")]
25+
[GeneratedDllImport(NativeExportsNE_Binary, EntryPoint = "invoke_managed_callback_blittable_args")]
2626
public static unsafe partial int InvokeWithBlittableArgument(delegate* <int, int, int> cb, int a, int b);
2727

2828
[GeneratedDllImport(NativeExportsNE_Binary, EntryPoint = "invoke_callback_blittable_args")]

src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/DllImportGenerator.UnitTests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
4+
<TargetFrameworks>$(NetCoreAppCurrent)</TargetFrameworks>
55
<IsPackable>false</IsPackable>
66
<LangVersion>Preview</LangVersion>
77
<Nullable>enable</Nullable>

src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/DelegatesAndFunctionPointers.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,31 @@ public static void InvokeCallbackAfterGCCollect(delegate* unmanaged<void> fptr)
2323
fptr();
2424
}
2525

26+
[UnmanagedCallersOnly(EntryPoint = "invoke_managed_callback_after_gc")]
27+
public static void InvokeManagedCallbackAfterGCCollect(void* fptr)
28+
{
29+
// We are at the mercy of the GC to verify our delegate has been retain
30+
// across the native function call. This is a best effort validation.
31+
for (int i = 0; i < 5; ++i)
32+
{
33+
GC.Collect();
34+
GC.WaitForPendingFinalizers();
35+
}
36+
37+
// If the corresponding Delegate was collected, the runtime will rudely abort.
38+
((delegate*<void>)fptr)();
39+
}
40+
2641
[UnmanagedCallersOnly(EntryPoint = "invoke_callback_blittable_args")]
2742
public static int InvokeCallbackWithBlittableArgument(delegate* unmanaged<int, int, int> fptr, int a, int b)
2843
{
2944
return fptr(a, b);
3045
}
46+
47+
[UnmanagedCallersOnly(EntryPoint = "invoke_managed_callback_blittable_args")]
48+
public static int InvokeManagedCallbackWithBlittableArgument(void* fptr, int a, int b)
49+
{
50+
return ((delegate*<int, int, int>)fptr)(a, b);
51+
}
3152
}
3253
}

src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
<EnableDynamicLoading>true</EnableDynamicLoading>
88
<DnneAddGeneratedBinaryToProject>true</DnneAddGeneratedBinaryToProject>
99
<DnneGenRollForward>Major</DnneGenRollForward>
10+
<!-- To integrate with DNNE's architecture calculation, we need to set the RID for this project. -->
11+
<RuntimeIdentifier>$(OutputRid)</RuntimeIdentifier>
12+
<AppHostRuntimeIdentifier>$(OutputRid)</AppHostRuntimeIdentifier>
1013
</PropertyGroup>
1114

1215
<ItemGroup>
@@ -17,4 +20,97 @@
1720
<ProjectReference Include="..\SharedTypes\SharedTypes.csproj" />
1821
</ItemGroup>
1922

23+
<Target Name="GetLinuxCrossBuildArgumentsForDNNE"
24+
Condition="'$(CrossBuild)' == 'true' and (
25+
'$(TargetOS)' == 'Linux' or
26+
'$(TargetOS)' == 'NetBSD' or
27+
'$(TargetOS)' == 'FreeBSD' or
28+
'$(TargetOS)' == 'illumos' or
29+
'$(TargetOS)' == 'Solaris')">
30+
<PropertyGroup>
31+
<NativeCompiler>$(Compiler)</NativeCompiler>
32+
<NativeCompiler Condition="'$(NativeCompiler)' == ''">clang</NativeCompiler>
33+
</PropertyGroup>
34+
35+
<Exec Command="bash -c 'source &quot;$(RepositoryEngineeringDir)/common/native/init-compiler.sh&quot; &quot;$(RepositoryEngineeringDir)/common/native&quot; $(TargetArchitecture) $(NativeCompiler) &amp;&amp; echo $CC '"
36+
EchoOff="true"
37+
ConsoleToMsBuild="true"
38+
StandardOutputImportance="Low">
39+
<Output TaskParameter="ConsoleOutput" PropertyName="DnneCompilerCommand" />
40+
</Exec>
41+
<Exec Command="cmake -P &quot;$(RepositoryEngineeringDir)/native/output-toolchain-info.cmake&quot;"
42+
EchoOff="true"
43+
ConsoleToMsBuild="true"
44+
StandardOutputImportance="Low"
45+
EnvironmentVariables="TARGET_BUILD_ARCH=$(TargetArchitecture)">
46+
<Output TaskParameter="ConsoleOutput" PropertyName="CrossTargetXml" />
47+
</Exec>
48+
49+
<XmlPeek XmlContent="$(CrossTargetXml)" Query="toolchain-info/target-triple/text()">
50+
<Output TaskParameter="Result" PropertyName="TargetTriple" />
51+
</XmlPeek>
52+
<XmlPeek XmlContent="$(CrossTargetXml)" Query="toolchain-info/linker-args/text()">
53+
<Output TaskParameter="Result" PropertyName="DnneLinkerUserFlags" />
54+
</XmlPeek>
55+
<XmlPeek XmlContent="$(CrossTargetXml)" Query="toolchain-info/compiler-args/text()">
56+
<Output TaskParameter="Result" PropertyName="DnneCompilerUserFlags" />
57+
</XmlPeek>
58+
59+
<PropertyGroup>
60+
<CommonToolchainArgs>--target=$(TargetTriple) --gcc-toolchain=$(ROOTFS_DIR)/usr --sysroot=$(ROOTFS_DIR)</CommonToolchainArgs>
61+
<DnneLinkerUserFlags>$(CommonToolchainArgs) $(DnneLinkerUserFlags.Replace(';',' '))</DnneLinkerUserFlags>
62+
<DnneCompilerUserFlags>$(CommonToolchainArgs) $(DnneCompilerUserFlags.Replace(';',' '))</DnneCompilerUserFlags>
63+
</PropertyGroup>
64+
</Target>
65+
66+
<Target Name="GetAppleCrossBuildArgumentsForDNNE"
67+
Condition="'$(TargetOS)' == 'OSX' or
68+
'$(TargetOS)' == 'MacCatalyst' or
69+
'$(TargetOS)' == 'iOS' or
70+
'$(TargetOS)' == 'iOSSimulator' or
71+
'$(TargetOS)' == 'tvOS' or
72+
'$(TargetOS)' == 'tvOSSimulator'">
73+
<PropertyGroup Condition=" '$(TargetOS)' == 'MacCatalyst'">
74+
<TargetTriple Condition="'$(TargetArchitecture)' == 'arm64'">arm64-apple-ios14.2-macabi</TargetTriple>
75+
<TargetTriple Condition="'$(TargetArchitecture)' == 'x64'">x86_64-apple-ios13.5-macabi</TargetTriple>
76+
</PropertyGroup>
77+
<PropertyGroup Condition="'$(TargetOS)' == 'OSX'">
78+
<TargetTriple Condition="'$(TargetArchitecture)' == 'arm64'">arm64-apple-macos11</TargetTriple>
79+
<TargetTriple Condition="'$(TargetArchitecture)' == 'x64'">x86_64-apple-macos10.13</TargetTriple>
80+
<XCodeSdkName>macosx</XCodeSdkName>
81+
</PropertyGroup>
82+
83+
<Error Condition="'$(TargetTriple)' == ''" Text="A target triple was not specified for the native components build. Update the 'GetAppleCrossBuildArgumentsForDNNE' target to specify a triple." />
84+
<Error Condition="'$(XCodeSdkName)' == ''" Text="The name of the XCode SDK for the target platform, as passed to xcrun to locate the sdk, must be specified." />
85+
86+
<!-- xcrun is used to locate the XCode SDKs and tools within them. See the xcrun manpage for usage information. -->
87+
<Exec Command="xcrun --sdk $(XCodeSdkName) --show-sdk-path"
88+
EchoOff="true"
89+
ConsoleToMsBuild="true"
90+
StandardOutputImportance="Low">
91+
<Output TaskParameter="ConsoleOutput" PropertyName="SysRootIncludePath" />
92+
</Exec>
93+
94+
<Exec Command="xcrun --sdk $(XCodeSdkName) --find clang"
95+
EchoOff="true"
96+
ConsoleToMsBuild="true"
97+
StandardOutputImportance="Low">
98+
<Output TaskParameter="ConsoleOutput" PropertyName="DnneCompilerCommand" />
99+
</Exec>
100+
101+
<PropertyGroup>
102+
<DnneLinkerUserFlags>-target $(TargetTriple)</DnneLinkerUserFlags>
103+
<DnneCompilerUserFlags>-isysroot &quot;$(SysRootIncludePath)&quot; -target $(TargetTriple)</DnneCompilerUserFlags>
104+
</PropertyGroup>
105+
</Target>
106+
107+
<Target Name="GetBuildArgumentsForDNNE"
108+
DependsOnTargets="ResolveFrameworkReferences;
109+
GetLinuxCrossBuildArgumentsForDNNE;
110+
GetAppleCrossBuildArgumentsForDNNE"
111+
BeforeTargets="DnneBuildNativeExports">
112+
<PropertyGroup>
113+
<DnneNetHostDir>$([System.IO.Path]::GetDirectoryName('$(AppHostSourcePath)'))</DnneNetHostDir>
114+
</PropertyGroup>
115+
</Target>
20116
</Project>

src/libraries/tests.proj

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@
3232
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Transactions.Local\tests\System.Transactions.Local.Tests.csproj" />
3333
</ItemGroup>
3434

35+
<ItemGroup Condition="'$(TargetsMobile)' == 'true'">
36+
<!-- DllImportGenerator runtime tests depend on DNNE, which does not support mobile platforms. -->
37+
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Runtime.InteropServices\tests\DllImportGenerator.Tests\DllImportGenerator.Tests.csproj" />
38+
</ItemGroup>
39+
40+
<ItemGroup Condition="'$(TargetOS)' == 'windows' and '$(TargetArchitecture)' == 'arm'">
41+
<!-- DllImportGenerator runtime tests depend on DNNE, which does not support Windows ARM32 as we don't officially support it. -->
42+
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Runtime.InteropServices\tests\DllImportGenerator.Tests\DllImportGenerator.Tests.csproj" />
43+
</ItemGroup>
44+
45+
<ItemGroup Condition="'$(TargetOS)' == 'FreeBSD'">
46+
<!-- DllImportGenerator runtime tests build depends pulling down a pre-built nethost binary, which is not available for FreeBSD. -->
47+
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Runtime.InteropServices\tests\DllImportGenerator.Tests\DllImportGenerator.Tests.csproj" />
48+
</ItemGroup>
49+
3550
<ItemGroup Condition="'$(TargetOS)' == 'Windows' and '$(RuntimeFlavor)' == 'Mono' and '$(RunDisabledMonoTestsOnWindows)' != 'true'">
3651
<!-- Issue: https://github.com/dotnet/runtime/issues/53281 -->
3752
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Net.WebSockets.Client\tests\System.Net.WebSockets.Client.Tests.csproj" />

src/samples/Directory.Build.props

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project>
2+
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.props, $(MSBuildThisFileDirectory)..))" />
3+
4+
<PropertyGroup>
5+
<EnableDefaultItems>true</EnableDefaultItems>
6+
<UseLocalTargetingRuntimePack>true</UseLocalTargetingRuntimePack>
7+
</PropertyGroup>
8+
</Project>

src/samples/Directory.Build.targets

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<Project>
2+
<Import Project="$(RepositoryEngineeringDir)targetingpacks.targets" />
3+
4+
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets, $(MSBuildThisFileDirectory)..))" />
5+
</Project>

src/samples/DllImportGeneratorSample/DllImportGeneratorSample.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
</PropertyGroup>
1717

1818
<ItemGroup>
19+
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
1920
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices\tests\Ancillary.Interop\Ancillary.Interop.csproj" />
2021
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices\tests\TestAssets\NativeExports\NativeExports.csproj" />
2122
</ItemGroup>

src/samples/DllImportGeneratorSample/Program.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
using System;
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
25
using System.Runtime.InteropServices;
36

47
namespace Demo
58
{
6-
partial class NativeExportsNE
9+
internal static partial class NativeExportsNE
710
{
811
public const string NativeExportsNE_Binary = "Microsoft.Interop.Tests." + nameof(NativeExportsNE);
912

@@ -17,9 +20,9 @@ partial class NativeExportsNE
1720
public static partial void Sum(int a, ref int b);
1821
}
1922

20-
class Program
23+
internal static class Program
2124
{
22-
static void Main(string[] args)
25+
public static void Main(string[] args)
2326
{
2427
int a = 12;
2528
int b = 13;

0 commit comments

Comments
 (0)