{"id":15616328,"url":"https://github.com/brendocosta/gwr","last_synced_at":"2026-04-17T08:04:03.703Z","repository":{"id":252712753,"uuid":"841230329","full_name":"BrendoCosta/gwr","owner":"BrendoCosta","description":"An experimental work-in-progress (WIP) WebAssembly runtime written in Gleam.","archived":false,"fork":false,"pushed_at":"2025-03-23T15:05:45.000Z","size":302,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-23T16:22:03.073Z","etag":null,"topics":["erlang","gleam","runtime","wasm","webassembly"],"latest_commit_sha":null,"homepage":"","language":"Gleam","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/BrendoCosta.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-08-12T01:28:59.000Z","updated_at":"2025-03-23T15:05:48.000Z","dependencies_parsed_at":null,"dependency_job_id":"7992cd0d-4ce4-467d-9c36-62b17061c5d8","html_url":"https://github.com/BrendoCosta/gwr","commit_stats":null,"previous_names":["brendocosta/gwr"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrendoCosta%2Fgwr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrendoCosta%2Fgwr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrendoCosta%2Fgwr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrendoCosta%2Fgwr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BrendoCosta","download_url":"https://codeload.github.com/BrendoCosta/gwr/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246200323,"owners_count":20739566,"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":["erlang","gleam","runtime","wasm","webassembly"],"created_at":"2024-10-03T07:06:35.085Z","updated_at":"2026-04-17T08:04:03.641Z","avatar_url":"https://github.com/BrendoCosta.png","language":"Gleam","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GWR - Gleam WebAssembly Runtime\n\n[![Package Version](https://img.shields.io/hexpm/v/gwr)](https://hex.pm/packages/gwr)\n[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/gwr/)\n[![Package License](https://img.shields.io/hexpm/l/gwr)](/LICENSE)\n[![Package Total Downloads Count](https://img.shields.io/hexpm/dt/gwr)](https://hex.pm/packages/gwr)\n[![Test Status](https://github.com/BrendoCosta/gwr/actions/workflows/test.yaml/badge.svg)](https://github.com/BrendoCosta/gwr/actions)\n[![Release Status](https://github.com/BrendoCosta/gwr/actions/workflows/release.yaml/badge.svg)](https://github.com/BrendoCosta/gwr/actions)\n![Available for the Erlang runtime](https://img.shields.io/badge/target-Erlang-a2003e)\n[![Total Stars Count](https://img.shields.io/github/stars/BrendoCosta/gwr)](https://hex.pm/packages/gwr)\n\n## Description\n\nAn experimental work-in-progress (WIP) WebAssembly runtime written in Gleam.\n\n## Purpose\n\nNowadays, many languages ​​support Wasm as a target, from mainstream ones like C++ and Rust, as well as newer ones like Odin and Grain. The purpose of this project is to use WebAssembly to create an alternative interoperability layer to Erlang's virtual machine NIFs.\n\n## Installation\n\n```sh\ngleam add gwr\n```\n\n## Usage\n\n\u003e [!IMPORTANT]\n\u003e Currently the project is in an extremely early stage of development; it is only possible to run very simple functions (consisting of basic integer arithmetic, function calls, and control flows). Keep in mind that code and APIs may change dramatically.\n\n### Step 1 - Build code targeting Wasm\n\n#### Example - Fibonacci sequence from Rust\n\n```rust\n// fib.rs\n\n#![no_std]\n\n#[panic_handler]\npub fn panic(_info: \u0026core::panic::PanicInfo) -\u003e !\n{\n    loop {}\n}\n\n#[unsafe(no_mangle)]\npub extern fn fib(value: i32) -\u003e i32\n{\n    match value\n    {\n        v if v \u003c= 0 =\u003e 0,\n        v if v \u003c= 2 =\u003e 1,\n        _ =\u003e fib(value - 1) + fib(value - 2)\n    }\n}\n```\n```sh\nrustc --crate-type cdylib --target wasm32-unknown-unknown -C debuginfo=none -C panic=abort -C strip=symbols -C opt-level=3 ./fib.rs -o ./fib.wasm\n```\n\n#### Example - Fibonacci sequence from WAT\n\nUsing the wat2wasm tool from [wabt](https://github.com/WebAssembly/wabt).\n\n```wasm\n;; fib.wat\n\n(module\n    (func $fib (export \"fib\") (param $value i32) (result i32)\n        local.get $value\n        i32.const 0\n        i32.le_s\n        if\n            i32.const 0\n            return\n        end\n        local.get $value\n        i32.const 2\n        i32.le_s\n        if\n            i32.const 1\n            return\n        end\n        local.get $value\n        i32.const 1\n        i32.sub\n        call $fib\n        local.get $value\n        i32.const 2\n        i32.sub\n        call $fib\n        i32.add\n        return\n    )\n)\n```\n```sh\nwat2wasm -o ./fib.wasm ./fib.wat\n```\n\n### Step 2 - Run it from Gleam with GWR\n\nUsing the [simplifile](https://hex.pm/packages/simplifile) package to read the module file.\n\n```sh\ngleam add simplifile\n```\n\n```gleam\nimport gwr/gwr\nimport gwr/spec\nimport simplifile\n\npub fn main()\n{\n    let assert Ok(data) = simplifile.read_bits(from: \"fib.wasm\")\n    let assert Ok(binary) = gwr.load(from: data)\n    let assert Ok(instance) = gwr.create(from: binary)\n    let assert Ok(#(_instance, result)) = gwr.call(instance, \"fib\", [spec.Integer32Value(18)])\n    let assert [spec.Integer32Value(2584)] = result\n}\n```\n\n## Building\n\n### Testing\n\nTo test the project, you must have [Devbox](https://www.jetify.com/docs/devbox/installing-devbox) installed in your environment. The project has a test suite written in Rust and WebAssembly text format intended to be built for the wasm target; Devbox setups a isolated build and testing environment with all the required tools so there is no need to install additional toolchains in your main environment.\n\n```sh\ndevbox shell\ndevbox run test\n```\n\nThe above command is equivalent to ```devbox run build_test_suite``` followed by ```gleam test```. Of course, once you have built the test suite, you can simply invoke ```gleam test```.\n\n## Contributing\n\nContributions are welcome! Feel free to submit either issues or PRs, but keep in mind that your code needs to be covered by tests.\n\n## License\n\nGWR source code is avaliable under the [MIT license](/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrendocosta%2Fgwr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrendocosta%2Fgwr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrendocosta%2Fgwr/lists"}