{"id":13643176,"url":"https://github.com/kanaka/wac","last_synced_at":"2025-04-04T22:06:20.998Z","repository":{"id":44357920,"uuid":"88188506","full_name":"kanaka/wac","owner":"kanaka","description":"WebAssembly interpreter in C","archived":false,"fork":false,"pushed_at":"2024-08-09T21:24:05.000Z","size":192,"stargazers_count":481,"open_issues_count":14,"forks_count":47,"subscribers_count":22,"default_branch":"master","last_synced_at":"2025-03-28T21:03:31.163Z","etag":null,"topics":["binaryen","c","docker-image","emscripten","gcc","javascript","mvp","native","repl","wasm","wasm-modules","webassembly"],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kanaka.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":"2017-04-13T17:11:59.000Z","updated_at":"2025-03-27T22:01:36.000Z","dependencies_parsed_at":"2024-10-30T18:02:29.147Z","dependency_job_id":"f9279d37-e2b3-42b8-b94a-3139965556ab","html_url":"https://github.com/kanaka/wac","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanaka%2Fwac","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanaka%2Fwac/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanaka%2Fwac/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kanaka%2Fwac/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kanaka","download_url":"https://codeload.github.com/kanaka/wac/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247256112,"owners_count":20909240,"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":["binaryen","c","docker-image","emscripten","gcc","javascript","mvp","native","repl","wasm","wasm-modules","webassembly"],"created_at":"2024-08-02T01:01:43.172Z","updated_at":"2025-04-04T22:06:20.971Z","avatar_url":"https://github.com/kanaka.png","language":"C","funding_links":[],"categories":["C","Non-Web Embeddings","Runtimes"],"sub_categories":["**C**"],"readme":"# wac - WebAssembly in C\n\nA Minimal WebAssembly interpreter written in C. Supports the\nWebAssembly MVP (minimum viable product) version of the WebAssembly\nspecification.\n\nThere are three different builds of wac:\n\n* **wac**: (WebAssembly in C) Minimal client with an interactive REPL\n  mode. Designed to run standalone wasm files compiled with\n  `wat2wasm` or `wasm-as`. Passes most spec tests apart from some\n  multi-module import/export tests.\n* **wax**: (WebAssembly in C with WASI) Client with WebAssembly System\n  Interface APIs (WASI).\n* **wace**: (WebAssembly in C with Emscripten) Client with host\n  library/memory integration. Designed to run wasm code that has been\n  built with Emscripten (using `-s SIDE_MODULE=1 -s LEGALIZE_JS_FFI=0`).\n\n## Prerequisites\n\nTo build wac/wax/wace you need a 32-bit version of gcc and 32-bit\nversions of SDL2 and libedit. On 64-bit Ubuntu/Debian these can be\ninstalled like this:\n\n```\ndpkg --add-architecture i386\napt-get update\napt-get install lib32gcc-4.9-dev libSDL2-dev:i386 libedit-dev:i386\n```\n\nTo compile wat source files to binary wasm modules you will need the\n`wasm-as` program from [Binaryen](https://github.com/WebAssembly/binaryen).\nTo compile C programs to wasm modules you will need Binaryen and\n[emscripten](https://github.com/kanaka/emscripten).\n\nAs an alternative to downloading and building the above tools, the\n`kanaka/wac` docker image (1.7GB) has 32-bit gcc compiler/libraries,\nemscripten, and binaryen preinstalled. The docker image can be started\nwith appropriate file mounts like this:\n\n```\ndocker run -v `pwd`:/wac -w /wac -it kanaka/wac bash\n```\n\nAll the build commands below can be run within the docker container.\n\n\n## wac usage\n\nBuild wac:\n\n```bash\n$ make wac\n```\n\nUse `wasm-as` to compile a simple wat program to a wasm:\n\n```bash\n$ make examples_wat/arith.wasm\n```\n\nNow load the compiled wasm file and invoke some functions:\n\n```bash\n$ ./wac examples_wat/arith.wasm add 2 3\n0x5:i32\n$ ./wac examples_wat/arith.wasm mul 7 8\n0x38:i32\n```\n\nwac also supports a very simple REPL (read-eval-print-loop) mode that\nruns commands in the form of `FUNC ARG...`:\n\n```\n$ ./wac --repl examples_wat/arith.wasm\n\u003e sub 10 5\n0x5:i32\n\u003e div 13 4\n0x3:i32\n```\n\n## wax usage\n\nBuild wax:\n\n```bash\n$ make wax\n```\n\nUse `wasm-as` to compile a wat program that uses the WASI interface:\n\n```bash\n$ make examples_wat/echo.wasm\n```\n\nNow run the compiled wasm file. The program reads text from stdin and\nechos it to stdout until an EOF (Ctrl-D) is sent.\n\n```bash\n$ ./wax examples_wat/echo.wasm\n\u003e foo\nfoo\n\u003e bar\nbar\n\u003e \u003cCtrl-D\u003e\n```\n\n\n## wace usage\n\nBuild wace:\n\n```bash\n$ make wace\n```\n\nUse emscripten/binaryen to compile some simple C programs and run them\nusing wace:\n\n```bash\n$ make examples_c/hello1.wasm\n$ ./wace examples_c/hello1.wasm\nhello world\n\n$ make examples_c/hello2.wasm\n$ ./wace examples_c/hello2.wasm\nhello malloc people\n```\n\nUse emscripten/binaryen to compile some C SDL programs and run them\nusing wace:\n\n```bash\n$ make examples_c/hello_sdl.wasm\n$ ./wace examples_c/hello_sdl.wasm\nINFO: OpenGL shaders: ENABLED\nINFO: Created renderer: opengl\n# Blue Window displayed for 2 seconds\nDone.\n\n$ make examples_c/triangle.wasm\n$ ./wace examples_c/triangle.wasm\n# A colorfully shaded triangle is rendered\n```\n\n## Running WebAssembly spec tests\n\nwac includes a `runtest.py` test driver which can be used for running\ntests from the WebAssembly specification.\n\nCheck out the spec:\n\n```\ngit clone https://github.com/WebAssembly/spec\n```\n\nYou will need `wat2wasm` to compile the spec tests. Check-out and\nbuild [wabt](https://github.com/WebAssembly/wabt) (wabbit):\n\n```\ngit clone --recursive https://github.com/WebAssembly/wabt\nmake -C wabt gcc-release\n```\n\nRun the `func.wast` test file (to test function calls) from the spec:\n\n```\n./runtest.py --wat2wasm ./wabt/out/gcc/Release/wat2wasm --interpreter ./wac spec/test/core/func.wast\n```\n\nRun all the spec tests apart from a few that currently fail (mostly due to\n`runtest.py` missing support for some syntax used in those test files):\n\n```\nBROKE_TESTS=\"comments exports imports linking names data elem inline-module\"\nfor t in $(ls spec/test/core/*.wast | grep -Fv \"${BROKE_TESTS// /$'\\n'}\"); do\n    echo -e \"\\nTESTING ${t}\"\n    ./runtest.py ${t} || break\ndone\n```\n\n\n## Standalone Builds using Fooboot\n\nwac and wace can be built to run as standalone bootable programs\nusing [fooboot](https://github.com/kanaka/fooboot):\n\n```\ncd wac\ngit clone https://github.com/kanaka/fooboot\nmake PLATFORM=fooboot clean\nmake PLATFORM=fooboot wac wace examples_wat/addTwo.wasm\n```\n\nThe `fooboot/runfoo` script can be used to boot wac/wace with QEMU.\n`fooboot/runfoo` also creates a connection on a serial port (COM2)\nthat allows files to be read from the host system:\n\n```\nfooboot/runfoo wac --repl examples_wat/addTwo.wasm\nQEMU waiting for connection on: disconnected:tcp:localhost:21118,server\nwebassembly\u003e addTwo 2 3\n0x5:i32\n```\n\nThe standalone wac/wace builds can also be built into an ISO image\nthat can boot directly on real hardware. You will need Grub 2 and the\nGrub PC/BIOS binary files (grub-pc-bin) and the xorriso program to be\nable to do this. Also, the wasm modules that you wish to run must be\nbuilt into the binary to become part of a simple in-memory\nfile-system:\n\n```\necho \"examples_wat/addTwo.wasm\" \u003e mem_fs_files\nmake PLATFORM=fooboot \\\n     FOO_TARGETS=\"wac\" \\\n     FOO_CMDLINE=\"examples_wat/addTwo.wasm addTwo 3 4\" \\\n     boot.iso\n```\n\nYou can now boot the ISO with QEMU like this:\n\n```\nqemu-system-i386 -cdrom boot.iso\n```\n\nOr you can burn the ISO to a USB device and boot from it on real\nhardware.  This will destroy any data on the USB device! Also, make\ncompletely sure that /dev/MY\\_USB\\_DEVICE is really the USB device you\nwant to overwrite and not your hard drive. You have been warned!\n\n```\nsudo dd if=boot.iso of=/dev/MY_USB_DEVICE \u0026\u0026 sync\n# Now boot you can boot from the USB device\n```\n\n## License\n\nMPL-2.0 (see LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkanaka%2Fwac","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkanaka%2Fwac","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkanaka%2Fwac/lists"}