Skip to contentSkip to conversation

package/z3: new package

Buildroot Yann E. MORIN 1 participant 1 message Nov 20, 2022 Arm MediaTek

lore
Share & tools
lore
#0 lore raw

commit: https://git.buildroot.net/buildroot/commit/?id=2ad68ff8df71a485085b0b83ff494081e4d926b7
branch: https://git.buildroot.net/buildroot/commit/?id=refs/heads/next

Z3, also known as the Z3 Theorem Prover, is a cross-platform satisfiability modulo theories (SMT) solver.

https://github.com/Z3Prover/z3

[[email protected]:
- python bindings 'depends on' python, not 'select' it
- fix check-package in test_z3.py
]

---
 DEVELOPERS                                         |  2 +
 package/Config.in                                  |  1 +
 package/z3/Config.in                               | 23 +++++++++++
 package/z3/z3.hash                                 |  3 ++
 package/z3/z3.mk                                   | 22 +++++++++++
 support/testing/tests/package/test_z3.py           | 44 ++++++++++++++++++++++
 .../package/test_z3/rootfs-overlay/root/z3test.py  | 21 +++++++++++
 .../test_z3/rootfs-overlay/root/z3test.smt2        |  8 ++++
 8 files changed, 124 insertions(+)
DEVELOPERS +2 -0
index bc026da4aa..fb6b329087 100644
@@ -1697,6 +1697,7 @@ F:	package/python-gnupg/
 F:	package/python-pyalsa/
 F:	package/riscv-isa-sim/
 F:	package/tinycompress/
+F:	package/z3/
 F:	package/zynaddsubfx/
 F:	support/testing/tests/package/sample_python_distro.py
 F:	support/testing/tests/package/sample_python_gnupg.py
@@ -1708,6 +1709,7 @@ F:	support/testing/tests/package/test_ola/
 F:	support/testing/tests/package/test_python_distro.py
 F:	support/testing/tests/package/test_python_gnupg.py
 F:	support/testing/tests/package/test_python_pyalsa.py
+F:	support/testing/tests/package/test_z3.py
 
 N:	Julien Viard de Galbert <[email protected]>
 F:	package/dieharder/
package/Config.in +1 -0
index c448e8bd97..7b18859d02 100644
@@ -2190,6 +2190,7 @@ menu "Miscellaneous"
 	source "package/wine/Config.in"
 	source "package/xmrig/Config.in"
 	source "package/xutil_util-macros/Config.in"
+	source "package/z3/Config.in"
 endmenu
 
 menu "Networking applications"
package/z3/Config.in new file +23 -0
new file mode 100644
index 0000000000..55b0e8bb3b
@@ -0,0 +1,23 @@
+config BR2_PACKAGE_Z3
+	bool "z3"
+	depends on BR2_INSTALL_LIBSTDCPP
+	depends on BR2_TOOLCHAIN_GCC_AT_LEAST_7 # c++17
+	# z3 needs fenv.h which is not provided by uclibc
+	depends on !BR2_TOOLCHAIN_USES_UCLIBC
+	# fenv.h lacks FE_INVALID, FE_OVERFLOW & FE_UNDERFLOW on nios2
+	depends on !BR2_nios2
+	help
+	  Z3, also known as the Z3 Theorem Prover, is a cross-platform
+	  satisfiability modulo theories (SMT) solver.
+
+	  https://github.com/Z3Prover/z3
+
+if BR2_PACKAGE_Z3
+
+config BR2_PACKAGE_Z3_PYTHON
+	bool "Python bindings"
+	depends on BR2_PACKAGE_PYTHON3
+	select BR2_PACKAGE_PYTHON3_PYEXPAT # runtime
+	select BR2_PACKAGE_PYTHON_SETUPTOOLS # runtime
+
+endif
package/z3/z3.hash new file +3 -0
new file mode 100644
index 0000000000..d38c5f1971
@@ -0,0 +1,3 @@
+# Locally calculated
+sha256  e3a82431b95412408a9c994466fad7252135c8ed3f719c986cd75c8c5f234c7e  z3-4.11.2.tar.gz
+sha256  e617cad2ab9347e3129c2b171e87909332174e17961c5c3412d0799469111337  LICENSE.txt
package/z3/z3.mk new file +22 -0
new file mode 100644
index 0000000000..2252e05395
@@ -0,0 +1,22 @@
+################################################################################
+#
+# z3
+#
+################################################################################
+
+Z3_VERSION = 4.11.2
+Z3_SITE = $(call github,Z3Prover,z3,z3-$(Z3_VERSION))
+Z3_LICENSE = MIT
+Z3_LICENSE_FILES = LICENSE.txt
+Z3_INSTALL_STAGING = YES
+Z3_SUPPORTS_IN_SOURCE_BUILD = NO
+
+ifeq ($(BR2_PACKAGE_Z3_PYTHON),y)
+Z3_CONF_OPTS += \
+	-DCMAKE_INSTALL_PYTHON_PKG_DIR=/usr/lib/python$(PYTHON3_VERSION_MAJOR)/site-packages \
+	-DZ3_BUILD_PYTHON_BINDINGS=ON
+else
+Z3_CONF_OPTS += -DZ3_BUILD_PYTHON_BINDINGS=OFF
+endif
+
+$(eval $(cmake-package))
support/testing/tests/package/test_z3.py new file +44 -0

44 lines not on this page · raw message

support/testing/tests/package/test_z3/rootfs-overlay/root/z3test.py new file +21 -0
new file mode 100755
index 0000000000..98b8e57b56
@@ -0,0 +1,21 @@
+#! /usr/bin/env python3
+
+import z3
+
+x = z3.Real('x')
+y = z3.Real('y')
+z = z3.Real('z')
+s = z3.Solver()
+
+s.add(3 * x + 2 * y - z == 1)
+s.add(2 * x - 2 * y + 4 * z == -2)
+s.add(-x + y / 2 - z == 0)
+
+check = s.check()
+model = s.model()
+
+print(check)
+print(model)
+
+assert check == z3.sat
+assert model[x] == 1 and model[y] == -2 and model[z] == -2
support/testing/tests/package/test_z3/rootfs-overlay/root/z3test.smt2 new file +8 -0
new file mode 100644
index 0000000000..08df9e27a2
@@ -0,0 +1,8 @@
+; From https://smtlib.cs.uiowa.edu/examples.shtml
+; Basic Boolean example
+(set-option :print-success false)
+(set-logic QF_UF)
+(declare-const p Bool)
+(assert (and p (not p)))
+(check-sat) ; returns 'unsat'
+(exit)

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot