This page walks you through the options avialable when building a Surrealism module from scratch.
Prerequisites
You need a recent Rust toolchain, the wasm32-wasip2 target, and the SurrealDB CLI (surreal) on your PATH.
Install SurrealDB from the installation guide if you have not already.
Scaffold a module project
The fastest way to start is surreal module init:
This creates the project scaffold (Cargo.toml, surrealism.toml, and src/lib.rs) ready for Surrealism builds.
To automatically set the name and organisation for a project, you can use the following flags:
Create a Rust project manually
Create a new library crate for your module:
Configure the library as a dynamic WASM library and add the Surrealism SDK plus any other crates you need to Cargo.toml, following versions recommended for your SurrealDB release:
For a full annotated example, follow the quick tutorial.
Configure surrealism.toml
Add a surrealism.toml file at the crate root next to Cargo.toml.
A minimal example:
Optional attached filesystem:
When [attach] fs = "fs" is present, the fs/ folder in your project is packed into the module archive as a read-only filesystem available to the module at runtime.
Annotate exported functions
Expose functions to SurrealQL by annotating them with #[surrealism]. Only functions you mark this way are included in the module and callable from the database.
For the full attribute reference (writeable, comment, init, and namespaced modules), see Surrealism attribute reference.
Compile with surreal module
From your project directory, compile to a .surli artefact with the Surreal CLI:
For faster local iteration, use debug builds. This works in the same way as cargo build --debug in skipping optimisation passes to speed up compiling time in exchange for lower performance.
See the module command reference for all flags.
Load into SurrealDB
Upload the .surli file with DEFINE BUCKET so SurrealDB can store it, then register exported functions with DEFINE MODULE. The exact names and paths must match your bucket and module identifiers.
Test your functions
Connect with the CLI, Surrealist, or an SDK and invoke your functions from SurrealQL. Confirm return values and error handling match what you expect.
If something fails:
verify that experimental capabilities include
surrealism(andfilesif using buckets/files);verify the module was rebuilt after source changes;
verify your SurrealDB build supports the Surrealism version your module targets.
For a high-level picture of how these steps fit together, see the Surrealism overview.