A template for creating Klyx extensions using Rust and WebAssembly.
This template provides a starting point for building Klyx extensions. It includes:
- Rust project structure with WebAssembly target
- Extension configuration
- Build script for packaging
- Example extension implementation
- Rust (latest stable version)
wasm32-wasip1target:rustup target add wasm32-wasip1zipcommand (usually pre-installed on Linux/macOS)
klyx-extension-template/
├── src/
│ └── lib.rs # Main extension code
├── extension.toml # Extension metadata
├── Cargo.toml # Rust project configuration
├── build.sh # Build and packaging script
└── README.md # This file
-
Clone or download this template
-
Update
extension.tomlwith your extension details:id = "your-extension-id" name = "Your Extension Name" version = "1.0.0" authors = ["Your Name <your.email@example.com>"] description = "Description of your extension" repository = "https://github.com/yourusername/your-extension"
-
Update
Cargo.tomlwith your project name:[package] name = "your-extension-name"
Edit src/lib.rs to implement your extension logic:
use klyx_extension_api as klyx;
pub struct YourExtension;
impl klyx::Extension for YourExtension {
fn new() -> Self {
// Your extension initialization code here
klyx::show_toast("Hello from YourExtension.", klyx::ToastDuration::Long);
Self
}
}
klyx::register_extension!(YourExtension);Run the build script to compile and package your extension:
./build.shThis will:
- Clean previous builds
- Compile your Rust code to WebAssembly
- Package the WASM file and extension configuration into a zip file
- Place the result in the
output/directory
The final package will be named {extension-id}-{version}.zip and contain:
extension.toml(extension metadata)src/your_extension_name.wasm(compiled WebAssembly)
The extension.toml file contains metadata about your extension:
| Field | Description |
|---|---|
id |
Unique identifier for your extension |
name |
Display name of your extension |
version |
Version number (semantic versioning) |
schema_version |
Extension schema version (currently 1) |
authors |
List of authors |
description |
Brief description of functionality |
repository |
Source code repository URL |
This template uses the klyx_extension_api crate. Check the official repository for the latest API reference.
Build fails with "target not found"
rustup target add wasm32-wasip1Permission denied on build.sh
chmod +x build.shMissing zip command
- Ubuntu/Debian:
apt install zip - macOS:
brew install zip - Windows: Use WSL or install zip manually
To debug WASM compilation issues:
cargo build --target wasm32-wasip1 --release --verboseTo inspect the generated WASM:
wasm-objdump -x target/wasm32-wasip1/release/your_extension.wasm- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This template is provided under the MIT License. See the LICENSE file for details.
For questions about Klyx extension development:
- Open an issue in the Klyx repository
- Join the community discussions
Happy extension building! 🚀