Skip to main content

Using wit2waas

wit2waas is a CLI tool that converts interfaces defined in WIT to C# interface definitions.
By combining it with Binding Generator, you can easily handle interfaces written in WIT on C#.

Installation

Install wit2waas with the following command after installing Rust toolchain.

cargo install wit2waas

Usage

Configuration of WIT

Save WIT in the following directory structure in advance.

- wit
- <your wit>.wit
- <your wit>.wit
- <your wit>.wit
- deps
- <dependency package>
- <dependency>.wit
- <dependency>.wit
- <dependency package>
- <dependency package>
info

You can configure package dependencies from package registries, etc. using tools such as wit-deps.

Running wit2waas

Next, run wit2waas in a directory containing the wit folder.

wit2waas

The result will be output to the out folder. Place *.cs contained in it in your C# project.

Options

$ wit2waas --help
Usage: wit2waas [OPTIONS]

Options:
-w, --wit-dir <WIT_DIR> [default: wit]
-o, --out <OUT> [default: out]
-h, --help Print help
-V, --version Print version

Problems with init accessors

wit2waas emits init accessors for type definitions of records in the WIT.
It cannot be compiled in environments earlier than .NET 5 such as Unity, but it can be made compilable by adding the following code.

namespace System.Runtime.CompilerServices
{
internal static class IsExternalInit { }
}