Skip to content
Closed
Changes from all 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
83 changes: 62 additions & 21 deletions pkgs/applications/science/math/singular/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,54 @@
, lib
, fetchpatch
, autoreconfHook
, sharutils
, file
, flint
, ntl
, cddlib
, enableFactory ? true
, enableGfanlib ? true
}:

stdenv.mkDerivation rec {
name = "singular-${version}";
version = "4.1.1p2";

src = let
# singular sorts its tarballs in directories by base release (without patch version)
# for example 4.1.1p1 will be in the directory 4-1-1
baseVersion = builtins.head (lib.splitString "p" version);
urlVersion = builtins.replaceStrings [ "." ] [ "-" ] baseVersion;
in
fetchurl {
version = "4.1.1p3";

# singular sorts its tarballs in directories by base release (without patch version)
# for example 4.1.1p1 will be in the directory 4-1-1
baseVersion = builtins.head (lib.splitString "p" version);
urlVersion = builtins.replaceStrings [ "." ] [ "-" ] baseVersion;
src = fetchurl {
url = "http://www.mathematik.uni-kl.de/ftp/pub/Math/Singular/SOURCES/${urlVersion}/singular-${version}.tar.gz";
sha256 = "07x9kri8vl4galik7lr6pscq3c51n8570pyw64i7gbj0m706f7wf";
sha256 = "1qqj9bm9pkzm0iyycpvm8x6s79wws3nq60lz25h8x1q61h3426sm";
};
tests = fetchurl {
url = "http://www.mathematik.uni-kl.de/ftp/pub/Math/Singular/SOURCES/${urlVersion}/singular-tst-${version}.tar.gz";
sha256 = "10w3iabx0ykxwfk07n3z752jinan425wkp00f74nkv745bfhz139";
};

configureFlags = [
"--with-ntl=${ntl}"
] ++ lib.optionals enableFactory [
"--enable-factory"
] ++ lib.optionals enableGfanlib [
"--enable-gfanlib"
];

postUnpack = ''
prePatch = ''
# move Tests into singular source root
tar xf "${tests}"

# don't let the tests depend on `hostname`
substituteInPlace Tst/regress.cmd --replace 'mysystem_catch("hostname")' 'nix_test_runner'

patchShebangs .
'';

patches = [
# NTL error handler was introduced in the library part, preventing users of
# the library from implementing their own error handling
# https://www.singular.uni-kl.de/forum/viewtopic.php?t=2769
# Fix bug with gcd in Z[x]
# https://www.singular.uni-kl.de:8005/trac/ticket/834
(fetchpatch {
name = "move_error_handler_out_of_libsingular.patch";
# rebased version of https://github.com/Singular/Sources/commit/502cf86d0bb2a96715be6764774b64a69c1ca34c.patch
url = "https://git.sagemath.org/sage.git/plain/build/pkgs/singular/patches/singular-ntl-error-handler.patch?h=50b9ae2fd233c30860e1cbb3e63a26f2cc10560a";
sha256 = "0vgh4m9zn1kjl0br68n04j4nmn5i1igfn28cph0chnwf7dvr9194";
name = "gcd-fix.patch";
url = "https://github.com/Singular/Sources/commit/55ec4f789df5836f21154a2d6e25c0e9cb8cf814.patch";
sha256 = "1jy5gngdh8xawbbh59w6fnks22h778wpaqvzpq4h2l7xhz7dgdnb";
})
];

Expand All @@ -68,6 +72,7 @@ stdenv.mkDerivation rec {
perl
pkgconfig
autoreconfHook
sharutils # needed for regress.cmd install checks
];

preAutoreconf = ''
Expand All @@ -85,6 +90,8 @@ stdenv.mkDerivation rec {
# do nothing
'';

doCheck = true; # very basic checks, does not test any libraries

installPhase = ''
mkdir -p "$out"
cp -r Singular/LIB "$out/lib"
Expand All @@ -94,14 +101,47 @@ stdenv.mkDerivation rec {
rm -rf libpolys factory resources omalloc Singular
'';

# singular tests are a bit complicated, see
# https://github.com/Singular/Sources/tree/spielwiese/Tst
# https://www.singular.uni-kl.de/forum/viewtopic.php&t=2773
testsToRun = [
"Old/universal.lst"
"Buch/buch.lst"
"Plural/short.lst"
"Old/factor.tst"
] ++ lib.optionals enableGfanlib [
# tests that require gfanlib
"Short/ok_s.lst"
];

# simple test to make sure singular starts and finds its libraries
doInstallCheck = true;
installCheckPhase = ''
# Very basic sanity check to make sure singular starts and finds its libraries.
# This is redundant with the below tests. It is only kept because the singular test
# runner is a bit complicated. In case we decide to give up those tests in the future,
# this will still be useful. It takes barely any time.
"$out/bin/Singular" -c 'LIB "freegb.lib"; exit;'
if [ $? -ne 0 ]; then
echo >&2 "Error loading the freegb library in Singular."
exit 1
fi

# Run the test suite
cd Tst
perl ./regress.cmd \
-s "$out/bin/Singular" \
${lib.concatStringsSep " " (map lib.escapeShellArg testsToRun)} \
2>"$TMPDIR/out-err.log"

# unfortunately regress.cmd always returns exit code 0, so check stderr
# https://www.singular.uni-kl.de/forum/viewtopic.php&t=2773
if [[ -s "$TMPDIR/out-err.log" ]]; then
cat "$TMPDIR/out-err.log"
exit 1
fi

echo "Exit status $?"
'';

enableParallelBuilding = true;
Expand All @@ -110,6 +150,7 @@ stdenv.mkDerivation rec {
description = "A CAS for polynomial computations";
maintainers = with maintainers; [ raskin timokau ];
# 32 bit x86 fails with some link error: `undefined reference to `__divmoddi4@GCC_7.0.0'`
# https://www.singular.uni-kl.de:8002/trac/ticket/837
platforms = subtractLists platforms.i686 platforms.linux;
license = licenses.gpl3; # Or GPLv2 at your option - but not GPLv4
homepage = http://www.singular.uni-kl.de;
Expand Down