Originally inspired by NativeBukkit
Suite for implementing Bukkit (Spigot) plugins in native code with an idiomatic Rust API provided.
This software is a heavy work in progress and probably shouldn't be used for anything remotely serious.
Performance is most likely also worse than just using a native JVM language, considering all of the allocation
and lookups required for this to work.
- /
RustLoader
Bukkit plugin that registers a native library loader as a Bukkit plugin loader interface, granting the server the ability to load dynamic libraries as plugins (see NativeBukkit). - /
TestPlugin
A simple plugin that tests all functionality provided byrustbukkit-sys
. Target binary should be placed in theplugins
folder of the Bukkit server. - /
rustbukkit
Idiomatic Rust bindings torustbukkit-sys
. Plugins written in Rust should depend on this crate as opposed to the sys crate. Plugins written in other languages will have to depend on sys. The compiled libraryrustbukkit_sys.dll
needs to be placed inplugins/RustLoader/
for this project to work.- ./
rustbukkit-sys
C-FFI compatible API surface provided to plugins. Only non-Rust plugins should depend on this crate (via the provided C header).- ./
c_headers
Non-Rust plugins should depend onrustbukkit.h
from this folder. This header is generated via thegen_bindings.ps1
script. - ./
gen_bindings.ps1
Automatically generates both the C header and jextract Java sources for use inRustLoader
(Java sources are automatically copied into the packageme.danny.nativeplug.jextract_gen
). Requiresjextract
(currently using the prebuilt binary provided by the OpenJDK website).
- ./
- ./
In Cargo.toml
:
[lib]
crate-type = ["cdylib"]
[dependencies]
# Use a specific version instead of "*"
rustbukkit = "*"
In lib.rs
:
/// All API methods go through the RustBukkit value
use rustbukkit::RustBukkit;
/// JavaPlugin#onLoad
#[no_mangle]
pub fn on_load(bukkit: RustBukkit) {}
/// JavaPlugin#onEnable
#[no_mangle]
pub fn on_enable(bukkit: RustBukkit) {}
/// JavaPlugin#onDisable
#[no_mangle]
pub fn on_disable(bukkit: RustBukkit) {}
$ cargo build --release
$ cp target/release/$CRATE_NAME.dll $SERVER_PATH/plugins/
As stated above, this project was originally inspired by NativeBukkit. Before Project Panama was in stable Java, this project used JNI (623f1dd), which is identical to how NativeBukkit works. After converting this to using Panama's FFM APIs, I feel this it's original enough to take full credit for it.