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

Initial pass of adding .NET 6 support for sustaining #586

Merged
merged 9 commits into from
Aug 28, 2021

Conversation

Perksey
Copy link
Member

@Perksey Perksey commented Aug 18, 2021

Draft for now as I want to lookover it myself.

Adds support for .NET 6 on 2.X for sustaining. Should work exactly as with Xamarin, but yet to be tested. Will strive to do this before we go any futher.

@Perksey Perksey added enhancement New feature or request area-Windowing labels Aug 18, 2021
@Perksey Perksey added this to the 2.X milestone Aug 18, 2021
@Perksey Perksey self-assigned this Aug 18, 2021
@Perksey Perksey added this to WIP / Next Monthly Update in 2.X Sustaining via automation Aug 18, 2021
@Perksey
Copy link
Member Author

Perksey commented Aug 21, 2021

Ready for review.

Noteworthy Changes

  • Introduced an UnmanagedCallersOnly shim to use the correct calling convention for DllImport overrides
    • Required due to a refactor in the .NET 6 mono threading state machine
    • Because of UnmanagedCallersOnly, fix is only available on .NET 5+. It is available on .NET 6's mobile platforms.
      • It worked on old mono, so should be benign
  • Multitargeted the SDL windowing packages and the windowing metapackage to .NET 6, with Android, iOS, and Mac Catalyst platforms
    • Changed native NuGet packaging accordingly (which, might I add, is now 1000x harder)
  • Added the Xamarin Android support in Silk.NET.Windowing.Sdl.Android to Silk.NET.Windowing.Sdl on the .NET 6 Android TFM.
    • No real changes needed, and Input required no changes either.
  • Stopped giving SDL control of screen orientation
  • Revived the SilkTouch name generator

Changelog Entries

  • Add .NET 6 support for Windowing and Input (Desktop and Android only at this time)
  • Fix SilkTouch so that on .NET 5+ it uses the correct calling convention for PInvokeOverride
  • Fix SDL taking control of orientation on Android & Silk.NET providing no way to control it.
  • Miscellaneous SilkTouch improvements and fixes.

@Perksey Perksey marked this pull request as ready for review August 21, 2021 20:50
@Perksey Perksey removed their assignment Aug 21, 2021
@HurricanKai
Copy link
Member

Have you verified the name gen works?

@Perksey
Copy link
Member Author

Perksey commented Aug 21, 2021

Yup, works flawlessly.

@Perksey
Copy link
Member Author

Perksey commented Aug 21, 2021

Also, I'll fix CI in this PR as well. Currently delayed by a unexpected VS update, so it'll be tomorrow now.

Comment on lines +30 to +32
- name: Install Workloads
# TODO: This is slow. Maybe we can make a docker container with this already done?
run: dotnet workload install android android-aot ios maccatalyst maui
Copy link
Member

Choose a reason for hiding this comment

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

Do we not want to matrix this and have separate CI for core, new Android, old Android, new IOS and old IOS?

Copy link
Member Author

@Perksey Perksey Aug 22, 2021

Choose a reason for hiding this comment

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

Given we're multitargeting we need all of them in any case. We'd need to do lots of build hacking to get each buildable separately and it also would just massively complicate the workflow.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also it turns out it's not that slow, it only takes 2 minutes. The runners clearly have very good internet connection.


There are more advanced build actions you can do too, such as FullBuild, Pack, FullPack, among others which you can view by doing `nuke --plan`.

Some projects may not build properly without being configured to use Desktop MSBuild (i.e. the MSBuild shipped with Visual Studio). As a result, you will ideally need to be on Windows and have Visual Studio 2019 Community (or greater) installed with .NET Core and Xamarin workloads. If you don't have this (i.e. because you're on Linux or Mac), you can still develop Silk.NET in a limited capacity but you will not be able to work on mobile workloads.
The older Xamarin projects will not build properly without being configured to use Desktop MSBuild (i.e. the MSBuild shipped with Visual Studio). As a result, you will ideally need to be on Windows and have Visual Studio 2019 Community (v16.10 or greater) installed with .NET Core and Xamarin workloads. If you don't have this (i.e. because you're on Linux or Mac), you won't be able to build the older Xamarin packages.
Copy link
Member

Choose a reason for hiding this comment

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

Is there actually a Rider configuration that allows to build one project with MSBuild v16 and another with v17? .NET 6 needs MSBuild v17

Copy link
Member Author

Choose a reason for hiding this comment

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

Rider can use desktop MSBuild if you configure it to. Why'd you ask?

using Microsoft.CodeAnalysis.CSharp.Syntax;

namespace Silk.NET.SilkTouch
{
public interface INativeContextOverride
{
TypeDeclarationSyntax Type(string name, string lib, EntryPoint[] entrypoints);
TypeDeclarationSyntax Type(string name, string lib, EntryPoint[] entrypoints, Compilation comp);
Copy link
Member

Choose a reason for hiding this comment

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

That doesn't seem right

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed to take a new context structure.


namespace Silk.NET.SilkTouch.NativeContextOverrides
{
public sealed class PInvokeNativeContextOverride : INativeContextOverride
{
/// <inheritdoc />
public TypeDeclarationSyntax Type(string name, string lib, EntryPoint[] entrypoints)
public TypeDeclarationSyntax Type(string name, string lib, EntryPoint[] entrypoints, Compilation comp)
{
Copy link
Member

Choose a reason for hiding this comment

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

if we only pass the compilation to get this bool, why not just pass the bool?

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed to use a new context structure which does not have a compilation within it.

android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true">
</application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Copy link
Member

Choose a reason for hiding this comment

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

What

Copy link
Member Author

Choose a reason for hiding this comment

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

Default.

Suggested change
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Comment on lines +12 to +23
<ItemGroup Condition="'$(TargetFramework)' != 'net6.0-android' And '$(TargetFramework)' != 'net6.0-ios' And '$(TargetFramework)' != 'net6.0-maccatalyst' And '$(TargetFramework)' != 'net6.0'">
<ProjectReference Include="..\Silk.NET.Windowing.Glfw\Silk.NET.Windowing.Glfw.csproj" />
<ProjectReference Include="..\Silk.NET.Windowing.Sdl\Silk.NET.Windowing.Sdl.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0-android' Or '$(TargetFramework)' == 'net6.0-ios' Or '$(TargetFramework)' == 'net6.0-maccatalyst'">
<ProjectReference Include="..\Silk.NET.Windowing.Sdl\Silk.NET.Windowing.Sdl.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<ProjectReference Include="..\Silk.NET.Windowing.Glfw\Silk.NET.Windowing.Glfw.csproj" />
</ItemGroup>
Copy link
Member

Choose a reason for hiding this comment

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

I'm sorry, what? Why? Why not just include both GLFW and SDL everywhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because we have no reason to. GLFW is priority one for desktop and there's zero reason to use SDL over GLFW on desktop - if for whatever reason you do want to use SDL you can go reference it yourself, but I don't think we should mandate that our users ship two extra (very large) DLLs (one for backend, and one for bindings) for a backend that they just don't need on their platform.

The SDL backend was only written to get us to platforms where GLFW doesn't work, so let's only use it on those platforms?

@Perksey
Copy link
Member Author

Perksey commented Aug 27, 2021

This is ready for another review.

Copy link
Member

@HurricanKai HurricanKai left a comment

Choose a reason for hiding this comment

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

Reviewed on my phone, so it's possible I missed something. Looks good.

public static FunctionPointerTypeSyntax GetFuncPtrType
(
this IEnumerable<FunctionPointerParameterSyntax> parameters,
CallingConvention? unmanagedCallingConvention
Copy link
Member

Choose a reason for hiding this comment

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

Should be non-null

Copy link
Member Author

Choose a reason for hiding this comment

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

Null is treated as managed i.e. there is no unmanaged calling convention.

public static FunctionPointerTypeSyntax GetFuncPtrType
(
this IEnumerable<ITypeSymbol> loadTypes,
CallingConvention? unmanagedCallingConvention
Copy link
Member

Choose a reason for hiding this comment

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

Should be non-null

Copy link
Member Author

Choose a reason for hiding this comment

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

Same comment as above.

@Perksey Perksey merged commit 0277641 into main Aug 28, 2021
2.X Sustaining automation moved this from WIP / Next Monthly Update to Confirmed / Next Monthly Update Aug 28, 2021
@Perksey Perksey deleted the feature/sustaining-net6 branch August 28, 2021 12:49
Perksey added a commit that referenced this pull request Mar 25, 2022
* Initial pass of adding .NET 6 support for sustaining

* Get packaging working properly (afiak)

* lol

* SilkTouch: Stop making managed conv assumptions (.NET 5+), short names

* Triangle on .NET 6 on Android now works

* Fix old android lab app for fullscreen

* Fix bad ifdef

* CI fix?

* Review fixes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Windowing enhancement New feature or request
Projects
No open projects
2.X Sustaining
Confirmed / Next Monthly Update
Development

Successfully merging this pull request may close these issues.

None yet

2 participants