libansilove icon indicating copy to clipboard operation
libansilove copied to clipboard

wasm

Open subtleGradient opened this issue 3 months ago • 1 comments

Screenshot 2025-09-18 at 8 25 41 PM

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.c implementing 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 .envrc for 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 using mmap/munmap on WASM builds, ensuring compatibility with Emscripten. [1] [2] [3] [4]

Documentation and Guidelines:

  • Expanded documentation with WASM build/run instructions in README.md and added detailed project guidelines in AGENTS.md. [1] [2]
  • Updated CLAUDE.md to reference new guidelines.

subtleGradient avatar Sep 19 '25 00:09 subtleGradient

working on adding some npm packages in here to make the wasm build usable in the ts/js ecosystem

subtleGradient avatar Sep 19 '25 04:09 subtleGradient