githubEdit

Native Plugins

!!! warning

The plugin api is highly experimental, and will most likely change soon and often. It also isn't ABI-stable, and will potentially break between midio/rust versions.

Midio supports writing native plugins which provide a way of interoperating with native libraries as well as provide custom parameter compilers like the ones used in Http.HttpEndpoint and Strings.Regex.

Currently, only plugins written in Rust are supported, but this will be expanded upon in the future if it proves to be useful. It is possible to wrap libraries in other languages in rust first, and then integrate with Midio.

How to write a plugin

First, create a new Rust library crate, for example:

cargo new --lib MyMidioPlugin

Then, add midio-plugin-api as a dependency.

cargo add `midio-plugin-api`

!!! note

The `midio-plugin-api` crate might not be publicly available yet.

Then implement the CorePlugin trait for your plugin.

struct MyPlugin;

impl MidioPlugin for MyPlugin {
    extern "C" fn get_plugins() -> CompilerPlugins {
        ...
    }

    extern "C" fn get_dependencies(package_id: PackageId, package: &ExecutablePackage) -> Result<EngineDependencies> {
        ...
    }
}

And finally, export it using the midio_plugin! macro, which simply adds two exportable, non-mangled functions which points those implementations.

Then configure the crate to build a dynamic library by adding the following to you cargo.toml file:

Then build your library:

Finally, add a declaration to your midio module which points to the produced dynamic library:

!!! note

Was this helpful?