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

Attempt to fix graalpy-install-package #259

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

bhoran
Copy link
Collaborator

@bhoran bhoran commented Feb 26, 2024

I've added a profile to the POM to build a native executable, which succeeds, but the resulting binary does not run. This is mainly due to resource files, AFAICT.

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Feb 26, 2024
@bhoran bhoran changed the title Update pom, update readme and add resources JSON Attempt to fix graalpy-install-package Feb 26, 2024
@bhoran
Copy link
Collaborator Author

bhoran commented Jun 19, 2024

@timfel -- when you get chance, could you take a look at this? I can't figure out what I need to change so that the Python module is included in the native executable. Thanks.

<!-- native-image-resources.json specifies what resources will be added to the
native executable.
See also https://www.graalvm.org/latest/reference-manual/native-image/dynamic-features/Resources/ -->
<buildArg>-H:ResourceConfigurationFiles=native-image-resources.json</buildArg>
Copy link
Member

Choose a reason for hiding this comment

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

A configuration file should be named resource-config.json. Could that be a reason? If you put it in META-INF/native-image/, native-image should pick it up, but not sure about the plugin.

@timfel
Copy link
Contributor

timfel commented Jun 20, 2024

@timfel -- when you get chance, could you take a look at this? I can't figure out what I need to change so that the Python module is included in the native executable. Thanks.

I think the entire thing should be deleted and recreated with the graalpy-maven-plugin. I'll try to make time to do that.

@timfel
Copy link
Contributor

timfel commented Jun 21, 2024

@timfel -- when you get chance, could you take a look at this? I can't figure out what I need to change so that the Python module is included in the native executable. Thanks.

I've updated the example using the maven plugin. Now the native image fails because of the use of AWT. IIRC this is documented to be complicated with native image, one has to use the tracing agent and some options to get it to work.

@bhoran
Copy link
Collaborator Author

bhoran commented Jun 25, 2024

@timfel -- when you get chance, could you take a look at this? I can't figure out what I need to change so that the Python module is included in the native executable. Thanks.

I've updated the example using the maven plugin. Now the native image fails because of the use of AWT. IIRC this is documented to be complicated with native image, one has to use the tracing agent and some options to get it to work.

Many thanks @timfel.

We're getting the following error on Windows 11

Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'PyfigletWrapper'
Exception in thread "main" org.graalvm.polyglot.PolyglotException
at org.graalvm.polyglot.Context.eval(Context.java:402)
at com.oracle.example.graalpy.Main.createPyfigletProxy(Main.java:140)
at com.oracle.example.graalpy.Main.main(Main.java:57)
[ERROR] Command execution failed.
org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
at org.apache.commons.exec.DefaultExecutor.executeInternal (DefaultExecutor.java:355)

As you say, native image on macOS and Linux fails because of AWT.

@timfel
Copy link
Contributor

timfel commented Jun 27, 2024

We're getting the following error on Windows 11
[...]
As you say, native image on macOS and Linux fails because of AWT.

That's a bug we had in 24.0 on Windows. I worked around it, but it still won't work, the native image on windows fails because of AWT as well:

D:\graalvm-demos\graalpy-install-package [fix-graalpy-package-install ≡ +0 ~2 -3 ~]> .\target\package-graalpy.exe
Exception in thread "main" java.lang.NoSuchMethodError: java.awt.Toolkit.getDefaultToolkit()Ljava/awt/Toolkit;
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.functions.JNIFunctions$Support.getMethodID(JNIFunctions.java:1347)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.functions.JNIFunctions$Support.getMethodID(JNIFunctions.java:1332)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.jni.functions.JNIFunctions.GetStaticMethodID(JNIFunctions.java:440)
        at [email protected]/java.awt.Toolkit.initIDs(Native Method)
        at [email protected]/java.awt.Toolkit.initStatic(Toolkit.java:1421)
        at [email protected]/java.awt.Toolkit.<clinit>(Toolkit.java:1393)
        at [email protected]/java.awt.Component.<clinit>(Component.java:624)
        at [email protected]/java.lang.Class.ensureInitialized(DynamicHub.java:599)
        at [email protected]/java.lang.Class.ensureInitialized(DynamicHub.java:599)
        at [email protected]/java.lang.Class.ensureInitialized(DynamicHub.java:599)
        at [email protected]/java.lang.Class.ensureInitialized(DynamicHub.java:599)
        at [email protected]/java.lang.Class.ensureInitialized(DynamicHub.java:599)
        at com.oracle.example.graalpy.Main.main(Main.java:59)
        at [email protected]/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)

@timfel
Copy link
Contributor

timfel commented Jun 27, 2024

A fix could be to add this:

modified   graalpy-install-package/pom.xml
@@ -131,6 +131,7 @@
           <arguments>
             <argument>-classpath</argument>
             <classpath />
+            <argument>-agentlib:native-image-agent=config-output-dir=${project.build.outputDirectory}/META-INF/native-image/awt/</argument>
             <argument>${main.class}</argument>
           </arguments>
         </configuration>

Then when you run mvn exec:exec on a Graal JDK once and build the native image after, it'll work. But then it won't run at all on Oracle JDK

@bhoran
Copy link
Collaborator Author

bhoran commented Jun 27, 2024

Not sure what changed, but this no longer compiles using mvn package.

[ERROR] Failed to execute goal org.graalvm.python:graalpy-maven-plugin:24.0.0:process-graalpy-resources (default) on project package-graalpy: failed to execute venv command [/Users/bhoran/Oracle/GraalVM/graalvm-demos/graalpy-install-package/target/classes/vfs/venv/bin/graalpy, -m, pip, install, pyfiglet==1.0.2]: Cannot run program "/Users/bhoran/Oracle/GraalVM/graalvm-demos/graalpy-install-package/target/classes/vfs/venv/bin/graalpy": error=2, No such file or directory -> [Help 1]

There's no /Users/bhoran/Oracle/GraalVM/graalvm-demos/graalpy-install-package/target/classes/vfs/venv/bin/graalpy.

@timfel
Copy link
Contributor

timfel commented Jun 28, 2024

Not sure what changed, but this no longer compiles using mvn package.

I tried on Windows and Linux with OpenJDK and Graal JDK and it works on both machines. Did you run mvn clean first?

@timfel
Copy link
Contributor

timfel commented Jun 28, 2024

@bhoran I updated the README with steps to make the native image work. I tested the steps on Linux and Windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants