Coder Social home page Coder Social logo

tanbinh123 / wasmtime-java Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kawamuray/wasmtime-java

1.0 0.0 0.0 223 KB

Java or JVM-language binding for Wasmtime

License: Apache License 2.0

Python 1.86% Java 56.45% Rust 41.22% Shell 0.47%

wasmtime-java's Introduction

wasmtime-java

Java (or any JVM) language binding for Wasmtime.

Some basic examples are working, but many API implementations are work in progress.

Declaring Dependencies

Gradle example:

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
Windows x86_64

Example

See examples for the full example.

public class HelloWasm {
    public static void main(String[] args) {
        try (Store store = new Store();
             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<Extern> 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:

$ ./gradlew -Pmain=examples.HelloWorld examples:run

How to build

$ ./gradlew build

License

Apache License Version 2.0

wasmtime-java's People

Contributors

kateinoigakukun avatar kawamuray avatar lbenard avatar superice666 avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.