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

Dllimport generator build and test fixes #59658

Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ea54b1f
Enable DllImportGenerator in more tests.
jkoritzinsky Sep 27, 2021
6f40531
Keep some of the P/Invokes using GeneratedDllImport for various reaso…
jkoritzinsky Sep 27, 2021
dbc141d
Use TargetFrameworks so the TargetFramework.Sdk sdk kicks in and auto…
jkoritzinsky Sep 27, 2021
2a65756
Disable DllImportGenerator runtime tests that depend on DNNE on mobil…
jkoritzinsky Sep 27, 2021
a24525e
Undo GeneratedDllImport on GetLongPathNameW for the same reason as Ge…
jkoritzinsky Sep 27, 2021
7a3148f
Make sure that the DllImportGeneratorSample can build.
jkoritzinsky Sep 28, 2021
fe101e4
Fix function pointer usage bug in tests. Disable one SetLastError tes…
jkoritzinsky Sep 28, 2021
ed44881
Merge branch 'feature/use-dllimport-generator' of github.com:dotnet/r…
jkoritzinsky Sep 28, 2021
e05c631
Pass the OutputRid property as the RuntimeIdentifier for NativeExport…
jkoritzinsky Sep 28, 2021
e5652ae
Disable DllImportGenerator.Tests on Mono wholesale due to a bug in ho…
jkoritzinsky Sep 29, 2021
986e9a5
Add MSBuild and CMake in NativeExports.csproj to enable correctly dis…
jkoritzinsky Sep 29, 2021
102a95d
Resolve nethost for NativeExports in a manner that will work with the…
jkoritzinsky Sep 30, 2021
4644434
Update issue reference for why DllImportGenerator.Tests don't run on …
jkoritzinsky Sep 30, 2021
ac37572
Fix handling custom user compilation/link flags correctly between CMa…
jkoritzinsky Sep 30, 2021
027ad10
Merge branch 'feature/use-dllimport-generator' of https://github.com/…
jkoritzinsky Sep 30, 2021
d5e66f1
Update DNNE so we can cross-build NativeExports.
jkoritzinsky Sep 30, 2021
f77cd70
Merge remote-tracking branch 'dotnet/feature/use-dllimport-generator'…
jkoritzinsky Oct 2, 2021
cf6e22b
Remove release runtime check since we now use a DNNE version that han…
jkoritzinsky Oct 2, 2021
a3efde9
Windows cross builds don't need to use the CMake info to set up the t…
jkoritzinsky Oct 3, 2021
c8fcd84
Move changes for toolchain.cmake to output-toolchain-info.cmake to av…
jkoritzinsky Oct 3, 2021
e77b7f0
Refactor NativeExports custom targets.
jkoritzinsky Oct 3, 2021
e320cbd
Add resolution step for target triplets for Apple platforms (OSX and …
jkoritzinsky Oct 3, 2021
d4aff51
Exclude tests for FreeBSD and (in a way that works) Mono on Desktop.
jkoritzinsky Oct 3, 2021
392ee65
Update DNNE
jkoritzinsky Oct 4, 2021
d633dc8
Merge branch 'feature/use-dllimport-generator' of https://github.com/…
jkoritzinsky Oct 4, 2021
6107024
Use TargetOS instead of TargetsX properties.
jkoritzinsky Oct 4, 2021
ff049ab
Fix macOS target triple calculations.
jkoritzinsky Oct 4, 2021
50c189e
Disable DllImportGenerator tests on Win-arm as it's not officially su…
jkoritzinsky Oct 4, 2021
6646f12
Set the nethost dir for all builds, not just for non-Apple Unix-like …
jkoritzinsky Oct 4, 2021
4d55f3a
Use xcrun to find the compiler and sysroot for Apple builds.
jkoritzinsky Oct 5, 2021
2c94662
Fix elinor's feedback for merging this PR.
jkoritzinsky Oct 6, 2021
00726aa
Merge branch 'feature/use-dllimport-generator' of https://github.com/…
jkoritzinsky Oct 6, 2021
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
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
<XunitPerformanceApiPackageVersion>1.0.0-beta-build0015</XunitPerformanceApiPackageVersion>
<MicrosoftDiagnosticsToolsRuntimeClientVersion>1.0.4-preview6.19326.1</MicrosoftDiagnosticsToolsRuntimeClientVersion>
<MicrosoftDiagnosticsNETCoreClientVersion>0.2.61701</MicrosoftDiagnosticsNETCoreClientVersion>
<DNNEVersion>1.0.23</DNNEVersion>
<DNNEVersion>1.0.26</DNNEVersion>
<!--
These are used as reference assemblies only, so they must not take a ProdCon/source-build
version. Insert "RefOnly" to avoid assignment via PVP.
Expand Down
21 changes: 21 additions & 0 deletions eng/native/output-toolchain-info.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Output the toolchain information required to create a command line that builds with the right rootfs as XML

set (ADDED_COMPILE_OPTIONS)
if (CMAKE_SCRIPT_MODE_FILE)
# add_compile_options and add_definitions can't be used in scripts,
# so override the implementations to append to a local property
macro(add_compile_options)
list(APPEND ADDED_COMPILE_OPTIONS ${ARGV})
endmacro()
macro(add_definitions)
list(APPEND ADDED_COMPILE_OPTIONS ${ARGV})
endmacro()
endif()

include(${CMAKE_CURRENT_LIST_DIR}/../common/cross/toolchain.cmake)

message("<toolchain-info>")
message("<target-triple>${TOOLCHAIN}</target-triple>")
message("<linker-args>${CMAKE_SHARED_LINKER_FLAGS_INIT}</linker-args>")
message("<compiler-args>${ADDED_COMPILE_OPTIONS}</compiler-args>")
message("</toolchain-info>")
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ internal static partial class Interop
{
internal static partial class Kernel32
{
#if DLLIMPORTGENERATOR_ENABLED
[GeneratedDllImport(Libraries.Kernel32, SetLastError = true)]
internal static partial bool CloseHandle(IntPtr handle);
#else
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
// Disabled since CloseHandle is a QCall in some scenarios and DllImportGenerator doesn't support QCalls.
AaronRobinsonMSFT marked this conversation as resolved.
Show resolved Hide resolved
[DllImport(Libraries.Kernel32, SetLastError = true)]
internal static extern bool CloseHandle(IntPtr handle);
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,18 @@ internal static partial class Kernel32
private const int FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100;
private const int ERROR_INSUFFICIENT_BUFFER = 0x7A;

#if DLLIMPORTGENERATOR_ENABLED
[GeneratedDllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, EntryPoint = "FormatMessageW", SetLastError = true, ExactSpelling = true)]
private static unsafe partial int FormatMessage(
#else
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
// Disabled since FormatMessage is a QCall in some scenarios and DllImportGenerator doesn't support QCalls.
jkoritzinsky marked this conversation as resolved.
Show resolved Hide resolved
[DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, EntryPoint = "FormatMessageW", SetLastError = true, BestFitMapping = true, ExactSpelling = true)]
private static extern unsafe int FormatMessage(
#endif
int dwFlags,
IntPtr lpSource,
uint dwMessageId,
int dwLanguageId,
void* lpBuffer,
int nSize,
IntPtr arguments);
#pragma warning restore DLLIMPORTGENANALYZER015

/// <summary>
/// Returns a string message for the specified Win32 error code.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ internal static partial class Interop
{
internal static partial class Kernel32
{
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
// Disabled since GetFullPathNameW takes 'ref's into buffers (the ref parameters don't represent single characters).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is going to be the recommended way to make these work with GeneratedDllImports?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This particular P/Invoke took a dependency on the fact that chars are conditionally blittable, so no copying was done. So far, the Interop team has decided to not consider chars as conditionally blittable.

To make this particular P/Invoke work, there are a few different options:

  1. Update the generator to consider char parameters as blittable when CharSet=CharSet.Unicode.
  2. Update this P/Invoke to take char* parameters instead of ref char and pass in pinned refs.
  3. Update the first parameter to take a string (which will be pinned) or a ReadOnlySpan<char> (using the new Span marshalers) and the second to take a char*, which will be passed without change. As the usage of this method calculates the refs to pass in, from a ReadOnlySpan<char> and a ValueStringBuilder, this would be possible without too much trouble.

Copy link
Member

@elinor-fung elinor-fung Oct 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We did (1) in #59700, so we should be able to switch this and GetLongPathNameW back.

Fine with getting this change in to the feature branch and updating in the main merge PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the merge conflicts I had after the property order normalization, I just fixed this as part of resolving those.

/// <summary>
/// WARNING: This method does not implicitly handle long paths. Use GetFullPathName or PathHelper.
/// </summary>
#if DLLIMPORTGENERATOR_ENABLED
[GeneratedDllImport(Libraries.Kernel32, SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true)]
internal static partial uint GetFullPathNameW(
#else
[DllImport(Libraries.Kernel32, SetLastError = true, CharSet = CharSet.Unicode, BestFitMapping = false, ExactSpelling = true)]
internal static extern uint GetFullPathNameW(
#endif
ref char lpFileName,
uint nBufferLength,
ref char lpBuffer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@ internal static partial class Interop
{
internal static partial class Kernel32
{
#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
// Disabled since GetFullPathNameW takes 'ref's into buffers (the ref parameters don't represent single characters).
/// <summary>
/// WARNING: This method does not implicitly handle long paths. Use GetFullPath/PathHelper.
/// </summary>
#if DLLIMPORTGENERATOR_ENABLED
[GeneratedDllImport(Libraries.Kernel32, SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true)]
internal static partial uint GetLongPathNameW(
#else
[DllImport(Libraries.Kernel32, SetLastError = true, CharSet = CharSet.Unicode, BestFitMapping = false, ExactSpelling = true)]
internal static extern uint GetLongPathNameW(
#endif
ref char lpszShortPath,
ref char lpszLongPath,
uint cchBuffer);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<EnableDllImportGenerator>true</EnableDllImportGenerator>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<IncludeRemoteExecutor>true</IncludeRemoteExecutor>
<EnableDllImportGenerator>true</EnableDllImportGenerator>
<!-- file locking can't be disabled on Windows -->
<TargetFrameworks>$(NetCoreAppCurrent)-Unix</TargetFrameworks>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<IncludeRemoteExecutor>true</IncludeRemoteExecutor>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Linux;$(NetCoreAppCurrent)-Browser;$(NetCoreAppCurrent)-OSX</TargetFrameworks>
<EnableDllImportGenerator>true</EnableDllImportGenerator>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Xunit;

// We build the libraries tests in CI once per target OS+Arch+Configuration, but we share it between runtime test runs.
// 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.
// 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
// for Mono-on-Desktop-Platforms test runs.
[assembly:ActiveIssue("https://github.com/dotnet/runtime/issues/59815", TestRuntimes.Mono)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do this via a ProjectExclusions based on RuntimeFlavor in tests.proj? The assembly attribute results in us still sending the test to Helix, running through test discovery for each test to determine that it should not be run, and uploading logs - which seems rather wasteful.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doh. I completely forgot about that. +1.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't do that because we don't build the libraries tests for each runtime flavor, we use one build for both CoreCLR and Mono on desktop platforms (like Linux and Mac). I tried that originally and it didn't work.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
<TargetFrameworks>$(NetCoreAppCurrent)</TargetFrameworks>
<IsPackable>false</IsPackable>
<LangVersion>Preview</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ partial class NativeExportsNE
{
public partial class FunctionPointer
{
[GeneratedDllImport(NativeExportsNE_Binary, EntryPoint = "invoke_callback_after_gc")]
[GeneratedDllImport(NativeExportsNE_Binary, EntryPoint = "invoke_managed_callback_after_gc")]
public static unsafe partial void InvokeAfterGC(delegate* <void> cb);

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

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

[GeneratedDllImport(NativeExportsNE_Binary, EntryPoint = "invoke_callback_blittable_args")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
<TargetFrameworks>$(NetCoreAppCurrent)</TargetFrameworks>
<IsPackable>false</IsPackable>
<LangVersion>Preview</LangVersion>
<Nullable>enable</Nullable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,31 @@ public static void InvokeCallbackAfterGCCollect(delegate* unmanaged<void> fptr)
fptr();
}

[UnmanagedCallersOnly(EntryPoint = "invoke_managed_callback_after_gc")]
public static void InvokeManagedCallbackAfterGCCollect(void* fptr)
{
// We are at the mercy of the GC to verify our delegate has been retain
// across the native function call. This is a best effort validation.
for (int i = 0; i < 5; ++i)
{
GC.Collect();
GC.WaitForPendingFinalizers();
}

// If the corresponding Delegate was collected, the runtime will rudely abort.
((delegate*<void>)fptr)();
}

[UnmanagedCallersOnly(EntryPoint = "invoke_callback_blittable_args")]
public static int InvokeCallbackWithBlittableArgument(delegate* unmanaged<int, int, int> fptr, int a, int b)
{
return fptr(a, b);
}

[UnmanagedCallersOnly(EntryPoint = "invoke_managed_callback_blittable_args")]
public static int InvokeManagedCallbackWithBlittableArgument(void* fptr, int a, int b)
{
return ((delegate*<int, int, int>)fptr)(a, b);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<EnableDynamicLoading>true</EnableDynamicLoading>
<DnneAddGeneratedBinaryToProject>true</DnneAddGeneratedBinaryToProject>
<DnneGenRollForward>Major</DnneGenRollForward>
<!-- To integrate with DNNE's architecture calculation, we need to set the RID for this project. -->
<RuntimeIdentifier>$(OutputRid)</RuntimeIdentifier>
<AppHostRuntimeIdentifier>$(OutputRid)</AppHostRuntimeIdentifier>
</PropertyGroup>

<ItemGroup>
Expand All @@ -17,4 +20,96 @@
<ProjectReference Include="..\SharedTypes\SharedTypes.csproj" />
</ItemGroup>

<Target Name="GetLinuxCrossBuildArgumentsForDNNE"
Condition="'$(CrossBuild)' == 'true' and (
'$(TargetOS)' == 'Linux' or
'$(TargetOS)' == 'NetBSD' or
'$(TargetOS)' == 'FreeBSD' or
'$(TargetOS)' == 'illumos' or
'$(TargetOS)' == 'Solaris')">
<PropertyGroup>
<NativeCompiler>$(Compiler)</NativeCompiler>
<NativeCompiler Condition="'$(NativeCompiler)' == ''">clang</NativeCompiler>
</PropertyGroup>

<Exec Command="bash -c 'source &quot;$(RepositoryEngineeringDir)/common/native/init-compiler.sh&quot; &quot;$(RepositoryEngineeringDir)/common/native&quot; $(TargetArchitecture) $(NativeCompiler) &amp;&amp; echo $CC '"
EchoOff="true"
ConsoleToMsBuild="true"
StandardOutputImportance="Low">
<Output TaskParameter="ConsoleOutput" PropertyName="DnneCompilerCommand" />
</Exec>
<Exec Command="cmake -P &quot;$(RepositoryEngineeringDir)/native/output-toolchain-info.cmake&quot;"
EchoOff="true"
ConsoleToMsBuild="true"
StandardOutputImportance="Low"
EnvironmentVariables="TARGET_BUILD_ARCH=$(TargetArchitecture)">
<Output TaskParameter="ConsoleOutput" PropertyName="CrossTargetXml" />
</Exec>

<XmlPeek XmlContent="$(CrossTargetXml)" Query="toolchain-info/target-triple/text()">
<Output TaskParameter="Result" PropertyName="TargetTriple" />
</XmlPeek>
<XmlPeek XmlContent="$(CrossTargetXml)" Query="toolchain-info/linker-args/text()">
<Output TaskParameter="Result" PropertyName="DnneLinkerUserFlags" />
</XmlPeek>
<XmlPeek XmlContent="$(CrossTargetXml)" Query="toolchain-info/compiler-args/text()">
<Output TaskParameter="Result" PropertyName="DnneCompilerUserFlags" />
</XmlPeek>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XmlPeek

Learned about a new task today - not sure I'm happy about it...


<PropertyGroup>
<CommonToolchainArgs>--target=$(TargetTriple) --gcc-toolchain=$(ROOTFS_DIR)/usr --sysroot=$(ROOTFS_DIR)</CommonToolchainArgs>
<DnneLinkerUserFlags>$(CommonToolchainArgs) $(DnneLinkerUserFlags.Replace(';',' '))</DnneLinkerUserFlags>
<DnneCompilerUserFlags>$(CommonToolchainArgs) $(DnneCompilerUserFlags.Replace(';',' '))</DnneCompilerUserFlags>
</PropertyGroup>
</Target>

<Target Name="GetAppleCrossBuildArgumentsForDNNE"
Condition="'$(TargetOS)' == 'OSX' or
'$(TargetOS)' == 'MacCatalyst' or
'$(TargetOS)' == 'iOS' or
'$(TargetOS)' == 'iOSSimulator' or
'$(TargetOS)' == 'tvOS' or
'$(TargetOS)' == 'tvOSSimulator'">
<PropertyGroup Condition=" '$(TargetOS)' == 'MacCatalyst'">
<TargetTriple Condition="'$(TargetArchitecture)' == 'arm64'">arm64-apple-ios14.2-macabi</TargetTriple>
<TargetTriple Condition="'$(TargetArchitecture)' == 'x64'">x86_64-apple-ios13.5-macabi</TargetTriple>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetOS)' == 'OSX'">
<TargetTriple Condition="'$(TargetArchitecture)' == 'arm64'">arm64-apple-macos11</TargetTriple>
<TargetTriple Condition="'$(TargetArchitecture)' == 'x64'">x86_64-apple-macos10.13</TargetTriple>
<XCodeSdkName>macosx</XCodeSdkName>
</PropertyGroup>

<Error Condition="'$(TargetTriple)' == ''" Text="A target triple was not specified for the native components build. Update the 'GetAppleCrossBuildArgumentsForDNNE' target to specify a triple." />
<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." />

<Exec Command="xcrun --sdk $(XCodeSdkName) --show-sdk-path"
jkoritzinsky marked this conversation as resolved.
Show resolved Hide resolved
EchoOff="true"
ConsoleToMsBuild="true"
StandardOutputImportance="Low">
<Output TaskParameter="ConsoleOutput" PropertyName="SysRootIncludePath" />
</Exec>

<Exec Command="xcrun --sdk $(XCodeSdkName) --find clang"
EchoOff="true"
ConsoleToMsBuild="true"
StandardOutputImportance="Low">
<Output TaskParameter="ConsoleOutput" PropertyName="DnneCompilerCommand" />
</Exec>

<PropertyGroup>
<DnneLinkerUserFlags>-target $(TargetTriple)</DnneLinkerUserFlags>
<DnneCompilerUserFlags>-isysroot &quot;$(SysRootIncludePath)&quot; -target $(TargetTriple)</DnneCompilerUserFlags>
</PropertyGroup>
</Target>

<Target Name="GetBuildArgumentsForDNNE"
DependsOnTargets="ResolveFrameworkReferences;
GetLinuxCrossBuildArgumentsForDNNE;
GetAppleCrossBuildArgumentsForDNNE"
BeforeTargets="DnneBuildNativeExports">
<PropertyGroup>
<DnneNetHostDir>$([System.IO.Path]::GetDirectoryName('$(AppHostSourcePath)'))</DnneNetHostDir>
</PropertyGroup>
</Target>
</Project>
15 changes: 15 additions & 0 deletions src/libraries/tests.proj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Transactions.Local\tests\System.Transactions.Local.Tests.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(TargetsMobile)' == 'true'">
<!-- DllImportGenerator runtime tests depend on DNNE, which does not support mobile platforms. -->
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Runtime.InteropServices\tests\DllImportGenerator.Tests\DllImportGenerator.Tests.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(TargetOS)' == 'windows' and '$(TargetArchitecture)' == 'arm'">
<!-- DllImportGenerator runtime tests depend on DNNE, which does not support Windows ARM32 as we don't officially support it. -->
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Runtime.InteropServices\tests\DllImportGenerator.Tests\DllImportGenerator.Tests.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(TargetOS)' == 'FreeBSD'">
<!-- DllImportGenerator runtime tests build depends pulling down a pre-built nethost binary, which is not available for FreeBSD. -->
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Runtime.InteropServices\tests\DllImportGenerator.Tests\DllImportGenerator.Tests.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(TargetOS)' == 'Windows' and '$(RuntimeFlavor)' == 'Mono' and '$(RunDisabledMonoTestsOnWindows)' != 'true'">
<!-- Issue: https://github.com/dotnet/runtime/issues/53281 -->
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Net.WebSockets.Client\tests\System.Net.WebSockets.Client.Tests.csproj" />
Expand Down
8 changes: 8 additions & 0 deletions src/samples/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.props, $(MSBuildThisFileDirectory)..))" />

<PropertyGroup>
<EnableDefaultItems>true</EnableDefaultItems>
<UseLocalTargetingRuntimePack>true</UseLocalTargetingRuntimePack>
</PropertyGroup>
</Project>
5 changes: 5 additions & 0 deletions src/samples/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project>
<Import Project="$(RepositoryEngineeringDir)targetingpacks.targets" />

<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets, $(MSBuildThisFileDirectory)..))" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
jkoritzinsky marked this conversation as resolved.
Show resolved Hide resolved
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices\tests\Ancillary.Interop\Ancillary.Interop.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime.InteropServices\tests\TestAssets\NativeExports\NativeExports.csproj" />
</ItemGroup>
Expand Down
11 changes: 7 additions & 4 deletions src/samples/DllImportGeneratorSample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System;
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.InteropServices;

namespace Demo
{
partial class NativeExportsNE
internal static partial class NativeExportsNE
{
public const string NativeExportsNE_Binary = "Microsoft.Interop.Tests." + nameof(NativeExportsNE);

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

class Program
internal static class Program
{
static void Main(string[] args)
public static void Main(string[] args)
{
int a = 12;
int b = 13;
Expand Down