{"id":25917,"library":"maiac","title":"MaiaC (WebC): C89-to-WebAssembly Compiler","description":"MaiaC (WebC) is a C-to-WebAssembly compiler written in JavaScript, targeting a C89 subset. Version 1.2.4 (as of March 2025) is released via npm, with development on GitHub. It parses C source using EBNF-generated parsers, lowers to WAT, emits WAT via templates, and validates/assembles via the MaiaWASM submodule. Supports Node.js >=18 and browser execution. Differentiators: pure JavaScript implementation (no native dependencies), built-in runtime bridges for host environment (e.g., console, Math), and distribution packaging for browser + Node workflows. Release cadence appears irregular; check GitHub for latest.","status":"active","version":"1.2.4","language":"javascript","source_language":"en","source_url":"https://github.com/souzamonteiro/maiac","tags":["javascript","c","compiler","c89","wasm","webassembly","wat"],"install":[{"cmd":"npm install maiac","lang":"bash","label":"npm"},{"cmd":"yarn add maiac","lang":"bash","label":"yarn"},{"cmd":"pnpm add maiac","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"WAT assembly and validation pipeline (submodule)","package":"maiawasm","optional":false},{"reason":"Grammar-to-parser generation (submodule)","package":"maiacc","optional":true}],"imports":[{"note":"ESM-only; no CommonJS export. Use import syntax.","wrong":"const webc = require('maiac')","symbol":"webc (default)","correct":"import webc from 'maiac'"},{"note":"Named export, not default.","wrong":"import createDist from 'maiac'","symbol":"createDist","correct":"import { createDist } from 'maiac'"},{"note":"Named export, lowercase; not a class.","wrong":"import HostEnvBuilder from 'maiac'","symbol":"hostEnvBuilder","correct":"import { hostEnvBuilder } from 'maiac'"}],"quickstart":{"code":"import webc from 'maiac';\nimport { readFileSync, writeFileSync } from 'fs';\n\nconst cSource = `int main() { return 42; }`;\nconst outDir = './out';\nconst name = 'test';\n\nconst result = await webc({\n  source: cSource,\n  outDir,\n  name,\n  wat: true,\n  run: false\n});\n\nconsole.log('Output files:', result.files);\n// Expected: out/test.wasm, out/test.js (if wrappers generated), out/test.wat\n\n// Or compile from file:\nconst sourceFile = './test.c';\nconst fileResult = await webc({\n  file: sourceFile,\n  outDir,\n  name: 'test',\n  wat: true\n});\nconsole.log('Compiled .wasm to:', fileResult.files[0]);","lang":"javascript","description":"Compile a C89 source string to WebAssembly using MaiaC with WAT output. Demonstrates ESM import and basic usage."},"warnings":[{"fix":"Write C89-compliant code: use /* */ comments, declare variables at block start.","message":"MaiaC only supports a C89 subset; C99 or later features (e.g., // comments, mixed declarations) will cause parse errors.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Call webc(options) directly without new.","message":"In v1.2.0, the default export changed from a class to a function. Using `new webc()` will throw.","severity":"breaking","affected_versions":">=1.2.0"},{"fix":"Run node tools/webc.js compiler/examples/test.c --dist instead of node tools/create-dist.js ...","message":"create-dist.js CLI wrapper is deprecated; use tools/webc.js --dist instead.","severity":"deprecated","affected_versions":">=1.2.0"},{"fix":"Declare I/O via extern __console__log(char* msg) and similar host bridges.","message":"C source must not use standard library includes like <stdio.h> unless you provide the stubs; external functions must be declared as extern __host__* functions.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Avoid using --resolve-system-includes for production; manually inline includes.","message":"The --resolve-system-includes flag is experimental and may expand includes incorrectly for nested paths.","severity":"gotcha","affected_versions":">=1.2.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run `npm install maiac` and ensure your script imports from 'maiac' not a relative path.","cause":"Running code in Node without installing the package or running from the wrong directory.","error":"Error: Cannot find module 'maiac'"},{"fix":"Call `webc(options)` directly without the `new` keyword.","cause":"Using `new webc()` after v1.2.0 when webc is now a plain function.","error":"TypeError: webc is not a constructor"},{"fix":"Move variable declarations to the beginning of blocks.","cause":"C code uses C99+ features like mixed declarations and code.","error":"Expected C89 declaration before statement"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}