vtx-sdk
Official Rust SDK for developing VTX Project plugins.
vtx-sdk provides safe, idiomatic Rust bindings for the VTX Host ABI. It abstracts away the complexity of the WebAssembly Component Model (wit-bindgen), allowing you to focus on building powerful video processing logic.
✨ Features
- Type-Safe APIs: Rust 封装覆盖全部 WIT import 接口(SQL / Stream I/O / FFmpeg / Context / Event Bus)。
- Low Boilerplate:
export_plugin!+VtxPlugin提供默认实现(migrations/resources/handle_event/authenticate)。 - Database Integration: SQLite helpers + JSON 自动反序列化。
- Helper Utilities:
ResponseBuilder/UserBuilder/BufferExt/VtxEventExt/VtxError。
🏗️ Architecture
Unlike traditional Wasm projects, this SDK does not maintain a local copy of the WIT interface definitions. Instead, it relies on the vtx-protocol crate as the Single Source of Truth (SSOT).
- Build Time: The
build.rsscript dynamically fetches the WIT definition path from thevtx-protocolbuild dependency and injects it into the compilation process. - Runtime/Metadata: The
WIT_DEFINITIONconstant is also sourced directly from the protocol crate, ensuring zero divergence between the SDK and the Protocol.
📦 Installation
Add vtx-sdk to your plugin's Cargo.toml:
[]
= "0.1.4"
= { = "1.0", = ["derive"] }
= "1.0"
= "1.0"
[]
= ["cdylib"] # Essential for compiling to Wasm
🚀 Quick Start
Here is a minimal example of a VTX plugin:
use *;
;
export_plugin!;
🛠️ Build & Deploy
Plugins must be compiled to the wasm32-wasip1 target.
Prerequisites
Building with vtx-cli (Recommended)
The official CLI handles building, stripping, and packaging (.vtx) automatically.
Manual Build
If you are not using the CLI, you can build the raw Wasm file:
Note: Raw Wasm files may need to be adapted using wasm-tools to work with the VTX runtime if not using vtx-cli.
📚 Modules Overview
-
db: Helpers for executing SQL queries and managing database transactions.- Example:
db::query("SELECT * FROM videos")
- Example:
-
http: HTTP request/response types and builders. -
auth: Utilities for parsing headers and constructingUserContext. -
stream: File open +Bufferread/write helpers (BufferExt). -
context: Current user helpers (current_user()). -
events: Event payload parsing helpers (VtxEventExt). -
event_bus: Publish events to the host (publish_json). -
plugin:VtxPlugin+export_plugin!(low boilerplate exports). -
error: Unified error model (VtxError::AuthDenied(401),VtxError::PermissionDenied(...), ...).
📄 License
This project is licensed under the Apache 2.0 License.