{"id":13472674,"url":"https://github.com/bytecodealliance/wasi-rs","last_synced_at":"2025-05-14T04:07:32.245Z","repository":{"id":35028521,"uuid":"196445196","full_name":"bytecodealliance/wasi-rs","owner":"bytecodealliance","description":"WASI bindings for Rust","archived":false,"fork":false,"pushed_at":"2025-02-28T17:50:53.000Z","size":670,"stargazers_count":292,"open_issues_count":2,"forks_count":50,"subscribers_count":17,"default_branch":"main","last_synced_at":"2025-05-03T03:09:52.504Z","etag":null,"topics":["rust","wasi"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/bytecodealliance.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE-APACHE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-11T18:18:29.000Z","updated_at":"2025-05-02T18:30:45.000Z","dependencies_parsed_at":"2024-03-28T00:31:47.029Z","dependency_job_id":"4b74499d-a423-43a3-8aa4-c38bb306e23e","html_url":"https://github.com/bytecodealliance/wasi-rs","commit_stats":{"total_commits":103,"total_committers":16,"mean_commits":6.4375,"dds":0.6990291262135923,"last_synced_commit":"e3328eff3d6c91fb5b7a35c2ab604126596f8c61"},"previous_names":["cranestation/wasi-core","bytecodealliance/wasi"],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytecodealliance%2Fwasi-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytecodealliance%2Fwasi-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytecodealliance%2Fwasi-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytecodealliance%2Fwasi-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bytecodealliance","download_url":"https://codeload.github.com/bytecodealliance/wasi-rs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253342251,"owners_count":21893556,"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","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":["rust","wasi"],"created_at":"2024-07-31T16:00:56.965Z","updated_at":"2025-05-14T04:07:32.201Z","avatar_url":"https://github.com/bytecodealliance.png","language":"Rust","readme":"\u003cdiv align=\"center\"\u003e\n  \u003ch1\u003e\u003ccode\u003ewasi\u003c/code\u003e\u003c/h1\u003e\n\n\u003cstrong\u003eA \u003ca href=\"https://bytecodealliance.org/\"\u003eBytecode Alliance\u003c/a\u003e project\u003c/strong\u003e\n\n  \u003cp\u003e\n    \u003cstrong\u003eWASI API Bindings for Rust\u003c/strong\u003e\n  \u003c/p\u003e\n\n  \u003cp\u003e\n    \u003ca href=\"https://crates.io/crates/wasi\"\u003e\u003cimg src=\"https://img.shields.io/crates/v/wasi.svg?style=flat-square\" alt=\"Crates.io version\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://crates.io/crates/wasi\"\u003e\u003cimg src=\"https://img.shields.io/crates/d/wasi.svg?style=flat-square\" alt=\"Download\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://docs.rs/wasi/\"\u003e\u003cimg src=\"https://img.shields.io/badge/docs-latest-blue.svg?style=flat-square\" alt=\"docs.rs docs\" /\u003e\u003c/a\u003e\n  \u003c/p\u003e\n\u003c/div\u003e\n\nThis crate contains bindings for [WASI](https://github.com/WebAssembly/WASI)\nAPIs for the worlds:\n\n* [`wasi:cli/command`]\n* [`wasi:http/proxy`]\n\nThis crate is procedurally generated from [WIT] files using [`wit-bindgen`].\n\n[`wasi:cli/command`]: https://github.com/WebAssembly/wasi-cli\n[`wasi:http/proxy`]: https://github.com/WebAssembly/wasi-http\n[WIT]: https://component-model.bytecodealliance.org/design/wit.html\n[`wit-bindgen`]: https://github.com/bytecodealliance/wit-bindgen\n[components]: https://component-model.bytecodealliance.org/\n[`wasm-tools`]: https://github.com/bytecodealliance/wasm-tools\n\n# Usage\n\nDepending on this crate can be done by adding it to your dependencies:\n\n```sh\n$ cargo add wasi\n```\n\nNext you can use the APIs in the root of the module like so:\n\n```rust\nfn main() {\n    let stdout = wasi::cli::stdout::get_stdout();\n    stdout.blocking_write_and_flush(b\"Hello, world!\\n\").unwrap();\n}\n```\n\nThis crate can currently be used in three main ways.\n\n- One is to use it and compile for the [`wasm32-wasip2` target] in Rust 1.82 and later.\n  This is the simplest approach, as all the tools needed are included in the\n  Rust tooling, however it doesn't yet support some of the features of the\n  other approaches.\n\n- Another is to use it and compile using [`cargo component`]. This is essentially\n  the same as the next option, except that `cargo component` handles most of the\n  steps for you. `cargo component` also has a number of additional features for\n  working with dependencies and custom WIT interfaces.\n\n- And the third is to compile for the `wasm32-wasip1` target, and then adapt\n  the resulting modules into component using `wasm-tools component new`; see\n  the next section here for details.\n\n[`wasm32-wasip2` target]: https://blog.rust-lang.org/2024/11/26/wasip2-tier-2.html\n[`cargo component`]: https://github.com/bytecodealliance/cargo-component\n\n## Building with wasm32-wasip1 and `cargo component new`.\n\nThe `wasm32-wasip2` target works with a simple `cargo build --target=wasm32-wasip2`\nand doesn't need a lot of documentation here, and `cargo component` has its own\ndocumentation, so here we have some documentation for the `wasm32-wasip1` way.\n\n```\n$ cargo build --target wasm32-wasip1\n```\n\nNext you'll want an \"adapter\" to convert the Rust standard library's usage of\n`wasi_snapshot_preview1` to the component model. An example adapter can be found\nfrom [Wasmtime's release page](https://github.com/bytecodealliance/wasmtime/releases/download/v17.0.0/wasi_snapshot_preview1.command.wasm).\n\n```\n$ curl -LO https://github.com/bytecodealliance/wasmtime/releases/download/v17.0.0/wasi_snapshot_preview1.command.wasm\n```\n\nNext to create a component you'll use the [`wasm-tools`] CLI to create a\ncomponent:\n\n```\n$ cargo install wasm-tools\n$ wasm-tools component new target/wasm32-wasip1/debug/foo.wasm \\\n    --adapt ./wasi_snapshot_preview1.command.wasm \\\n    -o component.wasm\n```\n\nAnd finally the component can be run by a runtime that has Component Model\nsupport, such as [Wasmtime]:\n\n```\n$ wasmtime run component.wasm\nHello, world!\n```\n\n[Wasmtime]: https://github.com/bytecodealliance/wasmtime\n\n# WASIp2 vs WASIp1\n\nIn January 2024 the WASI subgroup published WASI 0.2.0, colloquially known as\n\"WASIp2\". Around the same time the subgroup additionally decided to name the\nprevious iteration of WASI as \"WASIp1\", historically known as \"WASI preview1\".\nThis now-historical snapshot of WASI was defined with an entirely different set\nof primitives and worked very differently. This crate now targets WASIp2 and no\nlonger targets WASIp1.\n\n## Support for WASIp1\n\nThe last version of the `wasi` crate to support WASIp1 was the\n[0.11.0+wasi-snapshot-preview1\nversion](https://crates.io/crates/wasi/0.11.0+wasi-snapshot-preview1). This\nversion of the crate supported all WASIp1 APIs. WASIp1 was historically defined\nwith `*.witx` files and used a bindings generator called `witx-bindgen`.\n\n## Should I use WASIp1 or WASIp2?\n\nThis is a bit of a nuanced question/answer but the short answer is to probably\nuse the 0.11.0 release of `wasi` for now if you're unsure.\n\nThe longer-form answer of this is that it depends on the Rust targets that you\nwant to support. Rust WebAssembly targets include:\n\n* `wasm32-unknown-unknown` - do not use this crate because this target indicates\n  that WASI is not desired.\n* `wasm32-wasip1` - this target has been present in Rust for quite some time and\n  was previously known as `wasm32-wasi`. For this target you probably want the\n  0.11.0 track of this crate.\n* `wasm32-wasip2` - this target is a recent addition to rustc (as of the time of\n  this writing it's not merged yet into rustc). This is what the 0.12.0 version\n  of the crate is intended for.\n\nNote that if you use `wasm32-wasip1` it's not necessarily guaranteed you want\n0.11.0 of this crate. If your users are producing components then you probably\nwant 0.12.0 instead. If you don't know what your users are producing then you\nshould probably stick with 0.11.0.\n\nLong story short, it's a bit complicated. We're in a transition period from\nWASIp1 to WASIp2 and things aren't going to be perfect every step of the way, so\nunderstanding is appreciated!\n\n# Development\n\nThe bulk of the `wasi` crate is generated by the [`wit-bindgen`] tool. The\n`src/bindings.rs` file can be regenerated with:\n\n```\n$ ./ci/regenerate.sh\n```\n\nWASI definitions are located in the `wit` directory of this repository.\nCurrently they're copied from upstream repositories but are hoped to be better\nmanaged in the future.\n\n# License\n\nThis project is triple licenced under the Apache 2/ Apache 2 with LLVM exceptions/ MIT licences. The reasoning for this is:\n- Apache 2/ MIT is common in the rust ecosystem.\n- Apache 2/ MIT is used in the rust standard library, and some of this code may be migrated there.\n- Some of this code may be used in compiler output, and the Apache 2 with LLVM exceptions licence is useful for this.\n\nFor more details see\n- [Apache 2 Licence](LICENSE-APACHE)\n- [Apache 2 Licence with LLVM exceptions](LICENSE-Apache-2.0_WITH_LLVM-exception)\n- [MIT Licence](LICENSE-MIT)\n\n### Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in this project by you, as defined in the Apache 2/ Apache 2 with LLVM exceptions/ MIT licenses,\nshall be licensed as above, without any additional terms or conditions.\n","funding_links":[],"categories":["Rust"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbytecodealliance%2Fwasi-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbytecodealliance%2Fwasi-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbytecodealliance%2Fwasi-rs/lists"}