Skip to content

Commit e5f8327

Browse files
authored
Update emscripten (#7473)
* fixes for newer emscripten thread handling behavior * fix return type for async wrapper functions * update prettier * update typescript and fix errors * update emscripten version in CI * update js readme about tests
1 parent 4fbf54a commit e5f8327

17 files changed

+275
-108
lines changed

.github/workflows/wasm-release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ defaults:
1010
working-directory: src/api/js
1111

1212
env:
13-
EM_VERSION: 3.1.15
13+
EM_VERSION: 3.1.73
1414

1515
permissions:
1616
contents: read # to fetch code (actions/checkout)

.github/workflows/wasm.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ defaults:
1010
working-directory: src/api/js
1111

1212
env:
13-
EM_VERSION: 3.1.15
13+
EM_VERSION: 3.1.73
1414

1515
permissions:
1616
contents: read # to fetch code (actions/checkout)

src/api/js/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ The readme for the bindings themselves is located in [`PUBLISHED_README.md`](./P
77

88
## Building
99

10-
You'll need to have emscripten set up, along with all of its dependencies. The easiest way to do that is with [emsdk](https://github.com/emscripten-core/emsdk).
10+
You'll need to have emscripten set up, along with all of its dependencies. The easiest way to do that is with [emsdk](https://github.com/emscripten-core/emsdk). Newer versions of emscripten may break the build; you can find the version used in CI in [this file](https://github.com/Z3Prover/z3/blob/master/.github/workflows/wasm.yml#L13).
1111

1212
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.
1313

@@ -17,4 +17,4 @@ Consult the file [build-wasm.ts](https://github.com/Z3Prover/z3/blob/master/src/
1717

1818
## Tests
1919

20-
Current tests are very minimal: [`test-ts-api.ts`](./test-ts-api.ts) contains a couple real cases translated very mechanically from [this file](https://github.com/Z3Prover/z3/blob/90fd3d82fce20d45ed2eececdf65545bab769503/examples/c/test_capi.c).
20+
Run `npm test` after building to run tests.

src/api/js/examples/high-level/miracle-sudoku.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { init } from '../../build/node';
1+
import { init } from '../../build/node.js';
22

33
import type { Solver, Arith } from '../../build/node';
44

@@ -157,7 +157,9 @@ function parseSudoku(str: string) {
157157

158158
async function solve(str: string) {
159159
let solver = new Z3.Solver();
160-
let cells = Array.from({ length: 9 }, (_, col) => Array.from({ length: 9 }, (_, row) => Z3.Int.const(`c_${row}_${col}`)));
160+
let cells = Array.from({ length: 9 }, (_, col) =>
161+
Array.from({ length: 9 }, (_, row) => Z3.Int.const(`c_${row}_${col}`)),
162+
);
161163
for (let { row, col, value } of parseSudoku(str)) {
162164
solver.add(cells[row][col].eq(value));
163165
}
@@ -198,8 +200,6 @@ function parseSudoku(str: string) {
198200
.........
199201
.........
200202
`);
201-
202-
em.PThread.terminateAllThreads();
203203
})().catch(e => {
204204
console.error('error', e);
205205
process.exit(1);

src/api/js/examples/high-level/using_smtlib2.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@ import assert from 'assert';
2525
const model = solver.model();
2626
let modelStr = model.sexpr();
2727
modelStr = modelStr.replace(/\n/g, ' ');
28-
console.log("Model: ", modelStr);
28+
console.log('Model: ', modelStr);
2929

3030
const exprs = z3.ast_from_string(modelStr);
3131
console.log(exprs);
32-
3332
})().catch(e => {
3433
console.error('error', e);
3534
process.exit(1);
36-
});
35+
});

src/api/js/examples/low-level/example-raw.ts

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @ts-ignore we're not going to bother with types for this
22
import process from 'process';
3-
import { init, Z3_error_code } from '../../build/node';
3+
import { init, Z3_error_code } from '../../build/node.js';
44

55
// demonstrates use of the raw API
66

@@ -58,10 +58,24 @@ import { init, Z3_error_code } from '../../build/node';
5858
}
5959
console.log('confirming error messages work:', Z3.get_error_msg(ctx, Z3.get_error_code(ctx)));
6060

61+
Z3.global_param_set('verbose', '0');
62+
let result = await Z3.eval_smtlib2_string(
63+
ctx,
64+
`
65+
(declare-const p Bool)
66+
(declare-const q Bool)
67+
(declare-const r Bool)
68+
(declare-const s Bool)
69+
(declare-const t Bool)
70+
(assert ((_ pbeq 5 2 1 3 3 2) p q r s t))
71+
(check-sat)
72+
(get-model)
73+
`,
74+
);
75+
console.log('checking string evaluation', result);
76+
6177
Z3.dec_ref(ctx, strAst);
6278
Z3.del_context(ctx);
63-
64-
em.PThread.terminateAllThreads();
6579
})().catch(e => {
6680
console.error('error', e);
6781
process.exit(1);

src/api/js/examples/low-level/test-ts-api.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import type {
2020
Z3_sort,
2121
Z3_symbol,
2222
} from '../../build/node';
23-
import { init, Z3_ast_kind, Z3_lbool, Z3_sort_kind, Z3_symbol_kind } from '../../build/node';
23+
import { init, Z3_ast_kind, Z3_lbool, Z3_sort_kind, Z3_symbol_kind } from '../../build/node.js';
2424

2525
let printf = (str: string, ...args: unknown[]) => console.log(sprintf(str.replace(/\n$/, ''), ...args));
2626

@@ -383,9 +383,6 @@ let printf = (str: string, ...args: unknown[]) => console.log(sprintf(str.replac
383383

384384
await bitvector_example2();
385385
await unsat_core_and_proof_example();
386-
387-
// shut down
388-
em.PThread.terminateAllThreads();
389386
})().catch(e => {
390387
console.error('error', e);
391388
process.exit(1);

0 commit comments

Comments
 (0)