netgen: add support for Darwin platform (#404813)

This commit is contained in:
Robert Scott 2025-05-14 00:09:07 +01:00 committed by GitHub
commit 99d9da5883
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3,7 +3,10 @@
stdenv, stdenv,
fetchFromGitHub, fetchFromGitHub,
fetchpatch2, fetchpatch2,
makeWrapper, libicns,
imagemagick,
makeDesktopItem,
copyDesktopItems,
cmake, cmake,
python3Packages, python3Packages,
mpi, mpi,
@ -66,28 +69,38 @@ stdenv.mkDerivation (finalAttrs: {
url = "${patchSource}/include_stdlib.patch"; url = "${patchSource}/include_stdlib.patch";
hash = "sha256-W+NgGBuy/UmzVbPTSqR8FRUlyN/9dl9l9e9rxKklmIc="; hash = "sha256-W+NgGBuy/UmzVbPTSqR8FRUlyN/9dl9l9e9rxKklmIc=";
}) })
(fetchpatch2 {
url = "${patchSource}/fix-version.patch";
hash = "sha256-CT98Wq3UufB81z/jYLiH9nXvt+QzoZ7210OeuFXCfmc=";
})
]; ];
# when generating python stub file utilizing system python pybind11_stubgen module # when generating python stub file utilizing system python pybind11_stubgen module
# cmake need to inherit pythonpath # cmake need to inherit pythonpath
postPatch = '' postPatch =
substituteInPlace python/CMakeLists.txt \ ''
--replace-fail ''\'''${CMAKE_INSTALL_PREFIX}/''${NG_INSTALL_DIR_PYTHON}' \ sed -i '/-DBDIR=''\'''${CMAKE_CURRENT_BINARY_DIR}/a\
''\'''${CMAKE_INSTALL_PREFIX}/''${NG_INSTALL_DIR_PYTHON}:$ENV{PYTHONPATH}' -DNETGEN_VERSION_GIT=''\'''${NETGEN_VERSION_GIT}
' CMakeLists.txt
substituteInPlace ng/ng.tcl ng/onetcl.cpp \ substituteInPlace python/CMakeLists.txt \
--replace-fail "libnggui" "$out/lib/libnggui" --replace-fail ''\'''${CMAKE_INSTALL_PREFIX}/''${NG_INSTALL_DIR_PYTHON}' \
''; ''\'''${CMAKE_INSTALL_PREFIX}/''${NG_INSTALL_DIR_PYTHON}:$ENV{PYTHONPATH}'
substituteInPlace ng/ng.tcl ng/onetcl.cpp \
--replace-fail "libnggui" "$out/lib/libnggui"
substituteInPlace ng/Togl2.1/CMakeLists.txt \
--replace-fail "/usr/bin/gcc" "$CC"
''
+ lib.optionalString (!stdenv.hostPlatform.isx86_64) ''
# mesh generation differs on x86_64 and aarch64 platform
# test_tutorials will fail on aarch64 platform
rm tests/pytest/test_tutorials.py
'';
nativeBuildInputs = [ nativeBuildInputs = [
libicns
imagemagick
cmake cmake
makeWrapper
python3Packages.pybind11-stubgen python3Packages.pybind11-stubgen
]; ] ++ lib.optional stdenv.hostPlatform.isLinux copyDesktopItems;
buildInputs = [ buildInputs = [
metis metis
@ -111,6 +124,12 @@ stdenv.mkDerivation (finalAttrs: {
cmakeFlags = [ cmakeFlags = [
(lib.cmakeFeature "NETGEN_VERSION_GIT" "v${finalAttrs.version}-0") (lib.cmakeFeature "NETGEN_VERSION_GIT" "v${finalAttrs.version}-0")
(lib.cmakeFeature "NG_INSTALL_DIR_BIN" "bin")
(lib.cmakeFeature "NG_INSTALL_DIR_LIB" "lib")
(lib.cmakeFeature "NG_INSTALL_DIR_CMAKE" "lib/cmake/${finalAttrs.pname}")
(lib.cmakeFeature "NG_INSTALL_DIR_PYTHON" python3Packages.python.sitePackages)
(lib.cmakeFeature "NG_INSTALL_DIR_RES" "share")
(lib.cmakeFeature "NG_INSTALL_DIR_INCLUDE" "include")
(lib.cmakeFeature "CMAKE_CXX_FLAGS" archFlags) (lib.cmakeFeature "CMAKE_CXX_FLAGS" archFlags)
(lib.cmakeBool "USE_MPI" true) (lib.cmakeBool "USE_MPI" true)
(lib.cmakeBool "USE_MPI4PY" true) (lib.cmakeBool "USE_MPI4PY" true)
@ -124,9 +143,45 @@ stdenv.mkDerivation (finalAttrs: {
(lib.cmakeBool "ENABLE_UNIT_TESTS" finalAttrs.finalPackage.doInstallCheck) (lib.cmakeBool "ENABLE_UNIT_TESTS" finalAttrs.finalPackage.doInstallCheck)
]; ];
# mesh generation differs on x86_64 and aarch64 platform __darwinAllowLocalNetworking = true;
# tests will fail on aarch64 platform
doInstallCheck = stdenv.hostPlatform.isx86_64; desktopItems = [
(makeDesktopItem {
name = "netgen";
exec = "netgen";
comment = finalAttrs.meta.description;
desktopName = "Netgen Mesh Generator";
genericName = "3D Mesh Generator";
categories = [ "Science" ];
icon = "netgen";
})
];
postInstall =
lib.optionalString stdenv.hostPlatform.isDarwin ''
rm $out/bin/{Netgen1,startup.sh}
mkdir -p $out/Applications/${finalAttrs.pname}.app/Contents/{MacOS,Resouces}
substituteInPlace $out/Info.plist --replace-fail "Netgen1" "netgen"
mv $out/Info.plist $out/Applications/${finalAttrs.pname}.app/Contents
mv $out/Netgen.icns $out/Applications/${finalAttrs.pname}.app/Contents/Resouces
ln -s $out/bin/netgen $out/Applications/${finalAttrs.pname}.app/Contents/MacOS/netgen
''
+ lib.optionalString stdenv.hostPlatform.isLinux ''
# Extract pngs from the Apple icon image and create
# the missing ones from the 512x512 image.
icns2png --extract ../netgen.icns
for size in 16 24 32 48 64 128 256 512; do
mkdir -pv $out/share/icons/hicolor/"$size"x"$size"/apps
if [ -e netgen_"$size"x"$size"x32.png ]
then
mv netgen_"$size"x"$size"x32.png $out/share/icons/hicolor/"$size"x"$size"/apps/netgen.png
else
convert -resize "$size"x"$size" netgen_512x512x32.png $out/share/icons/hicolor/"$size"x"$size"/apps/netgen.png
fi
done;
'';
doInstallCheck = true;
preInstallCheck = '' preInstallCheck = ''
export PYTHONPATH=$out/${python3Packages.python.sitePackages}:$PYTHONPATH export PYTHONPATH=$out/${python3Packages.python.sitePackages}:$PYTHONPATH
@ -139,15 +194,19 @@ stdenv.mkDerivation (finalAttrs: {
python3Packages.pytest python3Packages.pytest
python3Packages.pytest-check python3Packages.pytest-check
python3Packages.pytest-mpi python3Packages.pytest-mpi
python3Packages.pythonImportsCheckHook
mpiCheckPhaseHook mpiCheckPhaseHook
]; ];
pythonImportsCheck = [ "netgen" ];
passthru = { passthru = {
inherit avxSupport avx2Support avx512Support; inherit avxSupport avx2Support avx512Support;
}; };
meta = { meta = {
homepage = "https://ngsolve.org"; homepage = "https://ngsolve.org";
downloadPage = "https://github.com/NGSolve/netgen";
description = "Atomatic 3d tetrahedral mesh generator"; description = "Atomatic 3d tetrahedral mesh generator";
license = with lib.licenses; [ license = with lib.licenses; [
lgpl2Plus lgpl2Plus
@ -157,10 +216,7 @@ stdenv.mkDerivation (finalAttrs: {
boost boost
publicDomain publicDomain
]; ];
platforms = [ platforms = lib.platforms.unix;
"x86_64-linux"
"aarch64-linux"
];
mainProgram = "netgen"; mainProgram = "netgen";
maintainers = with lib.maintainers; [ qbisi ]; maintainers = with lib.maintainers; [ qbisi ];
}; };