{"id":26830859,"url":"https://github.com/oltdaniel/zig-wasm-example","last_synced_at":"2026-04-29T18:33:00.766Z","repository":{"id":246707351,"uuid":"821775077","full_name":"oltdaniel/zig-wasm-example","owner":"oltdaniel","description":"exploring wasm with zig","archived":false,"fork":false,"pushed_at":"2024-07-16T16:49:34.000Z","size":60,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-30T14:17:56.904Z","etag":null,"topics":["wasm","zig"],"latest_commit_sha":null,"homepage":"","language":"Zig","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/oltdaniel.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-29T11:56:03.000Z","updated_at":"2024-12-04T00:16:14.000Z","dependencies_parsed_at":"2024-07-16T20:38:59.776Z","dependency_job_id":null,"html_url":"https://github.com/oltdaniel/zig-wasm-example","commit_stats":null,"previous_names":["oltdaniel/zig-wasm-example"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/oltdaniel/zig-wasm-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oltdaniel%2Fzig-wasm-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oltdaniel%2Fzig-wasm-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oltdaniel%2Fzig-wasm-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oltdaniel%2Fzig-wasm-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oltdaniel","download_url":"https://codeload.github.com/oltdaniel/zig-wasm-example/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oltdaniel%2Fzig-wasm-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32439179,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T18:12:22.909Z","status":"ssl_error","status_checked_at":"2026-04-29T18:11:33.322Z","response_time":110,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["wasm","zig"],"created_at":"2025-03-30T14:17:59.952Z","updated_at":"2026-04-29T18:33:00.751Z","avatar_url":"https://github.com/oltdaniel.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Zig WASM Example\n\n\u003e [!IMPORTANT]  \n\u003e This project has been re-written as an actual library and can be found at [oltdaniel/zig-js-interplay](https://github.com/oltdaniel/zig-js-interplay). This repo will probably be archived in the future.\n\nThis repo is playing with Zig and WASM to see how easy or hard it is passing values between them, without an ready-to-go generator like in `wasm-pack` for Rust.\n\n## Example\n\nThis is an example which hides type handling behind a Helper class.\n\n\u003e See full example in [`www/index.html`](./www/index.html) and [`src/wasm.zig`](./src/wasm.zig).\n\n```js\nimport ZigWASMWrapper from './helper.js';\n\nlet wasm = await ZigWASMWrapper.initialize(\"./main.wasm\");\n\nconsole.log(wasm.greet(\"Daniel\"));\n// =\u003e prints \"Hello Daniel!\"\n\nwasm.printJSON({message: \"Greetings\"});\n// =\u003e prints \"JSON = {\"message\":\"Greetings\"}!\"\n\nwasm.silence();\n// =\u003e does nothing\n\nwasm.testFunction((...args) =\u003e {\n    console.log('I got called from zig with these arguments=', args)\n})\n// =\u003e prints \"I got called from zig with these arguments= ['Hello', 'World]\"\n```\n\nAnd the zig code excluding the type hanlding is also straightforward:\n\n```zig\n// type definitions and imports\n\nexport fn greet(arg: String) String {\n    // Get the real value passed to us by javascript\n    const name = arg.value();\n\n    // ... this ignores some code of the actual code to print a message in between\n\n    // Generate a new greet message that we can return\n    const greetMessage = std.fmt.allocPrint(gpa, \"Hello {s}!\", .{name}) catch @panic(\"Oops\");\n\n    // Return the greet message as a compatible type\n    return String.init(greetMessage);\n}\n\nexport fn printJSON(arg: JSON) void {\n    const message = std.fmt.allocPrint(gpa, \"JSON = {s}!\", .{arg.value()}) catch @panic(\"Oops\");\n    js.log(String.init(message));\n}\n\nexport fn testFunction(arg: Function) AnyType {\n    const args = Array.from(\u0026.{ String.init(\"Hello\").asAny(), String.init(\"World\").asAny() });\n    return arg.call(args);\n}\n```\n\n## Documentation\n\n\u003e **TODO**: Write documentation on the encoding and examples for each type and scenario.\n\n## Requirements\n\n- zig, I'm running the latest release `0.13`\n- python, to serve the output\n- make, just as a command shortcut tool\n\n## Running\n\n```bash\n# compile the wasm file\nmake\n\n# start the server\nmake server\n```\n\n## Information\n\nA small blog article on how I ended up writing this repo: [Playing with zig and wasm](https://oltdaniel.eu/blog/2024/playing-with-zig-and-wasm.html)\n\n## Known pitfalls\n\n- Introducing the dynamic and untyped nature of JS into Zig requires additional verification of types during runtime. Other libraries generate the JS interface to avoid pitfalls like this, but they require an additional compile step and delivery of the custom compiled WASM file as well as the JS file. Thereby, assuming types is ignorant just like in JS and you need to verify them \"manually\". **NOTE**: The Compatible Types built in Zig verify their type when a type specific action is executed (like calling `.value()` or `.call()`).\n- When Zig returns or accepts non-compatible types, the behavior is undefined or rather the same was with not using the library. This means, the built-in abstraction on the JS side won't work as it expects compatible types.\n- There is currently no abstraction for memory allocation. If something like a string of length zero is requested for allocation, it fails.\n\n## ToDo\n\n- [ ] Memory abstraction for error handling\n- [ ] Clean-up of code\n- [ ] Documentation\n\n## License\n\n[LICENSE MIT](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foltdaniel%2Fzig-wasm-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foltdaniel%2Fzig-wasm-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foltdaniel%2Fzig-wasm-example/lists"}