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

[DO NOT MERGE] Initial script to build a working Graal binary, Windows #159

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

Conversation

GavinRay97
Copy link

@GavinRay97 GavinRay97 commented Sep 28, 2021

I deleted most of the example stuff just to get this working without building Skija locally since the dependency/build mgmt is done through Python scripts instead of Gradle/Maven (felt easier lol)

So don't merge this -- but the changes to native_image.py show a working (for me) path towards building a Windows binary. You could build a shared/static lib with @CEntrypoint() and consume the Java app from C/C++ too.

I am able to implement and test this for Linux as well, but I cannot test for Darwin unfortunately, as I don't own an Apple computer.

The Graal configuration needed for JNI and resources (the shared lib) to work can be distributed by putting them in the .jar, under: META-INF/native-image/<group-id>/<artifact-id>, so I've done that here with the output of the tracing agent:

image

Note there are some rough spots yet. Specifically:

    public static void main(String[] args) {
        App.init();

        // Window window = App.makeWindow();

        // Using the generic window seems to cause:
        // Exception in thread "main" java.lang.NoSuchMethodException: io.github.humbleui.jwm.WindowWin32.<init>()
        //     at java.lang.Class.getConstructor0(DynamicHub.java:3585)
        //     at java.lang.Class.getDeclaredConstructor(DynamicHub.java:2754)
        //     at io.github.humbleui.jwm.App.makeWindow(App.java:50)
        //     at io.github.humbleui.jwm.examples.Example.main(Example.java:18)

        // Maybe because the underlying constructor isn't directly invoked, so Graal doesn't statically analyze it?
        // Potential solution: Hard-code "if OS == WINDOWS { new WindowWin32() }" etc?

        WindowWin32 window = new WindowWin32();

I'm no Graal expert, just someone who has used it a bit. Can try to figure out more about this, but I think it may be because it never encounters the direct constructor invocation so doesn't include it in the compiled binary?

Not really sure.

@GavinRay97 GavinRay97 changed the title [DO NOT MERGE] Initial sample of working Graal binary, Windows [DO NOT MERGE] Initial script to build a working Graal binary, Windows Sep 28, 2021
@tonsky
Copy link
Collaborator

tonsky commented Sep 29, 2021

This is fantastic! I’ll take a look soon and see if I can run on/adopt it to macOS. Being able to run from native image is a very desirable property!

@tonsky tonsky force-pushed the main branch 2 times, most recently from b4a6c73 to bada613 Compare October 4, 2021 17:27
@tonsky
Copy link
Collaborator

tonsky commented Oct 4, 2021

The exception you see is probably due to reflection in App::makeWindow. Removed in 2a02339

@GavinRay97
Copy link
Author

Ohh, 🤦 yeah that makes complete sense.
I'd bet money you're spot-on with that change, would be surprised if it didn't fix it tbh.

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

Successfully merging this pull request may close these issues.

2 participants