3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-07-15 03:25:43 +00:00
z3/src/api/js
copilot-swe-agent[bot] 66b0f58e23
Add single-threaded WASM build for z3-solver without SharedArrayBuffer
- Add makeCCSinglethreadWrapper() in make-cc-wrapper.ts that generates
  synchronous async wrappers using EM_ASM instead of threads +
  MAIN_THREAD_ASYNC_EM_ASM. Refactor shared error-handler code into a
  SHARED_ERROR_HANDLERS constant used by both variants.

- Add build-wasm-singlethread.ts: new build script that compiles a
  separate libz3.a (in build-singlethread/) and z3-built-singlethread.js
  without -pthread / USE_PTHREADS=1. Uses -DSINGLE_THREAD -DPOLLING_TIMER
  and ALLOW_MEMORY_GROWTH instead of a fixed 2 GB SharedArrayBuffer.

- Add src/node-singlethread.ts and src/browser-singlethread.ts entry
  points. Browser variant reads initZ3SingleThread from global scope
  (load z3-built-singlethread.js via importScripts in a Web Worker).

- Add tests for both new entry points (node-singlethread.test.ts,
  browser-singlethread.test.ts).

- Update package.json: add build:wasm:singlethread script; add exports
  map so users can do import { init } from 'z3-solver/singlethread'.

- Update PUBLISHED_README.md: document the single-threaded variant,
  explain when to use it (no COOP/COEP headers), and provide a Web
  Worker usage example.

- Update wasm.yml CI: add check-singlethread parallel job.
- Update wasm-release.yml: build single-threaded artifact before publish.

- Guard scoped_timer.cpp with #if defined(SINGLE_THREAD) &&
  !defined(__EMSCRIPTEN_PTHREADS__) so that thread-based timer creation
  is skipped in single-threaded Emscripten builds (POLLING_TIMER covers
  the primary cancel_eh<reslimit> use-case).
2026-07-13 04:05:49 +00:00
..
examples Document Loop function semantics and fix review comments 2026-02-04 22:02:58 +00:00
scripts Add single-threaded WASM build for z3-solver without SharedArrayBuffer 2026-07-13 04:05:49 +00:00
src Add single-threaded WASM build for z3-solver without SharedArrayBuffer 2026-07-13 04:05:49 +00:00
.nvmrc Add high level bindings for js (#6048) 2022-06-14 09:55:58 -07:00
.prettierrc.json Add high level bindings for js (#6048) 2022-06-14 09:55:58 -07:00
jest.config.js Add high level bindings for js (#6048) 2022-06-14 09:55:58 -07:00
package-lock.json Bump markdown-it from 14.1.0 to 14.2.0 in /src/api/js (#9881) 2026-06-16 11:34:20 -06:00
package.json Add single-threaded WASM build for z3-solver without SharedArrayBuffer 2026-07-13 04:05:49 +00:00
PUBLISHED_README.md Add single-threaded WASM build for z3-solver without SharedArrayBuffer 2026-07-13 04:05:49 +00:00
README.md Update emscripten (#7473) 2024-12-06 18:11:14 -08:00
tsconfig.build.json Add high level bindings for js (#6048) 2022-06-14 09:55:58 -07:00
tsconfig.json Add high level bindings for js (#6048) 2022-06-14 09:55:58 -07:00
typedoc.json Add high level bindings for js (#6048) 2022-06-14 09:55:58 -07:00
TYPESCRIPT_API_ENHANCEMENTS.md Add Simplifier, Params, and ParamDescrs APIs to TypeScript bindings (#8146) 2026-01-10 19:44:24 -08:00

TypeScript Bindings

This directory contains JavaScript code to automatically derive TypeScript bindings for the C API, which are published on npm as z3-solver.

The readme for the bindings themselves is located in PUBLISHED_README.md.

Building

You'll need to have emscripten set up, along with all of its dependencies. The easiest way to do that is with emsdk. Newer versions of emscripten may break the build; you can find the version used in CI in this file.

Then run npm i to install dependencies, npm run build:ts to build the TypeScript wrapper, and npm run build:wasm to build the wasm artifact.

Build on your own

Consult the file build-wasm.ts for configurations used for building wasm.

Tests

Run npm test after building to run tests.