rfl-template

Crates.iorfl-template
lib.rsrfl-template
version0.1.5
created_at2025-12-05 09:21:56.807116+00
updated_at2025-12-07 17:17:19.081498+00
descriptionA CLI tool to scaffold Rust for Linux kernel modules
homepage
repositoryhttps://github.com/bensantora/rfl-template
max_upload_size
id1967921
size17,874
Ben Santora (bensantora)

documentation

README

Project retired

This crate is no longer actively maintained. The repository has been archived and no additional development or support will occur.

I consent to the transfer of this crate to the first person who asks help@crates.io for it.

Thank you for any past interest and usage.

rfl-template

A CLI tool to scaffold Rust for Linux (RFL) kernel modules with proper boilerplate and conventions.

Features

  • ✅ Generates complete kernel module structure
  • ✅ Follows RFL conventions and best practices
  • ✅ Includes proper SPDX headers and licensing
  • ✅ Creates Kbuild integration files
  • ✅ Validates module names
  • ✅ Provides build instructions

Installation

cargo install --path .

Or build from source:

cargo build --release
# Binary will be in target/release/rfl-template

Usage

Create a New Module

rfl-template new my_driver \
  --author "Your Name" \
  --description "My awesome kernel driver" \
  --license "GPL-2.0"

Minimal Usage

rfl-template new my_driver

This will use default values:

  • Author: "Unknown Author"
  • Description: "A Rust for Linux kernel module"
  • License: "GPL-2.0"

Generated Structure

my_driver/
├── Cargo.toml          # Rust package configuration
├── Kbuild              # Kernel build system integration
├── README.md           # Build and usage instructions
└── src/
    └── lib.rs         # Module implementation

Generated Code Example

The tool generates a basic kernel module with:

// SPDX-License-Identifier: GPL-2.0

//! My awesome kernel driver

use kernel::prelude::*;

module! {
    type: MyDriver,
    name: "my_driver",
    author: "Your Name",
    description: "My awesome kernel driver",
    license: "GPL-2.0",
}

struct MyDriver;

impl kernel::Module for MyDriver {
    fn init(_module: &'static ThisModule) -> Result<Self> {
        pr_info!("my_driver: Module loaded\n");
        Ok(MyDriver)
    }
}

impl Drop for MyDriver {
    fn drop(&mut self) {
        pr_info!("my_driver: Module unloaded\n");
    }
}

Module Name Requirements

Module names must:

  • Start with a lowercase letter
  • Contain only lowercase letters, numbers, and underscores
  • Be valid Rust identifiers

Valid: my_driver, test_module, driver2
Invalid: MyDriver, my-driver, 2driver

Building Generated Modules

Generated modules require a Linux kernel source tree with Rust support enabled.

See the generated README.md in each module for detailed build instructions.

Options

Usage: rfl-template new <NAME> [OPTIONS]

Arguments:
  <NAME>  Name of the kernel module

Options:
  -a, --author <AUTHOR>            Author name
  -d, --description <DESCRIPTION>  Module description
  -l, --license <LICENSE>          License [default: GPL-2.0]
  -h, --help                       Print help

Supported Licenses

Common kernel-compatible licenses:

  • GPL-2.0 (default)
  • GPL-2.0-only
  • GPL-2.0-or-later
  • MIT
  • Apache-2.0
  • BSD-3-Clause

Examples

Character Device Driver

rfl-template new char_device \
  --author "John Doe" \
  --description "A character device driver" \
  --license "GPL-2.0"

Network Driver

rfl-template new net_driver \
  --author "Jane Smith" \
  --description "A network device driver"

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

License

MIT OR Apache-2.0

Resources


Made for the Rust for Linux community 🦀🐧

Author

  • Ben Santora
Commit count: 0

cargo fmt