Crate rrplug

source ·
Expand description

rrplug is a safe wrapper around the plugin system in R2Norhtstar

Setup with template

install cargo-generate if you don’t have it

cargo install cargo-generate
cargo generate -g  https://github.com/catornot/rrplug.git

Manual setup

for Northstar to be able to use the plugin it must be compiled into a dll.

So natturaly you would want your plugin to be a cdylib lib crate.

adding this to your Cargo.toml would make your lib crate compile into a dll.

[lib]
crate-type = ["cdylib"]

Manifest

Northstar also requires plugins to have a manifest.json inserted into them.

it is possible to do so with windres and build.rs.

manifest.json

create manifest.json with the following contents

{
    "name": "plugin_name",
    "displayname": "plugin_name",
    "description": "plugin_name",
    "api_version": "2",
    "version": "1.0",
    "run_on_server": false,
    "run_on_client": true
}
build.rs

get Resource.rc and resource.h from NorthstarDiscordRPC.

now we have everything to make the build script

create build.rs in the root of your project with the following content

extern crate windres;
use windres::Build;

fn main() {
    Build::new().compile("manifest\\Resource.rc").unwrap();
}

and add windres as a build dependencie.

Basic lib.rs

use rrplug::prelude::*;

pub struct BasicPlugin;

impl Plugin for BasicPlugin {
    fn new() -> Self {
        Self {}
    }

    fn initialize(&mut self, plugin_data: &PluginData) {
        log::info!("yay logging :D");
    }

    fn main(&self) {}
}

entry!(BasicPlugin);

Modules

Macros

Attribute Macros

  • proc marco for generating compatible concommand callbacks
  • proc marco for generating compatible concommand callbacks
  • proc marco for generating compatible functions with the sqvm