javy-plugin-api

Crates.iojavy-plugin-api
lib.rsjavy-plugin-api
version4.0.0
created_at2024-11-12 22:24:52.323831+00
updated_at2025-08-29 17:33:39.98147+00
descriptionAPIs for Javy plugins
homepagehttps://github.com/bytecodealliance/javy/tree/main/crates/plugin-api
repositoryhttps://github.com/bytecodealliance/javy/tree/main/crates/plugin-api
max_upload_size
id1445657
size40,011
javy-publish (github:bytecodealliance:javy-publish)

documentation

README

javy-plugin-api

A crate for creating Javy plugins

Documentation Status crates.io status

Refer to the crate level documentation to learn more.

Example usage:

use javy_plugin_api::{
    javy::{quickjs::prelude::Func, Runtime},
    javy_plugin, Config,
};

wit_bindgen::generate!({ world: "my-javy-plugin-v1", generate_all });

fn config() -> Config {
    let mut config = Config::default();
    config
        .text_encoding(true)
        .javy_stream_io(true);
    config
}

fn modify_runtime(runtime: Runtime) -> Runtime {
    runtime.context().with(|ctx| {
        ctx.globals().set("plugin", true).unwrap();
    });
    runtime
}

struct Component;

// Dynamically linked modules will use `my_javy_plugin_v1` as the import
// namespace.
javy_plugin!("my-javy-plugin-v1", Component, config, modify_runtime);

export!(Component);

Migration for v2.0.0

Please read the extending Javy documentation for the new plugin API details.

To update your plugin:

  1. Create a directory named wit adjacent to the Cargo.toml file
  2. Inside that wit directory, create a WIT file matching the details in the extending Javy documentation
  3. Create a config() -> Config function that will return a Javy config
  4. Create a modify_runtime(runtime: Runtime) -> Runtime function that will perform whatever modifications to runtime that are necessary
  5. Add a dependency on wit-bindgen to your crate
  6. Use wit_bindgen::generate! to create the required traits from the WIT file
  7. Create a struct type
  8. Remove import_namespace! and use javy_plugin! instead. Ensure you use a different value for the import_namespace parameter since the API has changed. Pass your struct type, your config function, and your modify_runtime function.
  9. Call export! on your struct type.

Publishing to crates.io

To publish this crate to crates.io, run ./publish.sh.

Commit count: 1081

cargo fmt