Skip to content

Commit

Permalink
Add graalwasm-starter
Browse files Browse the repository at this point in the history
  • Loading branch information
jirkamarsik committed Sep 19, 2024
1 parent 7cc06df commit 7a819e5
Show file tree
Hide file tree
Showing 19 changed files with 1,066 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/graalwasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,32 @@ jobs:
./target/demo &
sleep 10
curl -s -D - -o /dev/null http://localhost:8080/photo/flipv
graalwasm-starter:
name: 'graalwasm-starter'
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: graalvm/setup-graalvm@v1
with:
java-version: '23.0.0'
distribution: 'graalvm'
github-token: ${{ secrets.GITHUB_TOKEN }}
cache: 'maven'
native-image-job-reports: 'true'
- name: Test 'graalwasm/graalwasm-starter' using Maven
run: |
cd graalwasm/graalwasm-starter
./mvnw --no-transfer-progress clean test
- name: Run 'graalwasm/graalwasm-starter' using Maven
run: |
cd graalwasm/graalwasm-starter
./mvnw --no-transfer-progress clean package exec:java
- name: Test 'graalwasm/graalwasm-starter' using Gradle
run: |
cd graalwasm/graalwasm-starter
./gradlew clean test
- name: Run 'graalwasm/graalwasm-starter' using Gradle
run: |
cd graalwasm/graalwasm-starter
./gradlew clean run
12 changes: 12 additions & 0 deletions graalwasm/graalwasm-starter/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# Linux start script should use lf
/gradlew text eol=lf

# These are Windows script files and should use crlf
*.bat text eol=crlf

# Binary files should be left untouched
*.jar binary

8 changes: 8 additions & 0 deletions graalwasm/graalwasm-starter/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Ignore Gradle project-specific cache directory
.gradle

# Ignore Gradle build output directory
build

# Ignore maven build output directory
target
Empty file.
Empty file.
19 changes: 19 additions & 0 deletions graalwasm/graalwasm-starter/.mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
wrapperVersion=3.3.2
distributionType=only-script
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.7/apache-maven-3.8.7-bin.zip
48 changes: 48 additions & 0 deletions graalwasm/graalwasm-starter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# GraalWasm Quick Start

This demo illustrates how GraalWasm can be used to embed a WebAssembly module in a Java application.

## Preparation

Install GraalVM for JDK 23 and set the value of `JAVA_HOME` accordingly.
We recommend using [SDKMAN!](https://sdkman.io/). (For other download options, see [GraalVM Downloads](https://www.graalvm.org/downloads/).)

```bash
sdk install java 23-graal
```

## Run the Application Using Maven

To build and test the demo, run:

```bash
./mvnw test
```

To execute the main method, run:

```bash
./mvnw exec:java
```

## Run the Application Using Gradle

To build and test the demo, run:

```bash
./gradlew test
```

To execute the main method, run:

```bash
./gradlew run
```

## Implementation Details

The WebAssembly is stored in the resource file `add-two.wasm`.
You can examine its textual representation in the resource file `add-two.wat`.
If you want to experiment with and tweak the WebAssembly module, then you will need to rebuild the `add-two.wasm` file from the `add-two.wat` file.
For that, you can use the `wat2wasm` tool from the [wabt toolkit](https://github.com/WebAssembly/wabt).
You can also use [this web app](https://webassembly.github.io/wabt/demo/wat2wasm/) to run `wat2wasm` in your browser instead of installing `wabt`.
29 changes: 29 additions & 0 deletions graalwasm/graalwasm-starter/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
plugins {
// Apply the application plugin to add support for building a CLI application in Java.
application
}

repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}

dependencies {
implementation("org.graalvm.polyglot:polyglot:24.1.0")
implementation("org.graalvm.polyglot:wasm:24.1.0")

// Use JUnit Jupiter for testing.
testImplementation("org.junit.jupiter:junit-jupiter:5.11.0")

testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}

application {
// Define the main class for the application.
mainClass = "com.example.App"
}

tasks.named<Test>("test") {
// Use JUnit Platform for unit tests.
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 7a819e5

Please sign in to comment.