{"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,"search_vec":"'1.2.4':25 '18':62 '2025':29 'appear':93 'bridg':77 'browser':64,88 'built':74 'built-in':73 'c':13,40,100 'c-to-webassembl':12 'c89':4,22,102 'c89-to-webassembly':3 'cadenc':92 'check':95 'compil':7,16,101 'consol':82 'depend':72 'develop':35 'differenti':66 'distribut':85 'e.g':81 'ebnf':44 'ebnf-gener':43 'emit':50 'environ':80 'execut':65 'generat':45 'github':37,96 'host':79 'implement':69 'irregular':94 'javascript':19,68,99 'latest':98 'lower':47 'maiac':1,8 'maiawasm':58 'march':28 'math':83 'nativ':71 'node':89 'node.js':61 'npm':33 'packag':86 'pars':39 'parser':46 'pure':67 'releas':31,91 'runtim':76 'sourc':41 'submodul':59 'subset':23 'support':60 'target':20 'templat':53 'use':42 'validates/assembles':55 'version':24 'via':32,52,56 'wasm':103 'wat':49,51,105 'webassembl':6,15,104 'webc':2,9 'workflow':90 'written':17","created_at":"2026-05-01T13:47:14.480584+00:00","updated_at":"2026-05-01T13:47:14.480584+00:00","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,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/souzamonteiro/maiac","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/maiac","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops","web-framework"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-05-01","next_check":"2026-07-30","install_tag":null}}