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

Make code a bit more NativeAOT friendly #468

Merged
merged 1 commit into from
Nov 15, 2021

Conversation

kant2002
Copy link
Contributor

I update where can

  • Marshal.SizeOf(Type) replaced with Marshal.SizeOt<T>()
  • Marshal.PtrToStructure(IntrPtr, Type) replaced with Marshal.PtrToStructure<T>(IntPtr)
  • Marshal.StructureToPtr(object, IntPtr, bool) replaced with Marshal.StructureToPtr<T>(T, IntPtr, bool)

This update change codegeneration piece and commented code,
since in case somebody willing to make that code works,
I would like that this part would not slip between cracks.

I update where can
- `Marshal.SizeOf(Type)` replaced with `Marshal.SizeOt<T>()`
- `Marshal.PtrToStructure(IntrPtr, Type)` replaced with `Marshal.PtrToStructure<T>(IntPtr)`
- `Marshal.StructureToPtr(object, IntPtr, bool)` replaced with `Marshal.StructureToPtr<T>(T, IntPtr, bool)`

This update change codegeneration piece and commented code,
since in case somebody willing to make that code works,
I would like that this part would not slip between cracks.
@badcel
Copy link
Member

badcel commented Nov 14, 2021

Thank you for your contribution, nice to see some interest from new faces 👍 . The code looks good to me.

As I'm currently working on a rewrite of the generator (#437) I think I'm stalling the code a bit until I work next on it so I don't forget to merge your changes directly into the generator3 branch as you did change templates which get replaced in the coming version.

@kant2002
Copy link
Contributor Author

@badcel I can re-target my changes to that branch if you like.

@badcel
Copy link
Member

badcel commented Nov 15, 2021

@kant2002 thank you but it is not necessary as the template change you did is not yet transfered into the new codebase.

@badcel badcel merged commit 7c2f3ec into gircore:develop Nov 15, 2021
@kant2002 kant2002 deleted the kant/nativeaot branch November 16, 2021 09:01
@DeafMan1983
Copy link

DeafMan1983 commented Nov 13, 2023

Hey @badcel,

Why do you use IntPtr, Marshal and Assembly for Net 7.0 and greater? 😒👎🤦‍♂️

Because some C# developers want pack into native executable ( native aot )

Please don't hesitate me!

I already uploaded Cairo with * like Pointer, modern function pointer.
Check out my repository!

I would like to help out with your Gir.Core without Marshal, Assembly and IntPtr.

Kind regards

@badcel
Copy link
Member

badcel commented Nov 13, 2023

Hi, I'm open for improvements in regard to AOT.

If you plan to contribute please start with very small PRs as I need to understand the direction you want to move.

Which feature of dotnet 7 do you mean which makes writing AOT friendly code easier?

As far as I'm aware IntPtr, Marshal and Assembly are not AOT unfriendly? Do you have some links to the documentation in this regard?

I'm aware that reflection is not very well supported in AOT scenarios. Removing reflection bit by bit is on the roadmap. See #919, #397.

@DeafMan1983
Copy link

As far as I'm aware IntPtr, Marshal and Assembly are not AOT unfriendly? Do you have some links to the documentation in this regard?

Yes you can check while you create simple console project for test with Marshal and Assembly.
You publish a project as native executable.
If you can verify different 2 versions like SDL-CS by Ethan Lee and my wrapper DeafMan1983.Interop.SDL2 for native public/deployment.

Look what's it going conflict with native aot?

Please be careful, if you use Marshal then I cannot publish/deploy as native executable with clang process.

I hope you understand me.

@kant2002
Copy link
Contributor Author

Marshal is not inherently not friendly to AOT. Some methods are, but not whole class. Same for Assembly, but to greater degree. For example NativeAOT provides handling of Assembly.GetExecutingAssembly()

I believe proper way to solve issues with NativeAOT is to solve all warnings from trim analyzers

@DeafMan1983
Copy link

DeafMan1983 commented Nov 13, 2023

@kant2002 you can test my repository AppWithPluginForNativeAot or TestLoadingImagesFromAnything they are an example for net 7 or greater. Sorry for only Linux if you add LoadLibraryEx, etc for Windows or libSystem for macOS.

There are my homemade testing examples.

@badcel
Copy link
Member

badcel commented Nov 13, 2023

I opened #975 to track suggestions in regard to native AOT / trimming. So this PR can rest as it was merged long ago.

@DeafMan1983
Copy link

Hello @kant2002 great news see in #975 !
Be friend with Native Aot!!!

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