- cargo.build (native): one source copy, tests under WASI, release build to /state/cargo/builds/<n>/, process groups killed on cancel. The host writes the SDK copy to /plugins/cargo/sdk/ at start. - sausage test-runner: one instance per test, in parallel, with its own mount table (empty world, package folder at its path); answers core.lock, core.unlock, core.notify, core.log. - The console: rustyline, notifications while typing, ls/cat through the process view, methods, ps, log, activate, revert, stop, kill. - core.notify on stdout is handled in order, before the response.
26 lines
505 B
Rust
26 lines
505 B
Rust
//! SDK plugin linked to a WASI C function.
|
|
unsafe extern "C" {
|
|
fn c_add(a: i32, b: i32) -> i32;
|
|
}
|
|
fn add(a: i32, b: i32) -> i32 {
|
|
unsafe { c_add(a, b) }
|
|
}
|
|
struct Plugin;
|
|
#[sausage_plugin::rpc]
|
|
impl Plugin {
|
|
/// Add two fixed numbers through C.
|
|
fn sum(&self) -> sausage_plugin::Result<i32> {
|
|
Ok(add(2, 3))
|
|
}
|
|
}
|
|
fn main() {
|
|
sausage_plugin::run(Plugin);
|
|
}
|
|
#[cfg(test)]
|
|
mod tests {
|
|
#[test]
|
|
fn c_code_runs_under_wasi() {
|
|
assert_eq!(super::add(2, 3), 5);
|
|
}
|
|
}
|