fswtch
Rust bindings for writing FreeSWITCH modules.
This workspace is split into two crates:
fswtch-sys: raw FreeSWITCH ABI bindings. By default it exposes a small handwritten module ABI that builds without a configured FreeSWITCH source tree. Enable thebindgenfeature to generate broader bindings fromswitch.h.fswtch: higher-level helpers for module exports, module interface creation, API command registration, and stream writes.fswtch-src: vendored FreeSWITCH headers used byfswtch-syswhen thebundledfeature is enabled.
Header Discovery
For generated bindings, point the build at configured FreeSWITCH headers:
FREESWITCH_INCLUDE_DIR=/usr/include/freeswitch
If FreeSWITCH is installed with pkg-config, fswtch-sys will also try the freeswitch package for link metadata. You can override linking with:
FREESWITCH_LIB_DIR=/usr/lib/freeswitch
The vendored freeswitch/ tree is useful source context, but it does not include generated config headers until FreeSWITCH has been configured.
The bundled feature enables bindgen and points it at the packaged fswtch-src vendored headers:
This feature is for generating Rust bindings from the vendored headers. It does not compile or statically link FreeSWITCH itself.
Publishing
Publish crates in dependency order:
For dry-runs before the first upload of a new version, fswtch-sys and fswtch will not fully resolve until their registry dependencies already exist. Start by dry-running and publishing fswtch-src.
Module Skeleton
See crates/fswtch/examples/mod_hello.rs for the current Rust module shape:
module_exports!
Inside switch_module_load, create a Module from the raw FreeSWITCH load arguments and register APIs with Module::add_api.
Additional compile-checked examples:
- mod_api_suite.rs: registers several API commands from one module.
- mod_lifecycle.rs: exports load, runtime, and shutdown callbacks.
- mod_registration_check.rs: queues an asynchronous registration check, parses a pretend JSON response, and fires a custom FreeSWITCH event.
- mod_remote_vad.rs: connects to a remote websocket VAD service, streams party audio frames during a call, parses JSON responses, and emits custom events.
- mod_stream_tools.rs: writes structured responses to FreeSWITCH streams and parses command arguments.