{"id":21262804,"url":"https://github.com/michaelfranzl/clang-wasm-browser-starterpack","last_synced_at":"2025-10-11T08:32:56.864Z","repository":{"id":147443543,"uuid":"360413295","full_name":"michaelfranzl/clang-wasm-browser-starterpack","owner":"michaelfranzl","description":"Minimal working examples of C and C++ software development targeting the web via WebAssembly.","archived":false,"fork":false,"pushed_at":"2025-07-20T09:41:40.000Z","size":483,"stargazers_count":20,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"dev","last_synced_at":"2025-08-03T15:40:42.273Z","etag":null,"topics":["browser","c","clang","cpp","javascript","wasi","wasi-libc","wasi-sdk","webassembly","webassembly-demo","webassembly-tutorial"],"latest_commit_sha":null,"homepage":"","language":"Nix","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/michaelfranzl.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,"zenodo":null}},"created_at":"2021-04-22T06:21:34.000Z","updated_at":"2025-07-20T09:41:40.000Z","dependencies_parsed_at":"2024-05-02T09:59:35.142Z","dependency_job_id":"56f98b68-e4a6-4e92-857d-ed0acf19a0ec","html_url":"https://github.com/michaelfranzl/clang-wasm-browser-starterpack","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/michaelfranzl/clang-wasm-browser-starterpack","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelfranzl%2Fclang-wasm-browser-starterpack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelfranzl%2Fclang-wasm-browser-starterpack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelfranzl%2Fclang-wasm-browser-starterpack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelfranzl%2Fclang-wasm-browser-starterpack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/michaelfranzl","download_url":"https://codeload.github.com/michaelfranzl/clang-wasm-browser-starterpack/tar.gz/refs/heads/dev","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelfranzl%2Fclang-wasm-browser-starterpack/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279006611,"owners_count":26084148,"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-10-11T02:00:06.511Z","response_time":55,"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":["browser","c","clang","cpp","javascript","wasi","wasi-libc","wasi-sdk","webassembly","webassembly-demo","webassembly-tutorial"],"created_at":"2024-11-21T04:59:25.741Z","updated_at":"2025-10-11T08:32:56.828Z","avatar_url":"https://github.com/michaelfranzl.png","language":"Nix","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Clang-WASM-Browser Starterpack\n\nMinimal working examples of C and C++ software development targeting the web via WebAssembly.\n\n## Background\n\nClang can directly emit WebAssembly since version 8. For simple scenarios, this allows a\nlean and direct software development workflow targeting the web,\nomitting more complete SDKs like [emscripten](https://emscripten.org/).\n\nThe [wasi-sdk](https://github.com/WebAssembly/wasi-sdk) project is a cornerstone in this workflow.\nIt contains no compiler or library code itself; it merely pulls in via *git submodules* the upstream\n`llvm-project` tree, as well as the `wasi-libc` tree. It contributes a `Makefile` which compiles these\ncomponents using suitable flags.\n\n[wasi-libc](https://github.com/WebAssembly/wasi-libc) is an\nimplementation of the C standard library which compiles down to [WASI](https://wasi.dev/) syscalls\n(calls which would 'normally' be done into the OS kernel). The implementation of the actually\nused syscalls has to be provided (in other words, *imported*) to the WebAssembly instance. Since we\nare targeting the web, the implementation is provided by the JavaScript library\n[@wasmer/wasi](https://github.com/wasmerio/wasmer-js/tree/master/packages/wasi) via the browser.\n\nThe `wasi-sdk` project lacks examples that show how it can be used; the present project aims to fill\nthat gap.\n\n\n## Motivation\n\nInspired by the awesome [emscripten](https://emscripten.org/) project, I wanted to understand the\nlow-level mechanics of getting compiled C and C++ code to run in the browser, and to find the leanest\npossible workflow.\n\n\n## Running\n\n### Using Nix\n\n```sh\nnix run\n# Wait for it:\n# Serving HTTP on 127.0.0.1 port 8000 (http://127.0.0.1:8000/) ...\n```\n\nThen open in your browser: http://127.0.0.1:8000 and click on one of the example directories.\n\n\n### Manual\n\nDownload and extract or install [wasi-sdk Release 22](https://github.com/WebAssembly/wasi-sdk/releases/tag/wasi-sdk-22).\n\nSet the path to the extracted or installed wasi-sdk as `WASI_SDK` (default: `/opt/wasi-sdk`) and run `make` in the `examples` subdirectory:\n\n```sh\ncd examples\n\nWASI_SDK=/path/to/wasi-sdk make\n\n# Start a generic web server:\npython3 -m http.server 8000 --bind 127.0.0.1\n```\n\nThen open in your browser: http://127.0.0.1:8000 and click on one of the example directories.\n\n\n## The Examples\n\nThe examples start as simple as possible, and then add more and more complexity:\n\n\n### Plain C\n\n* [Example 1: Exports](examples/01)\n* [Example 2: Default imports](examples/02)\n* [Example 3: Renamed imports](examples/03)\n\n### C with Standard Library\n\n* [Example 4: printf(\"Hello World!\\n\")](examples/04)\n\n###  String handling\n\n* [Example 5: Returning a string](examples/05)\n* [Example 6: Passing a string to a function](examples/06)\n* [Example 7: Calling int main(int argc, char* argv[])](examples/07)\n\n\n### Plain C++\n\n* [Example 10: Adding two numbers](examples/10)\n\n### C++ with Standard Library\n\n* [Example 11: Print a vector element](examples/11)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaelfranzl%2Fclang-wasm-browser-starterpack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichaelfranzl%2Fclang-wasm-browser-starterpack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaelfranzl%2Fclang-wasm-browser-starterpack/lists"}