libansilove
libansilove copied to clipboard
wasm
This pull request adds experimental WebAssembly (WASM) support to libansilove, enabling ANSI art rendering in browsers and Node.js. It introduces a WASM build target, scripts for building and testing the WASM wrapper, and a browser demo. Additionally, it improves platform compatibility and documents the new workflows and guidelines.
WebAssembly (WASM) Support:
- Added a new WASM build target in
CMakeLists.txt, with conditional logic to build a WASM wrapper (ansilove_wasm) using Emscripten and export key rendering functions for use in web environments. [1] [2] [3] - Introduced
wasm/ansilove_wasm.cimplementing the WASM interface, exposing version and ANSI rendering functions for JavaScript consumers. - Added a minimal GD header and implementation for WASM (
wasm/gd.h,wasm/minigd.c) to replace the system GD library in the browser context.
Build and Development Environment:
- Added a Nix flake (
flake.nix) and.envrcfor reproducible development environments, including all dependencies for native and WASM builds. [1] [2] - Provided scripts for building and testing the WASM wrapper (
scripts/test-wasm.sh,scripts/test-wasm-node.js), including automated smoke tests and artifact copying for browser demos. [1] [2]
Browser and Node.js Demo:
- Added an example browser demo (
example/wasm/index.html) that loads the WASM module, renders a sample ANSI string, and displays the resulting PNG.
Platform Compatibility and Code Changes:
- Updated source files (
src/clean.c,src/init.c) to avoid usingmmap/munmapon WASM builds, ensuring compatibility with Emscripten. [1] [2] [3] [4]
Documentation and Guidelines:
- Expanded documentation with WASM build/run instructions in
README.mdand added detailed project guidelines inAGENTS.md. [1] [2] - Updated
CLAUDE.mdto reference new guidelines.
working on adding some npm packages in here to make the wasm build usable in the ts/js ecosystem