dynpatch
Safe live code reloading for Rust. Hot-patch functions, services, and configurations at runtime with type/ABI validation, transactional swaps, and automatic rollback.
Features
- 🔥 Runtime hot patching - Update code without restarting your application
- 🛡️ Safety first - Strong ABI/type compatibility checks before activation
- ⚡ Transactional - All-or-nothing activation with automatic rollback on failure
- 🔄 State continuity - Optional state migration between patch versions
- 🚀 Minimal overhead - Lock-free implementation swapping using RCU patterns
- 🎯 Developer friendly - Ergonomic macros, CLI tools, and introspection APIs
Quick Start
Add dynpatch to your Cargo.toml:
[]
= "0.1"
Mark code as patchable
use *;
Load patches at runtime
use *;
Hot-reload configuration
use *;
use ;
Use Cases
- Backend services: Push logic fixes or feature updates without downtime
- Game engines: Live-swap gameplay logic, AI, or rendering code during development
- Long-running daemons: Apply hotfixes to production systems without restart
- Embedded systems: Update firmware modules at runtime
- ML pipelines: Test algorithm updates in live data processing
How It Works
- Mark patchable items using
#[patchable]and#[patch_trait]macros - Define interfaces as traits that both host and patches implement
- Build patches as dynamic libraries (
.so/.dylib/.dll) - Load at runtime with automatic ABI validation and transactional activation
- Rollback to previous versions if anything goes wrong
Safety Guarantees
- ABI validation: Type layout and signature checking before activation
- Version compatibility: Semantic versioning with compatibility rules
- Transactional swaps: Atomic activation with automatic rollback
- Thread safety: Lock-free RCU-like publication
- Panic safety: Initialization failures trigger automatic rollback
Command-Line Tool
Install the CLI for building and managing patches:
Commands:
dynpatch build- Compile a patch from sourcedynpatch apply- Apply a patch to a running processdynpatch rollback- Revert to previous versiondynpatch inspect- Show patch status and historydynpatch watch- Auto-apply patches from a directory
Features
watcher(default) - File watching and config reloadingabi_stable- Enhanced ABI checksmetrics- Performance metricssigning- Cryptographic signature verificationsandbox- Process isolation for untrusted patchesjson,yaml,toml- Config format support
Minimum Supported Rust Version
Rust 1.70.0 or later.
Platform Support
- Linux (
.so) - macOS (
.dylib) - Windows (
.dll)
Examples
See the examples/ directory for complete working examples:
http_handler- Hot-patching an HTTP request handlerconfig_reload- Live config reloading with file watchingservice_swap- Trait-based service swapping
Documentation
Contributing
Contributions are welcome! See CONTRIBUTING.md for guidelines.
License
MIT License - see LICENSE for details.
Repository
https://gitlab.com/TIVisionOSS/crates/dynpatch
Author
Eshan Roy m.eshanized@gmail.com