3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-08-02 12:13:25 +00:00
z3/src/api/js
Copilot 88612e329e
Export killThreads from z3-solver to allow Node.js thread cleanup (#10320)
Emscripten worker threads spawned for long-running Z3 operations (e.g.
`solver.check()`) are never cleaned up, keeping the Node.js process
alive after Z3 is done.

The `killThreads` helper already existed internally in `jest.ts` but was
never part of the public package.

## Changes

- **`src/kill-threads.ts`** (new) — extracts `killThreads(em)` into a
standalone module; calls `em.PThread.terminateAllThreads()` then polls
until all workers are gone (5 s timeout)
- **`src/node.ts`** — re-exports `killThreads` so it is part of the
published `z3-solver` API
- **`src/jest.ts`** — simplified to re-export from `./kill-threads`
instead of duplicating ~45 lines
- **`src/kill-threads.test.ts`** (new) — unit tests for the exported
function
- **`PUBLISHED_README.md`** — documents the new API

## Usage

```typescript
import { init, killThreads } from 'z3-solver';

const api = await init();
// ... use Z3 ...
await killThreads(api.em);
```

<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes #7070

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2026-07-31 12:00:04 -07:00
..
examples Document Loop function semantics and fix review comments 2026-02-04 22:02:58 +00:00
scripts fix(make-ts-wrapper): correct out buffer size for WASM (#9644) 2026-05-27 10:03:39 -07:00
src Export killThreads from z3-solver to allow Node.js thread cleanup (#10320) 2026-07-31 12:00:04 -07: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 shell-quote from 1.8.4 to 1.10.0 in /src/api/js (#10193) 2026-07-22 18:00:43 -07:00
package.json Update emscripten (#7473) 2024-12-06 18:11:14 -08:00
PUBLISHED_README.md Export killThreads from z3-solver to allow Node.js thread cleanup (#10320) 2026-07-31 12:00:04 -07: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.