-
Notifications
You must be signed in to change notification settings - Fork 1.4k
.NET 5 target for Toolkit and HighPerformance packages #3356
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
Conversation
|
Thanks Sergio0694 for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌 |
|
.NET 5 is flux still, so we probably have to sit on this a bit until we know more in terms of timings and plans. |
|
@michael-hawker Yeah absolutely, that's why I opened this as draft 👍 This was mostly to keep a working branch with .NET 5 up to date (so I can merge new changes from the other branches as they come in), and ready to go with the new .NET 5 features where applicable. Then whenever we're ready to actually add support for .NET 5 to the toolkit, the PR will be all setup already 🚀 |
277cd28 to
a03ef74
Compare
|
Hey @azchohfi, wanted to run an idea by you 😄 Once .NET 5 comes out, both CoreCLR and Mono will be able to run the same .NET 5 assemblies with no trouble, with Mono now officially supporting .NET 5 targets directly. This means that we will no longer have a way to tell what runtime we're currently on, so weird runtime-specific tricks are technically no longer guaranteed to work, since Mono has a different layout for some objects (eg. ND arrays). I've already done some work today in #3353 to improve the portable versions of those APIs, and I'm thinking with the new .NET 5 target we will probably just have to switch back to the portable implementation again to ensure it runs fine on both CoreCLR and Mono. I was thinking, would it be possible/reasonable to set the CI to run the .NET 5 unit test project for the I mean, I think I've addressed all the critical runtime specific hacks in the other PR, moving to a portable implementation we can also use on the .NET 5 target (adapted the implementation from the original Let me know what you think! EDIT: asked in the .NET Evolution Discord server and two Mono engineers suggested these two possible approaches: They both need Linux, but they should also work on WSL on Windows. In particular they said the second one was tested on WLS on an app created with EDIT 2: alright, this worked fine for me to run a sample .NET 5 project with Mono so far 😄
EDIT 3: shared unit test project for the base packages all passing on .NET 5 Mono! 🚀 Now on to test the Seeing if I can get a unit test project from the toolkit to work with this too now 😄 EDIT 4: victory! 🎉🎉🎉 All the unit tests from the EDIT 5: looks like adding the .NET 5 target and adjusting the compiler directives for the EDIT 6: as suggested by a Mono engineer in the .NET Evolution server, I added EDIT 7: well, using the MonoNET5Sample setup I could run a program with .NET 5 Mono LLVM just fine, but that doesn't work with EDIT 8: found a solution, see below 😄 |
|
I figured it out! 🎉🎉🎉 Here are the steps to modify a unit test project to run it on .NET 5 Mono:
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<PublishTrimmed>true</PublishTrimmed>
<TrimMode>link</TrimMode>
<RuntimeSuffix>.LLVM.AOT</RuntimeSuffix>
<StartupObject>UnitTests.NetCore.Program</StartupObject>
</PropertyGroup>
<ItemGroup>
<KnownFrameworkReference
Include="Microsoft.NETCore.App.Mono$(RuntimeSuffix)"
TargetFramework="$(TargetFramework)"
RuntimeFrameworkName="Microsoft.NETCore.App"
DefaultRuntimeFrameworkVersion="$(BundledNETCorePlatformsPackageVersion)"
LatestRuntimeFrameworkVersion="$(BundledNETCorePlatformsPackageVersion)"
TargetingPackName="Microsoft.NETCore.App.Ref"
TargetingPackVersion="$(BundledNETCorePlatformsPackageVersion)"
RuntimePackNamePatterns="Microsoft.NETCore.App.Runtime.Mono$(RuntimeSuffix).**RID**"
RuntimePackRuntimeIdentifiers="$(RuntimeIdentifier)"
IsTrimmable="true" />
<FrameworkReference Remove="Microsoft.NETCore.App" />
<FrameworkReference
Include="Microsoft.NETCore.App.Mono$(RuntimeSuffix)"
IsImplicitlyDefined="true"
Pack="true"
PrivateAssets="All" />
</ItemGroup>
export MONO_THREADS_SUSPEND="preemptive"
export MONO_ENV_OPTIONS="--llvm --ffast-math"
dotnet run -c Release -r linux-x64Final result: @alexchx @michael-hawker Not the simplest solution, but we now have a way to run our tests on Mono as well 😄 NOTE: 100% of the unit tests in both the standard and |
|
Adding this to the 7.0 milestone as we absolutely need to get this merged in for the next release or the |
d9791b7 to
aabf73d
Compare
|
Updated the PR, pulled all changes from |
| /// Throws an <see cref="OverflowException"/> when the "column" parameter is invalid. | ||
| /// </summary> | ||
| public static void ThrowOverflowException() | ||
| private static void ThrowOverflowException() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this public in 6.1? This is just an internal helper, eh?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thankfully not 🤣
This is just an internal helper that I added in #3353, but that accidentally left out as public there. I think it was because this was initially in an internal throw helper class (so the method was public), then I moved it here and forgot to change the accessibility modifier. Really glad I spotted it in time for 7.0 😅
| public static unsafe byte ToByte(this bool flag) | ||
| { | ||
| return Unsafe.As<bool, byte>(ref flag); | ||
| return *(byte*)&flag; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New optimization from .NET 5 compiler???
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahahah nope, just good old C# trickery 😄
This was actually a suggestion from Tanner, the idea here is that the two versions do exactly the same anyway, but using raw pointers means the GC doesn't have to also track the additional metadata to ensure that if a GC collection happens while this method is running, the locals are properly handled. In our case that's not needed since the target values are already pinned (they're just local arguments passed by copy). So using raw pointers will produce the same exact codegen, but with some theoretical minor indirect benefits on top of that 👍
|
Hello @michael-hawker! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
## PR Type What kind of change does this PR introduce? <!-- Please uncomment one or more that apply to this PR. --> <!-- - Bugfix --> - Feature - Optimization <!-- - Code style update (formatting) --> <!-- - Refactoring (no functional changes, no api changes) --> <!-- - Build or CI related changes --> <!-- - Documentation content changes --> <!-- - Sample app changes --> <!-- - Other... Please describe: --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying, or link to a relevant issue. --> There are no `nint`/`nuint` overloads for the any `Guard` APIs. These types have been introduced with C# 9, so it makes sense to add proper support for them given that #3356 added full support for C# 9 and .NET 5 to these packages. Also there were some codegen bits in `Guard.IsCloseTo` that were not ideal. Additionally, the codegen for the `Guard` APIs didn't leverage compiler support properly. ## What is the new behavior? <!-- Describe how was this issue resolved or changed? --> ✅ Added new `nint`/`nuint` overloads to `Guard` APIs 🚀 Improved codegen in a number of `Guard.IsCloseTo` overloads 🚀 Improved codegen for faulting blocks ## PR Checklist Please check if your PR fulfills the following requirements: - [X] Tested code with current [supported SDKs](../readme.md#supported) - [ ] Pull Request has been submitted to the documentation repository [instructions](..\contributing.md#docs). Link: <!-- docs PR link --> - [ ] Sample in sample app has been added / updated (for bug fixes / features) - [ ] Icon has been created (if new sample) following the [Thumbnail Style Guide and templates](https://github.com/windows-toolkit/WindowsCommunityToolkit-design-assets) - [X] Tests for the changes have been added (for bug fixes / features) (if applicable) - [X] Header has been added to all new source files (run *build/UpdateHeaders.bat*) - [X] Contains **NO** breaking changes



Adds the .NET 5 target to
Microsoft.Toolkit.HighPerformancePR Type
What kind of change does this PR introduce?
What is the current behavior?
The
Microsoft.Toolkit.HighPerformancepackage maxes out at .NET Core 3.1.The
Microsoft.Toolkitpackage maxes out at .NET Standard 2.1.Additionally,
Microsoft.Toolkitdoesn't have proper nullability annotations, and it reports installing additional dependencies if installed in a .NET 5 apps. The extra dependency isSystem.Runtime.CompilerServices.Unsafewhich is actually built-in on .NET 5, but consumers not aware of this would still see the installation prompt from NuGet as reporting an extra indirect dependency.What is the new behavior?
✅ Added .NET 5 target to
Microsoft.Toolkit.HighPerformance✅ Added .NET 5 target to
Microsoft.Toolkit✅ Enabled global nullability annotations to
Microsoft.Toolkitand improved the codebase.✅ Enabled C# 9 in both projects, with some extra code tweaks.
PR Checklist
Please check if your PR fulfills the following requirements: