From 3032dcc5eadaf4cc3a44d5a6311ac65f0de473ff Mon Sep 17 00:00:00 2001 From: Alexey Ignatiev Date: Tue, 7 Jul 2020 20:28:33 +1000 Subject: [PATCH] PKG Added the python-sat package (#710) --- packages/python-sat/meta.yaml | 16 +++ .../python-sat/patches/dummy_threading.patch | 13 ++ .../python-sat/patches/force_malloc.patch | 54 ++++++++ .../python-sat/patches/proper_build.patch | 120 ++++++++++++++++++ 4 files changed, 203 insertions(+) create mode 100644 packages/python-sat/meta.yaml create mode 100644 packages/python-sat/patches/dummy_threading.patch create mode 100644 packages/python-sat/patches/force_malloc.patch create mode 100644 packages/python-sat/patches/proper_build.patch diff --git a/packages/python-sat/meta.yaml b/packages/python-sat/meta.yaml new file mode 100644 index 000000000..5b66b9693 --- /dev/null +++ b/packages/python-sat/meta.yaml @@ -0,0 +1,16 @@ +package: + name: python-sat + version: 0.1.6.dev3 + +source: + sha256: 7dca4ad3a697db4fa50de4deb889ddd3ce9b2d9930abdc28c5e4203c6098683b + url: https://github.com/pysathq/pysat/releases/download/0.1.6.dev3/python-sat-0.1.6.dev3.tar.gz + + patches: + - patches/dummy_threading.patch + - patches/force_malloc.patch + - patches/proper_build.patch + +test: + imports: + - pysat diff --git a/packages/python-sat/patches/dummy_threading.patch b/packages/python-sat/patches/dummy_threading.patch new file mode 100644 index 000000000..f78fa81f3 --- /dev/null +++ b/packages/python-sat/patches/dummy_threading.patch @@ -0,0 +1,13 @@ +diff --git a/pysat/_utils.py b/pysat/_utils.py +index 8bdf132..74fb9fd 100644 +--- a/pysat/_utils.py ++++ b/pysat/_utils.py +@@ -32,7 +32,7 @@ + + # + #============================================================================== +-import threading ++import dummy_threading as threading + + + # diff --git a/packages/python-sat/patches/force_malloc.patch b/packages/python-sat/patches/force_malloc.patch new file mode 100644 index 000000000..06512ef6e --- /dev/null +++ b/packages/python-sat/patches/force_malloc.patch @@ -0,0 +1,54 @@ +diff --git a/cardenc/pycard.cc b/cardenc/pycard.cc +index 4ae27fe..5941d0a 100644 +--- a/cardenc/pycard.cc ++++ b/cardenc/pycard.cc +@@ -11,6 +11,7 @@ + #include + #include + #include ++#include + #include + + #include "card.hh" +@@ -122,8 +123,14 @@ static struct PyModuleDef module_def = { + NULL, /* m_free */ + }; + ++static volatile int *_dummy_malloc; ++ + PyMODINIT_FUNC PyInit_pycard(void) + { ++ _dummy_malloc = (int *)malloc(sizeof(int)); ++ *_dummy_malloc = 1; ++ free((void *)_dummy_malloc); ++ + PyObject *m = PyModule_Create(&module_def); + + if (m == NULL) +diff --git a/solvers/pysolvers.cc b/solvers/pysolvers.cc +index 7066cb4..6b4d7de 100644 +--- a/solvers/pysolvers.cc ++++ b/solvers/pysolvers.cc +@@ -15,6 +15,7 @@ + #include + #include + #include ++#include + #include + + #ifdef WITH_CADICAL +@@ -493,8 +494,14 @@ static struct PyModuleDef module_def = { + NULL, /* m_free */ + }; + ++static volatile int *_dummy_malloc; ++ + PyMODINIT_FUNC PyInit_pysolvers(void) + { ++ _dummy_malloc = (int *)malloc(sizeof(int)); ++ *_dummy_malloc = 1; ++ free((void *)_dummy_malloc); ++ + PyObject *m = PyModule_Create(&module_def); + + if (m == NULL) diff --git a/packages/python-sat/patches/proper_build.patch b/packages/python-sat/patches/proper_build.patch new file mode 100644 index 000000000..ac217a705 --- /dev/null +++ b/packages/python-sat/patches/proper_build.patch @@ -0,0 +1,120 @@ +diff --git a/setup.py b/setup.py +index 4e810df..d191d6d 100644 +--- a/setup.py ++++ b/setup.py +@@ -68,8 +68,8 @@ Details can be found at `https://pysathq.github.io `_ + + # solvers to install + #============================================================================== +-to_install = ['cadical', 'glucose30', 'glucose41', 'lingeling', 'maplechrono', +- 'maplecm', 'maplesat', 'minicard', 'minisat22', 'minisatgh'] ++to_install = ['cadical', 'glucose30', 'glucose41', 'maplechrono', 'maplecm', ++ 'maplesat', 'minicard', 'minisat22', 'minisatgh'] + + + # example scripts to install as standalone executables +@@ -77,47 +77,9 @@ to_install = ['cadical', 'glucose30', 'glucose41', 'lingeling', 'maplechrono', + scripts = ['fm', 'genhard', 'lbx', 'lsu', 'mcsls', 'models', 'musx', 'rc2'] + + +-# we need to redefine the build command to +-# be able to download and compile solvers +-#============================================================================== +-class build(distutils.command.build.build): +- """ +- Our custom builder class. +- """ +- +- def run(self): +- """ +- Download, patch and compile SAT solvers before building. +- """ +- # download and compile solvers +- if platform.system() != 'Windows': +- prepare.do(to_install) +- +- # now, do standard build +- distutils.command.build.build.run(self) +- +-# same with build_ext +-#============================================================================== +-class build_ext(distutils.command.build_ext.build_ext): +- """ +- Our custom builder class. +- """ +- +- def run(self): +- """ +- Download, patch and compile SAT solvers before building. +- """ +- # download and compile solvers +- if platform.system() != 'Windows': +- prepare.do(to_install) +- +- # now, do standard build +- distutils.command.build_ext.build_ext.run(self) +- +- + # compilation flags for C extensions + #============================================================================== +-compile_flags, cpplib = ['-std=c++11', '-Wall', '-Wno-deprecated'], ['stdc++'] ++compile_flags, cpplib = ['-std=c++11', '-O3', '-Wall', '-Wno-deprecated', '-DQUIET'], ['stdc++'] + if platform.system() == 'Darwin': + compile_flags += ['--stdlib=libc++'] + cpplib = ['c++'] +@@ -140,23 +102,19 @@ pycard_ext = Extension('pycard', + + pysolvers_sources = ['solvers/pysolvers.cc'] + +-if platform.system() == 'Windows': +- prepare.do(to_install) +- with chdir('solvers'): +- for solver in to_install: +- with chdir(solver): +- for filename in glob.glob('*.c*'): +- pysolvers_sources += ['solvers/%s/%s' % (solver, filename)] +- for filename in glob.glob('*/*.c*'): +- pysolvers_sources += ['solvers/%s/%s' % (solver, filename)] +- libraries = [] +- library_dirs = [] +-else: +- libraries = to_install + cpplib +- library_dirs = list(map(lambda x: os.path.join('solvers', x), to_install)) ++prepare.do(to_install) ++with chdir('solvers'): ++ for solver in to_install: ++ with chdir(solver): ++ for filename in glob.glob('*.c*'): ++ pysolvers_sources += ['solvers/%s/%s' % (solver, filename)] ++ for filename in glob.glob('*/*.c*'): ++ pysolvers_sources += ['solvers/%s/%s' % (solver, filename)] ++libraries = [] ++library_dirs = [] + + pysolvers_ext = Extension('pysolvers', +- sources=pysolvers_sources, ++ sources=sorted(pysolvers_sources), + extra_compile_args=compile_flags + \ + list(map(lambda x: '-DWITH_{0}'.format(x.upper()), to_install)), + include_dirs=['solvers'], +@@ -181,7 +139,6 @@ setup(name='python-sat', + url='https://github.com/pysathq/pysat', + ext_modules=[pycard_ext, pysolvers_ext], + scripts=['examples/{0}.py'.format(s) for s in scripts], +- cmdclass={'build': build, 'build_ext': build_ext}, + install_requires=['six'], + extras_require = { + 'aiger': ['py-aiger-cnf>=2.0.0'], +diff --git a/solvers/prepare.py b/solvers/prepare.py +index f947be1..97ccaa5 100644 +--- a/solvers/prepare.py ++++ b/solvers/prepare.py +@@ -421,8 +421,6 @@ def do(to_install): + adapt_files(solver) + patch_solver(solver) + +- if platform.system() != 'Windows': +- compile_solver(solver) + + # + #==============================================================================