Guide for porting a C module to Rust. Use this when starting to port a C module to Rust.
Guide for porting a C module to Rust.
The module name to port should be provided as an argument (e.g., /port-module triemap).
Module to port: $ARGUMENTS
Use this skill when starting to port a C module to Rust.
First, understand the C module you're porting (look for $ARGUMENTS.c and $ARGUMENTS.h in src/):
.c and .h files in src/tests/ are relevant to this moduleCreate a $ARGUMENTS_plan.md file to outline the steps and decisions for porting the module.
Determine if the C code should be modified, at this stage, to ease the porting process.
For example:
cd src/redisearch_rs
cargo new $ARGUMENTS --lib
criterionproptest for property-based testing where appropriateCreate an FFI crate to expose the new Rust module to the C codebase:
cd src/redisearch_rs/c_entrypoint
cargo new ${ARGUMENTS}_ffi --lib
FFI crate should:
#[unsafe(no_mangle)] pub extern "C" fn functions// SAFETY: commentsC header files for Rust FFI crates are auto-generated. No need to use their full path in imports,
use just their name (e.g. #include $ARGUMENTS.h; for ${ARGUMENTS}_ffi)
./build.sh RUN_UNIT_TESTS # C/C++ unit tests
./build.sh RUN_PYTEST # Integration tests
See src/redisearch_rs/trie_rs/ for a high-quality example:
c_entrypoint/trie_ffi/