Skip to content

Commit fd7d4b5

Browse files
committed
Upgrade graalwasm-starter.
1 parent 44af40c commit fd7d4b5

File tree

5 files changed

+147
-111
lines changed

5 files changed

+147
-111
lines changed

.github/workflows/graalwasm-starter.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
run: |
3030
cd graalwasm/graalwasm-starter
3131
./mvnw --no-transfer-progress test
32-
./mvnw --no-transfer-progress exec:java
32+
./mvnw --no-transfer-progress exec:exec
3333
- name: Build, test, and run 'graalwasm-starter' using Gradle
3434
run: |
3535
cd graalwasm/graalwasm-starter

graalwasm/graalwasm-starter/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ To build and test the demo, run:
2222
To execute the main method, run:
2323

2424
```bash
25-
./mvnw exec:java
25+
./mvnw exec:exec
2626
```
2727

2828
## Run the Application Using Gradle

graalwasm/graalwasm-starter/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@ application {
2323
mainClass = "com.example.App"
2424
}
2525

26+
val truffleJvmArgs = listOf("--enable-native-access=ALL-UNNAMED", "--sun-misc-unsafe-memory-access=allow")
27+
28+
tasks.named<JavaExec>("run") {
29+
jvmArgs = truffleJvmArgs
30+
}
31+
2632
tasks.named<Test>("test") {
33+
jvmArgs = truffleJvmArgs
2734
// Use JUnit Platform for unit tests.
2835
useJUnitPlatform()
2936
}
Lines changed: 135 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,145 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4-
<modelVersion>4.0.0</modelVersion>
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
55

6-
<groupId>com.example</groupId>
7-
<artifactId>demo</artifactId>
8-
<version>1.0-SNAPSHOT</version>
6+
<groupId>com.example</groupId>
7+
<artifactId>demo</artifactId>
8+
<version>1.0-SNAPSHOT</version>
99

10-
<name>demo</name>
11-
<url>https://www.example.com</url>
10+
<name>demo</name>
11+
<url>https://www.example.com</url>
1212

13-
<properties>
14-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15-
<maven.compiler.release>17</maven.compiler.release>
16-
</properties>
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
<maven.compiler.release>17</maven.compiler.release>
16+
<truffle.jvm.arg1>--enable-native-access=ALL-UNNAMED</truffle.jvm.arg1>
17+
<truffle.jvm.arg2>--sun-misc-unsafe-memory-access=allow</truffle.jvm.arg2>
18+
</properties>
1719

18-
<dependencyManagement>
19-
<dependencies>
20-
<dependency>
21-
<groupId>org.junit</groupId>
22-
<artifactId>junit-bom</artifactId>
23-
<version>5.11.0</version>
24-
<type>pom</type>
25-
<scope>import</scope>
26-
</dependency>
27-
</dependencies>
28-
</dependencyManagement>
20+
<dependencyManagement>
21+
<dependencies>
22+
<dependency>
23+
<groupId>org.junit</groupId>
24+
<artifactId>junit-bom</artifactId>
25+
<version>5.11.0</version>
26+
<type>pom</type>
27+
<scope>import</scope>
28+
</dependency>
29+
</dependencies>
30+
</dependencyManagement>
2931

30-
<dependencies>
31-
<dependency>
32-
<groupId>org.graalvm.polyglot</groupId>
33-
<artifactId>polyglot</artifactId>
34-
<version>25.0.0</version>
35-
</dependency>
36-
<dependency>
37-
<groupId>org.graalvm.polyglot</groupId>
38-
<artifactId>wasm</artifactId>
39-
<version>25.0.0</version>
40-
<type>pom</type>
41-
</dependency>
32+
<dependencies>
33+
<dependency>
34+
<groupId>org.graalvm.polyglot</groupId>
35+
<artifactId>polyglot</artifactId>
36+
<version>25.0.0</version>
37+
</dependency>
38+
<dependency>
39+
<groupId>org.graalvm.polyglot</groupId>
40+
<artifactId>wasm</artifactId>
41+
<version>25.0.0</version>
42+
<type>pom</type>
43+
</dependency>
4244

43-
<dependency>
44-
<groupId>org.junit.jupiter</groupId>
45-
<artifactId>junit-jupiter-api</artifactId>
46-
<scope>test</scope>
47-
</dependency>
48-
<!-- Optionally: parameterized tests support -->
49-
<dependency>
50-
<groupId>org.junit.jupiter</groupId>
51-
<artifactId>junit-jupiter-params</artifactId>
52-
<scope>test</scope>
53-
</dependency>
54-
</dependencies>
45+
<dependency>
46+
<groupId>org.junit.jupiter</groupId>
47+
<artifactId>junit-jupiter-api</artifactId>
48+
<scope>test</scope>
49+
</dependency>
50+
<!-- Optionally: parameterized tests support -->
51+
<dependency>
52+
<groupId>org.junit.jupiter</groupId>
53+
<artifactId>junit-jupiter-params</artifactId>
54+
<scope>test</scope>
55+
</dependency>
56+
</dependencies>
5557

56-
<build>
57-
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
58-
<plugins>
59-
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
60-
<plugin>
61-
<artifactId>maven-clean-plugin</artifactId>
62-
<version>3.4.0</version>
63-
</plugin>
64-
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
65-
<plugin>
66-
<artifactId>maven-resources-plugin</artifactId>
67-
<version>3.3.1</version>
68-
</plugin>
69-
<plugin>
70-
<artifactId>maven-compiler-plugin</artifactId>
71-
<version>3.13.0</version>
72-
</plugin>
73-
<plugin>
74-
<artifactId>maven-surefire-plugin</artifactId>
75-
<version>3.3.0</version>
76-
</plugin>
77-
<plugin>
78-
<groupId>org.codehaus.mojo</groupId>
79-
<artifactId>exec-maven-plugin</artifactId>
80-
<version>1.2.1</version>
81-
<executions>
82-
<execution>
83-
<goals>
84-
<goal>java</goal>
85-
</goals>
86-
</execution>
87-
</executions>
88-
<configuration>
89-
<mainClass>com.example.App</mainClass>
90-
</configuration>
91-
</plugin>
92-
<plugin>
93-
<artifactId>maven-jar-plugin</artifactId>
94-
<version>3.4.2</version>
95-
</plugin>
96-
<plugin>
97-
<artifactId>maven-install-plugin</artifactId>
98-
<version>3.1.2</version>
99-
</plugin>
100-
<plugin>
101-
<artifactId>maven-deploy-plugin</artifactId>
102-
<version>3.1.2</version>
103-
</plugin>
104-
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
105-
<plugin>
106-
<artifactId>maven-site-plugin</artifactId>
107-
<version>3.12.1</version>
108-
</plugin>
109-
<plugin>
110-
<artifactId>maven-project-info-reports-plugin</artifactId>
111-
<version>3.6.1</version>
112-
</plugin>
113-
</plugins>
114-
</pluginManagement>
115-
</build>
58+
<build>
59+
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
60+
<plugins>
61+
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
62+
<plugin>
63+
<artifactId>maven-clean-plugin</artifactId>
64+
<version>3.4.0</version>
65+
</plugin>
66+
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
67+
<plugin>
68+
<artifactId>maven-resources-plugin</artifactId>
69+
<version>3.3.1</version>
70+
</plugin>
71+
<plugin>
72+
<artifactId>maven-compiler-plugin</artifactId>
73+
<version>3.13.0</version>
74+
</plugin>
75+
<plugin>
76+
<artifactId>maven-surefire-plugin</artifactId>
77+
<version>3.3.0</version>
78+
</plugin>
79+
<plugin>
80+
<groupId>org.codehaus.mojo</groupId>
81+
<artifactId>exec-maven-plugin</artifactId>
82+
<version>1.2.1</version>
83+
<executions>
84+
<execution>
85+
<goals>
86+
<goal>java</goal>
87+
</goals>
88+
</execution>
89+
</executions>
90+
<configuration>
91+
<mainClass>com.example.App</mainClass>
92+
</configuration>
93+
</plugin>
94+
<plugin>
95+
<artifactId>maven-jar-plugin</artifactId>
96+
<version>3.4.2</version>
97+
</plugin>
98+
<plugin>
99+
<artifactId>maven-install-plugin</artifactId>
100+
<version>3.1.2</version>
101+
</plugin>
102+
<plugin>
103+
<artifactId>maven-deploy-plugin</artifactId>
104+
<version>3.1.2</version>
105+
</plugin>
106+
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
107+
<plugin>
108+
<artifactId>maven-site-plugin</artifactId>
109+
<version>3.12.1</version>
110+
</plugin>
111+
<plugin>
112+
<artifactId>maven-project-info-reports-plugin</artifactId>
113+
<version>3.6.1</version>
114+
</plugin>
115+
<plugin>
116+
<artifactId>exec-maven-plugin</artifactId>
117+
<version>1.2.1</version>
118+
</plugin>
119+
</plugins>
120+
</pluginManagement>
121+
<plugins>
122+
<plugin>
123+
<groupId>org.apache.maven.plugins</groupId>
124+
<artifactId>maven-surefire-plugin</artifactId>
125+
<configuration>
126+
<argLine>${truffle.jvm.arg1} ${truffle.jvm.arg2}</argLine>
127+
</configuration>
128+
</plugin>
129+
<plugin>
130+
<groupId>org.codehaus.mojo</groupId>
131+
<artifactId>exec-maven-plugin</artifactId>
132+
<configuration>
133+
<executable>java</executable>
134+
<arguments>
135+
<argument>-classpath</argument>
136+
<classpath/>
137+
<argument>${truffle.jvm.arg1}</argument>
138+
<argument>${truffle.jvm.arg2}</argument>
139+
<argument>com.example.App</argument>
140+
</arguments>
141+
</configuration>
142+
</plugin>
143+
</plugins>
144+
</build>
116145
</project>

graalwasm/graalwasm-starter/src/main/java/com/example/App.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ public class App {
1818
public static void main(String[] args) throws IOException {
1919
try (Context context = Context.create()) {
2020
URL wasmFile = App.class.getResource("add-two.wasm");
21-
String moduleName = "main";
22-
context.eval(Source.newBuilder("wasm", wasmFile).name(moduleName).build());
23-
Value addTwo = context.getBindings("wasm").getMember(moduleName).getMember("addTwo");
21+
Value mainModule = context.eval(Source.newBuilder("wasm", wasmFile).build());
22+
Value mainInstance = mainModule.newInstance();
23+
Value addTwo = mainInstance.getMember("exports").getMember("addTwo");
2424
System.out.println("addTwo(40, 2) = " + addTwo.execute(40, 2));
2525
}
2626
}

0 commit comments

Comments
 (0)