{"id":13563577,"url":"https://github.com/guregu/hammertime","last_synced_at":"2025-08-23T10:37:40.331Z","repository":{"id":184874134,"uuid":"672611201","full_name":"guregu/hammertime","owner":"guregu","description":"alternative WASI for wasmtime-go","archived":false,"fork":false,"pushed_at":"2023-08-11T11:37:12.000Z","size":84,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-19T17:38:11.453Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/guregu.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},"funding":{"github":"guregu"}},"created_at":"2023-07-30T17:05:36.000Z","updated_at":"2023-07-31T12:32:16.000Z","dependencies_parsed_at":"2023-07-30T18:22:50.932Z","dependency_job_id":"ed560dbb-0bb4-493d-92b2-9d3f872be1d3","html_url":"https://github.com/guregu/hammertime","commit_stats":null,"previous_names":["guregu/hammertime"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/guregu/hammertime","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guregu%2Fhammertime","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guregu%2Fhammertime/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guregu%2Fhammertime/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guregu%2Fhammertime/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/guregu","download_url":"https://codeload.github.com/guregu/hammertime/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guregu%2Fhammertime/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271746667,"owners_count":24813576,"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","status":"online","status_checked_at":"2025-08-23T02:00:09.327Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-08-01T13:01:20.929Z","updated_at":"2025-08-23T10:37:40.308Z","avatar_url":"https://github.com/guregu.png","language":"Go","funding_links":["https://github.com/sponsors/guregu"],"categories":["Go"],"sub_categories":[],"readme":"# 🔨 hammertime [![GoDoc](https://godoc.org/github.com/guregu/hammertime?status.svg)](https://godoc.org/github.com/guregu/hammertime)\n\n`import \"github.com/guregu/hammertime\"`\n\nDo you want to use the excellent [wasmtime-go](https://github.com/bytecodealliance/wasmtime-go) Wasm runtime library, but are missing some features like [capturing stdout or setting stdin](https://github.com/bytecodealliance/wasmtime-go/issues/34)?\n\nThis library is a WASI implementation in Go for wasmtime-go. Its goal is to integrate Wasm more deeply with Go but still take advantage of Wasmtime's speedy runtime.\n\n#### Status\n\nRough proof of concept targeting `wasi_snapshot_preview1`. If this project proves to be useful, I'm thinking a code generation approach targeting preview2 would be the next step.\n\nTL;DR: Alpha!\n\n- ⛔️ Note that hammertime does not implement the preview1 capabilities model (yet?).\n- ☣️ It's also not safe to share WASI instances concurrently or across instances (yet?).\n- 😇 Lots of `unsafe`. Needs fuzzing or something.\n- 🤠 Experimental. Ideas welcome!\n\n## Features\n\n- Uses `fs.FS` for the Wasm filesystem. Supports [`hackpadfs`](https://github.com/hack-pad/hackpadfs#file-systems) extensions to add writing, etc.\n- `stdin` can be set to an `io.Reader`.\n- `stdout` and `stderr` can be set to a `io.Writer`.\n- More experimental stuff coming soon?\n\n| WASI API                  | Vibe   |\n|---------------------------|--------|\n| args_sizes_get            | 😎     |\n| args_get                  | 😎     |\n| environ_sizes_get         | 😎     |\n| environ_get               | 😎     |\n| clock_time_get            | 🧐     |\n| fd_close                  | 🧐     |\n| fd_fdstat_get             | 🙂     |\n| fd_fdstat_set_flags       | 😶‍🌫️     |\n| fd_prestat_get            | 🙂     |\n| fd_prestat_dir_name       | 😎     |\n| fd_filestat_get           | 🧐     |\n| fd_seek                   | 🙂     |\n| fd_write                  | 🙂     |\n| fd_read                   | 🙂     |\n| fd_pread                  | 🧐     |\n| fd_readdir                | 🙂     |\n| path_open                 | 🧐     |\n| path_filestat_get         | 🧐     |\n| path_readlink             | 🧐     |\n| path_rename               | 🧐     |\n| path_create_directory     | 🙂     |\n| path_remove_directory     | 🙂     |\n| path_unlink_file          | 🙂     |\n| poll_oneoff               | 😶‍🌫️     |\n| proc_exit                 | 😶‍🌫️     |\n\n#### Legend\n\n|    | Interpretation                 |\n| -- | ------------------------------ |\n| 😎 | Pretty good                    |\n| 🙂 | Not bad                        |\n| 🧐 | Needs more work/testing/love   |\n| 😶‍🌫️ | Stub/missing                   |\n\n# Usage\n\nSee: [Godoc](https://godoc.org/github.com/guregu/hammertime)\n\n### Quick Start\n\nImagine we have this C program we want to execute as WebAssembly. It's a simple program that receives a newline-separated list of who to greet via standard input, and writes \"hello {name}\" to standard output.\n\n```c\nint main() {\n    char *line = NULL;\n    size_t len = 0;\n    ssize_t read = 0;\n    while ((read = getline(\u0026line, \u0026len, stdin)) != -1) {\n        printf(\"hello %s\", line);\n    }\n    free(line);\n    return 0;\n}\n```\n\nWe can embed and execute it in a Go program like so, capturing the output:\n\n```go\nimport (\n    \"bytes\"\n    _ \"embed\"\n    \"log\"\n    \"os\"\n\n    \"github.com/bytecodealliance/wasmtime-go/v11\"\n    \"github.com/guregu/hammertime\"\n)\n\n//go:embed hello.wasm\nvar wasmModule []byte // Protip: stuff your modules into your binary with embed\n\nfunc main() {\n    // Standard boilerplate\n    engine := wasmtime.NewEngine()\n    store := wasmtime.NewStore(engine)\n    module, err := wasmtime.NewModule(engine, wasmModule)\n    if err != nil {\n        panic(err)\n    }\n    linker := wasmtime.NewLinker(engine)\n\n    // Prepare our input and output\n    input := \"alice\\nbob\\n\"\n    stdin := strings.NewReader(input)\n    stdout := new(bytes.Buffer)\n\n    // Set up our custom WASI\n    wasi := hammertime.NewWASI(\n        WithArgs([]string{\"hello.wasm\"}),\n        WithStdin(stdin),             // Stdin can be any io.Reader\n        WithStdout(stdout),           // Capture stdout to a *bytes.Buffer!\n        WithFS(os.DirFS(\"testdata\")), // Works with Go's fs.FS! (kind of)\n    )\n    // Link our WASI\n    if err := wasi.Link(store, linker); err != nil {\n        panic(err)\n    }\n\n    // Use wasmtime as normal\n    instance, err := linker.Instantiate(store, module)\n    if err != nil {\n        panic(err)\n    }\n    start := instance.GetFunc(store, \"_start\")\n    _, err = start.Call(store)\n    if err != nil {\n        panic(err)\n    }\n\n    // Grab captured stdout data\n    output := stdout.String()\n    fmt.Println(output)\n    // Prints: hello alice\n    // hello bob\n}\n```\n\nThis gives us an easy way to communicate with wasm modules.\n\n# Testing\n\nEach testdata/*.c file is a little self-contained C program that tests a WASI feature.\n\nTo build/run the test files, [install WASI SDK](https://github.com/WebAssembly/wasi-sdk#install), then do something like:\n\n```console\n$ export WASI_CC=/path/to/wasi-sdk-XX.0/bin/clang\n$ make -j8\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguregu%2Fhammertime","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguregu%2Fhammertime","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguregu%2Fhammertime/lists"}