wasi-testsuite icon indicating copy to clipboard operation
wasi-testsuite copied to clipboard

Rust wasip3 tests import wasip2 interfaces

Open wingo opened this issue 3 months ago • 0 comments

So, until WASI preview 3 is out, we compile our Rust tests using a wasip2 toolchain. One can import and test the WASIp3 APIs just fine, but the wasm files also include wasip2 imports.

Consider the simple monotonic-clock.rs test. Its compiled wasm component includes the following imports:

[dev-env] wingo@beastie ~/src/wasip3/wasi-testsuite$ wasm-tools component wit tests/rust/testsuite/wasm32-wasip3/multi-clock-wait.wasm 
package root:component;

world root {
  import wasi:clocks/[email protected];
  import wasi:io/[email protected];
  import wasi:io/[email protected];
  import wasi:cli/[email protected];
  import wasi:cli/[email protected];
  import wasi:cli/[email protected];
  import wasi:cli/[email protected];

  export wasi:cli/[email protected];
  export wasi:cli/[email protected];
}
package wasi:[email protected] {
  interface monotonic-clock {
    type instant = u64;

    now: func() -> instant;

    wait-until: async func(when: instant);
  }
}


package wasi:[email protected] {
  interface error {
    resource error {
      to-debug-string: func() -> string;
    }
  }
  interface streams {
    use error.{error};

    resource output-stream {
      blocking-write-and-flush: func(contents: list<u8>) -> result<_, stream-error>;
    }

    variant stream-error {
      last-operation-failed(error),
      closed,
    }
  }
}


package wasi:[email protected] {
  interface environment {
    get-environment: func() -> list<tuple<string, string>>;
  }
  interface exit {
    exit: func(status: result);
  }
  interface stdout {
    use wasi:io/[email protected].{output-stream};

    get-stdout: func() -> output-stream;
  }
  interface stderr {
    use wasi:io/[email protected].{output-stream};

    get-stderr: func() -> output-stream;
  }
  interface run {
    run: func() -> result;
  }
}


package wasi:[email protected] {
  interface run {
    run: async func() -> result;
  }
}

I.e., note the use of the wasi:[email protected] and wasi:[email protected] imports. This is OK -- all wasip3 hosts will support wasip2, because that's where they are right now -- but it's not a pure wasip3 test.

wingo avatar Sep 30 '25 13:09 wingo