{"id":14156446,"url":"https://github.com/second-state/witc","last_synced_at":"2025-10-10T02:42:07.561Z","repository":{"id":65716666,"uuid":"569591776","full_name":"second-state/witc","owner":"second-state","description":"wasm-interface-types supplement \u0026 compiler of wasmedge","archived":false,"fork":false,"pushed_at":"2023-08-25T13:57:17.000Z","size":666,"stargazers_count":15,"open_issues_count":0,"forks_count":4,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-05-07T18:57:36.795Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/WasmEdge/WasmEdge","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/second-state.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-11-23T07:13:48.000Z","updated_at":"2024-12-29T21:04:25.000Z","dependencies_parsed_at":"2024-01-14T04:52:59.889Z","dependency_job_id":"b5171744-59b7-4eef-a333-4f9c8aae6c4a","html_url":"https://github.com/second-state/witc","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/second-state/witc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/second-state%2Fwitc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/second-state%2Fwitc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/second-state%2Fwitc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/second-state%2Fwitc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/second-state","download_url":"https://codeload.github.com/second-state/witc/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/second-state%2Fwitc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279002541,"owners_count":26083403,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-17T08:05:28.764Z","updated_at":"2025-10-10T02:42:07.529Z","avatar_url":"https://github.com/second-state.png","language":"Haskell","funding_links":[],"categories":["others"],"sub_categories":[],"readme":"# witc\n\n\u003e **Warning**\n\u003e This is an early-stage project\n\nA compiler generates code for `*.wit` files, this project purpose to make `*.wit` supportment for [wasmedge](https://github.com/WasmEdge/WasmEdge).\n\n- [benchmark tracking](https://second-state.github.io/witc/dev/bench/index.html)\n\n### Overview\n\nTo understand this project, I will show you what's `*.wit` stand for first. The story starts by passing a string as an argument to function in the wasm instance, if you do so, you will find out that wasm has no type called `string`. You will figure out that you only need to encode the string as a pair of `i32`, which means `(i32, i32)` and one for address, one for string length. However, the address valid out of an instance will not be valid in that instance. Then you found runtime(e.g. wasmedge, wasmtime) can operate the memory of instances, write data to somewhere in the instance, and use that address, problem solved!\n\nQuickly, your program grows, and now you manage tons of mappings.\n\n```rust\nfn foo(s: String, s2: String) -\u003e String\n// \u003c-\u003e\nfn foo(s_addr: i32, s_size: i32, s2_addr: i32, s2_size: i32) -\u003e (i32, i32)\n```\n\nThe thing is a bit out of control, not to say compound types like **structure**, **enum**, and **list**. In this sense, **wit** stands for one source code that is reusable for multi-target, and multi-direction and **witc** does code generation and manages ABI and memory operations. Thus, you can import/export types or functions from instance or runtime.\n\n### Installation\n\n`witc` has pre-built binary can be installed via our bash installation script.\n\n```sh\ncurl -sSf https://raw.githubusercontent.com/second-state/witc/main/install.sh | bash\n```\n\n#### Windows\n\n`witc` has a powershell installation script, but it's not full automatic.\n\n```powershell\nwget https://raw.githubusercontent.com/second-state/witc/main/install.ps1\n./install.ps1\n```\n\nOnce you run the installation script, it should download the latest executable to **current path** you run the script, so you have to add this path into `$env:PATH` or move the executable to somewhere in `$env:PATH`.\n\n#### Build from Haskell source\n\nIf you want the latest executable, you need to build from source.\n\n```sh\nstack install\n# install to `~/.local/bin`\n```\n\n### Usage\n\n`*.wit` files are sharing interface and common types between different component in the wasm ecosystem, a runtime is a component, a running wasm module is a component. In our context, wasmedge is the runtime, and wasm module instance is the instance. Under **witc**, you have three directions\n\n1. instance invokes a runtime function\n2. instance invokes an instance function\n3. runtime invokes an instance function\n\nWithout **witc** you can still invoke these function, but have to convert typing by yourself and figuring out complicated layout. Now, development is easy and lovely, all callsite and implementation using the native type of that language.\n\n#### Rust examples\n\n\u003e **Note** Don't forget to install rust supplyment when you are trying to run example out of box\n\nTo illustrate how to use witc, we have the following examples, and you can use the following command to run them\n\n```sh\ncargo run --release\n```\n\n- [demo: keyvalue](./example/keyvalue-demo/): instance invokes runtime\n- [demo: logging](./example/logging-demo/): instance invokes instance\n- [demo: traffic lights](./example/traffic-lights/): runtime invokes instance\n\n#### Generate Plugin header\n\nThis is new experiment we are doing, this ability will relief wasmedge plugin users from manually management for the standard API, there will have `*.wit` definitions for these plugins. All you need to is using witc to manage it, here is an example:\n\n```sh\n$ witc plugin ./example/wasmedge_opencvmini.wit\n\n#[link(wasm_import_module = \"wasmedge_opencvmini\")]\nextern \"C\" {\n    #[link_name = \"wasmedge_opencvmini_imdecode\"]\n    pub fn imdecode(buf_ptr: *const u8, buf_len: usize) -\u003e u32;\n    #[link_name = \"wasmedge_opencvmini_imshow\"]\n    pub fn imshow(window_name_ptr: *const u8, window_name_len: usize, mat_key: u32) -\u003e ();\n    #[link_name = \"wasmedge_opencvmini_waitkey\"]\n    pub fn waitkey(delay: u32) -\u003e ();\n}\n```\n\n#### CLI\n\nYou can also use following commands to let compiler output to stdout\n\n- instance\n\n  - import `witc instance import xxx.wit`, or `witc instance import xxx.wit yyy` if you want to have different import name(usually happened when you import code from another instance)\n  - export `witc instance export xxx.wit`\n\n- runtime\n\n  - export `witc runtime export xxx.wit`\n\n### Development\n\nTo get the proper Haskell configuration, we recommend you install the following combination with [`ghcup`](https://www.haskell.org/ghcup/).\n\n```shell\nghcup install ghc 9.2.7\nghcup install hls 1.10.0.0\n```\n\n### Why witc?\n\nYou might wonder why you need `witc` since `wit-bindgen` already exists. Although `wit-bindgen` is good, it is currently in active development, and `witc` will explore different approach that increases the diversity of wit related toolchain. Additionally, the Component Model and Canonical ABI change frequently with large updates, in this sense `witc` will serve as a middle project to wait for `wit-bindgen` to become stable. We will contribute to `wit-bindgen` at that point, for these reasons, we will support a small number of features in `witc` that only ensuring that the basic demo works.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsecond-state%2Fwitc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsecond-state%2Fwitc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsecond-state%2Fwitc/lists"}