Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add high level bindings for js #6048

Merged
merged 22 commits into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/wasm-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ jobs:
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: 'lts/*'
registry-url: 'https://registry.npmjs.org'
node-version: "lts/*"
registry-url: "https://registry.npmjs.org"

- name: Prepare for publish
run: |
Expand All @@ -37,13 +37,13 @@ jobs:
with:
no-install: true
version: ${{env.EM_VERSION}}
actions-cache-folder: 'emsdk-cache'
actions-cache-folder: "emsdk-cache"

- name: Install dependencies
run: npm ci

- name: Build TypeScript
run: npm run build-ts
run: npm run build:ts

- name: Build wasm
run: |
Expand All @@ -52,7 +52,7 @@ jobs:
source $(dirname $(which emsdk))/emsdk_env.sh
which node
which clang++
npm run build-wasm
npm run build:wasm

- name: Test
run: npm test
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: WebAssembly Build

on:
push:
branches: [ master ]
branches: [master]
pull_request:

defaults:
Expand All @@ -23,20 +23,20 @@ jobs:
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: 'lts/*'
node-version: "lts/*"

- name: Setup emscripten
uses: mymindstorm/setup-emsdk@v11
with:
no-install: true
version: ${{env.EM_VERSION}}
actions-cache-folder: 'emsdk-cache'
actions-cache-folder: "emsdk-cache"

- name: Install dependencies
run: npm ci

- name: Build TypeScript
run: npm run build-ts
run: npm run build:ts

- name: Build wasm
run: |
Expand All @@ -45,7 +45,7 @@ jobs:
source $(dirname $(which emsdk))/emsdk_env.sh
which node
which clang++
npm run build-wasm
npm run build:wasm

- name: Test
run: npm test
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ src/api/python/z3/z3consts.py
src/api/python/z3/z3core.py
src/ast/pattern/database.h
src/util/version.h
src/util/z3_version.h
src/api/java/Native.cpp
src/api/java/Native.java
src/api/java/enumerations/*.java
Expand All @@ -76,11 +77,8 @@ src/api/ml/z3native.mli
src/api/ml/z3enums.mli
src/api/ml/z3.mllib
src/api/js/node_modules/
src/api/js/*.js
src/api/js/build/
src/api/js/**/*.d.ts
!src/api/js/scripts/*.js
!src/api/js/src/*.js
src/api/js/**/*.__GENERATED__.*
debug/*

out/**
Expand Down
43 changes: 25 additions & 18 deletions scripts/mk_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,13 @@ def rmf(fname):

def exec_compiler_cmd(cmd):
r = exec_cmd(cmd)
if is_windows() or is_cygwin_mingw() or is_cygwin() or is_msys2():
rmf('a.exe')
else:
rmf('a.out')
# Windows
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these changes are fine, but could you add them in a self-contained pull request?
They seem to work regardless of the new work on js/ts.
It is better to get such independent pieces in earlier instead of in a single bulk.

rmf('a.exe')
# Unix
rmf('a.out')
# Emscripten
rmf('a.wasm')
rmf('a.worker.js')
return r

def test_cxx_compiler(cc):
Expand Down Expand Up @@ -293,6 +296,10 @@ def test_fpmath(cc):
t.commit()
# -Werror is needed because some versions of clang warn about unrecognized
# -m flags.
# TODO(ritave): Safari doesn't allow SIMD WebAssembly extension, add a flag to build script
if exec_compiler_cmd([cc, CPPFLAGS, '-Werror', 'tstsse.cpp', LDFLAGS, '-msse -msse2 -msimd128']) == 0:
FPMATH_FLAGS='-msse -msse2 -msimd128'
return 'SSE2-EMSCRIPTEN'
if exec_compiler_cmd([cc, CPPFLAGS, '-Werror', 'tstsse.cpp', LDFLAGS, '-mfpmath=sse -msse -msse2']) == 0:
FPMATH_FLAGS="-mfpmath=sse -msse -msse2"
return "SSE2-GCC"
Expand Down Expand Up @@ -499,7 +506,7 @@ def find_ml_lib():

def is64():
global LINUX_X64
if is_sunos() and sys.version_info.major < 3:
if is_sunos() and sys.version_info.major < 3:
return LINUX_X64
else:
return LINUX_X64 and sys.maxsize >= 2**32
Expand Down Expand Up @@ -625,11 +632,11 @@ def check_eol():
else:
LINUX_X64=False


if os.name == 'posix' and os.uname()[4] == 'arm64':
IS_ARCH_ARM64 = True


def display_help(exit_code):
print("mk_make.py: Z3 Makefile generator\n")
print("This script generates the Makefile for the Z3 theorem prover.")
Expand Down Expand Up @@ -792,7 +799,7 @@ def extract_c_includes(fname):
linenum = 1
for line in f:
m1 = std_inc_pat.match(line)
if m1:
if m1:
root_file_name = m1.group(1)
slash_pos = root_file_name.rfind('/')
if slash_pos >= 0 and root_file_name.find("..") < 0 : #it is a hack for lp include files that behave as continued from "src"
Expand Down Expand Up @@ -1650,7 +1657,7 @@ def set_key_file(self):
else:
print("Keyfile '%s' could not be found; %s.dll will be unsigned." % (self.key_file, self.dll_name))
self.key_file = None


# build for dotnet core
class DotNetDLLComponent(Component):
Expand All @@ -1664,7 +1671,7 @@ def __init__(self, name, dll_name, path, deps, assembly_info_dir, default_key_fi
self.assembly_info_dir = assembly_info_dir
self.key_file = default_key_file


def mk_makefile(self, out):
if not is_dotnet_core_enabled():
return
Expand All @@ -1680,7 +1687,7 @@ def mk_makefile(self, out):
out.write(' ')
out.write(cs_file)
out.write('\n')

set_key_file(self)
key = ""
if not self.key_file is None:
Expand Down Expand Up @@ -1724,7 +1731,7 @@ def mk_makefile(self, out):
ous.write(core_csproj_str)

dotnetCmdLine = [DOTNET, "build", csproj]

dotnetCmdLine.extend(['-c'])
if DEBUG_MODE:
dotnetCmdLine.extend(['Debug'])
Expand All @@ -1733,19 +1740,19 @@ def mk_makefile(self, out):

path = os.path.join(os.path.abspath(BUILD_DIR), ".")
dotnetCmdLine.extend(['-o', "\"%s\"" % path])

MakeRuleCmd.write_cmd(out, ' '.join(dotnetCmdLine))
out.write('\n')
out.write('\n')
out.write('%s: %s\n\n' % (self.name, dllfile))

def main_component(self):
return is_dotnet_core_enabled()

def has_assembly_info(self):
# TBD: is this required for dotnet core given that version numbers are in z3.csproj file?
return False


def mk_win_dist(self, build_path, dist_path):
if is_dotnet_core_enabled():
mk_dir(os.path.join(dist_path, INSTALL_BIN_DIR))
Expand Down Expand Up @@ -2038,7 +2045,7 @@ def mk_makefile(self, out):
out.write('ml: %s.cma %s.cmxa %s.cmxs\n' % (z3mls, z3mls, z3mls))
if IS_OSX:
out.write('\tinstall_name_tool -id %s/libz3.dylib libz3.dylib\n' % (stubs_install_path))
out.write('\tinstall_name_tool -change libz3.dylib %s/libz3.dylib api/ml/dllz3ml.so\n' % (stubs_install_path))
out.write('\tinstall_name_tool -change libz3.dylib %s/libz3.dylib api/ml/dllz3ml.so\n' % (stubs_install_path))
out.write('\n')

if IS_WINDOWS:
Expand Down Expand Up @@ -3117,7 +3124,7 @@ def get_platform_toolset_str():
if len(tokens) < 2:
return default
else:
if tokens[0] == "15":
if tokens[0] == "15":
# Visual Studio 2017 reports 15.* but the PlatformToolsetVersion is 141
return "v141"
else:
Expand Down
1 change: 1 addition & 0 deletions src/api/js/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v16.15.0
6 changes: 6 additions & 0 deletions src/api/js/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"singleQuote": true,
"arrowParens": "avoid",
"printWidth": 120,
"trailingComma": "all"
}
23 changes: 0 additions & 23 deletions src/api/js/build-wasm.sh

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { init, Z3_error_code } from './build/node-wrapper';
import process from 'process';
import { init, Z3_error_code } from '../../build/node';

// demonstrates use of the raw API

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
// TypeScript can infer all of them.
// They're just here so readers can see what types things are.

// @ts-ignore we're not going to bother with types for this
import process from 'process';
import { sprintf } from 'sprintf-js';
import type {
Z3_app,
Z3_ast,
Z3_ast_vector,
Z3_config,
Z3_context,
Z3_func_decl,
Z3_func_entry,
Z3_func_interp,
Z3_model,
Z3_solver,
Z3_sort,
Z3_ast,
Z3_app,
Z3_model,
Z3_symbol,
Z3_ast_vector,
Z3_func_decl,
Z3_func_interp,
Z3_func_entry,
} from './build/node-wrapper';
import { init, Z3_lbool, Z3_ast_kind, Z3_sort_kind, Z3_symbol_kind } from './build/node-wrapper';

// @ts-ignore we're not going to bother with types for this
import { sprintf } from 'sprintf-js';
} from '../../build/node';
import { init, Z3_ast_kind, Z3_lbool, Z3_sort_kind, Z3_symbol_kind } from '../../build/node';

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

Expand Down
7 changes: 7 additions & 0 deletions src/api/js/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
roots: ['<rootDir>/src'],
verbose: true,
};
Loading