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

How to get started with GraalVM Polyglot framework since GraalVM 23.1? #8042

Closed
fabrice-ducos opened this issue Dec 16, 2023 · 4 comments
Closed
Assignees
Labels

Comments

@fabrice-ducos
Copy link

fabrice-ducos commented Dec 16, 2023

Describe GraalVM and your environment :

  • GraalVM version or commit id if built from source: 21.0.1+12.1
  • CE or EE: CE
  • JDK version: JDK21
  • OS and OS Version: Linux DESKTOP-WIN10 4.4.0-19041-Microsoft 3636-Microsoft Thu Oct 19 17:41:00 PST 2023 x86_64 x86_64 x86_64 GNU/Linux
  • Architecture: x86_64
  • The output of java -Xinternalversion:
Java HotSpot(TM) 64-Bit Server VM (21.0.1+12-jvmci-23.1-b19) for linux-amd64 JRE (21.0.1+12-jvmci-23.1-b19), built on 2023-10-06T21:19:10Z by "buildslave" with gcc 11.2.0

Have you verified this issue still happens when using the latest snapshot? No
You can find snapshot builds here: https://github.com/graalvm/graalvm-ce-dev-builds/releases

Describe the issue
I am new to GraalVM. My current interest is mostly its polyglot abilities (calling various scripting languages from the GraalVM, and having them communicate in both directions with some JVM languages, Java, Scala, Groovy...).

According to the documentation, in order to experiment with scripting languages (without having to write embedding code, e.g. from Java, that can be done in a second step), one needs special versions of interpreters (js, node, ...) that are not provided by default with the graalvm package (that is understandable).

After going through the online doc, I discovered that earlier, these tools could be installed easily with the GraalVM updater gu, up to version 23.0. I also discovered that this tool was deprecated and removed since version 23.1 (the one I got).

While the gu tool was easy to use and understand, I do understand the rationale behind its deprecation, that is clearly explained in the issue #6852. However, the current alternative doesn't look that clear or user-friendly to me.

Now users are offered to get the dependencies directly from a pom.xml file, also provided in the above issue #6852:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.yourcorp.yourapp</groupId>
    <artifactId>yourartefact</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <dependencies>
        <dependency> <!-- We also move from graal-sdk => polyglot -->
            <groupId>org.graalvm.polyglot</groupId>
            <artifactId>polyglot</artifactId>
            <version>23.1.0</version>
        </dependency>
        <dependency> <!-- you can also depend on org.graalvm.polyglot:languages for all languages -->
            <groupId>org.graalvm.python</groupId>
            <artifactId>python</artifactId>
            <version>23.1.0</version>
            <type>pom</type>
        </dependency>
        <dependency> <!-- all tools we include in Oracle GraalVM -->
            <groupId>org.graalvm.polyglot</groupId>
            <artifactId>tools</artifactId>
            <version>23.1.0</version>
            <type>pom</type>
        </dependency>
    </dependencies>
</project>

That is well and good, but one meets two problems here (at least I do, please confirm).

  1. The mvn package fails (see below)
  2. In the event it works, what to do next? One expects to get a .jar, what to do with it in order to run th examples from the online documentation? Is it straightforward like with gu?

Steps to reproduce the issue
mvn package

[WARNING] The POM for org.graalvm.python:python:pom:23.1.0 is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.390 s
[INFO] Finished at: 2023-12-16T19:21:30+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project yourartefact: Could not resolve dependencies for project com.yourcorp.yourapp:yourartefact:jar:1.0-SNAPSHOT: The following artifacts could not be resolved: org.graalvm.python:python:pom:23.1.0 (absent): org.graalvm.python:python:pom:23.1.0 was not found in https://repo.maven.apache.org/maven2 during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]

Expected behavior
A target directory containing a .jar file is produced. But what to do next? (e.g. to easily get or implement a GraalVM interpreter such as js, node... referred to in the GraalVM documentation)

It seems that the pom file from issue #6852 is either outdated or incomplete. I didn't find any more recent reference on this topic. I can also simply miss some silly point. Of course, it contains only dependencies, but if even the dependencies fail, it makes little sense to build upon them. Is there a special repository to add?

It would be nice to find somewhere a minimal working example based on this.

The only temporary solution I see at the moment is to use an older version of GraalVM that provides gu, investing some time in a tool that is already deprecated (but that works).

Can anyone provide some guidance or advice?

Thanks

@alina-yur
Copy link
Member

hi @fabrice-ducos, I think the issue might be in the way you are adding the Python dependency; can you try replacing

            <groupId>org.graalvm.python</groupId>
            <artifactId>python</artifactId>

with

    <groupId>org.graalvm.polyglot</groupId>
           <artifactId>python</artifactId>

?

@alina-yur alina-yur self-assigned this Jan 9, 2024
@fabrice-ducos
Copy link
Author

fabrice-ducos commented Jan 10, 2024

Dear @alina-yur,

That was it! Thank you very much. This typo actually comes from this post #6852 (comment), I just pasted and copied it here (maybe it was correct in the original post at the time it was written, but it is certainly outdated now, and I found no other documentation anywhere about the new Polyglot API in 23.1 and later, without the GraalVM Updater).

Now, when one performs mvn package on this pom.xml, one gets a jar file, e.g. target/yourartefact-1.0-SNAPSHOT.jar. Is there any documentation somewhere about how to use it, in order to get the GraalVM python interpreter, that was straightforward before with gu install python?

The same issue applies to other GraalVM supported languages (Ruby, Javascript...).

Best regards

@alina-yur
Copy link
Member

alina-yur commented Jan 10, 2024

Hi @fabrice-ducos. The ticket you're linking to is pre-release, so it could have been that it was our thinking at the time, but it's not final documentation. Please refer to https://www.graalvm.org/latest/reference-manual/embed-languages/ for official guidance.
You don't need to get the Python runtime separately now. Python/any other GraalVM language is just a Maven dependency as any other depepency you might be using in your project. A project like this would also run on any JDK, but it's strongly recommended that you run on GraalVM JDK so that the languages can benefit from the Graal compiler.
You can also find more info here: https://medium.com/graalvm/truffle-unchained-13887b77b62c, and a full reproducible example: https://github.com/graalvm/polyglot-embedding-demo/

@fabrice-ducos
Copy link
Author

Dear @alina-yur, thank you for the clarification.

I will read your links thoroughly.
I consider this issue closed.

Best regards!

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

No branches or pull requests

2 participants