Subject: [PATCH] Correct freecad runtime errors

From: Ekaitz Zarraga <[email-masked]>
Date: Thu, 31 Dec 2020 18:47:59 +0000

Hi,

I attach 4 patches that correct the runtime issues freecad has and also supply some packages needed as a dependency.

Freecad is a very complex package that is hard to build because many of its dependencies' buildsystem is broken. The approach followed here is the same that Nix follows and appears to work correctly.

The changes correct the Draft module, which wasn't available because pivy was not added as a dependency.

For context, see this message:
https://lists.gnu.org/archive/html/guix-devel/2020-12/msg00123.html

Thanks

From 8b6b170a6e810c6de896555702b7730a29b2568c Mon Sep 17 00:00:00 2001
From: Ekaitz Zarraga <[email-masked]>
Date: Thu, 31 Dec 2020 19:32:34 +0100
Subject: [PATCH 1/4] gnu: Add coin3D-4.

    * gnu/packages/graphics.scm (coin3D-4): New variable.
---
 gnu/packages/graphics.scm | 49 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/gnu/packages/graphics.scm b/gnu/packages/graphics.scm
index 7a61084f24..86f68e4cb7 100644
--- a/gnu/packages/graphics.scm
+++ b/gnu/packages/graphics.scm
@@ -1732,6 +1732,55 @@ standard graphics library for 3D visualization and visual simulation
 software in the scientific and engineering community.")
       (license license:bsd-3))))
 
+(define-public coin3D-4
+    (package
+    (name "coin3D-4")
+    (version "4.0.0")
+    (source
+      (origin
+        (method git-fetch)
+        (uri (git-reference
+               (url "https://github.com/coin3d/coin")
+               (commit (string-append "Coin-" version))
+               (recursive? #t)))
+        (file-name (git-file-name name version))
+        (sha256
+          (base32 "1ayg0hl8wanhadahm5xbghghxw1qjwqbrs3dl3ngnff027hsyf8p"))
+        (modules '((guix build utils)))
+        (snippet
+          '(begin
+             (for-each delete-file
+                       '("cfg/csubst.exe"
+                         "cfg/wrapmsvc.exe"))
+             (substitute* "CMakeLists.txt"
+               ((".*cpack.d.*") ""))
+             #t))))
+    (build-system cmake-build-system)
+    (native-inputs
+      `(("doxygen" ,doxygen)
+        ("graphviz" ,graphviz)))
+    (inputs
+      `(("boost" ,boost)
+        ("freeglut" ,freeglut)
+        ("glew" ,glew)))
+    (arguments
+      `(#:configure-flags
+        (list
+          "-DCOIN_BUILD_DOCUMENTATION_MAN=ON"
+          (string-append "-DBOOST_ROOT="
+                         (assoc-ref %build-inputs "boost")))))
+    (home-page "https://github.com/coin3d/coin")
+    (synopsis
+      "High-level 3D visualization library with Open Inventor 2.1 API")
+    (description
+      "Coin is a 3D graphics library with an Application Programming Interface
+based on the Open Inventor 2.1 API.  For those who are not familiar with Open
+Inventor, it is a scene-graph based retain-mode rendering and model interaction
+library, written in C++, which has become the de facto standard graphics
+library for 3D visualization and visual simulation software in the scientific
+and engineering community.")
+      (license license:bsd-3)))
+
 (define-public superfamiconv
   (package
     (name "superfamiconv")
-- 
2.29.2

From 3a4cc6fcd17d4ba4d45b15833caecf81c8f516ac Mon Sep 17 00:00:00 2001
From: Ekaitz Zarraga <[email-masked]>
Date: Thu, 31 Dec 2020 19:35:28 +0100
Subject: [PATCH 3/4] gnu: Add python-pivy.

    * gnu/packages/python-xyz.scm (python-pivy): New variable.
---
 gnu/packages/python-xyz.scm | 43 +++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/gnu/packages/python-xyz.scm b/gnu/packages/python-xyz.scm
index d07c91121a..83b55a329a 100644
--- a/gnu/packages/python-xyz.scm
+++ b/gnu/packages/python-xyz.scm
@@ -175,6 +175,7 @@
   #:use-module (gnu packages shells)
   #:use-module (gnu packages sphinx)
   #:use-module (gnu packages ssh)
+  #:use-module (gnu packages swig)
   #:use-module (gnu packages terminals)
   #:use-module (gnu packages tex)
   #:use-module (gnu packages texinfo)
@@ -23238,3 +23239,45 @@ process.")
      "Gamera is a toolkit for building document image recognition systems.")
     (home-page "https://gamera.informatik.hsnr.de/")
     (license license:gpl2+)))
+
+(define-public python-pivy
+  (package
+    (name "python-pivy")
+    (version "0.6.5")
+    (source
+      (origin
+        (method git-fetch)
+        (uri (git-reference
+               (url "https://github.com/coin3d/pivy")
+               (commit version)))
+        (file-name (git-file-name name version))
+        (sha256
+          (base32 "0vids7sxk8w5vr73xdnf8xdci71a7syl6cd35aiisppbqyyfmykx"))
+
+        (modules '((guix build utils)))
+        (snippet
+          '(begin
+             (substitute* "CMakeLists.txt"
+                          (("\\$\\{SoQt_INCLUDE_DIRS}")
+                           "${Coin_INCLUDE_DIR};${SoQt_INCLUDE_DIRS}"))
+             #t))))
+    (build-system python-build-system)
+    (arguments
+      `(#:tests? #f))
+    (native-inputs
+      `(("cmake" ,cmake)
+        ("swig" ,swig)))
+    (inputs
+      `(("python-wrapper" ,python-wrapper)
+        ("qtbase" ,qtbase)
+        ("libxi" ,libxi)
+        ("libice" ,libice)
+        ("soqt" ,soqt)
+        ("glew" ,glew)
+        ("coin3D-4" ,coin3D-4)))
+    (home-page "https://github.com/coin3d/pivy")
+    (synopsis "Python bindings to Coin3D")
+    (description
+      "Pivy provides python bindings for Coin, a 3D graphics library with an
+Application Programming Interface based on the Open Inventor 2.1 API.")
+    (license license:isc)))
-- 
2.29.2

From e1e59a8a15908747305b629005d63116a1c34f34 Mon Sep 17 00:00:00 2001
From: Ekaitz Zarraga <[email-masked]>
Date: Thu, 31 Dec 2020 19:36:14 +0100
Subject: [PATCH 4/4] gnu: freecad correct runtime errors

    * gnu/packages/engineering.scm (freecad): Update package
    [inputs]: Move python-pyside-2-tools to native-inputs
    [inputs]: Add pivy
    [inputs]: Add qtxmlpatterns
    [inputs]: Add qtwebkit
---
 gnu/packages/engineering.scm | 50 ++++++++++++++++--------------------
 1 file changed, 22 insertions(+), 28 deletions(-)

diff --git a/gnu/packages/engineering.scm b/gnu/packages/engineering.scm
index e436994492..f8563085ac 100644
--- a/gnu/packages/engineering.scm
+++ b/gnu/packages/engineering.scm
@@ -36,7 +36,6 @@
 ;;;
 ;;; You should have received a copy of the GNU General Public License
 ;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
-
 (define-module (gnu packages engineering)
   #:use-module (guix packages)
   #:use-module (guix download)
@@ -2431,35 +2430,30 @@ full programmatic control over your models.")
     (home-page "https://www.openscad.org/")
     (license license:gpl2+)))
 
+
 (define-public freecad
-  (package
-    (name "freecad")
-    (version "0.18.5")
-    (source
-     (origin
-       (method git-fetch)
-       (uri (git-reference
-             (url "https://github.com/FreeCAD/FreeCAD")
-             (commit version)))
-       (modules '((guix build utils)))
-       (snippet
-        '(begin
-           ;; Fix build with Python 3.8, see
-           ;; <https://tracker.freecadweb.org/view.php?id=4143>.
-           (substitute* "src/Base/swigpyrun.inl"
-             (("PyObject \\*modules = interp->modules;")
-              "PyObject *modules = PyEval_GetBuiltins();"))
-           #t))
-       (file-name (git-file-name name version))
-       (sha256
-        (base32
-         "0r31jzzkamf76l19fb175hhv48irk06fpi8ldxdlr31w8c1ix4aa"))))
+  (let ((commit-ref "7616153b3c31ace006169cdc2fdafab484498858")
+        (revision "1"))
+    (package
+      (name "freecad")
+      (version (git-version "0.18.5" revision commit-ref))
+      (source
+        (origin
+          (method git-fetch)
+          (uri (git-reference
+                 (url "https://github.com/FreeCAD/FreeCAD")
+                 (commit commit-ref)))
+          (file-name (git-file-name name version))
+          (sha256
+            (base32
+              "16965yxnp2pq7nm8z3p0pjkzjdyq62vfrj8j3nk26bwc898czyn2"))))
     (build-system qt-build-system)
     (native-inputs
      `(("doxygen" ,doxygen)
        ("graphviz" ,graphviz)
        ("qttools" ,qttools)
        ("pkg-config" ,pkg-config)
+       ("python-pyside-2-tools" ,python-pyside-2-tools)
        ("swig" ,swig)))
     (inputs
      `(("boost" ,boost)
@@ -2477,16 +2471,15 @@ full programmatic control over your models.")
        ("opencascade-occt" ,opencascade-occt)
        ("python-matplotlib" ,python-matplotlib)
        ("python-pyside-2" ,python-pyside-2)
-       ("python-pyside-2-tools" ,python-pyside-2-tools)
        ("python-shiboken-2" ,python-shiboken-2)
+       ("python-pivy" ,python-pivy)
        ("python-wrapper" ,python-wrapper)
        ("qtbase" ,qtbase)
        ("qtsvg" ,qtsvg)
        ("qtx11extras" ,qtx11extras)
        ("qtxmlpatterns" ,qtxmlpatterns)
-       ;; qtwebkit is optional. We remove it currently, because it takes
-       ;; much time to compile and substitutes are often unavailable
-       ;;("qtwebkit" ,qtwebkit)
+       ("qtwebkit" ,qtwebkit)
+       ("qtxmlpatterns" ,qtxmlpatterns)
        ("tbb" ,tbb)
        ("vtk" ,vtk)
        ("xerces-c" ,xerces-c)
@@ -2546,7 +2539,8 @@ customization.")
       license:lgpl2.1+
       license:lgpl2.0+
       license:gpl3+
-      license:bsd-3))))
+      license:bsd-3)))))
+
 
 (define-public libmedfile
   (package
-- 
2.29.2

From 3c3fde8f5aa3433de076d6bbb90f9e60333f31b0 Mon Sep 17 00:00:00 2001
From: Ekaitz Zarraga <[email-masked]>
Date: Thu, 31 Dec 2020 19:34:45 +0100
Subject: [PATCH 2/4] gnu: Add soqt.

    * gnu/packages/qt.scm (soqt): New variable.
---
 gnu/packages/qt.scm | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/gnu/packages/qt.scm b/gnu/packages/qt.scm
index 2e621e758c..2af7e40734 100644
--- a/gnu/packages/qt.scm
+++ b/gnu/packages/qt.scm
@@ -67,6 +67,7 @@
   #:use-module (gnu packages glib)
   #:use-module (gnu packages gnupg)
   #:use-module (gnu packages gperf)
+  #:use-module (gnu packages graphics)
   #:use-module (gnu packages gstreamer)
   #:use-module (gnu packages gtk)
   #:use-module (gnu packages icu4c)
@@ -2824,3 +2825,36 @@ being fully customizable and easy to extend.")
     ;; According to LICENSE, either version 2 or version 3 of the GNU GPL may
     ;; be used.
     (license (list license:gpl2 license:gpl3))))
+
+
+(define-public soqt
+  (let ((commit-ref "fb8f655632bb9c9c60e0ff9fa69a5ba22d3ff99d")
+        (revision "1"))
+    (package
+    (name "soqt")
+    (version (git-version "1.6.0" revision commit-ref))
+    (source
+      (origin
+        (method git-fetch)
+        (uri (git-reference
+               (url "https://github.com/coin3d/soqt")
+               (commit commit-ref)
+               (recursive? #t)))
+        (file-name (git-file-name name version))
+        (sha256
+          (base32 "16vikb3fy8rmk10sg5g0gy2c343hi3x7zccsga90ssnkzpq6m032"))))
+    (build-system cmake-build-system)
+    (arguments
+      '(#:tests? #f))
+    (native-inputs
+      `(("pkg-config" ,pkg-config)
+        ("cmake" ,cmake)))
+    (inputs
+      `(("qtbase" ,qtbase)
+        ("coin3D-4" ,coin3D-4)))
+    (home-page "https://github.com/coin3d/soqt")
+    (synopsis "Qt GUI component toolkit library for Coin")
+    (description "SoQt is a Qt GUI component toolkit library for Coin.  It is
+also compatible with SGI and TGS Open Inventor, and the API is based on the API
+of the InventorXt GUI component toolkit.")
+    (license license:bsd-3))))
-- 
2.29.2