{"id":17223123,"url":"https://github.com/daboross/wasm-wrapper-gen","last_synced_at":"2026-07-07T00:30:29.751Z","repository":{"id":57671936,"uuid":"112238161","full_name":"daboross/wasm-wrapper-gen","owner":"daboross","description":"JS-\u003eRust binding generation for Rust compiled to Web Assembly (deprecated, use stdweb instead!)","archived":true,"fork":false,"pushed_at":"2017-12-08T07:53:54.000Z","size":101,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-20T00:46:07.184Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/daboross.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-27T19:20:28.000Z","updated_at":"2024-10-22T23:24:10.000Z","dependencies_parsed_at":"2022-08-31T01:22:50.832Z","dependency_job_id":null,"html_url":"https://github.com/daboross/wasm-wrapper-gen","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daboross%2Fwasm-wrapper-gen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daboross%2Fwasm-wrapper-gen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daboross%2Fwasm-wrapper-gen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daboross%2Fwasm-wrapper-gen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daboross","download_url":"https://codeload.github.com/daboross/wasm-wrapper-gen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240454053,"owners_count":19803888,"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":[],"created_at":"2024-10-15T04:07:26.137Z","updated_at":"2026-07-07T00:30:29.692Z","avatar_url":"https://github.com/daboross.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"wasm-wrapper-gen\n================\n\nJavaScript wrapper generation for rust code targeting wasm32-unknown-unknown.\n\nI believe in \"release early, release often\", so `wasm-wrapper-gen` is available on crates.io as version 0.0.3.\nThat said, the project is still a work in progress, and breaking changes are to be expected.\n\n---\n\nThe main idea:\n\n```rust\nfn fib_str(nth: u32) -\u003e String {\n    let mut last = 0;\n    let mut current = 1u64;\n    for _ in 0..(nth as u64) {\n        let temp = current + last;\n        last = current;\n        current = temp;\n    }\n    format!(\"fibonacci sequence #{}: {}\", nth, current)\n}\n\njs_fn! {\n    fn fib_str(_: u32) -\u003e String =\u003e fib_str;\n}\n```\n\n```js\nlet module = new WebAssembly.Module(/*..*/);\nlet fib = new Fibonacci(module);\n\nconsole.log(fib.fib_str(20));\n```\n\nThere are multiple full example projects available in `examples/`, each which tests a different aspect of `wasm-wrapper-gen`. All of these should be directly copyable out of the repository as a starter if needed.\n\n---\n\n### Repository structure:\n\n`wasm-wrapper-gen` is composed of two interlocking parts:\n- `wasm-wrapper-gen` provides the `js_fn!()` macro which generates `extern \"C\"` functions\n- `wasm-wrapper-gen-build` is a build-script utility which scrapes the source for usages of `js_fn!()` and generates a JavaScript class using those exported functions.\n\n### Implementation notes:\n\n- The default way to access memory is through a single pre-made DataView. This is efficient for small arrays/strings,\n  but TypedArrays are also supported via a configuration option.\n- Strings are always converted from utf16-\u003eutf8 and vice-versa inside Rust. This means all JavaScript ever does is\n  `string.charCodeAt` and `String.fromCharCode`, but that all String arguments and return values require one extra\n  allocation for a `Vec\u003cu16\u003e` separately from the `String` or `\u0026'static str`\n\n### Currently supported:\n\n- Argument types:\n  - `bool`, `u8`, `u16`, `u32`, `usize`, `i8`, `i16`, `i32`, `isize`, `f32`, `f64`\n  - `\u0026[_]`, `\u0026mut [_]`, `Vec\u003c_\u003e` where `_` is any of the above\n  - `String` (not `\u0026str` because passing strings in always requires more allocation for utf16-\u003eutf8 in rust)\n- Return types:\n  - `bool`, `u8`, `u16`, `u32`, `usize`, `i8`, `i16`, `i32`, `isize`, `f32`, `f64`\n  - `Vec\u003c_\u003e` where `_` is any of the above\n  - `String` and `\u0026'static str`\n- Full automatic memory management and freeing unless rust function panics\n- Configuration to use either a single DataView or a TypedArray instance per argument\n  to access arrays\n- Configurable output JS indentation\n\n### Unimplemented:\n\n- Next to do:\n  - Add support for making an async constructor rather than sync one.\n  - Add support for `impl` blocks with `self` arguments and creating wrapper JS types\n    which manage allocation sanely.\n\n- Further future:\n  - Make real tests and figure out how to do a build.rs script which only runs for tests\n  - Arbitrary argument types implementing some serialization trait\n  - Macro to wrap individual structs in separate JavaScript classes\n    which all reference the same WebAssembly.Instance\n\n### Links:\n\n- [Full example of usage](docs/usage-example.md)\n- [Full example of generated code](docs/compiled-example.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaboross%2Fwasm-wrapper-gen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaboross%2Fwasm-wrapper-gen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaboross%2Fwasm-wrapper-gen/lists"}