From b2557f76532a4d3804615f9e64cff3bc732b199b Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Fri, 30 Dec 2022 09:16:19 -0500 Subject: [PATCH 1/5] gmsh: Enable shared library This allows use of the Python and other bindings. --- pkgs/applications/science/math/gmsh/default.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkgs/applications/science/math/gmsh/default.nix b/pkgs/applications/science/math/gmsh/default.nix index 22eee8b305a5..23c1e1dab2a3 100644 --- a/pkgs/applications/science/math/gmsh/default.nix +++ b/pkgs/applications/science/math/gmsh/default.nix @@ -20,6 +20,12 @@ stdenv.mkDerivation rec { xorg.libICE ]; + # N.B. the shared object is used by bindings + cmakeFlags = [ + "-DENABLE_BUILD_SHARED=ON" + "-DENABLE_BUILD_DYNAMIC=ON" + ]; + nativeBuildInputs = [ cmake gfortran ]; doCheck = true; From 24de35c698cf210cc23a711e7ce5ca40044d93fb Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Fri, 30 Dec 2022 09:18:27 -0500 Subject: [PATCH 2/5] gmsh: 4.11 -> 4.11.1 --- pkgs/applications/science/math/gmsh/default.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/applications/science/math/gmsh/default.nix b/pkgs/applications/science/math/gmsh/default.nix index 23c1e1dab2a3..0ae213e60135 100644 --- a/pkgs/applications/science/math/gmsh/default.nix +++ b/pkgs/applications/science/math/gmsh/default.nix @@ -5,11 +5,11 @@ assert (!blas.isILP64) && (!lapack.isILP64); stdenv.mkDerivation rec { pname = "gmsh"; - version = "4.11.0"; + version = "4.11.1"; src = fetchurl { url = "https://gmsh.info/src/gmsh-${version}-source.tgz"; - sha256 = "sha256-PPLyRFXuCSUsmeZNTmRilW5o8P8fN7rKC3jICdbMVXo="; + sha256 = "sha256-xf4bfL1AOIioFJKfL9D11p4nYAIioYx4bbW3boAFs2U="; }; buildInputs = [ From 0af966f3681e7608b3afaf6a68713c7d87ed68a0 Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Wed, 4 Jan 2023 11:24:04 -0500 Subject: [PATCH 3/5] gmsh: Enable OpenMP support As this is parallelism that essentially comes for free. --- pkgs/applications/science/math/gmsh/default.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/applications/science/math/gmsh/default.nix b/pkgs/applications/science/math/gmsh/default.nix index 0ae213e60135..f88e59857aa1 100644 --- a/pkgs/applications/science/math/gmsh/default.nix +++ b/pkgs/applications/science/math/gmsh/default.nix @@ -24,6 +24,7 @@ stdenv.mkDerivation rec { cmakeFlags = [ "-DENABLE_BUILD_SHARED=ON" "-DENABLE_BUILD_DYNAMIC=ON" + "-DENABLE_OPENMP=ON" ]; nativeBuildInputs = [ cmake gfortran ]; From 4ed69ca0957e29c40bcabb6f55c634b590b3a669 Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Fri, 6 Jan 2023 15:12:02 -0500 Subject: [PATCH 4/5] gmsh: enable parallel building --- pkgs/applications/science/math/gmsh/default.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/applications/science/math/gmsh/default.nix b/pkgs/applications/science/math/gmsh/default.nix index f88e59857aa1..3153c128057a 100644 --- a/pkgs/applications/science/math/gmsh/default.nix +++ b/pkgs/applications/science/math/gmsh/default.nix @@ -20,6 +20,8 @@ stdenv.mkDerivation rec { xorg.libICE ]; + enableParallelBuilding = true; + # N.B. the shared object is used by bindings cmakeFlags = [ "-DENABLE_BUILD_SHARED=ON" From 34dd176116870d24d6a5b93e263e79edad06fd00 Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Fri, 6 Jan 2023 15:11:47 -0500 Subject: [PATCH 5/5] gmsh: enable python bindings --- .../science/math/gmsh/default.nix | 18 ++++++- .../science/math/gmsh/fix-python.patch | 50 +++++++++++++++++++ pkgs/top-level/python-packages.nix | 4 ++ 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 pkgs/applications/science/math/gmsh/fix-python.patch diff --git a/pkgs/applications/science/math/gmsh/default.nix b/pkgs/applications/science/math/gmsh/default.nix index 3153c128057a..4d9b3afe31ca 100644 --- a/pkgs/applications/science/math/gmsh/default.nix +++ b/pkgs/applications/science/math/gmsh/default.nix @@ -1,7 +1,9 @@ { lib, stdenv, fetchurl, cmake, blas, lapack, gfortran, gmm, fltk, libjpeg -, zlib, libGL, libGLU, xorg, opencascade-occt }: +, zlib, libGL, libGLU, xorg, opencascade-occt +, python ? null, enablePython ? false }: assert (!blas.isILP64) && (!lapack.isILP64); +assert enablePython -> (python != null); stdenv.mkDerivation rec { pname = "gmsh"; @@ -18,10 +20,16 @@ stdenv.mkDerivation rec { libGL libGLU xorg.libXrender xorg.libXcursor xorg.libXfixes xorg.libXext xorg.libXft xorg.libXinerama xorg.libX11 xorg.libSM xorg.libICE - ]; + ] ++ lib.optional enablePython python; enableParallelBuilding = true; + patches = [ ./fix-python.patch ]; + + postPatch = '' + substituteInPlace api/gmsh.py --subst-var-by LIBPATH ${placeholder "out"}/lib/libgmsh.so + ''; + # N.B. the shared object is used by bindings cmakeFlags = [ "-DENABLE_BUILD_SHARED=ON" @@ -31,6 +39,12 @@ stdenv.mkDerivation rec { nativeBuildInputs = [ cmake gfortran ]; + postFixup = lib.optionalString enablePython '' + mkdir -p $out/lib/python${python.pythonVersion}/site-packages + mv $out/lib/gmsh.py $out/lib/python${python.pythonVersion}/site-packages + mv $out/lib/*.dist-info $out/lib/python${python.pythonVersion}/site-packages + ''; + doCheck = true; meta = { diff --git a/pkgs/applications/science/math/gmsh/fix-python.patch b/pkgs/applications/science/math/gmsh/fix-python.patch new file mode 100644 index 000000000000..ac07c169c99b --- /dev/null +++ b/pkgs/applications/science/math/gmsh/fix-python.patch @@ -0,0 +1,50 @@ +diff --git a/api/gmsh.py b/api/gmsh.py +index 747acb203..02004da5d 100644 +--- a/api/gmsh.py ++++ b/api/gmsh.py +@@ -44,44 +44,7 @@ moduledir = os.path.dirname(os.path.realpath(__file__)) + parentdir1 = os.path.dirname(moduledir) + parentdir2 = os.path.dirname(parentdir1) + +-if platform.system() == "Windows": +- libname = "gmsh-4.11.dll" +-elif platform.system() == "Darwin": +- libname = "libgmsh.4.11.dylib" +-else: +- libname = "libgmsh.so.4.11" +- +-# check if the library is in the same directory as the module... +-libpath = os.path.join(moduledir, libname) +- +-# ... or in the parent directory or its lib or Lib subdirectory +-if not os.path.exists(libpath): +- libpath = os.path.join(parentdir1, libname) +-if not os.path.exists(libpath): +- libpath = os.path.join(parentdir1, "lib", libname) +-if not os.path.exists(libpath): +- libpath = os.path.join(parentdir1, "Lib", libname) +- +-# ... or in the parent of the parent directory or its lib or Lib subdirectory +-if not os.path.exists(libpath): +- libpath = os.path.join(parentdir2, libname) +-if not os.path.exists(libpath): +- libpath = os.path.join(parentdir2, "lib", libname) +-if not os.path.exists(libpath): +- libpath = os.path.join(parentdir2, "Lib", libname) +- +-# if we couldn't find it, use ctype's find_library utility... +-if not os.path.exists(libpath): +- if platform.system() == "Windows": +- libpath = find_library("gmsh-4.11") +- if not libpath: +- libpath = find_library("gmsh") +- else: +- libpath = find_library("gmsh") +- +-# ... and print a warning if everything failed +-if not os.path.exists(libpath): +- print("Warning: could not find Gmsh shared library " + libname) ++libpath = "@LIBPATH@" + + lib = CDLL(libpath) + diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index d47835b1568e..972ae3b4b3df 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -3807,6 +3807,10 @@ self: super: with self; { gmpy = callPackage ../development/python-modules/gmpy { }; + gmsh = toPythonModule (callPackage ../applications/science/math/gmsh { + enablePython = true; + }); + gntp = callPackage ../development/python-modules/gntp { }; gnureadline = callPackage ../development/python-modules/gnureadline { };