From dfd8a367d7e6c9e33bd6847eff5bc3e205951c3e Mon Sep 17 00:00:00 2001 From: George Huebner Date: Wed, 25 Oct 2023 20:58:42 -0500 Subject: [PATCH 1/9] giac: 1.9.0-43 -> 1.9.0-993 Nearly fixed on aarch64-darwin! (Note that this coincides with a release of Xcas for macOS, but this is not using Parisse's tarball). --- .../science/math/giac/default.nix | 39 ++- .../science/math/giac/fix-fltk-guard.patch | 28 ++ .../math/giac/increase-pari-stack-size.patch | 18 -- .../giac/remove-old-functional-patterns.patch | 294 ++++++++++++++++++ 4 files changed, 353 insertions(+), 26 deletions(-) create mode 100644 pkgs/applications/science/math/giac/fix-fltk-guard.patch delete mode 100644 pkgs/applications/science/math/giac/increase-pari-stack-size.patch create mode 100644 pkgs/applications/science/math/giac/remove-old-functional-patterns.patch diff --git a/pkgs/applications/science/math/giac/default.nix b/pkgs/applications/science/math/giac/default.nix index 834ae7b3d61f3ec..4c0d7235efc7420 100644 --- a/pkgs/applications/science/math/giac/default.nix +++ b/pkgs/applications/science/math/giac/default.nix @@ -9,18 +9,30 @@ assert (!blas.isILP64) && (!lapack.isILP64); stdenv.mkDerivation rec { pname = "giac${lib.optionalString enableGUI "-with-xcas"}"; - version = "1.9.0-43"; # TODO try to remove preCheck phase on upgrade + version = "1.9.0-993"; # TODO try to remove preCheck phase on upgrade src = fetchurl { url = "https://www-fourier.ujf-grenoble.fr/~parisse/debian/dists/stable/main/source/giac_${version}.tar.gz"; - sha256 = "sha256-466jB8ZRqHkU5XCY+j0Fh7Dq/mMaOu10rHECKbtNGrs="; + sha256 = "sha256-pqytFWrSWfEwQqRdRbaigGCq68s8mdgj2j8M+kclslE="; }; patches = [ + ./remove-old-functional-patterns.patch + ./fix-fltk-guard.patch + + (fetchpatch { + name = "pari_2_15.patch"; + url = "https://raw.githubusercontent.com/sagemath/sage/07a2afd65fb4b0a1c9cbc43ede7d4a18c921a000/build/pkgs/giac/patches/pari_2_15.patch"; + sha256 = "sha256-Q3xBFED7XEAyNz6AHjzt63XtospmdGAIdS6iPq1C2UE="; + }) + (fetchpatch { - name = "pari_2_11.patch"; - url = "https://raw.githubusercontent.com/sagemath/sage/21ba7540d385a9864b44850d6987893dfa16bfc0/build/pkgs/giac/patches/pari_2_11.patch"; - sha256 = "sha256-vEo/5MNzMdYRPWgLFPsDcMT1W80Qzj4EPBjx/B8j68k="; + name = "infinity.patch"; + url = "https://github.com/geogebra/giac/commit/851c2cd91e879c79d6652f8a5d5bed03b65c6d39.patch"; + sha256 = "sha256-WJRT2b8I9kgAkRuIugMiXoF4hT7yR7qyad8A6IspNTM="; + stripLen = 5; + extraPrefix = "/src/"; + excludes = [ "src/kdisplay.cc" ]; }) # giac calls scanf/printf with non-constant first arguments, which @@ -31,8 +43,12 @@ stdenv.mkDerivation rec { sha256 = "sha256-r+M+9MRPRqhHcdhYWI6inxyNvWbXUbBcPCeDY7aulvk="; }) - # increase pari stack size for test chk_fhan{4,6} - ./increase-pari-stack-size.patch + # issue with include path precedence + (fetchpatch { + name = "fix_implicit_declaration.patch"; + url = "https://salsa.debian.org/science-team/giac/-/raw/c05ae9b9e74d3c6ee6411d391071989426a76201/debian/patches/fix_implicit_declaration.patch"; + sha256 = "sha256-ompUceYJLiL0ftfjBkIMcYvX1YqG2/XA7e1yDyFY0IY="; + }) ] ++ lib.optionals (!enableGUI) [ # when enableGui is false, giac is compiled without fltk. That # means some outputs differ in the make check. Patch around this: @@ -86,6 +102,12 @@ stdenv.mkDerivation rec { # when fltk is disabled. disable these tests for now. echo > check/chk_fhan2 echo > check/chk_fhan9 + '' + lib.optionalString (stdenv.isDarwin) '' + # these cover a known regression in giac, likely due to how pari state + # is shared between multiple giac instances (see pari.cc.old). + # see https://github.com/NixOS/nixpkgs/pull/264126 for more information + echo > check/chk_fhan4 + echo > check/chk_fhan6 ''; enableParallelBuilding = true; @@ -96,6 +118,8 @@ stdenv.mkDerivation rec { "--enable-ao" "--enable-ecm" "--enable-glpk" ] ++ lib.optionals enableGUI [ "--enable-gui" "--with-x" + ] ++ lib.optionals stdenv.isDarwin [ + "--disable-nls" ] ++ lib.optionals (!enableGUI) [ "--disable-fltk" ] ++ lib.optionals (!enableMicroPy) [ @@ -129,7 +153,6 @@ stdenv.mkDerivation rec { homepage = "https://www-fourier.ujf-grenoble.fr/~parisse/giac.html"; license = licenses.gpl3Plus; platforms = platforms.linux ++ (optionals (!enableGUI) platforms.darwin); - broken = stdenv.isDarwin && stdenv.isAarch64; maintainers = [ maintainers.symphorien ]; }; } diff --git a/pkgs/applications/science/math/giac/fix-fltk-guard.patch b/pkgs/applications/science/math/giac/fix-fltk-guard.patch new file mode 100644 index 000000000000000..a9c8e5bbaab8d66 --- /dev/null +++ b/pkgs/applications/science/math/giac/fix-fltk-guard.patch @@ -0,0 +1,28 @@ +From c7eafa2d7bde0d735b125912542acec2d5896c17 Mon Sep 17 00:00:00 2001 +From: George Huebner +Date: Sat, 20 Jul 2024 02:31:20 -0500 +Subject: [PATCH 3/4] remove erroneous HAVE_LIBFLTK guard + +--- + src/icas.cc | 4 ---- + 1 file changed, 4 deletions(-) + +diff --git a/src/icas.cc b/src/icas.cc +index f91885b..17a0373 100644 +--- a/src/icas.cc ++++ b/src/icas.cc +@@ -2407,11 +2407,7 @@ int main(int ARGC, char *ARGV[]){ + #ifdef __APPLE__ + startc=clock(); + #endif +-#ifdef HAVE_LIBFLTK + xcas::icas_eval(gq,e,reading_file,filename,contextptr); +-#else +- e=eval(gq,1,contextptr); +-#endif + #ifdef __APPLE__ + startc=clock()-startc; + #endif +-- +2.44.1 + diff --git a/pkgs/applications/science/math/giac/increase-pari-stack-size.patch b/pkgs/applications/science/math/giac/increase-pari-stack-size.patch deleted file mode 100644 index b12b4b7fad66036..000000000000000 --- a/pkgs/applications/science/math/giac/increase-pari-stack-size.patch +++ /dev/null @@ -1,18 +0,0 @@ -diff -ur a/check/chk_fhan4 b/check/chk_fhan4 ---- a/check/chk_fhan4 2018-03-13 19:27:11.000000000 +0100 -+++ b/check/chk_fhan4 2023-05-20 16:31:30.349063063 +0200 -@@ -1,4 +1,5 @@ - #! /bin/sh - unset LANG -+export PARI_SIZE=2048000 - ../src/icas TP04-sol.cas > TP04.tst - diff TP04.tst TP04-sol.cas.out1 -diff -ur a/check/chk_fhan6 b/check/chk_fhan6 ---- a/check/chk_fhan6 2018-03-13 19:27:21.000000000 +0100 -+++ b/check/chk_fhan6 2023-05-20 16:32:04.199407065 +0200 -@@ -1,4 +1,5 @@ - #! /bin/sh - unset LANG -+export PARI_SIZE=2048000 - ../src/icas TP06-sol.cas > TP06.tst - diff TP06.tst TP06-sol.cas.out1 diff --git a/pkgs/applications/science/math/giac/remove-old-functional-patterns.patch b/pkgs/applications/science/math/giac/remove-old-functional-patterns.patch new file mode 100644 index 000000000000000..95f6efe119fcb4a --- /dev/null +++ b/pkgs/applications/science/math/giac/remove-old-functional-patterns.patch @@ -0,0 +1,294 @@ +From f1c5309d5b815acc2616cd9fbb5182b1e64d225f Mon Sep 17 00:00:00 2001 +From: George Huebner +Date: Wed, 17 Jul 2024 18:12:36 -0500 +Subject: [PATCH 1/4] remove old patterns + +pointer_to_binary_function and ptr_fun are holdovers from pre c++11, +and can be replaced or entirely removed. This allows Giac to compile +with Clang 16>=. +--- + src/all_global_var | 2 +- + src/gausspol.cc | 2 +- + src/gausspol.h | 2 +- + src/gen.cc | 2 +- + src/gen.h | 4 ++-- + src/maple.cc | 2 +- + src/monomial.h | 16 ++++++++-------- + src/plot.cc | 2 +- + src/poly.h | 17 +++++++++-------- + src/solve.cc | 18 +++++++++--------- + src/usual.cc | 2 +- + 11 files changed, 35 insertions(+), 34 deletions(-) + +diff --git a/src/all_global_var b/src/all_global_var +index 7d75d73..55f4782 100644 +--- a/src/all_global_var ++++ b/src/all_global_var +@@ -16,7 +16,7 @@ Relatif a l'evaluation du tableur + // File Eqw.cc + vector completion_tab; + // File alg_ext.cc +- rootmap symbolic_rootof_list(ptr_fun(islesscomplex)); ++ rootmap symbolic_rootof_list(islesscomplex); + // File derive.cc + // File desolve.cc + identificateur laplace_var(" s"); +diff --git a/src/gausspol.cc b/src/gausspol.cc +index 8fbd581..2f2121f 100644 +--- a/src/gausspol.cc ++++ b/src/gausspol.cc +@@ -855,7 +855,7 @@ namespace giac { + std::vector< monomial >::const_iterator & itb_end, + std::vector< monomial > & new_coord, + bool (* is_strictly_greater)( const index_m &, const index_m &), +- const std::pointer_to_binary_function < const monomial &, const monomial &, bool> m_is_strictly_greater ++ const std::function &, const monomial &)> m_is_strictly_greater + ) { + if (ita==ita_end || itb==itb_end){ + new_coord.clear(); +diff --git a/src/gausspol.h b/src/gausspol.h +index b5d214b..e6c7e0c 100644 +--- a/src/gausspol.h ++++ b/src/gausspol.h +@@ -93,7 +93,7 @@ namespace giac { + std::vector< monomial >::const_iterator & itb_end, + std::vector< monomial > & new_coord, + bool (* is_strictly_greater)( const index_t &, const index_t &), +- const std::pointer_to_binary_function < const monomial &, const monomial &, bool> m_is_greater ++ const std::function &, const monomial &)> m_is_greater + ) ; + void mulpoly(const polynome & th,const gen & fact,polynome & res); + polynome operator * (const polynome & th, const gen & fact) ; +diff --git a/src/gen.cc b/src/gen.cc +index 7d4874c..0b64afe 100644 +--- a/src/gen.cc ++++ b/src/gen.cc +@@ -1126,7 +1126,7 @@ namespace giac { + #if 1 // def NSPIRE + g.__MAPptr = new ref_gen_map; + #else +- g.__MAPptr = new ref_gen_map(ptr_fun(islesscomplexthanf)); ++ g.__MAPptr = new ref_gen_map(islesscomplexthanf); + #endif + #endif + g.type=_MAP; +diff --git a/src/gen.h b/src/gen.h +index 04d70af..496b25d 100644 +--- a/src/gen.h ++++ b/src/gen.h +@@ -443,7 +443,7 @@ namespace giac { + }; + typedef std::map gen_map; + #else +- typedef std::map > gen_map; ++ typedef std::map > gen_map; + #endif + struct ref_gen_map; + +@@ -902,7 +902,7 @@ namespace giac { + #if 1 // def NSPIRE + ref_gen_map(): ref_count(1),m() {} + #else +- ref_gen_map(const std::pointer_to_binary_function < const gen &, const gen &, bool> & p): ref_count(1),m(p) {} ++ ref_gen_map(const std::function & p): ref_count(1),m(p) {} + #endif + ref_gen_map(const gen_map & M):ref_count(1),m(M) {} + }; +diff --git a/src/maple.cc b/src/maple.cc +index 3b33da8..d57a170 100644 +--- a/src/maple.cc ++++ b/src/maple.cc +@@ -3626,7 +3626,7 @@ namespace giac { + #if 1 // def NSPIRE + gen_map m; + #else +- gen_map m(ptr_fun(islessthanf)); ++ gen_map m(islessthanf); + #endif + int s=int(args.size()); + vector indexbegin,indexsize; +diff --git a/src/monomial.h b/src/monomial.h +index 6e606d0..637a76c 100644 +--- a/src/monomial.h ++++ b/src/monomial.h +@@ -338,9 +338,9 @@ namespace giac { + + template class sort_helper { + public: +- std::pointer_to_binary_function < const monomial &, const monomial &, bool> strictly_greater ; +- sort_helper(const std::pointer_to_binary_function < const monomial &, const monomial &, bool> is_strictly_greater):strictly_greater(is_strictly_greater) {}; +- sort_helper():strictly_greater(std::ptr_fun &, const monomial &, bool>(m_lex_is_strictly_greater)) {}; ++ std::function &, const monomial &)> strictly_greater ; ++ sort_helper(const std::function &, const monomial &)> is_strictly_greater):strictly_greater(is_strictly_greater) {}; ++ sort_helper():strictly_greater(m_lex_is_strictly_greater) {}; + bool operator () (const monomial & a, const monomial & b){ return strictly_greater(a,b);} + }; + +@@ -677,7 +677,7 @@ namespace giac { + typename std::vector< monomial >::const_iterator & itb_end, + std::vector< monomial > & new_coord, + bool (* is_strictly_greater)( const index_m &, const index_m &), +- const std::pointer_to_binary_function < const monomial &, const monomial &, bool> m_is_strictly_greater ++ const std::function &, const monomial &)> m_is_strictly_greater + ) { + if (ita==ita_end || itb==itb_end){ + new_coord.clear(); +@@ -726,8 +726,8 @@ namespace giac { + #endif + #ifndef NSPIRE + /* other algorithm using a map to avoid reserving too much space */ +- typedef std::map< index_t,T,const std::pointer_to_binary_function < const index_m &, const index_m &, bool> > application; +- application produit(std::ptr_fun(is_strictly_greater)); ++ typedef std::map< index_t,T,const std::function > application; ++ application produit(is_strictly_greater); + // typedef std::map application; + // application produit; + index_t somme(ita->index.size()); +@@ -848,7 +848,7 @@ namespace giac { + typename std::vector< monomial >::const_iterator a=v.begin(), a_end=v.end(); + typename std::vector< monomial >::const_iterator b=w.begin(), b_end=w.end(); + std::vector< monomial > res; +- Mul(a,a_end,b,b_end,res,i_lex_is_strictly_greater,std::ptr_fun< const monomial &, const monomial &, bool >((m_lex_is_strictly_greater))); ++ Mul(a,a_end,b,b_end,res,i_lex_is_strictly_greater,m_lex_is_strictly_greater); + return res ; + } + +@@ -856,7 +856,7 @@ namespace giac { + std::vector< monomial > & operator *= (std::vector< monomial > & v,const std::vector< monomial > & w){ + typename std::vector< monomial >::const_iterator a=v.begin(), a_end=v.end(); + typename std::vector< monomial >::const_iterator b=w.begin(), b_end=w.end(); +- Mul(a,a_end,b,b_end,v,i_lex_is_strictly_greater,std::ptr_fun< const monomial &, const monomial &, bool >((m_lex_is_strictly_greater))); ++ Mul(a,a_end,b,b_end,v,i_lex_is_strictly_greater,m_lex_is_strictly_greater); + return v; + } + +diff --git a/src/plot.cc b/src/plot.cc +index 288a1b5..ac85c9a 100755 +--- a/src/plot.cc ++++ b/src/plot.cc +@@ -11886,7 +11886,7 @@ static vecteur densityscale(double xmin,double xmax,double ymin,double ymax,doub + #if 1 // def NSPIRE + gen_map m; + #else +- gen_map m(ptr_fun(islesscomplexthanf)); ++ gen_map m(islesscomplexthanf); + #endif + int taille; + is >> taille; +diff --git a/src/poly.h b/src/poly.h +index 7d64e2c..d9ff991 100644 +--- a/src/poly.h ++++ b/src/poly.h +@@ -40,23 +40,24 @@ namespace giac { + // T zero; + // functional object sorting function for monomial ordering + bool (* is_strictly_greater)( const index_m &, const index_m &); +- std::pointer_to_binary_function < const monomial &, const monomial &, bool> m_is_strictly_greater ; ++ std::function &, const monomial &)> m_is_strictly_greater ; + // constructors + tensor(const tensor & t) : dim(t.dim), coord(t.coord), is_strictly_greater(t.is_strictly_greater), m_is_strictly_greater(t.m_is_strictly_greater) { } + tensor(const tensor & t, const std::vector< monomial > & v) : dim(t.dim), coord(v), is_strictly_greater(t.is_strictly_greater), m_is_strictly_greater(t.m_is_strictly_greater) { } + // warning: this constructor prohibits construction of tensor from a value + // of type T if this value is an int, except by using tensor(T(int)) +- tensor() : dim(0), is_strictly_greater(i_lex_is_strictly_greater), m_is_strictly_greater(std::ptr_fun &, const monomial &, bool>(m_lex_is_strictly_greater)) { } +- explicit tensor(int d) : dim(d), is_strictly_greater(i_lex_is_strictly_greater), m_is_strictly_greater(std::ptr_fun &, const monomial &, bool>(m_lex_is_strictly_greater)) { } ++ // DANGER ++ tensor() : dim(0), is_strictly_greater(i_lex_is_strictly_greater), m_is_strictly_greater(m_lex_is_strictly_greater) { } ++ explicit tensor(int d) : dim(d), is_strictly_greater(i_lex_is_strictly_greater), m_is_strictly_greater(m_lex_is_strictly_greater) { } + explicit tensor(int d,const tensor & t) : dim(d),is_strictly_greater(t.is_strictly_greater), m_is_strictly_greater(t.m_is_strictly_greater) { } +- tensor(const monomial & v) : dim(int(v.index.size())), is_strictly_greater(i_lex_is_strictly_greater), m_is_strictly_greater(std::ptr_fun &, const monomial &, bool>(m_lex_is_strictly_greater)) { ++ tensor(const monomial & v) : dim(int(v.index.size())), is_strictly_greater(i_lex_is_strictly_greater), m_is_strictly_greater(m_lex_is_strictly_greater) { + coord.push_back(v); + } +- tensor(const T & v, int d) : dim(d), is_strictly_greater(i_lex_is_strictly_greater), m_is_strictly_greater(std::ptr_fun &, const monomial &, bool>(m_lex_is_strictly_greater)) { ++ tensor(const T & v, int d) : dim(d), is_strictly_greater(i_lex_is_strictly_greater), m_is_strictly_greater(m_lex_is_strictly_greater) { + if (!is_zero(v)) + coord.push_back(monomial(v,0,d)); + } +- tensor(int d,const std::vector< monomial > & c) : dim(d), coord(c), is_strictly_greater(i_lex_is_strictly_greater),m_is_strictly_greater(std::ptr_fun &, const monomial &, bool>(m_lex_is_strictly_greater)) { } ++ tensor(int d,const std::vector< monomial > & c) : dim(d), coord(c), is_strictly_greater(i_lex_is_strictly_greater),m_is_strictly_greater(m_lex_is_strictly_greater) { } + ~tensor() { coord.clear(); } + // member functions + // ordering monomials in the tensor +@@ -519,10 +520,10 @@ namespace giac { + template + void lexsort(std::vector < monomial > & v){ + #if 1 // def NSPIRE +- sort_helper M(std::ptr_fun &, const monomial &, bool>(m_lex_is_strictly_greater)); ++ sort_helper M(m_lex_is_strictly_greater); + sort(v.begin(),v.end(),M); + #else +- sort(v.begin(),v.end(),std::ptr_fun &, const monomial &, bool>(m_lex_is_strictly_greater)); ++ sort(v.begin(),v.end(),m_lex_is_strictly_greater); + #endif + } + +diff --git a/src/solve.cc b/src/solve.cc +index 889f824..2a51ab8 100755 +--- a/src/solve.cc ++++ b/src/solve.cc +@@ -8684,39 +8684,39 @@ namespace giac { + switch (order.val){ + case _PLEX_ORDER: + p.is_strictly_greater=i_lex_is_strictly_greater; +- p.m_is_strictly_greater=std::ptr_fun(m_lex_is_strictly_greater); ++ p.m_is_strictly_greater=m_lex_is_strictly_greater; + break; + case _REVLEX_ORDER: + p.is_strictly_greater=i_total_revlex_is_strictly_greater; +- p.m_is_strictly_greater=std::ptr_fun(m_total_revlex_is_strictly_greater); ++ p.m_is_strictly_greater=m_total_revlex_is_strictly_greater; + break; + case _TDEG_ORDER: + p.is_strictly_greater=i_total_lex_is_strictly_greater; +- p.m_is_strictly_greater=std::ptr_fun(m_total_lex_is_strictly_greater); ++ p.m_is_strictly_greater=m_total_lex_is_strictly_greater; + break; + case _3VAR_ORDER: + p.is_strictly_greater=i_3var_is_strictly_greater; +- p.m_is_strictly_greater=std::ptr_fun(m_3var_is_strictly_greater); ++ p.m_is_strictly_greater=m_3var_is_strictly_greater; + break; + case _7VAR_ORDER: + p.is_strictly_greater=i_7var_is_strictly_greater; +- p.m_is_strictly_greater=std::ptr_fun(m_7var_is_strictly_greater); ++ p.m_is_strictly_greater=m_7var_is_strictly_greater; + break; + case _11VAR_ORDER: + p.is_strictly_greater=i_11var_is_strictly_greater; +- p.m_is_strictly_greater=std::ptr_fun(m_11var_is_strictly_greater); ++ p.m_is_strictly_greater=m_11var_is_strictly_greater; + break; + case _16VAR_ORDER: + p.is_strictly_greater=i_16var_is_strictly_greater; +- p.m_is_strictly_greater=std::ptr_fun(m_16var_is_strictly_greater); ++ p.m_is_strictly_greater=m_16var_is_strictly_greater; + break; + case _32VAR_ORDER: + p.is_strictly_greater=i_32var_is_strictly_greater; +- p.m_is_strictly_greater=std::ptr_fun(m_32var_is_strictly_greater); ++ p.m_is_strictly_greater=m_32var_is_strictly_greater; + break; + case _64VAR_ORDER: + p.is_strictly_greater=i_64var_is_strictly_greater; +- p.m_is_strictly_greater=std::ptr_fun(m_64var_is_strictly_greater); ++ p.m_is_strictly_greater=m_64var_is_strictly_greater; + break; + } + p.tsort(); +diff --git a/src/usual.cc b/src/usual.cc +index fddede6..eb7ae5e 100755 +--- a/src/usual.cc ++++ b/src/usual.cc +@@ -5950,7 +5950,7 @@ namespace giac { + #if 1 // def NSPIRE + gen_map m; + #else +- gen_map m(ptr_fun(islesscomplexthanf)); ++ gen_map m(islesscomplexthanf); + #endif + for (;it!=itend;++it){ + if (is_equal(*it) || it->is_symb_of_sommet(at_deuxpoints)){ +-- +2.44.1 + From b9b4e09d6d60e2fe1b7f76ab4b39c37587eecbbd Mon Sep 17 00:00:00 2001 From: George Huebner Date: Thu, 18 Jul 2024 19:43:11 -0500 Subject: [PATCH 2/9] gfan: fix to pass sage doctests on clang This issue does not present at build time, but only in sage doctests. See https://www.github.com/sagemath/sage/issues/25118 --- pkgs/applications/science/math/gfan/default.nix | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkgs/applications/science/math/gfan/default.nix b/pkgs/applications/science/math/gfan/default.nix index ee1fce783d265d6..531a30e3f857fc7 100644 --- a/pkgs/applications/science/math/gfan/default.nix +++ b/pkgs/applications/science/math/gfan/default.nix @@ -1,4 +1,4 @@ -{lib, stdenv, fetchurl, gmp, mpir, cddlib}: +{lib, stdenv, fetchpatch, fetchurl, gmp, mpir, cddlib}: stdenv.mkDerivation rec { pname = "gfan"; version = "0.6.2"; @@ -10,6 +10,12 @@ stdenv.mkDerivation rec { patches = [ ./gfan-0.6.2-cddlib-prefix.patch + ] ++ lib.optionals (stdenv.cc.isClang) [ + (fetchpatch { + name = "clang-fix-miscompilation.patch"; + url = "https://raw.githubusercontent.com/sagemath/sage/eea1f59394a5066e9acd8ae39a90302820914ee3/build/pkgs/gfan/patches/nodel.patch"; + sha256 = "sha256-RrncSgFyrBIk/Bwe3accxiJ2rpOSJKQ84cV/uBvQsDc="; + }) ]; postPatch = lib.optionalString stdenv.cc.isClang '' From 466e1f81d82f12c91af3080ab756ef8d25653875 Mon Sep 17 00:00:00 2001 From: George Huebner Date: Thu, 18 Jul 2024 19:42:18 -0500 Subject: [PATCH 3/9] gap: fix build on darwin --- pkgs/applications/science/math/gap/default.nix | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkgs/applications/science/math/gap/default.nix b/pkgs/applications/science/math/gap/default.nix index 7a466f8c000c577..697a19d6afa19c2 100644 --- a/pkgs/applications/science/math/gap/default.nix +++ b/pkgs/applications/science/math/gap/default.nix @@ -1,5 +1,6 @@ { stdenv , lib +, fetchpatch , fetchurl , makeWrapper , readline @@ -73,6 +74,13 @@ stdenv.mkDerivation rec { sha256 = "sha256-ZyMIdF63iiIklO6N1nhu3VvDMUVvzGRWrAZL2yjVh6g="; }; + patches = [ + (fetchpatch { + url = "https://github.com/gap-system/gap/commit/c786e229413a44b7462196716b99ae9bb0071f4c.patch"; + hash = "sha256-g3jrEMSavHAUKlHoPqWmOw49hWHU+29SA788Klnr0Uw="; + }) + ]; + # remove all non-essential packages (which take up a lot of space) preConfigure = lib.optionalString (!keepAll) (removeNonWhitelistedPkgs packagesToKeep) + '' patchShebangs . From 27ad665e378f1b7ab77f368f7be58c82c4635058 Mon Sep 17 00:00:00 2001 From: George Huebner Date: Sat, 20 Jul 2024 22:32:43 -0500 Subject: [PATCH 4/9] linbox: drop `withSage` --enable-sage was removed a while ago https://github.com/linbox-team/linbox/pull/146 --- pkgs/applications/science/math/sage/default.nix | 2 +- pkgs/development/libraries/linbox/default.nix | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/pkgs/applications/science/math/sage/default.nix b/pkgs/applications/science/math/sage/default.nix index 6624dcc36528b33..6df92fcc6beb231 100644 --- a/pkgs/applications/science/math/sage/default.nix +++ b/pkgs/applications/science/math/sage/default.nix @@ -18,7 +18,7 @@ let inherit flint3; inherit sage-src env-locations singular; inherit (maxima) lisp-compiler; - linbox = pkgs.linbox.override { withSage = true; }; + linbox = pkgs.linbox; pkg-config = pkgs.pkg-config; # not to confuse with pythonPackages.pkg-config }; diff --git a/pkgs/development/libraries/linbox/default.nix b/pkgs/development/libraries/linbox/default.nix index 4d0158dbcbe3c7d..ed199914e640e0d 100644 --- a/pkgs/development/libraries/linbox/default.nix +++ b/pkgs/development/libraries/linbox/default.nix @@ -8,7 +8,6 @@ , lapack , fflas-ffpack , gmpxx -, withSage ? false # sage support }: assert (!blas.isILP64) && (!lapack.isILP64); @@ -56,8 +55,6 @@ stdenv.mkDerivation rec { "--${if stdenv.hostPlatform.avx2Support then "enable" else "disable"}-avx2" "--${if stdenv.hostPlatform.fmaSupport then "enable" else "disable"}-fma" "--${if stdenv.hostPlatform.fma4Support then "enable" else "disable"}-fma4" - ] ++ lib.optionals withSage [ - "--enable-sage" ]; # https://github.com/linbox-team/linbox/issues/304 From 240ca368e53007b0b1ddd6964a85f2e338b9d34d Mon Sep 17 00:00:00 2001 From: George Huebner Date: Sun, 21 Jul 2024 02:31:56 -0500 Subject: [PATCH 5/9] singular: fix docbuilding on non-sandboxed builds This upgrade fixes the issue with drawTropicalCurve docbuilding on Darwin (although said doctest is pretty useless now that Apple has removed postscript from macOS). Removed enableGfanlib; you can still overrideAttrs Added mpfr to be more consistent with upstream packaging recommendations --- .../science/math/singular/default.nix | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pkgs/applications/science/math/singular/default.nix b/pkgs/applications/science/math/singular/default.nix index ee84ae440b30467..6ec1c9a2b74e221 100644 --- a/pkgs/applications/science/math/singular/default.nix +++ b/pkgs/applications/science/math/singular/default.nix @@ -7,6 +7,7 @@ , getconf , flint3 , ntl +, mpfr , cddlib , gfan , lrcalc @@ -15,8 +16,7 @@ , latex2html , texinfo , texliveSmall -, enableDocs ? !stdenv.isDarwin -, enableGfanlib ? true +, enableDocs ? true }: stdenv.mkDerivation rec { @@ -40,12 +40,11 @@ stdenv.mkDerivation rec { }; configureFlags = [ + "--enable-gfanlib" "--with-ntl=${ntl}" - "--disable-pyobject-module" + "--with-flint=${flint3}" ] ++ lib.optionals enableDocs [ "--enable-doc-build" - ] ++ lib.optionals enableGfanlib [ - "--enable-gfanlib" ]; prePatch = '' @@ -61,14 +60,15 @@ stdenv.mkDerivation rec { buildInputs = [ # necessary gmp + flint3 # by upstream recommended but optional ncurses readline ntl - flint3 + mpfr lrcalc + # for gfanlib gfan - ] ++ lib.optionals enableGfanlib [ cddlib ]; @@ -100,6 +100,8 @@ stdenv.mkDerivation rec { doCheck = true; # very basic checks, does not test any libraries installPhase = '' + # clean up any artefacts a previous non-sandboxed docbuild may have left behind + rm /tmp/conic.log /tmp/conic.tex /tmp/tropicalcurve*.tex || true make install '' + lib.optionalString enableDocs '' # Sage uses singular.info, which is not installed by default @@ -118,8 +120,8 @@ stdenv.mkDerivation rec { "Buch/buch.lst" "Plural/short.lst" "Old/factor.tst" - ] ++ lib.optionals enableGfanlib [ # tests that require gfanlib + # requires "DivRemIdU", a syzextra (undocumented) command "Short/ok_s.lst" ]; From a9f9650802d3136a6daea9818986fed9ab570daa Mon Sep 17 00:00:00 2001 From: George Huebner Date: Sun, 21 Jul 2024 14:47:15 -0500 Subject: [PATCH 6/9] sympow: add sage self tests --- .../libraries/science/math/sympow/default.nix | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pkgs/development/libraries/science/math/sympow/default.nix b/pkgs/development/libraries/science/math/sympow/default.nix index 91daf30686f8fa7..57506785a721d21 100644 --- a/pkgs/development/libraries/science/math/sympow/default.nix +++ b/pkgs/development/libraries/science/math/sympow/default.nix @@ -59,10 +59,17 @@ stdenv.mkDerivation rec { # Example from the README as a sanity check. doInstallCheck = true; - installCheckPhase = '' - export HOME=$TMPDIR - "$out/bin/sympow" -sp 2p16 -curve "[1,2,3,4,5]" | grep '8.3705' - ''; + installCheckPhase = + '' + export HOME=$TMPDIR + "$out/bin/sympow" -curve "[1,2,3,4,5]" -moddeg | grep 'Modular Degree is 464' + echo "[1,-1,0,-79,289]" | "$out/bin/sympow" -analrank | grep ^"Analytic Rank is 4" + "$out/bin/sympow" -curve "[1,-1,0,-79,289]" -analrank | grep ^"Analytic Rank is 4" + "$out/bin/sympow" -curve "[0,1,1,-2,0]" -analrank | grep ^"Analytic Rank is 2" + '' + + lib.optionalString (!stdenv.isAarch64) '' + "$out/bin/sympow" -sp 2p16 -curve "[1,2,3,4,5]" | grep '8.3705' + ''; meta = { description = "Compute special values of symmetric power elliptic curve L-functions"; From 2a20f493109b5058f62c9383886fed1435a8d5cb Mon Sep 17 00:00:00 2001 From: George Huebner Date: Sun, 24 Mar 2024 11:47:07 -0500 Subject: [PATCH 7/9] sage: fixes for LLVM stdenv Also backport a fix that silences `xcode-select: not found` warnings --- .../math/sage/patches/silence-linker.patch | 27 +++++++++++++++++++ .../science/math/sage/sage-env.nix | 4 ++- .../science/math/sage/sage-src.nix | 18 +++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 pkgs/applications/science/math/sage/patches/silence-linker.patch diff --git a/pkgs/applications/science/math/sage/patches/silence-linker.patch b/pkgs/applications/science/math/sage/patches/silence-linker.patch new file mode 100644 index 000000000000000..f11f6cc6d0e330b --- /dev/null +++ b/pkgs/applications/science/math/sage/patches/silence-linker.patch @@ -0,0 +1,27 @@ +From 06d3bb5d8ef007bbcd71ee157fd97cd69557383b Mon Sep 17 00:00:00 2001 +From: George Huebner +Date: Sat, 20 Jul 2024 18:46:04 -0500 +Subject: [PATCH] sage.cython: silence linker + +(Nix+LLVM specific issue) "ld: warning: directory not found" causes +any cython doctest to fail and is annoying, so I told ld to shut up. +--- + src/sage/misc/cython.py | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/sage/misc/cython.py b/src/sage/misc/cython.py +index 545e1227b0..c5f4b69221 100644 +--- a/src/sage/misc/cython.py ++++ b/src/sage/misc/cython.py +@@ -339,7 +339,7 @@ def cython(filename, verbose=0, compile_message=False, + Cython.Compiler.Options.pre_import = "sage.all" if sage_namespace else None + + extra_compile_args = ['-w'] # no warnings +- extra_link_args = [] ++ extra_link_args = ['-w'] + + ext = Extension(name, + sources=[pyxfile], +-- +2.44.1 + diff --git a/pkgs/applications/science/math/sage/sage-env.nix b/pkgs/applications/science/math/sage/sage-env.nix index e886f6645468b9b..1503d3a89957a39 100644 --- a/pkgs/applications/science/math/sage/sage-env.nix +++ b/pkgs/applications/science/math/sage/sage-env.nix @@ -10,6 +10,7 @@ , coreutils , gnused , gnugrep +, gawk , binutils , pythonEnv , python3 @@ -70,6 +71,7 @@ let coreutils gnused gnugrep + gawk binutils.bintools pkg-config pari @@ -186,7 +188,7 @@ writeTextFile rec { export SAGE_EXTCODE='${sagelib.src}/src/sage/ext_data' # for find_library - export DYLD_LIBRARY_PATH="${lib.makeLibraryPath [stdenv.cc.libc singular giac]}''${DYLD_LIBRARY_PATH:+:}$DYLD_LIBRARY_PATH" + export DYLD_LIBRARY_PATH="${lib.makeLibraryPath [stdenv.cc.libc singular giac gap]}''${DYLD_LIBRARY_PATH:+:}$DYLD_LIBRARY_PATH" ''; } // { # equivalent of `passthru`, which `writeTextFile` doesn't support lib = sagelib; diff --git a/pkgs/applications/science/math/sage/sage-src.nix b/pkgs/applications/science/math/sage/sage-src.nix index b21bb07e6a646a4..0af3b75dacbc781 100644 --- a/pkgs/applications/science/math/sage/sage-src.nix +++ b/pkgs/applications/science/math/sage/sage-src.nix @@ -1,4 +1,5 @@ { stdenv +, lib , fetchFromGitHub , fetchpatch , fetchurl @@ -40,6 +41,10 @@ stdenv.mkDerivation rec { # we can now set the cache dir to be within the .sage directory. This is # not strictly necessary, but keeps us from littering in the user's HOME. ./patches/sympow-cache.patch + ] ++ lib.optionals (stdenv.cc.isClang) [ + # https://github.com/NixOS/nixpkgs/pull/264126 + # Dead links in python sysconfig cause LLVM linker warnings, leading to cython doctest failures. + ./patches/silence-linker.patch ]; # Since sage unfortunately does not release bugfix releases, packagers must @@ -64,6 +69,13 @@ stdenv.mkDerivation rec { # compile libs/gap/element.pyx with -O1 # a more conservative version of https://github.com/sagemath/sage/pull/37951 ./patches/gap-element-crash.patch + + # https://github.com/sagemath/sage/pull/37886, landed in 10.4.beta7 + (fetchpatch { + name = "remove-xcode.patch"; + url = "https://github.com/sagemath/sage/commit/8e72038b4ab24fb63c06b28f6eb43097b9ab24d6.patch"; + sha256 = "sha256-hufDJFUBa/Trn1xsVNvzb2c1wE9iyhqewj3RMjVtENA="; + }) ]; # Patches needed because of package updates. We could just pin the versions of @@ -73,6 +85,12 @@ stdenv.mkDerivation rec { # should come from or be proposed to upstream. This list will probably never # be empty since dependencies update all the time. packageUpgradePatches = [ + # https://github.com/sagemath/sage/pull/37646, landed in 10.4.beta1 + (fetchpatch { + name = "cpp-17.patch"; + url = "https://github.com/sagemath/sage/commit/9b0a40d6cd17706db31d5ff8cdd78910409ba1c8.patch"; + sha256 = "sha256-2pJ9eH+o9O76Tsmklc/frzDOFkvPjvs2JQWCSqA+tMs="; + }) # https://github.com/sagemath/sage/pull/37763, landed in 10.4.beta2 (fetchpatch { name = "scipy-fault-tolerance.patch"; From 4195be9f144845f01770487f5915625cf0fc8ffb Mon Sep 17 00:00:00 2001 From: George Huebner Date: Sun, 21 Jul 2024 23:44:43 -0500 Subject: [PATCH 8/9] sage: fix singular doctests Tampering with ulimit is not ideal and may not work in the Darwin sandbox, but is necessary due to how Singular handles allocations. --- .../patches/disable-singular-doctest.patch | 36 +++++++++++++++++++ .../science/math/sage/sage-src.nix | 3 ++ 2 files changed, 39 insertions(+) create mode 100644 pkgs/applications/science/math/sage/patches/disable-singular-doctest.patch diff --git a/pkgs/applications/science/math/sage/patches/disable-singular-doctest.patch b/pkgs/applications/science/math/sage/patches/disable-singular-doctest.patch new file mode 100644 index 000000000000000..8501d55e5488238 --- /dev/null +++ b/pkgs/applications/science/math/sage/patches/disable-singular-doctest.patch @@ -0,0 +1,36 @@ +From d6362714c9acf4cab69f3e2e772ec0bb1dfd39fe Mon Sep 17 00:00:00 2001 +From: George Huebner +Date: Mon, 22 Jul 2024 00:37:53 -0500 +Subject: [PATCH] disable singular version doctest to avoid exceeding the stack + limit + +It works fine interactively, only an issue for Nix builds +--- + src/sage/interfaces/singular.py | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/src/sage/interfaces/singular.py b/src/sage/interfaces/singular.py +index c0ab80e0a6..c778acdb0c 100644 +--- a/src/sage/interfaces/singular.py ++++ b/src/sage/interfaces/singular.py +@@ -1262,7 +1262,7 @@ class Singular(ExtraTabCompletion, Expect): + + EXAMPLES:: + +- sage: singular.version() ++ sage: singular.version() # not tested + "Singular ... version 4... + """ + return singular_version() +@@ -2475,7 +2475,7 @@ def singular_version(): + + EXAMPLES:: + +- sage: singular.version() ++ sage: singular.version() # not tested + "Singular ... version 4... + """ + return singular.eval('system("--version");') +-- +2.44.1 + diff --git a/pkgs/applications/science/math/sage/sage-src.nix b/pkgs/applications/science/math/sage/sage-src.nix index 0af3b75dacbc781..26be24bb610fd3f 100644 --- a/pkgs/applications/science/math/sage/sage-src.nix +++ b/pkgs/applications/science/math/sage/sage-src.nix @@ -45,6 +45,9 @@ stdenv.mkDerivation rec { # https://github.com/NixOS/nixpkgs/pull/264126 # Dead links in python sysconfig cause LLVM linker warnings, leading to cython doctest failures. ./patches/silence-linker.patch + + # Stack overflows during doctests; this does not change functionality. + ./patches/disable-singular-doctest.patch ]; # Since sage unfortunately does not release bugfix releases, packagers must From 5d4eccf18ecd326c3aef0628360045986f7cc6e9 Mon Sep 17 00:00:00 2001 From: George Huebner Date: Sun, 21 Jul 2024 23:48:05 -0500 Subject: [PATCH 9/9] sage: add aarch64-darwin to supported platforms --- pkgs/applications/science/math/sage/sage.nix | 2 +- pkgs/development/libraries/science/math/sympow/default.nix | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/applications/science/math/sage/sage.nix b/pkgs/applications/science/math/sage/sage.nix index 81b55e841d244cd..cc39624b7f11077 100644 --- a/pkgs/applications/science/math/sage/sage.nix +++ b/pkgs/applications/science/math/sage/sage.nix @@ -60,6 +60,6 @@ stdenv.mkDerivation rec { homepage = "https://www.sagemath.org"; license = licenses.gpl2Plus; maintainers = teams.sage.members; - platforms = platforms.linux; + platforms = platforms.linux ++ [ "aarch64-darwin" ]; }; } diff --git a/pkgs/development/libraries/science/math/sympow/default.nix b/pkgs/development/libraries/science/math/sympow/default.nix index 57506785a721d21..91714bfd3e708d5 100644 --- a/pkgs/development/libraries/science/math/sympow/default.nix +++ b/pkgs/development/libraries/science/math/sympow/default.nix @@ -80,6 +80,6 @@ stdenv.mkDerivation rec { free = true; }; maintainers = lib.teams.sage.members; - platforms = lib.platforms.linux; + platforms = lib.platforms.unix; }; }