https://github.com/kawamuray/wasmtime-java
Java or JVM-language binding for Wasmtime
https://github.com/kawamuray/wasmtime-java
java wasm wasmtime webassembly
Last synced: 11 months ago
JSON representation
Java or JVM-language binding for Wasmtime
- Host: GitHub
- URL: https://github.com/kawamuray/wasmtime-java
- Owner: kawamuray
- License: apache-2.0
- Created: 2020-07-23T16:15:17.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-10-07T06:27:30.000Z (over 2 years ago)
- Last Synced: 2024-11-14T20:58:34.639Z (about 1 year ago)
- Topics: java, wasm, wasmtime, webassembly
- Language: Java
- Homepage:
- Size: 335 KB
- Stars: 129
- Watchers: 8
- Forks: 29
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
wasmtime-java
=============
Java (or any JVM) language binding for [Wasmtime](https://github.com/bytecodealliance/wasmtime).
Some basic examples are working, but many API implementations are work in progress.
# Declaring Dependencies
Gradle example:
```groovy
repositories {
mavenCentral()
}
dependencies {
implementation "io.github.kawamuray.wasmtime:wasmtime-java:$LATEST_VERSION"
}
```
An artifact (JAR) of `wasmtime-java` ships along with prebuilt JNI libraries for some major platforms, so just adding the above dependency provides you a self-contained `wasmtime` runtime on supported platforms:
| OS | Arch |
| ---- | ---- |
| Linux (ELF) | x86_64 |
| Mac OS | x86_64 |
| Mac OS | aarch64 |
| Windows | x86_64 |
# Example
See [examples](./examples) for the full example.
```java
public class HelloWasm {
public static void main(String[] args) {
try (Store store = Store.withoutData();
Engine engine = store.engine();
Module module = Module.fromFile(engine, "./hello.wat");
Func helloFunc = WasmFunctions.wrap(store, () -> {
System.err.println(">>> Calling back...");
System.err.println(">>> Hello World!");
})) {
Collection imports = Arrays.asList(Extern.fromFunc(helloFunc));
try (Instance instance = new Instance(store, module, imports)) {
try (Func f = instance.getFunc("run").get()) {
WasmFunctions.Consumer0 fn = WasmFunctions.consumer(f);
fn.accept();
}
}
}
}
}
```
Run example:
```sh
$ ./gradlew -Pmain=examples.HelloWorld examples:run
```
# How to build
```sh
$ ./gradlew build
```
# License
Apache License Version 2.0