Skip to content

Commit 7457f3d

Browse files
stp: 2.3.3 -> 2.3.4; fix tests; fix aarch64 compatibility; fix Python bindings; fix Darwin compatibility (#348447)
2 parents 194d313 + 8f31d53 commit 7457f3d

File tree

3 files changed

+164
-61
lines changed

3 files changed

+164
-61
lines changed

pkgs/by-name/st/stp/package.nix

Lines changed: 160 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,186 @@
1-
{ lib
2-
, stdenv
3-
, cmake
4-
, boost
5-
, bison
6-
, flex
7-
, fetchFromGitHub
8-
, fetchpatch
9-
, perl
10-
, python3
11-
, zlib
12-
, minisat
13-
, cryptominisat
1+
{
2+
lib,
3+
stdenv,
4+
cmake,
5+
boost,
6+
bison,
7+
flex,
8+
pkg-config,
9+
fetchFromGitHub,
10+
fetchpatch,
11+
symlinkJoin,
12+
perl,
13+
python3,
14+
zlib,
15+
minisat,
16+
cryptominisat,
17+
gmp,
18+
cadical,
19+
gtest,
20+
lit,
21+
outputcheck,
22+
nix-update-script,
23+
useCadical ? true,
1424
}:
1525

16-
stdenv.mkDerivation rec {
26+
stdenv.mkDerivation (finalAttrs: {
1727
pname = "stp";
18-
version = "2.3.3";
28+
version = "2.3.4";
1929

2030
src = fetchFromGitHub {
2131
owner = "stp";
2232
repo = "stp";
23-
rev = version;
24-
hash = "sha256-B+HQF4TJPkYrpodE4qo4JHvlu+a5HTJf1AFyXTnZ4vk=";
33+
tag = "${finalAttrs.version}_cadical";
34+
hash = "sha256-fNx3/VS2bimlVwCejEZtNGDqVKnwBm0O2YkIUQm6eDM=";
2535
};
2636
patches = [
27-
# Fix missing type declaration
28-
# due to undeterminisitic compilation
29-
# of circularly dependent headers
30-
./stdint.patch
31-
3237
# Python 3.12+ compatibility for build: https://github.com/stp/stp/pull/450
3338
(fetchpatch {
3439
url = "https://github.com/stp/stp/commit/fb185479e760b6ff163512cb6c30ac9561aadc0e.patch";
3540
hash = "sha256-guFgeWOrxRrxkU7kMvd5+nmML0rwLYW196m1usE2qiA=";
3641
})
3742
];
43+
postPatch =
44+
''
45+
substituteInPlace CMakeLists.txt \
46+
--replace-fail GIT-hash-notfound "$version"
3847
39-
postPatch = ''
40-
# Upstream fix for gcc-13 support:
41-
# https://github.com/stp/stp/pull/462
42-
# Can't apply it as is as patch context changed in ither patches.
43-
# TODO: remove me on 2.4 release
44-
sed -e '1i #include <cstdint>' -i include/stp/AST/ASTNode.h
45-
'';
48+
# We want to use the Nix wrapper for the output check tool instead of running it through Python.
49+
substituteInPlace tests/query-files/lit.cfg \
50+
--replace-fail "pythonExec + ' ' +OutputCheckTool" "OutputCheckTool"
51+
52+
# Results in duplication of Nix store paths and trouble finding the Python library at runtime
53+
substituteInPlace bindings/python/stp/library_path.py.in_install \
54+
--replace-fail "@CMAKE_INSTALL_PREFIX@/" ""
55+
''
56+
+ lib.optionalString useCadical ''
57+
# Fix up Cadical paths.
58+
substituteInPlace include/stp/Sat/Cadical.h \
59+
--replace-fail "src/cadical.hpp" "cadical.hpp"
60+
61+
substituteInPlace CMakeLists.txt \
62+
--replace-fail "build/libcadical.a" "lib/libcadical.a" \
63+
--replace-fail 'include_directories(''${CADICAL_DIR}/)' 'include_directories(''${CADICAL_DIR}/include)'
64+
'';
4665

4766
buildInputs = [
4867
boost
4968
zlib
50-
minisat
51-
cryptominisat
5269
python3
70+
gmp
71+
minisat
72+
] ++ lib.optional (!useCadical) cryptominisat;
73+
74+
nativeBuildInputs = [
75+
cmake
76+
bison
77+
flex
78+
perl
79+
pkg-config
80+
];
81+
82+
cmakeFlags =
83+
let
84+
# STP expects Cadical dependencies to all be in the same place.
85+
cadicalDependency = symlinkJoin {
86+
name = "stp-${finalAttrs.version}-cadical";
87+
paths = [
88+
cadical.lib
89+
cadical.dev
90+
];
91+
};
92+
in
93+
[
94+
(lib.cmakeBool "BUILD_SHARED_LIBS" true)
95+
(lib.cmakeBool "USE_CADICAL" useCadical)
96+
(lib.cmakeBool "NOCRYPTOMINISAT" useCadical)
97+
(lib.cmakeBool "FORCE_CMS" (!useCadical))
98+
(lib.cmakeBool "ENABLE_TESTING" finalAttrs.doCheck)
99+
]
100+
++ lib.optional finalAttrs.doCheck (lib.cmakeFeature "LIT_ARGS" "-v")
101+
++ lib.optional useCadical (lib.cmakeFeature "CADICAL_DIR" (toString cadicalDependency));
102+
103+
# Fixes the following warning in the aarch64 build on Linux:
104+
# lib/extlib-abc/aig/cnf/cnfData.c:4591:25: warning: result of comparison of
105+
# constant 255 with expression of type 'signed char' is always false [-Wtautological-constant-out-of-range-compare]
106+
# 4591 | if ( pMemory[k] == (char)(-1) )
107+
#
108+
# This seems to cause an infinite loop in tests on aarch64-linux platforms.
109+
#
110+
# TODO: Remove these CFLAGS when they update to the version that pulls `abc` in with a submodule.
111+
# https://github.com/stp/stp/issues/498#issuecomment-2611251631
112+
CFLAGS = [ "-fsigned-char" ];
113+
114+
outputs = [
115+
"dev"
116+
"out"
53117
];
54-
nativeBuildInputs = [ cmake bison flex perl ];
55-
preConfigure = ''
56-
python_install_dir=$out/${python3.sitePackages}
57-
mkdir -p $python_install_dir
58-
cmakeFlagsArray=(
59-
$cmakeFlagsArray
60-
"-DBUILD_SHARED_LIBS=ON"
61-
"-DPYTHON_LIB_INSTALL_DIR=$python_install_dir"
62-
)
118+
119+
preConfigure =
120+
''
121+
python_install_dir=$out/${python3.sitePackages}
122+
mkdir -p $python_install_dir
123+
cmakeFlagsArray+=(
124+
"-DPYTHON_LIB_INSTALL_DIR=$python_install_dir"
125+
)
126+
''
127+
+ lib.optionalString finalAttrs.doCheck ''
128+
# Link in gtest and the output check utility.
129+
mkdir -p deps
130+
ln -s ${gtest.src} deps/gtest
131+
ln -s ${outputcheck} deps/OutputCheck
132+
'';
133+
134+
nativeCheckInputs = [
135+
gtest
136+
lit
137+
outputcheck
138+
];
139+
140+
doCheck = true;
141+
142+
postInstall = ''
143+
# Clean up installed gtest/gmock files that shouldn't be there.
144+
shopt -s globstar nocaseglob
145+
rm -rf $out/**/*g{test,mock}*
146+
147+
# Some of the gtest/gmock files were in the pkgconfig folders, which may now be empty.
148+
find $out/ -name pkgconfig -type d -empty -delete
149+
150+
# Python bindings are broken:
151+
substituteInPlace $python_install_dir/**/stp.py \
152+
--replace-fail "from library_path import PATHS" "from .library_path import PATHS"
63153
'';
64154

65-
meta = with lib; {
155+
doInstallCheck = true;
156+
postInstallCheck = ''
157+
$out/bin/stp --version | tee /dev/stderr | grep -F "STP version $version"
158+
159+
# Run the examples from the docs: https://stp.readthedocs.io/en/latest/#python-usage
160+
for binary in stp stp_simple; do
161+
echo "(set-logic QF_BV) (assert (= (bvsdiv (_ bv3 2) (_ bv2 2)) (_ bv0 2))) (check-sat) (exit)" | tee /dev/stderr | $out/bin/$binary | grep "^sat$"
162+
done
163+
PYTHONPATH=$out/${python3.sitePackages} ${lib.getExe python3} -c \
164+
"import stp; s = stp.Solver(); a, b, c = s.bitvec('a', 32), s.bitvec('b', 32), s.bitvec('c', 32); s.add(a == 5); s.add(b == 6); s.add(a + b == c); assert s.check(); print(s.model())" >&2
165+
'';
166+
167+
passthru = {
168+
updateScript = nix-update-script {
169+
extraArgs = [
170+
"--version-regex"
171+
"^v(2\\.3\\.[0-9]+)$"
172+
];
173+
};
174+
};
175+
176+
meta = {
66177
description = "Simple Theorem Prover";
67-
maintainers = with maintainers; [ McSinyx numinit ];
68-
platforms = platforms.linux;
69-
license = licenses.mit;
178+
homepage = "https://stp.github.io/";
179+
maintainers = with lib.maintainers; [
180+
McSinyx
181+
numinit
182+
];
183+
platforms = with lib.platforms; linux ++ darwin;
184+
license = lib.licenses.mit;
70185
};
71-
}
186+
})

pkgs/by-name/st/stp/stdint.patch

Lines changed: 0 additions & 16 deletions
This file was deleted.

pkgs/top-level/python-packages.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15779,6 +15779,10 @@ self: super: with self; {
1577915779

1578015780
stop-words = callPackage ../development/python-modules/stop-words { };
1578115781

15782+
stp = toPythonModule (pkgs.stp.override {
15783+
python3 = self.python;
15784+
});
15785+
1578215786
stransi = callPackage ../development/python-modules/stransi { };
1578315787

1578415788
strategies = callPackage ../development/python-modules/strategies { };

0 commit comments

Comments
 (0)