rust-samp

Introduction

rust-samp is a Rust toolkit for building server plugins for SA-MP (San Andreas Multiplayer) and native components for Open Multiplayer. The same compiled binary works on both servers: SA-MP loads it through the legacy plugin ABI, and Open Multiplayer loads it as a first-class component without any extra configuration.

Fork of samp-rs by ZOTTCE. Modernized for Rust edition 2024 and extended with a pure-Rust implementation of the Open Multiplayer component ABI (Itanium and MSVC), without bindgen or any C/C++ dependency.

Why Rust

Traditional plugins are written in C/C++, where memory errors (buffer overflow, use-after-free, dangling pointers) are the leading cause of server crashes. Rust eliminates those bugs at compile time while keeping performance on par with C.

rust-samp adds, on top of that foundation:

Workspace structure

Crate Version Description
samp 3.0.0 Main crate — depend on this one. Re-exports the SDK and the proc macros.
samp-sdk 3.0.0 Low-level bindings: AMX VM + Open Multiplayer component ABI.
samp-codegen 1.3.0 Procedural macros (#[native], initialize_plugin!, SampPlugin).

In practice, only the samp crate is referenced by a plugin’s Cargo.toml. It re-exports everything from samp-sdk and samp-codegen.

A first taste

use samp::prelude::*;
use samp::{native, initialize_plugin, SampPlugin};

#[derive(SampPlugin, Default)]
struct Plugin;

impl Plugin {
    #[native(name = "TestNative")]
    fn my_native(&mut self, _amx: &Amx, text: &AmxString) -> AmxResult<bool> {
        println!("rust plugin: {}", &**text);
        Ok(true)
    }
}

initialize_plugin!(
    type: Plugin,
    natives: [Plugin::my_native],
);

The next chapters set up the toolchain and walk through a plugin from scratch.