Skip to content

Code change for PublishAot compliance #692

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ThomasFOG
Copy link

@ThomasFOG ThomasFOG commented Mar 20, 2025

This is a working copy to discuss #686

For now it has the functional changes required for the PublishAot compliance and fixes the IL warnings.

To be discussed:

  • Marshal.SizeOf<T>() and Marshal.PtrToStructure<T>(IntPtr ptr) both require .NET 4.5.1 (netstandard 1.2)
  • DynamicallyAccessedMembers requires .NET 5, and is not part of netstandard (which is not used by modern .NET platforms anymore)

For the standalone version, it is likely safe to switch the TargetFramework to net5.0. It wouldn't change much of the current nuget coverage. It would remove support for pre-net6 mono/Xamarin (which are irrelevant since they are mobile targets), and the non-mobile targets would remain the same. Then it would be possible to add <IsAotCompatible>true</IsAotCompatible>.

For the Unity version, the marshalling methods would require Unity 5.6 (aka 2017.0), which seems fine since the Unity package targets 2019.4, but DynamicallyAccessedMembers will be a problem no matter which targeted Unity version because modern .NET 5+ is not supported at all. In this specific case it seems reasonable to have preprocessing switches around it.

For the old-school .NET 4.0 .csproj, if it desired to keep having it around (as I understand, it is there for users willing to compile an old-school lib from source, and it is not distributed in the nuget nor on the pre-built releases, right?), then preprocessing or proxy types would be required to keep it running.

@rlabrecque
Copy link
Owner

I did a bit of the archeology and it looks like we do indeed only support Unity 2019 LTS+ since switching to the package format, because everything before that doesn't support the modern incarnation of the package format.

Is any of this still valuable without "DynamicallyAccessedMembers" ? Seems like we could get the Marshal changes in pretty easily; then at least your fork is more similar to upstream as we figure out what to do about DynamicallyAccessedMembers.

@ThomasFOG
Copy link
Author

ThomasFOG commented Mar 21, 2025

Is any of this still valuable without "DynamicallyAccessedMembers" ? Seems like we could get the Marshal changes in pretty easily; then at least your fork is more similar to upstream as we figure out what to do about DynamicallyAccessedMembers.

It would prevent a proper usage of IsAotCompatible and generate IL2091 warnings if callbacks are used. Which makes the idea of those changes not very valuable.

Functionally speaking, nothing will break when using PublishAot even without any of these changes. It's just about addressing warnings but there is nothing that Steamworks.NET does that I see could be an actual problem with AOT. It's mostly about the user experience and not generating misleading warnings (and quite honeslty it's just fine without the changes, it's just being picky).

We could very well just #pragma warning disable all the thing, slap IsAotCompatible and calling it a day (but that opens to regressions and possibly invisibilize issues).

@Akarinnnnn
Copy link
Contributor

Is any of this still valuable without "DynamicallyAccessedMembers" ?

D.A.M. attribute probably not a problem to Unity user. Once it's guarded under #ifdef NET_5_0_OR_GREATER preprocessor directive, this attribute will only seen in SDK style standalone project. For such using of preprocessor symbol, we already use STEAMWORKS_WIN etc. to distinguish platforms and CPU arch. So I think use directives here is OK.

@ThomasFOG
Copy link
Author

I need to update this PR. I intend to just remove DynamicallyAccessedMembers. This attribute doesn't do what I think it does (and I mostly still don't know what it actually does). I believe that Steamworks.NET will be as robust as it can get with just the marshalling changed to generics.

The other warnings can be ignored, and if someone complains about those warnings, they can be silenced to get a clean output.

@Akarinnnnn
Copy link
Contributor

Akarinnnnn commented May 30, 2025 via email

@ThomasFOG
Copy link
Author

That's what I thought it was doing, but working on another project where we added the attribute showed that it does absolutely not that and would still trim those types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants