This document analyzes the key Rust crates (dependencies) used in rCandle, their purpose, alternatives, and rationale for selection.
- Purpose: Async runtime for I/O operations (serial, network)
- Features Used:
full(includes all features for ease of use) - Why: Industry standard, excellent ecosystem, well-maintained
- Alternatives:
async-std: Simpler API, but smaller ecosystemsmol: Lightweight, but less mature ecosystem
- License: MIT
- Purpose: Cross-platform serial port access for GRBL communication
- Why: Most mature Rust serial port library, tokio compatible
- GRBL Protocol Support: Implements serial communication following GRBL interface specifications
- Documented at: https://github.com/craftweeks/grbl-1.1f.customized-for-laser/blob/master/doc/markdown/interface.md
- Supports real-time commands, status queries, and command streaming
- Alternatives:
tokio-serial: Wrapper around serialport, could be used in addition- Direct OS APIs: Too much platform-specific code
- License: MPL-2.0
- Platform Support: Windows, Linux, macOS, BSD
- Purpose: Immediate mode GUI framework
- Why:
- Simple to use and highly flexible
- Excellent for tools and technical applications
- Mature and stable with proven track record
- Very flexible for custom widgets
- Great performance
- Pros:
- Rapid development
- Easy to integrate with custom rendering (wgpu)
- Portable (can run in browser with wasm)
- Great for prototyping and iteration
- Excellent documentation and examples
- Works great with async Rust
- Cons:
- Immediate mode may be less familiar
- More manual state management required
- Some styling limitations compared to retained mode
- License: MIT/Apache-2.0
Decision Rationale: egui was chosen as the primary UI framework for rCandle due to its maturity, flexibility, and proven success in similar technical applications. The immediate mode paradigm, while different from Qt, offers simplicity and direct control that's ideal for a tool like rCandle. Its excellent integration with wgpu for 3D rendering and ability to create custom widgets makes it perfect for our needs.
- Purpose: Modern, safe graphics API
- Why:
- Cross-platform (Vulkan, Metal, DX12, OpenGL/ES fallback)
- Safe Rust API
- Future-proof (based on WebGPU standard)
- Good ecosystem
- Alternatives:
glium: OpenGL wrapper, simpler but less modernglow: Lower-level OpenGL, more control but more unsafeash: Vulkan bindings, too low-level for this project
- License: MIT/Apache-2.0
- Shader Language: WGSL (WebGPU Shading Language)
- Purpose: Fast vector/matrix math for graphics
- Why:
- Designed for game/graphics programming
- SIMD optimized
- Small binary size
- Works well with wgpu
- Features:
serdefor serialization - Alternatives:
nalgebra: More comprehensive, but heaviercgmath: Good but less active development
- License: MIT/Apache-2.0
- Purpose: Linear algebra for height map interpolation
- Why: More complete for numerical computations
- Use Case: Height map interpolation, scientific calculations
- License: Apache-2.0
- Purpose: Parser combinator library for G-Code parsing
- Why:
- Zero-copy parsing
- Composable parsers
- Excellent error messages
- Battle-tested
- Alternatives:
pest: PEG parser, more declarative but slowercombine: Similar to nom, slightly different API- Manual parsing: Error-prone, not recommended
- License: MIT
- Purpose: Regular expressions for pattern matching
- Why: Sometimes simpler than parser combinators for simple patterns
- License: MIT/Apache-2.0
- Purpose: Serialization/deserialization framework
- Why: De facto standard, huge ecosystem
- License: MIT/Apache-2.0
- Purpose: JSON format support
- Use Case: Configuration files, data interchange
- License: MIT/Apache-2.0
- Purpose: TOML format support
- Use Case: Primary configuration file format
- Why: More human-friendly than JSON for config
- License: MIT/Apache-2.0
- Purpose: Derive macro for error types
- Use Case: Library code (internal crates)
- Why: Clean error definitions, good error messages
- License: MIT/Apache-2.0
- Purpose: Flexible error handling
- Use Case: Application code
- Why: Easy error propagation with context
- License: MIT/Apache-2.0
- Purpose: Structured logging and instrumentation
- Why:
- More powerful than
logcrate - Async-aware
- Structured logging
- Excellent for debugging
- More powerful than
- License: MIT
- Purpose: Log formatting and output
- Features:
env-filter,json - Why: Flexible log configuration
- License: MIT
- Purpose: Embedded scripting language
- Why:
- Designed for Rust integration
- Simple syntax (similar to JavaScript)
- Safe by default
- Good performance
- Easy to sandbox
- Features:
syncfor thread safety - Alternatives:
mlua: Lua bindings, more mature language but less Rust-nativedeno_core: JavaScript engine, heavy dependencyrlua: Older Lua bindings, less maintained
- License: MIT/Apache-2.0
Example Rhai Script:
// Simple and familiar syntax
let x = 10;
send_command("G0 X" + x);
wait_idle();
print("Done!");- Purpose: WebSocket client/server
- Use Case: WebSocket connection to GRBL
- Why: Async, integrates with tokio
- License: MIT
- Purpose: Native file dialogs
- Why: Cross-platform, native look-and-feel
- License: MIT
- Purpose: Command-line argument parsing
- Features:
derivefor clean API - Use Case: CLI tools for testing
- License: MIT/Apache-2.0
- Purpose: Layered configuration system
- Why: Supports multiple sources (files, env vars, defaults)
- License: MIT/Apache-2.0
- Purpose: Date and time handling
- Use Case: Timestamps, time estimates
- License: MIT/Apache-2.0
- Purpose: Cross-platform directory paths
- Use Case: Config, cache, data directories
- Why: Follows platform conventions
- License: MPL-2.0
- Purpose: Safe casting for vertex data
- Features:
derive - Use Case: GPU vertex buffers
- Why: Safe, zero-cost abstraction
- License: Zlib/MIT/Apache-2.0
- Purpose: Testing utilities for async code
- License: MIT
- Purpose: Mock object generation
- Use Case: Testing with mock connections
- License: MIT/Apache-2.0
- Purpose: Property-based testing
- Use Case: Parser fuzzing
- License: MIT/Apache-2.0
- Purpose: Benchmarking framework
- Use Case: Performance regression detection
- License: MIT/Apache-2.0
# Install cargo-audit
cargo install cargo-audit
# Run security audit
cargo audit
# Check for advisories
cargo audit --deny warningsAll dependencies must be compatible with GPL-3.0. Current selections are:
- MIT: Compatible ✅
- Apache-2.0: Compatible ✅
- MPL-2.0: Compatible ✅
- Zlib: Compatible ✅
# Install cargo-deny
cargo install cargo-deny
# Check licenses and security
cargo deny checkMinimal build dependencies to reduce build complexity:
- No C++ dependencies
- No Qt dependencies
- No external build tools beyond Cargo
libudev-dev: Required by serialport- No additional runtime dependencies
- No additional dependencies (uses Windows API)
- No additional dependencies (uses IOKit)
- Review updates monthly
- Test thoroughly before updating major versions
- Pin versions in
Cargo.lockfor reproducible builds - Use
cargo-outdatedto check for updates
cargo install cargo-outdated
cargo outdated- Use
^(caret) for version requirements (default) - Allows patch and minor updates
- Example:
tokio = "1.35"allows 1.35.x and 1.x.x (x < 2.0)
- Target: < 50 MB
- Achieved through:
- LTO (Link Time Optimization)
- Strip symbols
- Optimize dependencies
- Avoid unnecessary features
- Development build: < 1 minute
- Release build: < 2 minutes
- Incremental builds: < 10 seconds
| Feature | Candle (C++/Qt) | rCandle (Rust) |
|---|---|---|
| Language | C++ | Rust |
| UI Framework | Qt5 | egui + eframe |
| Graphics | OpenGL 2.0 | WGPU (Vulkan/Metal/DX12) |
| Memory Safety | Manual | Guaranteed by compiler |
| Async I/O | Qt event loop | Tokio async runtime |
| Build System | CMake | Cargo |
| Package Manager | vcpkg | Cargo |
| Target Platforms | Windows, Linux, macOS | Windows, Linux, macOS |
If creating a headless CLI version:
- Remove: iced/egui, wgpu
- Add:
termionorcrosstermfor terminal UI - Benefit: Much smaller binary, faster compile
If targeting WebAssembly:
- Keep: Most core logic
- Replace: serialport (use Web Serial API via wasm-bindgen)
- Replace: Native file dialogs (use browser APIs)
- Benefit: Runs in browser
If targeting embedded systems:
- Remove: Full UI, scripting
- Use:
embedded-halfor hardware access - Target: No-std or embedded-friendly crates
The selected dependencies provide a solid foundation for rCandle, balancing:
- Maturity: Proven crates with active maintenance
- Performance: Efficient implementations
- Safety: Rust-native, memory-safe APIs
- Compatibility: GPL-3.0 compatible licenses
- Maintainability: Good documentation and community support
The modular architecture allows for dependency substitution if needed without major refactoring.