libfive: add python bindings

This commit is contained in:
Wulfsta 2023-10-15 00:50:08 -04:00
parent d6c2a45122
commit b3858cb6b8
3 changed files with 36 additions and 4 deletions

View File

@ -10,6 +10,7 @@
, libpng , libpng
, boost , boost
, guile , guile
, python
, qtbase , qtbase
, darwin , darwin
}: }:
@ -25,8 +26,8 @@ stdenv.mkDerivation {
hash = "sha256-OITy3fJx+Z6856V3D/KpSQRJztvOdJdqUv1c65wNgCc="; hash = "sha256-OITy3fJx+Z6856V3D/KpSQRJztvOdJdqUv1c65wNgCc=";
}; };
nativeBuildInputs = [ wrapQtAppsHook cmake ninja pkg-config ]; nativeBuildInputs = [ wrapQtAppsHook cmake ninja pkg-config python.pkgs.pythonImportsCheckHook ];
buildInputs = [ eigen zlib libpng boost guile qtbase ] buildInputs = [ eigen zlib libpng boost guile python qtbase ]
++ lib.optionals stdenv.isDarwin [ darwin.apple_sdk_11_0.frameworks.Cocoa ]; ++ lib.optionals stdenv.isDarwin [ darwin.apple_sdk_11_0.frameworks.Cocoa ];
preConfigure = '' preConfigure = ''
@ -42,6 +43,14 @@ stdenv.mkDerivation {
--replace "LIBFIVE_STDLIB_DIR=$<TARGET_FILE_DIR:libfive-stdlib>" \ --replace "LIBFIVE_STDLIB_DIR=$<TARGET_FILE_DIR:libfive-stdlib>" \
"LIBFIVE_STDLIB_DIR=$out/lib" "LIBFIVE_STDLIB_DIR=$out/lib"
substituteInPlace libfive/bind/python/CMakeLists.txt \
--replace ' ''${PYTHON_SITE_PACKAGES_DIR}' \
" $out/${python.sitePackages}" \
substituteInPlace libfive/bind/python/libfive/ffi.py \
--replace "os.path.join('libfive', folder)" \
"os.path.join('$out/${python.sitePackages}/libfive', folder)" \
export XDG_CACHE_HOME=$(mktemp -d)/.cache export XDG_CACHE_HOME=$(mktemp -d)/.cache
''; '';
@ -63,12 +72,29 @@ stdenv.mkDerivation {
'' + '' '' + ''
# Link "Studio" binary to "libfive-studio" to be more obvious: # Link "Studio" binary to "libfive-studio" to be more obvious:
ln -s "$out/bin/Studio" "$out/bin/libfive-studio" ln -s "$out/bin/Studio" "$out/bin/libfive-studio"
# Create links since libfive looks for the library in a specific path.
mkdir -p "$out/${python.sitePackages}/libfive/src"
ln -s "$out"/lib/libfive.* "$out/${python.sitePackages}/libfive/src/"
mkdir -p "$out/${python.sitePackages}/libfive/stdlib"
ln -s "$out"/lib/libfive-stdlib.* "$out/${python.sitePackages}/libfive/stdlib/"
# Create links so Studio can find the bindings.
mkdir -p "$out/libfive/bind"
ln -s "$out/${python.sitePackages}" "$out/libfive/bind/python"
''; '';
pythonImportsCheck = [
"libfive"
"libfive.runner"
"libfive.shape"
"libfive.stdlib"
];
meta = with lib; { meta = with lib; {
description = "Infrastructure for solid modeling with F-Reps in C, C++, and Guile"; description = "Infrastructure for solid modeling with F-Reps in C, C++, and Guile";
homepage = "https://libfive.com/"; homepage = "https://libfive.com/";
maintainers = with maintainers; [ hodapp kovirobi ]; maintainers = with maintainers; [ hodapp kovirobi wulfsta ];
license = with licenses; [ mpl20 gpl2Plus ]; license = with licenses; [ mpl20 gpl2Plus ];
platforms = with platforms; all; platforms = with platforms; all;
}; };

View File

@ -22848,7 +22848,9 @@ with pkgs;
libfabric = callPackage ../development/libraries/libfabric { }; libfabric = callPackage ../development/libraries/libfabric { };
libfive = qt6Packages.callPackage ../development/libraries/libfive { }; libfive = qt6Packages.callPackage ../development/libraries/libfive {
python = python3;
};
libfixposix = callPackage ../development/libraries/libfixposix { }; libfixposix = callPackage ../development/libraries/libfixposix { };

View File

@ -6084,6 +6084,10 @@ self: super: with self; {
pythonSupport = true; pythonSupport = true;
}); });
libfive = toPythonModule (pkgs.libfive.override {
inherit python;
});
libgpiod = callPackage ../development/python-modules/libgpiod { libgpiod = callPackage ../development/python-modules/libgpiod {
inherit (pkgs) libgpiod; inherit (pkgs) libgpiod;
}; };