More cleanup during review

This commit is contained in:
Isaac Clayton 2022-07-11 10:56:21 +02:00
parent 5ec828a3e2
commit 14bccb4a90
9 changed files with 16 additions and 122 deletions

View file

@ -39,10 +39,19 @@ Here's an example Rust Wasm plugin that doubles the value of every float in a `V
```rust
use plugin::prelude::*;
#[bind]
#[export]
pub fn double(mut x: Vec<f64>) -> Vec<f64> {
x.into_iter().map(|x| x * 2.0).collect()
}
```
All the serialization code is automatically generated by `#[bind]`.
All the serialization code is automatically generated by `#[export]`.
You can specify functions that must be defined host-side by using the `#[import]` attribute. This attribute must be attached to a function signature:
```rust
#[import]
fn run(command: String) -> Vec<u8>;
```
The `#[import]` macro will generate a function body that performs the proper serialization/deserialization needed to call out to the host rust runtime. Note that the same ABI is used for both `#[import]` and `#[export]`.

View file

@ -5,7 +5,7 @@ fn main() {
let base = Path::new("../../plugins");
// println!("cargo:rerun-if-changed=../../plugins/*");
println!("cargo:warning=Rebuilding plugins...");
println!("cargo:warning=Precompiling plugins...");
let _ = std::fs::remove_dir_all(base.join("bin"));
let _ =
@ -27,7 +27,6 @@ fn main() {
let binaries = std::fs::read_dir(base.join("target/wasm32-wasi/release"))
.expect("Could not find compiled plugins in target");
println!("cargo:warning={:?}", binaries);
let engine = create_engine();

View file

@ -36,8 +36,6 @@ mod tests {
.host_function_async("import_half", |a: u32| async move { a / 2 })
.unwrap()
.host_function_async("command_async", |command: String| async move {
// TODO: actual thing
dbg!(&command);
let mut args = command.split(' ');
let command = args.next().unwrap();
smol::process::Command::new(command)
@ -45,10 +43,7 @@ mod tests {
.output()
.await
.ok()
.map(|output| {
dbg!("Did run command!");
output.stdout
})
.map(|output| output.stdout)
})
.unwrap()
.init(