mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
A new L4 crate runs plug-ins in wasmi (pure Rust, MIT/Apache) with no host imports, a fuel budget metered in slices with a wall-clock deadline, a memory cap, a recursion cap and wasmi's strict module limits. Every band gets a fresh instance; traps, budgets, bad manifests and bad pointers are all Errors. Pixels go over as interleaved normalised f32 in tile-aligned bands, in parallel on native, blended by the selection. Includes the example Invert plug-in (no_std Rust, examples/plugins/invert-rs) built into a test fixture, hostile-module tests, and docs/plugins.md. Co-Authored-By: Claude Opus 5.5 <[email protected]>
31 lines
1.0 KiB
Rust
31 lines
1.0 KiB
Rust
//! Compiles a WebAssembly text plug-in to a `.wasm` module and checks that it loads:
|
|
//! `cargo run -p photocraft-plugins --example wat2wasm -- plugin.wat plugin.wasm`
|
|
|
|
use photocraft_plugins::{Limits, Plugin};
|
|
|
|
fn main() {
|
|
let args: Vec<String> = std::env::args().skip(1).collect();
|
|
let (Some(input), Some(output)) = (args.first(), args.get(1)) else {
|
|
eprintln!("usage: wat2wasm <in.wat> <out.wasm>");
|
|
std::process::exit(2);
|
|
};
|
|
let bytes = match wat::parse_file(input) {
|
|
Ok(b) => b,
|
|
Err(e) => {
|
|
eprintln!("{e}");
|
|
std::process::exit(1);
|
|
}
|
|
};
|
|
match Plugin::load(&bytes, Limits::default()) {
|
|
Ok(p) => println!("{} ({}): {} bytes, params {}", p.manifest().name, p.id(), bytes.len(), p.manifest().params_notation()),
|
|
Err(e) => {
|
|
eprintln!("not a valid plug-in: {e}");
|
|
std::process::exit(1);
|
|
}
|
|
}
|
|
if let Err(e) = std::fs::write(output, &bytes) {
|
|
eprintln!("{output}: {e}");
|
|
std::process::exit(1);
|
|
}
|
|
}
|