{"id":13667936,"url":"https://github.com/tauri-apps/tauri-bindgen","last_synced_at":"2025-03-22T01:07:18.307Z","repository":{"id":63824893,"uuid":"568607737","full_name":"tauri-apps/tauri-bindgen","owner":"tauri-apps","description":"Typesafe language bindings generator for the Tauri IPC bridge","archived":false,"fork":false,"pushed_at":"2024-09-24T06:19:13.000Z","size":2971,"stargazers_count":146,"open_issues_count":28,"forks_count":5,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-10-29T15:44:17.356Z","etag":null,"topics":["bindings","javascipt","javascript","rollup-plugin","rust","tauri","typescript","wasm","webassembly"],"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/tauri-apps.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE_APACHE-2.0","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-21T02:32:00.000Z","updated_at":"2024-10-19T12:23:54.000Z","dependencies_parsed_at":"2023-09-21T15:35:12.946Z","dependency_job_id":"8c2b115d-fef1-4db8-8d09-99b673068a1f","html_url":"https://github.com/tauri-apps/tauri-bindgen","commit_stats":{"total_commits":473,"total_committers":7,"mean_commits":67.57142857142857,"dds":"0.32769556025369984","last_synced_commit":"16e49f59c4c15ace9ac35a1506f35e457b04ee25"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tauri-apps%2Ftauri-bindgen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tauri-apps%2Ftauri-bindgen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tauri-apps%2Ftauri-bindgen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tauri-apps%2Ftauri-bindgen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tauri-apps","download_url":"https://codeload.github.com/tauri-apps/tauri-bindgen/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244890092,"owners_count":20527033,"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":["bindings","javascipt","javascript","rollup-plugin","rust","tauri","typescript","wasm","webassembly"],"created_at":"2024-08-02T07:00:54.915Z","updated_at":"2025-03-22T01:07:18.276Z","avatar_url":"https://github.com/tauri-apps.png","language":"Rust","readme":"\u003cdiv align=\"center\"\u003e\n  \u003ch1\u003e\n    \u003ccode\u003etauri-bindgen\u003c/code\u003e\n  \u003c/h1\u003e\n  \u003cp\u003e\n    \u003cstrong\u003eTypesafe language bindings generator for the Tauri IPC bridge\u003c/strong\u003e\n  \u003c/p\u003e\n  \u003cp\u003e\n  \u003ca href=\"https://bindgen.tauri.tech/\"\u003eOnline playground\u003c/a\u003e\n  \n[![MIT or Apache 2.0 licensed][mit-or-apache-badge]][mit-or-apache-url]\n  \n  \u003c/p\u003e\n\u003c/div\u003e\n\n\n[mit-or-apache-badge]: https://img.shields.io/badge/license-MIT%20or%20Apache%202.0-blue.svg\n[mit-or-apache-url]: LICENSE\n\n\n\u003e **Note**: **This project is still under heavy development and may not support all features yet. Feel free to try it out though, create issues, and open PRs!**\n\n## About\n\nGenerate type-safe bindings for Tauri's IPC bridge. Currently supports Rust [Host](#host) **and** Webview frontends (called [Guests](#guest)) in JavaScript, TypeScript, and Rust. Bindings are declared using [`*.wit`](docs/WIT.md) files that describe exposed functions and shared types.\n\n### Rationale\n\nUnder the current IPC system, Tauri can make no compile-time guarantees on the correctness of your `invoke` calls and any mistakes will result in nasty runtime errors. For example you might have misspelled a command or parameter name which you will only notice when actually running the app!\n\n`tauri-bindgen` will generate traits and invoke-handlers for the [Host](#host) and [Guest](#guest) bindings for JavaScript, TypeScript, Rust and ReScript from a single, shared source of truth using the [`*.wit`](https://github.com/WebAssembly/component-model/blob/main/design/mvp/WIT.md) format as a Interface Definition Language (IDL). The generated bindings automatically take care of the heavy lifting, such as correctly calling the `invoke` function and serializing/deserializing parameters and results.\n\nHere are a few reasons why that is cool:\n\n- **Compile-time Checks**\n\nWhen using strongly typed languages, such as Rust, TypeScript or ReScript the generated code will automatically ensure that you are calling the API correctly, as long as it passes the type checking your golden. This is especially neat **when working in a team**, so your colleagues can't just change command signatures and pull the rug out from under you.\n\n- **Easily auditable**\n\nSometimes in bigger apps it's easy to loose track of all the commands your backend exposes, there might be an old version left somewhere that still get's exposed to the frontend. This is of course a big security risk. Having all possible commands be declared in a single place makes them easily auditable for you and possibly external security auditing professionals.\n\n- **Automatic documentation**\n\n`tauri-bindgen` can also generate easy to read markdown and html descriptions of your interfaces for documentation purposes.\n\n- **Future proof**\n\nWe're planning a big rework of the IPC bridge in the coming months and `tauri-bindgen` has been designed with some of the early design-work in mind. A big rework of course means breaking changes, but using tauri bindgen isolates from these changes, just update Tauri, update `tauri-bindgen`, and re-generate your bindings and your code will continue to work!\n\n## Terminology\n\n### **`Host`**\n\nHost refers to the Tauri rust core, so the place where your commands are implemented.\n\n### **`Guest`**\n\nGuest refers to the code running in the Webview, this will usually be written in JavaScript/TypeScript, but can also be written in any other language that runs on the Web (through WASM) like Rust, C, or Swift.\n\n## Supported Bindings\n\n- **Host** - Generates a trait declaration and an `invoke_handler` from the interface. This generator can also be used through the `tauri-bindgen-host` crate (located at `crates/host`) and, has a generate! macro for generating code.\n- **Guest JavaScript** - Generates a module exposing all functions, functions internally know how to serialize and invoke their host counterpart.\n- **Guest Typescript** - The same as the JavaScript guest, but generates Typescript files.\n- **Guest Rust** - Generates bindings using `wasm_bindgen` that can be used in Rust compile-to-wasm frontend frameworks such as sycamore. You probably want to depend on the `tauri-bindgen-guest-rust` crate (located at `crates/guest-rust`) and use the `generate!` macro to generate code.\n- **Guest ReScript** - Generates bindings for the ReScript language.\n- **Markdown** - Generates a markdown description of the interface for documentation purposes.\n\n## Example\n\nDeclare your interface in a `*.wit` file:\n\n```wit\ninterface greet {\n  func greet(name: string) -\u003e string\n}\n```\n\nthen you can generate the host bindings:\n\n```rust\nuse tauri_bindgen_host::ipc_router_wip::{BuilderExt, Caller, Router};\n\ntauri_bindgen_host::generate!({\n    path: \"../greet.wit\",\n    async: false,\n    tracing: true\n});\n\n#[derive(Clone, Copy)]\nstruct GreetCtx;\n\nimpl greet::Greet for GreetCtx {\n    fn greet(\u0026self, name: String) -\u003e String {\n        format!(\n            \"Hello, {}! You've been greeted from code-generated Rust!\",\n            name\n        )\n    }\n}\n\nfn main() {\n    let mut router: Router\u003cGreetCtx\u003e = Router::new(GreetCtx {});\n\n    greet::add_to_router(\u0026mut router, |ctx| ctx).unwrap();\n\n    tauri::Builder::default()\n        .ipc_router(router)\n        .run(tauri::generate_context!())\n        .expect(\"error while running tauri application\");\n}\n```\n\nand lastly generate client bindings, this can be done for JavaScript, Typescript or ReScript using the following commands:\n\n```\ntauri-bindgen guest javascript greet.wit --prettier // we can run prettier on the generated code. requires a global prettier install\ntauri-bindgen guest typescript greet.wit --prettier\ntauri-bindgen guest rescript greet.wit --fmt // run `rescript format` on the generated code. requires a global rescript install\n```\n\nor for rust using the provided `generate!` macro:\n\n```rust\ntauri_bindgen_guest_rust::generate!({\n    path: \"greet.wit\"\n});\n\n// now we can call greet\nlet greeting = greet::greet(\"Jonas\").await;\n```\n\nsee also [the example](./examples/).\n\n## Contributing\n\nPRs are welcome!\n\n## Credits\n\nThis project has been inspired by and based off of the awesome [`wit-bindgen`](https://github.com/bytecodealliance/wit-bindgen) tool for WebAssembly by the [Bytecode Alliance](https://bytecodealliance.org).\n\n#### License\n\n\u003csup\u003e\nLicensed under either of \u003ca href=\"LICENSE-APACHE\"\u003eApache License, Version\n2.0\u003c/a\u003e or \u003ca href=\"LICENSE-MIT\"\u003eMIT license\u003c/a\u003e at your option.\n\u003c/sup\u003e\n\n\u003cbr\u003e\n\n\u003csub\u003e\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in this crate by you, as defined in the Apache-2.0 license, shall\nbe dual licensed as above, without any additional terms or conditions.\n\u003c/sub\u003e\n","funding_links":[],"categories":["Rust"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftauri-apps%2Ftauri-bindgen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftauri-apps%2Ftauri-bindgen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftauri-apps%2Ftauri-bindgen/lists"}