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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.midio.com/midio-docs/internal/native-plugins.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
