> For the complete documentation index, see [llms.txt](https://docs.midio.com/midio-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.midio.com/midio-docs/internal/native-plugins.md).

# 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.

```rust
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:

```toml
[lib]
crate-type = ["cdylib", "rlib"]
```

Then build your library:

```
cargo build --release
```

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

```midio
native_dependencies_location("./target/release/libmy_midio_plugin")
```

!!! note

```
Don't add the file ending to this declaration, which is different for each platform.
```
