Skip to content

Commit 9723cf9

Browse files
authored
Merge pull request #12 from tzezula/polyglot-isolate
Support for polyglot isolates for specific platforms was added.
2 parents dda1813 + ce1ce68 commit 9723cf9

File tree

2 files changed

+194
-10
lines changed

2 files changed

+194
-10
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ https://www.graalvm.org/latest/reference-manual/embed-languages/
1616

1717
Download Maven or import as Maven project into your IDE.
1818

19-
* `mvn package` build using javac
19+
* `mvn package` build using `javac`. Starting from GraalVM Polyglot API version 24.1.0, you can use `mvn -Pisolated package` to build with the native isolate version of a guest language. By default, only the native isolate library for the current platform is installed. To install native isolate libraries for all supported platforms, use `mvn -Pisolated -Disolated.all.platforms package`.
2020
* `mvn test` to run the tests
21-
* `mvn exec:exec` to run the Main application
21+
* `mvn exec:exec` to run the application. Starting from GraalVM Polyglot API version 24.1.0, you can use `mvn -Pisolated exec:exec` to embed the native isolate version of a guest language.
2222
* `mvn -Pnative package` to build a native-image
2323
* `mvn -Passembly package` to build an uber JAR containing all dependencies using the Maven Assembly Plugin. The resulting JAR can be executed using `java -jar embedding-1.0-SNAPSHOT-jar-with-dependencies.jar`. We do recommend not using shading whenever possible.
2424
* `mvn -Pshade package` to build an uber JAR containing all dependencies using the Maven Shade Plugin. The resulting JAR can be executed using `java -jar embedding-1.0-SNAPSHOT.jar`. We do recommend not using shading whenever possible.

pom.xml

Lines changed: 192 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
4545
Switch to community licenses by adding a `-community` suffix to the artefact id (e.g. `js-communtiy`).
4646
Switch to native isolate versions of languages by adding a `-isolate` suffix. (`js-isolate`).
47+
Starting from GraalVM Polyglot API version 24.1.0, native isolate versions of languages for specific platforms are supported.
48+
Refer to the `isolate` profiles for instructions on how to activate them.
4749
4850
Any dependency in the org.graalvm.polyglot group is intended for use by polyglot embeddings.
4951
-->
@@ -106,8 +108,10 @@
106108
<configuration>
107109
<executable>${java.home}/bin/java</executable>
108110
<arguments>
109-
<!-- We recommend running from the module-path by default.
110-
But you can also switch to the class-path here.-->
111+
<!--
112+
We recommend running from the module path by default.
113+
You can also switch to the classpath here.
114+
-->
111115
<argument>--module-path</argument>
112116
<modulepath/>
113117
<argument>-m</argument>
@@ -119,8 +123,10 @@
119123
<configuration>
120124
<executable>${java.home}/bin/java</executable>
121125
<arguments>
122-
<!-- We recommend running from the module-path by default.
123-
But you can also switch to the class-path here.-->
126+
<!--
127+
We recommend running from the module path by default.
128+
You can also switch to the classpath here.
129+
-->
124130
<argument>--module-path</argument>
125131
<modulepath/>
126132
<argument>-m</argument>
@@ -223,7 +229,7 @@
223229
<executions>
224230
<!--
225231
Copies compiler dependencies to the target/compiler folder. In order to run with an
226-
optimizing runtime on other JDKs than GraalVM we need to put the compiler on the upgrade-module-path.
232+
optimizing runtime on other JDKs than GraalVM we need to put the compiler on the upgrade module path.
227233
-->
228234
<execution>
229235
<id>copy-dependencies</id>
@@ -401,8 +407,186 @@
401407
</plugins>
402408
</build>
403409
</profile>
410+
<!--
411+
Profiles for using a native isolate language version for a specific platform.
412+
Native isolate versions of languages for a specific platforms are supported since
413+
Polyglot version 24.1 for JavaScript (js) and Python (python).
414+
These profiles may be removed if you are not using native isolate versions of languages.
415+
-->
416+
<!-- Linux AMD64 -->
417+
<profile>
418+
<id>isolated-linux-amd64</id>
419+
<activation>
420+
<os>
421+
<family>unix</family>
422+
<name>linux</name>
423+
<arch>amd64</arch>
424+
</os>
425+
</activation>
426+
<properties>
427+
<isolate.platform.suffix>-linux-amd64</isolate.platform.suffix>
428+
</properties>
429+
</profile>
430+
<!-- Linux AARCH64 -->
431+
<profile>
432+
<id>isolated-linux-aarch64</id>
433+
<activation>
434+
<os>
435+
<family>unix</family>
436+
<name>linux</name>
437+
<arch>aarch64</arch>
438+
</os>
439+
</activation>
440+
<properties>
441+
<isolate.platform.suffix>-linux-aarch64</isolate.platform.suffix>
442+
</properties>
443+
</profile>
444+
<!-- macOS AMD64 -->
445+
<profile>
446+
<id>isolated-darwin-amd64</id>
447+
<activation>
448+
<os>
449+
<family>mac</family>
450+
<arch>x86_64</arch>
451+
</os>
452+
</activation>
453+
<properties>
454+
<isolate.platform.suffix>-darwin-amd64</isolate.platform.suffix>
455+
</properties>
456+
</profile>
457+
<!-- macOS AARCH64 -->
458+
<profile>
459+
<id>isolated-darwin-aarch64</id>
460+
<activation>
461+
<os>
462+
<family>mac</family>
463+
<arch>aarch64</arch>
464+
</os>
465+
</activation>
466+
<properties>
467+
<isolate.platform.suffix>-darwin-aarch64</isolate.platform.suffix>
468+
</properties>
469+
</profile>
470+
<!-- Windows AMD64 -->
471+
<profile>
472+
<id>isolated-windows-amd64</id>
473+
<activation>
474+
<os>
475+
<family>windows</family>
476+
<arch>x86_64</arch>
477+
</os>
478+
</activation>
479+
<properties>
480+
<isolate.platform.suffix>-windows-amd64</isolate.platform.suffix>
481+
</properties>
482+
</profile>
483+
<!--
484+
Profile to package polyglot isolate libraries for all supported platforms.
485+
The profile is activated using `mvn -Pisolated -Disolated.all.platforms`
486+
-->
487+
<profile>
488+
<id>isolated-all-platforms</id>
489+
<activation>
490+
<property>
491+
<name>isolated.all.platforms</name>
492+
</property>
493+
</activation>
494+
<properties>
495+
<isolate.platform.suffix></isolate.platform.suffix>
496+
</properties>
497+
</profile>
498+
<!--
499+
Profile for using isolated version of a guest language.
500+
The profile is activated by `mvn -Pisolated`.
501+
-->
502+
<profile>
503+
<id>isolated</id>
504+
<properties>
505+
<isolated.language.id>js</isolated.language.id>
506+
</properties>
507+
<dependencies>
508+
<dependency>
509+
<groupId>org.graalvm.polyglot</groupId>
510+
<artifactId>js-isolate${isolate.platform.suffix}</artifactId>
511+
<version>${graalvm.version}</version>
512+
<type>pom</type>
513+
</dependency>
514+
<!--
515+
Including the non-isolated language as a provided dependency ensures that the non-isolated language
516+
included in the project dependencies is excluded from the Java module path.
517+
-->
518+
<dependency>
519+
<groupId>org.graalvm.polyglot</groupId>
520+
<artifactId>js</artifactId>
521+
<version>${graalvm.version}</version>
522+
<type>pom</type>
523+
<scope>provided</scope>
524+
</dependency>
525+
</dependencies>
526+
<build>
527+
<plugins>
528+
<plugin>
529+
<groupId>org.apache.maven.plugins</groupId>
530+
<artifactId>maven-surefire-plugin</artifactId>
531+
<version>3.1.2</version>
532+
<configuration>
533+
<systemPropertyVariables>
534+
<!--
535+
The Maven Surefire plugin sets the `polyglot.engine.SpawnIsolate=<language>`
536+
system property to utilize the isolated version of the language during unit tests.
537+
-->
538+
<polyglot.engine.SpawnIsolate>${isolated.language.id}</polyglot.engine.SpawnIsolate>
539+
</systemPropertyVariables>
540+
</configuration>
541+
</plugin>
542+
<plugin>
543+
<groupId>org.codehaus.mojo</groupId>
544+
<artifactId>exec-maven-plugin</artifactId>
545+
<version>3.1.0</version>
546+
<executions>
547+
<execution>
548+
<goals>
549+
<goal>exec</goal>
550+
</goals>
551+
</execution>
552+
<execution>
553+
<id>no-runtime-compilation</id>
554+
<goals>
555+
<goal>exec</goal>
556+
</goals>
557+
<configuration>
558+
<executable>${java.home}/bin/java</executable>
559+
<arguments>
560+
<argument>-Dpolyglot.engine.SpawnIsolate=${isolated.language.id}</argument>
561+
<!--
562+
We recommend running from the module path by default.
563+
You can also switch to the classpath here.
564+
-->
565+
<argument>--module-path</argument>
566+
<modulepath/>
567+
<argument>-m</argument>
568+
<argument>embedding/org.example.embedding.Main</argument>
569+
</arguments>
570+
</configuration>
571+
</execution>
572+
</executions>
573+
<configuration>
574+
<executable>${java.home}/bin/java</executable>
575+
<arguments>
576+
<argument>-Dpolyglot.engine.SpawnIsolate=${isolated.language.id}</argument>
577+
<!--
578+
We recommend running from the module path by default.
579+
You can also switch to the classpath here.
580+
-->
581+
<argument>--module-path</argument>
582+
<modulepath/>
583+
<argument>-m</argument>
584+
<argument>embedding/org.example.embedding.Main</argument>
585+
</arguments>
586+
</configuration>
587+
</plugin>
588+
</plugins>
589+
</build>
590+
</profile>
404591
</profiles>
405-
406592
</project>
407-
408-

0 commit comments

Comments
 (0)