1{
2 lib,
3 stdenv,
4 wrapQtAppsHook,
5 fetchFromGitHub,
6 unstableGitUpdater,
7 cmake,
8 ninja,
9 pkg-config,
10 eigen,
11 zlib,
12 libpng,
13 boost,
14 guile,
15 python,
16 qtbase,
17 darwin,
18}:
19
20stdenv.mkDerivation {
21 pname = "libfive";
22 version = "0-unstable-2024-10-10";
23
24 src = fetchFromGitHub {
25 owner = "libfive";
26 repo = "libfive";
27 rev = "71899313d36ce14de6646ef760fa6bbc5c0cc067";
28 hash = "sha256-bA+4wGAygdbHcOMGFwNyzn2daQ8E7NeOTUF2Tr3RQww=";
29 };
30
31 nativeBuildInputs = [
32 wrapQtAppsHook
33 cmake
34 ninja
35 pkg-config
36 python.pkgs.pythonImportsCheckHook
37 ];
38 buildInputs = [
39 eigen
40 zlib
41 libpng
42 boost
43 guile
44 python
45 qtbase
46 ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ darwin.apple_sdk_11_0.frameworks.Cocoa ];
47
48 preConfigure = ''
49 substituteInPlace studio/src/guile/interpreter.cpp \
50 --replace '"libfive/bind/guile"' \
51 '"libfive/bind/guile:${placeholder "out"}/${guile.siteCcacheDir}"' \
52 --replace '(app_resource_dir + ":" + finder_build_dir).toLocal8Bit()' \
53 '"libfive/bind/guile:${placeholder "out"}/${guile.siteCcacheDir}"'
54
55 substituteInPlace libfive/bind/guile/CMakeLists.txt \
56 --replace "LIBFIVE_FRAMEWORK_DIR=$<TARGET_FILE_DIR:libfive>" \
57 "LIBFIVE_FRAMEWORK_DIR=$out/lib" \
58 --replace "LIBFIVE_STDLIB_DIR=$<TARGET_FILE_DIR:libfive-stdlib>" \
59 "LIBFIVE_STDLIB_DIR=$out/lib"
60
61 substituteInPlace libfive/bind/python/CMakeLists.txt \
62 --replace ' ''${PYTHON_SITE_PACKAGES_DIR}' \
63 " $out/${python.sitePackages}" \
64
65 substituteInPlace libfive/bind/python/libfive/ffi.py \
66 --replace "os.path.join('libfive', folder)" \
67 "os.path.join('$out/${python.sitePackages}/libfive', folder)" \
68
69 export XDG_CACHE_HOME=$(mktemp -d)/.cache
70 '';
71
72 cmakeFlags =
73 [
74 "-DGUILE_CCACHE_DIR=${placeholder "out"}/${guile.siteCcacheDir}"
75 ]
76 ++ lib.optionals
77 (stdenv.hostPlatform.isDarwin && lib.versionOlder stdenv.hostPlatform.darwinMinVersion "11")
78 [
79 # warning: 'aligned_alloc' is only available on macOS 10.15 or newer
80 "-DCMAKE_OSX_DEPLOYMENT_TARGET=10.15"
81 ];
82
83 env = lib.optionalAttrs stdenv.cc.isClang {
84 NIX_CFLAGS_COMPILE = "-Wno-error=enum-constexpr-conversion";
85 };
86
87 postInstall =
88 lib.optionalString stdenv.hostPlatform.isDarwin ''
89 # No rules to install the mac app, so do it manually.
90 mkdir -p $out/Applications
91 cp -r studio/Studio.app $out/Applications/Studio.app
92
93 install_name_tool -add_rpath $out/lib $out/Applications/Studio.app/Contents/MacOS/Studio
94
95 makeWrapper $out/Applications/Studio.app/Contents/MacOS/Studio $out/bin/Studio
96 ''
97 + ''
98 # Link "Studio" binary to "libfive-studio" to be more obvious:
99 ln -s "$out/bin/Studio" "$out/bin/libfive-studio"
100
101 # Create links since libfive looks for the library in a specific path.
102 mkdir -p "$out/${python.sitePackages}/libfive/src"
103 ln -s "$out"/lib/libfive.* "$out/${python.sitePackages}/libfive/src/"
104 mkdir -p "$out/${python.sitePackages}/libfive/stdlib"
105 ln -s "$out"/lib/libfive-stdlib.* "$out/${python.sitePackages}/libfive/stdlib/"
106
107 # Create links so Studio can find the bindings.
108 mkdir -p "$out/libfive/bind"
109 ln -s "$out/${python.sitePackages}" "$out/libfive/bind/python"
110 '';
111
112 pythonImportsCheck = [
113 "libfive"
114 "libfive.runner"
115 "libfive.shape"
116 "libfive.stdlib"
117 ];
118
119 passthru.updateScript = unstableGitUpdater {
120 tagFormat = "";
121 };
122
123 meta = with lib; {
124 description = "Infrastructure for solid modeling with F-Reps in C, C++, and Guile";
125 homepage = "https://libfive.com/";
126 maintainers = with maintainers; [
127 hodapp
128 kovirobi
129 wulfsta
130 ];
131 license = with licenses; [
132 mpl20
133 gpl2Plus
134 ];
135 platforms = with platforms; all;
136 };
137}