z3-static 4.16.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,35 @@
1
+ cmake_minimum_required(VERSION 3.26)
2
+ project(z3_static LANGUAGES NONE)
3
+
4
+ find_package(Python3 REQUIRED COMPONENTS Interpreter)
5
+
6
+ if(NOT "$ENV{STATICLIB_Z3_ALLOW_SOURCE_BUILD}" STREQUAL "1")
7
+ message(FATAL_ERROR
8
+ "z3-static source builds are disabled by default. Install a prebuilt "
9
+ "wheel, or set STATICLIB_Z3_ALLOW_SOURCE_BUILD=1 to build Z3 from source "
10
+ "explicitly.")
11
+ endif()
12
+
13
+ set(Z3_STATICLIB_PACKAGE_DIR "${CMAKE_BINARY_DIR}/z3_static")
14
+ set(Z3_STATICLIB_BUILD_ROOT "${CMAKE_BINARY_DIR}/z3-build")
15
+ set(Z3_STATICLIB_TAG "$ENV{STATICLIB_Z3_TAG}")
16
+ if(Z3_STATICLIB_TAG STREQUAL "")
17
+ set(Z3_STATICLIB_TAG "z3-4.16.0")
18
+ endif()
19
+
20
+ add_custom_target(stage_z3_static ALL
21
+ COMMAND
22
+ "${CMAKE_COMMAND}" -E env
23
+ "STATICLIB_Z3_TAG=${Z3_STATICLIB_TAG}"
24
+ "STATICLIB_Z3_PACKAGE_DIR=${Z3_STATICLIB_PACKAGE_DIR}"
25
+ "STATICLIB_Z3_BUILD_ROOT=${Z3_STATICLIB_BUILD_ROOT}"
26
+ "STATICLIB_Z3_SOURCE_DIR=$ENV{STATICLIB_Z3_SOURCE_DIR}"
27
+ "MACOSX_DEPLOYMENT_TARGET=$ENV{MACOSX_DEPLOYMENT_TARGET}"
28
+ "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/scripts/z3_static_builder.py"
29
+ WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
30
+ COMMENT "Building static Z3 artifacts"
31
+ VERBATIM
32
+ )
33
+
34
+ install(DIRECTORY "${Z3_STATICLIB_PACKAGE_DIR}/static" DESTINATION z3_static)
35
+
@@ -0,0 +1,5 @@
1
+ This package is distributed under the MIT License.
2
+
3
+ The packaged Z3 artifacts are distributed under the upstream Z3 MIT License,
4
+ which is included in the wheel as z3_static/static/LICENSE.Z3.
5
+
@@ -0,0 +1,5 @@
1
+ include README.md
2
+ include LICENSE
3
+ recursive-include scripts *.py
4
+ global-exclude __pycache__ *.py[cod]
5
+
@@ -0,0 +1,59 @@
1
+ Metadata-Version: 2.4
2
+ Name: z3-static
3
+ Version: 4.16.0
4
+ Summary: Static Z3 development artifacts for native build systems
5
+ Keywords: z3,smt,static-library,cmake
6
+ Author-Email: MLC AI <mlc.ai.dev@gmail.com>
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Classifier: Topic :: Software Development :: Build Tools
14
+ Project-URL: Repository, https://github.com/mlc-ai/package
15
+ Requires-Python: >=3.8
16
+ Description-Content-Type: text/markdown
17
+
18
+ # z3-static
19
+
20
+ `z3-static` is a Python package that carries native Z3 development artifacts
21
+ for build systems. It does not provide Z3 Python bindings.
22
+
23
+ The wheel contains:
24
+
25
+ - Z3 C and C++ headers.
26
+ - A PIC static Z3 library (`libz3.a` on Unix-like platforms, `.lib` on Windows).
27
+ - Z3 CMake package files under `z3_static/static/lib/cmake/z3`.
28
+ - Z3 pkg-config metadata when upstream install provides it.
29
+
30
+ Build systems can locate the package from Python:
31
+
32
+ ```python
33
+ import z3_static
34
+
35
+ print(z3_static.get_cmake_dir())
36
+ ```
37
+
38
+ ## Local Build
39
+
40
+ Build a wheel from an upstream Z3 tag:
41
+
42
+ ```bash
43
+ STATICLIB_Z3_TAG=z3-4.16.0 \
44
+ STATICLIB_Z3_ALLOW_SOURCE_BUILD=1 \
45
+ python -m build --wheel
46
+ ```
47
+
48
+ Use an existing Z3 checkout:
49
+
50
+ ```bash
51
+ STATICLIB_Z3_TAG=z3-4.16.0 \
52
+ STATICLIB_Z3_SOURCE_DIR=/path/to/z3 \
53
+ STATICLIB_Z3_ALLOW_SOURCE_BUILD=1 \
54
+ python -m build --wheel
55
+ ```
56
+
57
+ Source builds are opt-in to avoid accidental long Z3 builds on unsupported
58
+ platforms when pip cannot find a matching prebuilt wheel.
59
+
@@ -0,0 +1,42 @@
1
+ # z3-static
2
+
3
+ `z3-static` is a Python package that carries native Z3 development artifacts
4
+ for build systems. It does not provide Z3 Python bindings.
5
+
6
+ The wheel contains:
7
+
8
+ - Z3 C and C++ headers.
9
+ - A PIC static Z3 library (`libz3.a` on Unix-like platforms, `.lib` on Windows).
10
+ - Z3 CMake package files under `z3_static/static/lib/cmake/z3`.
11
+ - Z3 pkg-config metadata when upstream install provides it.
12
+
13
+ Build systems can locate the package from Python:
14
+
15
+ ```python
16
+ import z3_static
17
+
18
+ print(z3_static.get_cmake_dir())
19
+ ```
20
+
21
+ ## Local Build
22
+
23
+ Build a wheel from an upstream Z3 tag:
24
+
25
+ ```bash
26
+ STATICLIB_Z3_TAG=z3-4.16.0 \
27
+ STATICLIB_Z3_ALLOW_SOURCE_BUILD=1 \
28
+ python -m build --wheel
29
+ ```
30
+
31
+ Use an existing Z3 checkout:
32
+
33
+ ```bash
34
+ STATICLIB_Z3_TAG=z3-4.16.0 \
35
+ STATICLIB_Z3_SOURCE_DIR=/path/to/z3 \
36
+ STATICLIB_Z3_ALLOW_SOURCE_BUILD=1 \
37
+ python -m build --wheel
38
+ ```
39
+
40
+ Source builds are opt-in to avoid accidental long Z3 builds on unsupported
41
+ platforms when pip cannot find a matching prebuilt wheel.
42
+
@@ -0,0 +1,34 @@
1
+ [build-system]
2
+ requires = ["scikit-build-core>=0.11", "cmake>=3.26", "ninja", "packaging"]
3
+ build-backend = "scikit_build_core.build"
4
+
5
+ [project]
6
+ name = "z3-static"
7
+ dynamic = ["version"]
8
+ description = "Static Z3 development artifacts for native build systems"
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ authors = [{ name = "MLC AI", email = "mlc.ai.dev@gmail.com" }]
14
+ keywords = ["z3", "smt", "static-library", "cmake"]
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "Intended Audience :: Developers",
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3 :: Only",
20
+ "Topic :: Software Development :: Build Tools",
21
+ ]
22
+
23
+ [project.urls]
24
+ Repository = "https://github.com/mlc-ai/package"
25
+
26
+ [tool.scikit-build]
27
+ cmake.version = ">=3.26"
28
+ wheel.py-api = "py3"
29
+ wheel.packages = ["z3_static"]
30
+
31
+ [tool.scikit-build.metadata.version]
32
+ provider = "scikit_build_core.metadata.regex"
33
+ input = "z3_static/_version.py"
34
+
@@ -0,0 +1,69 @@
1
+ """Verify that CMake can consume the packaged static Z3 library."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ import shutil
7
+ import subprocess
8
+ import sys
9
+ import tempfile
10
+ from pathlib import Path
11
+
12
+ import z3_static
13
+
14
+
15
+ def run(cmd: list[str], *, cwd: Path) -> None:
16
+ print("+", " ".join(cmd), flush=True)
17
+ subprocess.check_call(cmd, cwd=cwd)
18
+
19
+
20
+ def main() -> None:
21
+ cmake = shutil.which("cmake")
22
+ if not cmake:
23
+ raise RuntimeError("cmake is required")
24
+
25
+ with tempfile.TemporaryDirectory() as tmp:
26
+ root = Path(tmp)
27
+ (root / "CMakeLists.txt").write_text(
28
+ """
29
+ cmake_minimum_required(VERSION 3.20)
30
+ project(z3_static_smoke LANGUAGES CXX)
31
+ set(CMAKE_CXX_STANDARD 20)
32
+ set(CMAKE_CXX_STANDARD_REQUIRED ON)
33
+ find_package(Z3 CONFIG REQUIRED)
34
+ add_executable(smoke main.cc)
35
+ target_link_libraries(smoke PRIVATE z3::libz3)
36
+ """.strip()
37
+ + "\n"
38
+ )
39
+ (root / "main.cc").write_text(
40
+ """
41
+ #include <z3++.h>
42
+
43
+ int main() {
44
+ z3::context ctx;
45
+ z3::solver solver(ctx);
46
+ z3::expr x = ctx.int_const("x");
47
+ solver.add(x > 0);
48
+ return solver.check() == z3::sat ? 0 : 1;
49
+ }
50
+ """.strip()
51
+ + "\n"
52
+ )
53
+
54
+ build = root / "build"
55
+ env = os.environ.copy()
56
+ env["Z3_DIR"] = z3_static.get_cmake_dir()
57
+ run([cmake, "-S", str(root), "-B", str(build), f"-DZ3_DIR={z3_static.get_cmake_dir()}"], cwd=root)
58
+ if sys.platform == "win32":
59
+ run([cmake, "--build", str(build), "--config", "Release"], cwd=root)
60
+ exe = build / "Release" / "smoke.exe"
61
+ else:
62
+ run([cmake, "--build", str(build)], cwd=root)
63
+ exe = build / "smoke"
64
+ run([str(exe)], cwd=root)
65
+
66
+
67
+ if __name__ == "__main__":
68
+ main()
69
+
@@ -0,0 +1,145 @@
1
+ """Build and stage static Z3 development artifacts."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ import shutil
7
+ import subprocess
8
+ import sys
9
+ import tarfile
10
+ import urllib.request
11
+ from pathlib import Path
12
+
13
+
14
+ def _run(cmd: list[str], *, cwd: Path | None = None, env: dict[str, str] | None = None) -> None:
15
+ print("+", " ".join(cmd), flush=True)
16
+ subprocess.check_call(cmd, cwd=cwd, env=env)
17
+
18
+
19
+ def _tool(name: str) -> str:
20
+ path = shutil.which(name)
21
+ if not path:
22
+ raise RuntimeError(f"Required tool not found on PATH: {name}")
23
+ return path
24
+
25
+
26
+ def _download_source(tag: str, build_root: Path) -> Path:
27
+ archive = build_root / f"{tag}.tar.gz"
28
+ source_dir = build_root / f"z3-{tag}"
29
+ if source_dir.exists():
30
+ return source_dir
31
+
32
+ url = f"https://github.com/Z3Prover/z3/archive/refs/tags/{tag}.tar.gz"
33
+ print(f"Downloading {url}", flush=True)
34
+ urllib.request.urlretrieve(url, archive)
35
+
36
+ extract_dir = build_root / "src"
37
+ shutil.rmtree(extract_dir, ignore_errors=True)
38
+ extract_dir.mkdir(parents=True, exist_ok=True)
39
+ with tarfile.open(archive, "r:gz") as tar:
40
+ tar.extractall(extract_dir)
41
+
42
+ children = [p for p in extract_dir.iterdir() if p.is_dir()]
43
+ if len(children) != 1:
44
+ raise RuntimeError(f"Expected one extracted Z3 source directory, got {children}")
45
+ children[0].rename(source_dir)
46
+ return source_dir
47
+
48
+
49
+ def _copy_tree(src: Path, dst: Path) -> None:
50
+ if src.exists():
51
+ shutil.copytree(src, dst, dirs_exist_ok=True)
52
+
53
+
54
+ def _normalize_metadata_library_dirs(static_dir: Path) -> None:
55
+ """Point staged CMake/pkg-config metadata at the normalized lib directory."""
56
+ metadata_files = [
57
+ *static_dir.glob("lib/cmake/z3/*.cmake"),
58
+ *static_dir.glob("lib/pkgconfig/*.pc"),
59
+ ]
60
+ for path in metadata_files:
61
+ text = path.read_text(encoding="utf-8")
62
+ normalized = text.replace("/lib64", "/lib")
63
+ if normalized != text:
64
+ path.write_text(normalized, encoding="utf-8")
65
+
66
+
67
+ def main() -> None:
68
+ tag = os.environ.get("STATICLIB_Z3_TAG", "z3-4.16.0")
69
+ package_dir = Path(
70
+ os.environ.get("STATICLIB_Z3_PACKAGE_DIR", Path.cwd() / "build/local-package/z3_static")
71
+ ).resolve()
72
+ build_root = Path(os.environ.get("STATICLIB_Z3_BUILD_ROOT", Path.cwd() / "build/z3")).resolve()
73
+ source_env = os.environ.get("STATICLIB_Z3_SOURCE_DIR") or None
74
+
75
+ cmake = _tool("cmake")
76
+ ninja = _tool("ninja")
77
+
78
+ build_root.mkdir(parents=True, exist_ok=True)
79
+ source_dir = Path(source_env).resolve() if source_env else _download_source(tag, build_root)
80
+ if not source_dir.exists():
81
+ raise RuntimeError(f"Z3 source directory does not exist: {source_dir}")
82
+
83
+ build_dir = build_root / "build"
84
+ install_dir = build_root / "install"
85
+ shutil.rmtree(build_dir, ignore_errors=True)
86
+ shutil.rmtree(install_dir, ignore_errors=True)
87
+ build_dir.mkdir(parents=True, exist_ok=True)
88
+
89
+ cmake_args = [
90
+ cmake,
91
+ "-S",
92
+ str(source_dir),
93
+ "-B",
94
+ str(build_dir),
95
+ "-G",
96
+ "Ninja",
97
+ f"-DCMAKE_MAKE_PROGRAM={ninja}",
98
+ f"-DCMAKE_INSTALL_PREFIX={install_dir}",
99
+ "-DCMAKE_BUILD_TYPE=Release",
100
+ "-DCMAKE_POSITION_INDEPENDENT_CODE=ON",
101
+ "-DBUILD_SHARED_LIBS=OFF",
102
+ "-DZ3_BUILD_LIBZ3_SHARED=OFF",
103
+ "-DZ3_BUILD_EXECUTABLE=OFF",
104
+ "-DZ3_BUILD_PYTHON_BINDINGS=OFF",
105
+ "-DZ3_BUILD_TEST_EXECUTABLES=OFF",
106
+ ]
107
+ if sys.platform == "darwin":
108
+ deployment_target = os.environ.get("MACOSX_DEPLOYMENT_TARGET") or "14.0"
109
+ cmake_args.append(f"-DCMAKE_OSX_DEPLOYMENT_TARGET={deployment_target}")
110
+ _run(cmake_args)
111
+ _run([cmake, "--build", str(build_dir), "--parallel"])
112
+ _run([cmake, "--install", str(build_dir)])
113
+
114
+ static_dir = package_dir / "static"
115
+ shutil.rmtree(static_dir, ignore_errors=True)
116
+ static_dir.mkdir(parents=True, exist_ok=True)
117
+
118
+ _copy_tree(install_dir / "include", static_dir / "include")
119
+ _copy_tree(install_dir / "lib", static_dir / "lib")
120
+ _copy_tree(install_dir / "lib64", static_dir / "lib")
121
+ _copy_tree(install_dir / "share", static_dir / "share")
122
+ _normalize_metadata_library_dirs(static_dir)
123
+
124
+ license_src = source_dir / "LICENSE.txt"
125
+ if not license_src.exists():
126
+ license_src = source_dir / "LICENSE"
127
+ if not license_src.exists():
128
+ raise RuntimeError("Could not find upstream Z3 license file")
129
+ shutil.copy2(license_src, static_dir / "LICENSE.Z3")
130
+
131
+ if not (static_dir / "include" / "z3++.h").exists():
132
+ raise RuntimeError("Z3 C++ header was not staged")
133
+ libs = list((static_dir / "lib").glob("libz3.a")) + list((static_dir / "lib").glob("*.lib"))
134
+ if not libs:
135
+ raise RuntimeError("Static Z3 library was not staged")
136
+ cmake_dirs = list((static_dir / "lib").glob("cmake/z3"))
137
+ if not cmake_dirs:
138
+ raise RuntimeError("Z3 CMake package files were not staged")
139
+
140
+ print(f"Staged Z3 static artifacts under {static_dir}", flush=True)
141
+
142
+
143
+ if __name__ == "__main__":
144
+ main()
145
+
@@ -0,0 +1,28 @@
1
+ """Locate the packaged static Z3 development artifacts."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pathlib import Path
6
+
7
+ from ._version import __version__
8
+
9
+
10
+ def get_prefix() -> str:
11
+ """Return the packaged native artifact prefix."""
12
+ return str(Path(__file__).resolve().parent / "static")
13
+
14
+
15
+ def get_cmake_dir() -> str:
16
+ """Return the Z3 CMake package directory."""
17
+ return str(Path(get_prefix()) / "lib" / "cmake" / "z3")
18
+
19
+
20
+ def get_include_dir() -> str:
21
+ """Return the Z3 include directory."""
22
+ return str(Path(get_prefix()) / "include")
23
+
24
+
25
+ def get_library_dir() -> str:
26
+ """Return the Z3 library directory."""
27
+ return str(Path(get_prefix()) / "lib")
28
+
@@ -0,0 +1,4 @@
1
+ """Version generated from the upstream Z3 release tag."""
2
+
3
+ __version__ = "4.16.0"
4
+