Subject: [bug#78555] [PATCH] gnu: Add pythonscad

From: nomike <[email-masked]>
Date: Fri, 23 May 2025 04:00:40 +0200

* gnu/packages/engineering.scm (pythonscad): New variable

Change-Id: I66737d0eaaa7546dcd407d7371166c9b5d5d9b31
---
 gnu/packages/engineering.scm | 77 +++++++++++++++++++++++++++++++++++-
 1 file changed, 75 insertions(+), 2 deletions(-)

diff --git a/gnu/packages/engineering.scm b/gnu/packages/engineering.scm
index 8b1332e186..c81f4d5dbe 100644
--- a/gnu/packages/engineering.scm
+++ b/gnu/packages/engineering.scm
@@ -3315,6 +3315,79 @@ (define-public openscad
       (home-page "https://openscad.org/")
       (license license:gpl2+))))
 
+(define-public pythonscad
+  (let ((commit "b856456fcf26e089a616e5a9b5d685b8a8f2e2c1")
+        (version "2025.05.21")
+        (revision "0"))
+    (package
+      (inherit openscad)
+      (name "pythonscad")
+      (version (git-version version revision commit))
+      (source
+       (origin
+         (method git-fetch)
+         (uri (git-reference
+               (url "https://github.com/pythonscad/pythonscad")
+               (commit commit)
+               (recursive? #t)))
+         (sha256
+          (base32 "0bjpvj94m3kplpnmnlai7mjx45d5acnqw943w3p1mprg8wrp3ap6"))
+         (file-name (git-file-name name version))))
+      (arguments
+       (list
+        #:configure-flags
+        #~(list "-DCMAKE_BUILD_TYPE=Release"
+                "-DUSE_BUILTIN_OPENCSG=ON"
+                "-DMANIFOLD_PYBIND=OFF"
+                "-DMANIFOLD_TEST=OFF"
+                "-DENABLE_TESTS=OFF"
+                "-DEXPERIMENTAL=ON"
+                "-DSNAPSHOT=ON"
+                "-DENABLE_PYTHON=ON"
+                (string-append "-DPYTHON_VERSION="
+                               (string-join (reverse (list-tail (reverse (string-split #$
+                                                                          (package-version
+                                                                           (this-package-input
+                                                                            "python"))
+                                                                          #\.))
+                                                                1)) "."))
+                "-DUSE_BUILTIN_CLIPPER2=OFF"
+                (string-append "-DOPENSCAD_VERSION="
+                               #$version)
+                (string-append "-DOPENSCAD_COMMIT="
+                               #$commit)
+                "-DENABLE_EGL=ON"
+                "-DENABLE_GLX=ON")
+        #:phases
+        #~(modify-phases %standard-phases
+            (delete 'check)
+            (add-after 'unpack 'patch-source
+              (lambda* (#:key inputs #:allow-other-keys)
+                ;; <https://github.com/openscad/openscad/issues/5877>
+                (substitute* "cmake/Modules/FindLib3MF.cmake"
+                  (("PC_LIB3MF_INCLUDE_DIRS")
+                   "PC_LIB3MF_INCLUDEDIR"))
+                (substitute* "CMakeLists.txt"
+                  ;; <https://github.com/openscad/openscad/issues/5880>
+                  (("target_link_libraries\\(OpenSCAD PRIVATE OpenGL::EGL\\)")
+                   "      find_package(ECM REQUIRED NO_MODULE)
+      list(APPEND CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
+      find_package(EGL REQUIRED)
+      target_link_libraries(OpenSCAD PRIVATE EGL::EGL)")
+                  ;; <https://github.com/openscad/openscad/issues/5897>
+                  (("find_package\\(Nettle 3.4\\)")
+                   "find_package(Nettle 3.4 REQUIRED)")
+                  ;; Use the system sanitizers-cmake module.
+                  (("\\$\\{CMAKE_SOURCE_DIR\\}/submodules/sanitizers-cmake/cmake")
+                   (string-append (assoc-ref inputs "sanitizers-cmake")
+                                  "/share/sanitizers-cmake/cmake"))))))))
+      (inputs (modify-inputs (package-inputs openscad)
+                (append libjpeg-turbo curl python nettle)))
+      (home-page "https://openscad.org/")
+      (description
+       "A fork of @code{OpenSCAD} that lets you use Python as its native language."))))
+
+
 (define-public emacs-scad-mode
   (package
     (name "emacs-scad-mode")
@@ -3349,8 +3422,8 @@ (define-public emacs-scad-mode
 @item
 Org Babel support (@code{scad} source blocks)
 @end itemize")
-    (home-page "https://openscad.org/")
-    (license license:gpl3+)))
+   (home-page "https://openscad.org/")
+   (license license:gpl3+)))
 
 (define-public emacs-scad-dbus
   (package
-- 
2.49.0