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

Optimize code to allow trimming / native aot #975

Open
badcel opened this issue Nov 13, 2023 · 3 comments
Open

Optimize code to allow trimming / native aot #975

badcel opened this issue Nov 13, 2023 · 3 comments

Comments

@badcel
Copy link
Member

badcel commented Nov 13, 2023

Optimize code to allow trimming / native AOT:

A first step is probably to enable analyzers and fix the resulting warnings, like @kant2002 mentioned in #468 (comment)

Probably depends on #698.

@DeafMan1983
Copy link

Hello @badcel

Great news!

I made Gtk4 into C# with modern function pointer ( delegate* <...> ) and some referenced instances like GTK_WINDOW, G_APPLICATION etc...

Example:

namespace Gtk4Test;

using static DeafMan1983.ConvFunctions;

using DeafMan1983.Interop.GTK4;
using static DeafMan1983.Interop.GTK4.Gtk;
using static DeafMan1983.Interop.GTK4.GObject;
using static DeafMan1983.Interop.GTK4.Gio;

unsafe class Program
{
    static void activate(GtkApplication* app, void* user_data)
    {
        GtkWidget* window = gtk_application_window_new(app);
        gtk_window_set_title(GTK_WINDOW(window), SBytePointerFromString("Window"));
        gtk_window_set_default_size(GTK_WINDOW (window), 200, 200);
        gtk_window_present(GTK_WINDOW(window));
    }

    static int Main(string[] args)
    {
        GtkApplication *app = gtk_application_new(SBytePointerFromString("org.gtk.example"), GApplicationFlags.G_APPLICATION_FLAGS_NONE);
        g_signal_connect(app, SBytePointerFromString("activate"), G_CALLBACK (&activate), null);
        int status = g_application_run(G_APPLICATION (app), args.Length, SByteDoublePointersFromStringArray(args));
        g_object_unref (app);
        return status;
    }
}

But It is still working in process with Gtk4 :)
Check out my workstatiion if you want know about this.
image
image

And I want to tell about GObject will to be as void* because C# understands hard with instance like other structures example GtkButton or GdkDisplay etc....

They should to know void*

I hope I can complete Gtk4 then I will release my complete Gtk4 in C#.

I publish into native aot.
image

Woohoo! It works fine :D

@DeafMan1983
Copy link

And more details: adding button...
image

@badcel
Copy link
Member Author

badcel commented Nov 15, 2023

Great that it works.

In general I think unsafe code should only be used in areas where it makes sense to allow native aot to work. Making the whole internal namespace completely unsafe is probably not the way to go.

If you want to help out you could create a small test program which creates a new GObject (I think you need to derive from GObject.Object to use this constructor) and compile this program into native code and see what it is complaining about.

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

No branches or pull requests

2 participants