hotg-ai / proc-blocks

Common processing blocks used with your Runes.
https://hotg-ai.github.io/proc-blocks
9 stars 3 forks source link

Introduce "cargo xtask" commands for interacting with a compiled proc-block #46

Closed Michael-F-Bryan closed 2 years ago

Michael-F-Bryan commented 2 years ago

This PR introduces the cargo xtask metadata, cargo xtask graph, and cargo xtask kernel commands.

Running it against the wit-files repo's modulo example, we get the following:

$ cargo xtask metadata modulo.wasm
{
  "name": "modulo",
  "version": "0.1.0",
  "description": "The modulo proc-block.",
  "arguments": [ ... ],
  "inputs": [
    { "name": "input", ... }
  ],
  "outputs": [
    { "name": "output", ... }
  ]
}

$ cargo xtask graph modulo.wasm modulus=42
{
  "inputs": [
    {
      "name": "input",
      "element-type": "f64",
      "dimensions": { "type": "dynamic" }
    }
  ],
  "outputs": [
    {
      "name": "output",
      "element-type": "f64",
      "dimensions": { "type": "dynamic" }
    }
  ]
}

$ cargo xtask kernel modulo.wasm modulus=42
TODO: show the output

I'm particularly happy with how we propagate errors from the proc-block to the host:

$ cargo xtask graph modulo.wasm modulo=42
Error: Unable to infer the input and output tensors

Caused by:
    0: The "modulus" argument was invalid
    1: The argument wasn't provided

$ cargo xtask graph modulo.wasm modulus=3.14 element_type=something-else
Error: Unable to infer the input and output tensors

Caused by:
    0: The "element_type" argument was invalid
    1: Unsupported element type