From ea54b1f1a7fbc92add44c30f0d9a944b7d9631fb Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Mon, 27 Sep 2021 09:46:37 -0700 Subject: [PATCH 01/27] Enable DllImportGenerator in more tests. --- .../tests/System.IO.Compression.ZipFile.Tests.csproj | 2 ++ .../System.IO.FileSystem.DisabledFileLocking.Tests.csproj | 1 + .../FunctionalTests/System.Net.Http.Functional.Tests.csproj | 1 + 3 files changed, 4 insertions(+) diff --git a/src/libraries/System.IO.Compression.ZipFile/tests/System.IO.Compression.ZipFile.Tests.csproj b/src/libraries/System.IO.Compression.ZipFile/tests/System.IO.Compression.ZipFile.Tests.csproj index 9fbde72eef7b46..7a2fed130efe48 100644 --- a/src/libraries/System.IO.Compression.ZipFile/tests/System.IO.Compression.ZipFile.Tests.csproj +++ b/src/libraries/System.IO.Compression.ZipFile/tests/System.IO.Compression.ZipFile.Tests.csproj @@ -1,5 +1,7 @@  + true + true $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser diff --git a/src/libraries/System.IO.FileSystem/tests/DisabledFileLockingTests/System.IO.FileSystem.DisabledFileLocking.Tests.csproj b/src/libraries/System.IO.FileSystem/tests/DisabledFileLockingTests/System.IO.FileSystem.DisabledFileLocking.Tests.csproj index 87afaa0fb079f6..b9739cb42fb81b 100644 --- a/src/libraries/System.IO.FileSystem/tests/DisabledFileLockingTests/System.IO.FileSystem.DisabledFileLocking.Tests.csproj +++ b/src/libraries/System.IO.FileSystem/tests/DisabledFileLockingTests/System.IO.FileSystem.DisabledFileLocking.Tests.csproj @@ -2,6 +2,7 @@ true true + true $(NetCoreAppCurrent)-Unix diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj b/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj index 718551f9b65d55..29bbd6f8f083e9 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj @@ -7,6 +7,7 @@ true true $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Linux;$(NetCoreAppCurrent)-Browser;$(NetCoreAppCurrent)-OSX + true From 6f4053131a3f6f0ddb92ef1dc32de7cc167e5041 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Mon, 27 Sep 2021 10:10:49 -0700 Subject: [PATCH 02/27] Keep some of the P/Invokes using GeneratedDllImport for various reasons (marked in source with analyzer suppressions). --- .../src/Interop/Windows/Kernel32/Interop.CloseHandle.cs | 7 ++----- .../src/Interop/Windows/Kernel32/Interop.FormatMessage.cs | 8 +++----- .../Interop/Windows/Kernel32/Interop.GetFullPathNameW.cs | 7 ++----- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.CloseHandle.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.CloseHandle.cs index 9c12510d83f269..0e4280b39dbf43 100644 --- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.CloseHandle.cs +++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.CloseHandle.cs @@ -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. [DllImport(Libraries.Kernel32, SetLastError = true)] internal static extern bool CloseHandle(IntPtr handle); -#endif } } diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.FormatMessage.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.FormatMessage.cs index e327cb2851f458..ba9ab43f798d9e 100644 --- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.FormatMessage.cs +++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.FormatMessage.cs @@ -15,13 +15,10 @@ 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. [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, @@ -29,6 +26,7 @@ private static extern unsafe int FormatMessage( void* lpBuffer, int nSize, IntPtr arguments); +#pragma warning restore DLLIMPORTGENANALYZER015 /// /// Returns a string message for the specified Win32 error code. diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetFullPathNameW.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetFullPathNameW.cs index f824fd79d76fe2..a4d40207139025 100644 --- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetFullPathNameW.cs +++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetFullPathNameW.cs @@ -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). /// /// WARNING: This method does not implicitly handle long paths. Use GetFullPathName or PathHelper. /// -#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, From dbc141d7b961dcab4346efcf42267696c8ca1505 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Mon, 27 Sep 2021 11:34:50 -0700 Subject: [PATCH 03/27] Use TargetFrameworks so the TargetFramework.Sdk sdk kicks in and automatically excludes these test projects from the .NET Framework test build. --- .../DllImportGenerator.Tests/DllImportGenerator.Tests.csproj | 2 +- .../DllImportGenerator.UnitTests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/DllImportGenerator.Tests.csproj b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/DllImportGenerator.Tests.csproj index 887a041b0e0618..351241b66278d6 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/DllImportGenerator.Tests.csproj +++ b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/DllImportGenerator.Tests.csproj @@ -1,6 +1,6 @@  - $(NetCoreAppCurrent) + $(NetCoreAppCurrent) false Preview true diff --git a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/DllImportGenerator.UnitTests.csproj b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/DllImportGenerator.UnitTests.csproj index 89b2d192140cec..6186cea54a53be 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/DllImportGenerator.UnitTests.csproj +++ b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/DllImportGenerator.UnitTests.csproj @@ -1,7 +1,7 @@  - $(NetCoreAppCurrent) + $(NetCoreAppCurrent) false Preview enable From 2a65756d0c3fbbe54035c5be20e6ee588bde3b34 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Mon, 27 Sep 2021 14:07:59 -0700 Subject: [PATCH 04/27] Disable DllImportGenerator runtime tests that depend on DNNE on mobile/browser platforms. --- src/libraries/tests.proj | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libraries/tests.proj b/src/libraries/tests.proj index 3288e59a9e1b5f..f4ff25c7482bd7 100644 --- a/src/libraries/tests.proj +++ b/src/libraries/tests.proj @@ -26,6 +26,11 @@ + + + + + @@ -143,7 +148,7 @@ - + From a24525ef863ccb106f3d2cdb55cdcfaea5658221 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Mon, 27 Sep 2021 16:01:32 -0700 Subject: [PATCH 05/27] Undo GeneratedDllImport on GetLongPathNameW for the same reason as GetFullPathNameW. --- .../Interop/Windows/Kernel32/Interop.GetLongPathNameW.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetLongPathNameW.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetLongPathNameW.cs index b3be36d9007f5f..a509004f60587c 100644 --- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetLongPathNameW.cs +++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetLongPathNameW.cs @@ -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). /// /// WARNING: This method does not implicitly handle long paths. Use GetFullPath/PathHelper. /// -#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); From 7a3148fc017201c3063c8822d59dc603c94edc74 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Tue, 28 Sep 2021 13:58:09 -0700 Subject: [PATCH 06/27] Make sure that the DllImportGeneratorSample can build. --- src/samples/Directory.Build.props | 8 ++++++++ src/samples/Directory.Build.targets | 5 +++++ .../DllImportGeneratorSample.csproj | 1 + src/samples/DllImportGeneratorSample/Program.cs | 11 +++++++---- 4 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 src/samples/Directory.Build.props create mode 100644 src/samples/Directory.Build.targets diff --git a/src/samples/Directory.Build.props b/src/samples/Directory.Build.props new file mode 100644 index 00000000000000..4590be123eb7f9 --- /dev/null +++ b/src/samples/Directory.Build.props @@ -0,0 +1,8 @@ + + + + + true + true + + diff --git a/src/samples/Directory.Build.targets b/src/samples/Directory.Build.targets new file mode 100644 index 00000000000000..74fb272013ea8d --- /dev/null +++ b/src/samples/Directory.Build.targets @@ -0,0 +1,5 @@ + + + + + diff --git a/src/samples/DllImportGeneratorSample/DllImportGeneratorSample.csproj b/src/samples/DllImportGeneratorSample/DllImportGeneratorSample.csproj index f42621f44c254b..32bd062dfe8c7e 100644 --- a/src/samples/DllImportGeneratorSample/DllImportGeneratorSample.csproj +++ b/src/samples/DllImportGeneratorSample/DllImportGeneratorSample.csproj @@ -16,6 +16,7 @@ + diff --git a/src/samples/DllImportGeneratorSample/Program.cs b/src/samples/DllImportGeneratorSample/Program.cs index 6e2f1defd97c7e..4a1c8335bf4180 100644 --- a/src/samples/DllImportGeneratorSample/Program.cs +++ b/src/samples/DllImportGeneratorSample/Program.cs @@ -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); @@ -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; From fe101e40478f68ff2fde61177851a650468c6cf8 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Tue, 28 Sep 2021 14:00:32 -0700 Subject: [PATCH 07/27] Fix function pointer usage bug in tests. Disable one SetLastError test against an issue with debug/checked CoreCLR. --- .../TestUtilities/System/PlatformDetection.cs | 2 ++ .../FunctionPointerTests.cs | 4 ++-- .../SetLastErrorTests.cs | 3 ++- .../DelegatesAndFunctionPointers.cs | 21 +++++++++++++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs index fbd5df9afdde75..41bdc7bd7d6970 100644 --- a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs +++ b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs @@ -28,6 +28,8 @@ public static partial class PlatformDetection public static bool IsMonoInterpreter => GetIsRunningOnMonoInterpreter(); public static bool IsMonoAOT => Environment.GetEnvironmentVariable("MONO_AOT_MODE") == "aot"; public static bool IsNotMonoAOT => Environment.GetEnvironmentVariable("MONO_AOT_MODE") != "aot"; + public static bool IsReleaseRuntime => typeof(object).Assembly.GetCustomAttribute().Configuration == "Release"; + public static bool IsNotReleaseRuntime => !IsReleaseRuntime; public static bool IsFreeBSD => RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD")); public static bool IsNetBSD => RuntimeInformation.IsOSPlatform(OSPlatform.Create("NETBSD")); public static bool IsAndroid => RuntimeInformation.IsOSPlatform(OSPlatform.Create("ANDROID")); diff --git a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/FunctionPointerTests.cs b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/FunctionPointerTests.cs index 9de487153f724b..a3dfcee20a27b1 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/FunctionPointerTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/FunctionPointerTests.cs @@ -10,7 +10,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* cb); [GeneratedDllImport(NativeExportsNE_Binary, EntryPoint = "invoke_callback_after_gc")] @@ -19,7 +19,7 @@ public partial class FunctionPointer [GeneratedDllImport(NativeExportsNE_Binary, EntryPoint = "invoke_callback_after_gc")] public static unsafe partial void InvokeAfterGC(delegate* unmanaged[Stdcall] 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* cb, int a, int b); [GeneratedDllImport(NativeExportsNE_Binary, EntryPoint = "invoke_callback_blittable_args")] diff --git a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/SetLastErrorTests.cs b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/SetLastErrorTests.cs index 6d6dca8cb87124..7240d8e51dd8fe 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/SetLastErrorTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/SetLastErrorTests.cs @@ -30,7 +30,7 @@ public partial class SetLastError [GeneratedDllImport(NativeExportsNE_Binary, EntryPoint = "set_error", SetLastError = true)] public static partial int SetError(int error, byte shouldSetError); - [GeneratedDllImport(NativeExportsNE_Binary, EntryPoint = "set_error_return_string", SetLastError = true)] + [GeneratedDllImport(NativeExportsNE_Binary, EntryPoint = "set_error", SetLastError = true)] [return: MarshalUsing(typeof(SetLastErrorMarshaller))] public static partial int SetError_CustomMarshallingSetsError(int error, byte shouldSetError); @@ -68,6 +68,7 @@ public void LastWin32Error_HasExpectedValue(int error) } [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/59721", typeof(PlatformDetection), nameof(PlatformDetection.IsNotReleaseRuntime), nameof(PlatformDetection.IsNotMonoRuntime))] public void ClearPreviousError() { int error = 100; diff --git a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/DelegatesAndFunctionPointers.cs b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/DelegatesAndFunctionPointers.cs index 16fc451c9de89d..5bcdef94556ce3 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/DelegatesAndFunctionPointers.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/DelegatesAndFunctionPointers.cs @@ -20,10 +20,31 @@ public static void InvokeCallbackAfterGCCollect(delegate* unmanaged 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*)fptr)(); + } + [UnmanagedCallersOnly(EntryPoint = "invoke_callback_blittable_args")] public static int InvokeCallbackWithBlittableArgument(delegate* unmanaged 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*)fptr)(a, b); + } } } From e05c631ee62b04d93dfed778abfdada48517ddd7 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Tue, 28 Sep 2021 15:06:20 -0700 Subject: [PATCH 08/27] Pass the OutputRid property as the RuntimeIdentifier for NativeExports.csproj to enable DNNE's architecture detection on Windows. --- .../tests/TestAssets/NativeExports/NativeExports.csproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj index 00a8f53fd133bd..69d28d4926603b 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj +++ b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj @@ -7,6 +7,8 @@ true true Major + + $(OutputRid) From e5652aeb69ab0f6e6a80cb4f2bc3794961eb08ac Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Wed, 29 Sep 2021 11:08:49 -0700 Subject: [PATCH 09/27] Disable DllImportGenerator.Tests on Mono wholesale due to a bug in how Mono loads (or more acurately doesn't) the native library component of these tests. --- src/libraries/tests.proj | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libraries/tests.proj b/src/libraries/tests.proj index f4ff25c7482bd7..bd4fc02055de3a 100644 --- a/src/libraries/tests.proj +++ b/src/libraries/tests.proj @@ -31,6 +31,11 @@ + + + + + From 986e9a5f86a3daca0a6e0de2d344bfb99ef0b0ac Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Wed, 29 Sep 2021 16:35:39 -0700 Subject: [PATCH 10/27] Add MSBuild and CMake in NativeExports.csproj to enable correctly discovering the native toolchain for DNNE. --- eng/native/output-toolchain-info.cmake | 10 +++++ .../NativeExports/NativeExports.csproj | 40 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 eng/native/output-toolchain-info.cmake diff --git a/eng/native/output-toolchain-info.cmake b/eng/native/output-toolchain-info.cmake new file mode 100644 index 00000000000000..be970002e12e26 --- /dev/null +++ b/eng/native/output-toolchain-info.cmake @@ -0,0 +1,10 @@ +# Output the toolchain information required to create a command line that builds with the right rootfs as XML + +include(${CMAKE_CURRENT_LIST_DIR}/../common/cross/toolchain.cmake) + +message("") +message("${TOOLCHAIN}") +message("${CMAKE_SHARED_LINKER_FLAGS_INIT}") +get_directory_property(COMPILER_ARGS COMPILE_OPTIONS) +message("${COMPILER_ARGS}") +message("") \ No newline at end of file diff --git a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj index 69d28d4926603b..426f310f107b7d 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj +++ b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj @@ -19,4 +19,44 @@ + + + + + + + $(Compiler) + clang + + + + + + + + + + + + + + + + + + --target=$(TargetTriple) --gcc-toolchain=$(ROOTFS_DIR)/usr --sysroot=$(ROOTFS_DIR) + $(CommonToolchainArgs) $(DnneLinkerUserFlags) + $(CommonToolchainArgs) $(DnneCompilerUserFlags) + + From 102a95d472104ebd6e084be332e3e477446ad526 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Wed, 29 Sep 2021 17:04:42 -0700 Subject: [PATCH 11/27] Resolve nethost for NativeExports in a manner that will work with the next DNNE version. --- .../tests/TestAssets/NativeExports/NativeExports.csproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj index 426f310f107b7d..a000c44148a63e 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj +++ b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj @@ -9,6 +9,7 @@ Major $(OutputRid) + $(OutputRid) @@ -57,6 +58,7 @@ --target=$(TargetTriple) --gcc-toolchain=$(ROOTFS_DIR)/usr --sysroot=$(ROOTFS_DIR) $(CommonToolchainArgs) $(DnneLinkerUserFlags) $(CommonToolchainArgs) $(DnneCompilerUserFlags) + $([System.IO.Path]::GetDirectoryName('$(AppHostSourcePath)')) From 4644434bcd3b1cc0d7bacfcc62614b2555b77c62 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 30 Sep 2021 09:36:09 -0700 Subject: [PATCH 12/27] Update issue reference for why DllImportGenerator.Tests don't run on Mono. --- src/libraries/tests.proj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/tests.proj b/src/libraries/tests.proj index bd4fc02055de3a..ed2f6365667ca0 100644 --- a/src/libraries/tests.proj +++ b/src/libraries/tests.proj @@ -32,7 +32,7 @@ - + From ac37572bb99344895be61d8c45ccfa330e25b6e6 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 30 Sep 2021 10:20:38 -0700 Subject: [PATCH 13/27] Fix handling custom user compilation/link flags correctly between CMake and MSBuild. --- eng/common/cross/toolchain.cmake | 12 ++++++++++++ eng/native/output-toolchain-info.cmake | 3 +-- .../TestAssets/NativeExports/NativeExports.csproj | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/eng/common/cross/toolchain.cmake b/eng/common/cross/toolchain.cmake index 6501c3a955f782..53d82f239bf3f3 100644 --- a/eng/common/cross/toolchain.cmake +++ b/eng/common/cross/toolchain.cmake @@ -56,6 +56,18 @@ if(DEFINED ENV{TOOLCHAIN}) set(TOOLCHAIN $ENV{TOOLCHAIN}) endif() +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() + # Specify include paths if(DEFINED TIZEN_TOOLCHAIN) if(TARGET_ARCH_NAME STREQUAL "armel") diff --git a/eng/native/output-toolchain-info.cmake b/eng/native/output-toolchain-info.cmake index be970002e12e26..c048d83b01207c 100644 --- a/eng/native/output-toolchain-info.cmake +++ b/eng/native/output-toolchain-info.cmake @@ -5,6 +5,5 @@ include(${CMAKE_CURRENT_LIST_DIR}/../common/cross/toolchain.cmake) message("") message("${TOOLCHAIN}") message("${CMAKE_SHARED_LINKER_FLAGS_INIT}") -get_directory_property(COMPILER_ARGS COMPILE_OPTIONS) -message("${COMPILER_ARGS}") +message("${ADDED_COMPILE_OPTIONS}") message("") \ No newline at end of file diff --git a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj index a000c44148a63e..24870387ca7c20 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj +++ b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj @@ -56,8 +56,8 @@ --target=$(TargetTriple) --gcc-toolchain=$(ROOTFS_DIR)/usr --sysroot=$(ROOTFS_DIR) - $(CommonToolchainArgs) $(DnneLinkerUserFlags) - $(CommonToolchainArgs) $(DnneCompilerUserFlags) + $(CommonToolchainArgs) $(DnneLinkerUserFlags.Replace(';',' ')) + $(CommonToolchainArgs) $(DnneCompilerUserFlags.Replace(';',' ')) $([System.IO.Path]::GetDirectoryName('$(AppHostSourcePath)')) From d5e66f10698b28ca86925a74d94ebc924aec527d Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Thu, 30 Sep 2021 15:12:24 -0700 Subject: [PATCH 14/27] Update DNNE so we can cross-build NativeExports. --- eng/Versions.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/Versions.props b/eng/Versions.props index 8737a4debcb1a0..e1470fc4c0107d 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -144,7 +144,7 @@ 1.0.0-beta-build0015 1.0.4-preview6.19326.1 0.2.61701 - 1.0.23 + 1.0.25 + $(Compiler) clang @@ -42,6 +34,19 @@ StandardOutputImportance="Low"> + + + + + + From c8fcd84f3e8b13ae3d43f73ee427ff6f680f5e73 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Sun, 3 Oct 2021 14:39:06 -0700 Subject: [PATCH 17/27] Move changes for toolchain.cmake to output-toolchain-info.cmake to avoid changing anything in eng/common. --- eng/common/cross/toolchain.cmake | 12 ------------ eng/native/output-toolchain-info.cmake | 12 ++++++++++++ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/eng/common/cross/toolchain.cmake b/eng/common/cross/toolchain.cmake index 53d82f239bf3f3..6501c3a955f782 100644 --- a/eng/common/cross/toolchain.cmake +++ b/eng/common/cross/toolchain.cmake @@ -56,18 +56,6 @@ if(DEFINED ENV{TOOLCHAIN}) set(TOOLCHAIN $ENV{TOOLCHAIN}) endif() -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() - # Specify include paths if(DEFINED TIZEN_TOOLCHAIN) if(TARGET_ARCH_NAME STREQUAL "armel") diff --git a/eng/native/output-toolchain-info.cmake b/eng/native/output-toolchain-info.cmake index c048d83b01207c..8eed988e598ac0 100644 --- a/eng/native/output-toolchain-info.cmake +++ b/eng/native/output-toolchain-info.cmake @@ -1,5 +1,17 @@ # 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("") From e77b7f0956bef46a2ed1af44b63f6bb5d33c6613 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Sun, 3 Oct 2021 14:51:14 -0700 Subject: [PATCH 18/27] Refactor NativeExports custom targets. --- .../tests/TestAssets/NativeExports/NativeExports.csproj | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj index 5bf29c94ff8e0d..19ea4baca795ad 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj +++ b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj @@ -36,10 +36,9 @@ - + Condition="'$(CrossBuild)' == 'true' and '$(TargetsLinux)' == 'true'"> $([System.IO.Path]::GetDirectoryName('$(AppHostSourcePath)')) + + From e320cbd3cac61f81a8d46ef9c664f279660072a2 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Sun, 3 Oct 2021 15:03:28 -0700 Subject: [PATCH 19/27] Add resolution step for target triplets for Apple platforms (OSX and MacCatalyst only now for simplicity since DNNE doesn't support mobile platforms anyway) --- .../NativeExports/NativeExports.csproj | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj index 19ea4baca795ad..162f403b37524e 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj +++ b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj @@ -65,7 +65,33 @@ + + + arm64-apple-ios14.2-macabi + x86_64-apple-ios13.5-macabi + + + arm64-apple-macos11 + x86_64-apple-macos10.13 + + + + + + -target $(TargetTriple) + -target $(TargetTriple) + + + From d4aff51ad3ec9d358825f0126bc975c8e76122c9 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Sun, 3 Oct 2021 16:53:41 -0700 Subject: [PATCH 20/27] Exclude tests for FreeBSD and (in a way that works) Mono on Desktop. --- .../tests/DllImportGenerator.Tests/AssemblyInfo.cs | 10 ++++++++++ src/libraries/tests.proj | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/AssemblyInfo.cs diff --git a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/AssemblyInfo.cs b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/AssemblyInfo.cs new file mode 100644 index 00000000000000..f95036d8de482b --- /dev/null +++ b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/AssemblyInfo.cs @@ -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)] diff --git a/src/libraries/tests.proj b/src/libraries/tests.proj index 51f664e6f1abc3..2856608086327b 100644 --- a/src/libraries/tests.proj +++ b/src/libraries/tests.proj @@ -37,8 +37,8 @@ - - + + From 392ee651f99e7c0d00624a7ab2f4236023c938ed Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Mon, 4 Oct 2021 10:25:56 -0700 Subject: [PATCH 21/27] Update DNNE --- eng/Versions.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/Versions.props b/eng/Versions.props index d1d702bda29a05..0d459b88e7be3d 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -144,7 +144,7 @@ 1.0.0-beta-build0015 1.0.4-preview6.19326.1 0.2.61701 - 1.0.25 + 1.0.26 + Condition="'$(TargetOS)' != 'windows'"> $(Compiler) clang @@ -38,7 +38,12 @@ + Condition="'$(CrossBuild)' == 'true' and ( + '$(TargetOS)' == 'Linux' or + '$(TargetOS)' == 'NetBSD' or + '$(TargetOS)' == 'FreeBSD' or + '$(TargetOS)' == 'illumos' or + '$(TargetOS)' == 'Solaris')"> + Condition="'$(TargetOS)' == 'OSX' or + '$(TargetOS)' == 'MacCatalyst' or + '$(TargetOS)' == 'iOS' or + '$(TargetOS)' == 'iOSSimulator' or + '$(TargetOS)' == 'tvOS' or + '$(TargetOS)' == 'tvOSSimulator'"> arm64-apple-ios14.2-macabi x86_64-apple-ios13.5-macabi From ff049ab0ee7a3abf1bb01381992d2361ae1906f0 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Mon, 4 Oct 2021 13:22:09 -0700 Subject: [PATCH 23/27] Fix macOS target triple calculations. --- .../tests/TestAssets/NativeExports/NativeExports.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj index b71c63847e97d5..cbf8612ed35fcd 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj +++ b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj @@ -77,11 +77,11 @@ '$(TargetOS)' == 'iOSSimulator' or '$(TargetOS)' == 'tvOS' or '$(TargetOS)' == 'tvOSSimulator'"> - + arm64-apple-ios14.2-macabi x86_64-apple-ios13.5-macabi - + arm64-apple-macos11 x86_64-apple-macos10.13 From 50c189e605a300f69d13244dc9eaba8b727bcf41 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Mon, 4 Oct 2021 14:16:03 -0700 Subject: [PATCH 24/27] Disable DllImportGenerator tests on Win-arm as it's not officially supported and DNNE doesn't support it. --- src/libraries/tests.proj | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libraries/tests.proj b/src/libraries/tests.proj index 2856608086327b..05d56f00feedd8 100644 --- a/src/libraries/tests.proj +++ b/src/libraries/tests.proj @@ -37,6 +37,11 @@ + + + + + From 6646f1295b6bfb13a0aa1b549dc2ae1b512ca9c6 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Mon, 4 Oct 2021 14:49:17 -0700 Subject: [PATCH 25/27] Set the nethost dir for all builds, not just for non-Apple Unix-like builds. --- .../NativeExports/NativeExports.csproj | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj index cbf8612ed35fcd..052be4d6953543 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj +++ b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj @@ -39,10 +39,10 @@ --target=$(TargetTriple) --gcc-toolchain=$(ROOTFS_DIR)/usr --sysroot=$(ROOTFS_DIR) $(CommonToolchainArgs) $(DnneLinkerUserFlags.Replace(';',' ')) $(CommonToolchainArgs) $(DnneCompilerUserFlags.Replace(';',' ')) - $([System.IO.Path]::GetDirectoryName('$(AppHostSourcePath)')) arm64-apple-ios14.2-macabi @@ -95,8 +94,13 @@ + BeforeTargets="DnneBuildNativeExports"> + + $([System.IO.Path]::GetDirectoryName('$(AppHostSourcePath)')) + + From 4d55f3a747ae1487f6eec8f811c9a4633dc27275 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Tue, 5 Oct 2021 09:30:37 -0700 Subject: [PATCH 26/27] Use xcrun to find the compiler and sysroot for Apple builds. --- .../NativeExports/NativeExports.csproj | 39 ++++++++++++------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj index 052be4d6953543..08defdf7600b60 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj +++ b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj @@ -20,9 +20,13 @@ - - + $(Compiler) clang @@ -34,16 +38,6 @@ StandardOutputImportance="Low"> - - - arm64-apple-macos11 x86_64-apple-macos10.13 + macosx + + + + + + + + + -target $(TargetTriple) - -target $(TargetTriple) + -isysroot "$(SysRootIncludePath)" -target $(TargetTriple) From 2c946628bde90147a0666d0fa51b9b0980e28f67 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Wed, 6 Oct 2021 09:36:10 -0700 Subject: [PATCH 27/27] Fix elinor's feedback for merging this PR. --- eng/generators.targets | 10 +++++----- .../TestAssets/NativeExports/NativeExports.csproj | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/eng/generators.targets b/eng/generators.targets index 45f5cb6c4bac1a..e20fa992012aab 100644 --- a/eng/generators.targets +++ b/eng/generators.targets @@ -33,10 +33,10 @@ - - - - + + + + $(DefineConstants);DLLIMPORTGENERATOR_INTERNALUNSAFE - diff --git a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj index 08defdf7600b60..c93a8ac56d9e0d 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj +++ b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj @@ -83,6 +83,7 @@ +