Subject: [bug#70880] [PATCH 8/8] gnu: prusa-slicer: Update to 2.7.4.

From: "Artyom V. Poptsov" <[email-masked]>
Date: Sat, 11 May 2024 20:58:36 +0300

* gnu/packages/engineering.scm (prusa-slicer): Update to 2.7.4.
  [source]: Add "prusa-slicer-boost-fixes.patch".  Move some part of the
  snippet code to custom build phases.
  [arguments]: In configure flags add paths to external libraries.
  Add "fix-include-paths" phase.
  [native-inputs]: Add "catch2".
  [inputs]: Use "prusa-wxwidgets" instead of "wxwidgets" to fix segfaults.
  Ad "qhull", "nanosvg", "heatshrink" and "prusa-libbgcode".
* gnu/packages/patches/prusa-slicer-boost-fixes.patch,
  gnu/packages/patches/prusa-slicer-with-cereal-1.3.1.patch: Remove unused
  patches.
* gnu/local.mk (dist_patch_DATA): Remove unused "prusa-slicer" patches.

Change-Id: I15e85d63c9ad6c731c8040ef2d8ec8b2f31f2ab7
---
 gnu/local.mk                                  |  2 -
 gnu/packages/engineering.scm                  | 51 ++++++----
 .../patches/prusa-slicer-boost-fixes.patch    | 97 -------------------
 .../prusa-slicer-with-cereal-1.3.1.patch      | 52 ----------
 4 files changed, 33 insertions(+), 169 deletions(-)
 delete mode 100644 gnu/packages/patches/prusa-slicer-boost-fixes.patch
 delete mode 100644 gnu/packages/patches/prusa-slicer-with-cereal-1.3.1.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 3ba9253ae2..3b61666803 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1816,9 +1816,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/pokerth-boost.patch			\
   %D%/packages/patches/ppsspp-disable-upgrade-and-gold.patch		\
   %D%/packages/patches/procps-strtod-test.patch                 \
-  %D%/packages/patches/prusa-slicer-boost-fixes.patch		\
   %D%/packages/patches/prusa-slicer-fix-tests.patch		\
-  %D%/packages/patches/prusa-slicer-with-cereal-1.3.1.patch	\
   %D%/packages/patches/pthreadpool-system-libraries.patch	\
   %D%/packages/patches/python-3.12-fix-tests.patch		\
   %D%/packages/patches/python-accupy-use-matplotx.patch		\
diff --git a/gnu/packages/engineering.scm b/gnu/packages/engineering.scm
index 08ff06fa94..99f7c82d7d 100644
--- a/gnu/packages/engineering.scm
+++ b/gnu/packages/engineering.scm
@@ -3828,7 +3828,7 @@ (define-public prusa-wxwidgets
 (define-public prusa-slicer
   (package
     (name "prusa-slicer")
-    (version "2.5.2")
+    (version "2.7.4")
     (source
      (origin
        (method git-fetch)
@@ -3837,13 +3837,11 @@ (define-public prusa-slicer
          (url "https://github.com/prusa3d/PrusaSlicer")
          (commit (string-append "version_" version))))
        (file-name (git-file-name name version))
-       (sha256 (base32 "02qcrw3fa0d8ldbp73hp14l1qxbp3f4608j4csc07ny00ra42151"))
-       (patches (search-patches "prusa-slicer-boost-fixes.patch"
-                                "prusa-slicer-fix-tests.patch"
-                                "prusa-slicer-with-cereal-1.3.1.patch"))
+       (sha256 (base32 "0s1cfvhfilyv0y98asr61c6rwlgyr1hf5v5hg8q9zwmzm2bkcql3"))
+       (patches (search-patches "prusa-slicer-fix-tests.patch"))
        (modules '((guix build utils)))
        (snippet
-        '(begin
+        `(begin
            ;; Prusa slicer bundles a lot of dependencies in src/ directory.
            ;; Most of them contain prusa-specific modifications (e.g. avrdude),
            ;; but others do not. Here we replace the latter with Guix packages.
@@ -3851,10 +3849,12 @@ (define-public prusa-slicer
            (delete-file-recursively "src/hidapi")
            (delete-file-recursively "src/eigen")
            (delete-file-recursively "src/libigl/igl")
+           (substitute* "CMakeLists.txt"
+             (("add_library\\(libexpat INTERFACE\\)")
+              ""))
+           (substitute* "src/libigl/CMakeLists.txt"
+             (("target_link_libraries\\(libigl INTERFACE igl::core\\)") ""))
            (substitute* "src/CMakeLists.txt"
-             (("add_subdirectory\\(libigl\\)" all)
-              (string-append
-               all "\ninclude_directories(libigl INTERFACE libigl::core)"))
              (("add_subdirectory\\(hidapi\\)")
               "pkg_check_modules(HIDAPI REQUIRED hidapi-hidraw)")
              (("include_directories\\(hidapi/include\\)")
@@ -3867,13 +3867,24 @@ (define-public prusa-slicer
              (("\\bhidapi\\b") "${HIDAPI_LIBRARIES}"))))))
     (build-system cmake-build-system)
     (arguments
-     `(#:configure-flags
-       '("-DSLIC3R_FHS=1" ;; Use The Filesystem Hierarchy Standard.
-         "-DSLIC3R_GTK=3" ;; Use GTK+
-         ;; Use wxWidgets 3.0.x.x to prevent GUI crashes when adding support enforcers.
-         "-DSLIC3R_WX_STABLE=1")))
+     (list #:configure-flags
+           #~(list "-DSLIC3R_FHS=1" ;; Use The Filesystem Hierarchy Standard.
+                   "-DSLIC3R_GTK=3" ;; Use GTK+
+                   ;; Use wxWidgets 3.0.x.x to prevent GUI crashes when adding support enforcers.
+                   "-DSLIC3R_WX_STABLE=1"
+                   (format #f "-Dlibigl_DIR=~a/lib/cmake/igl/"
+                           #$(this-package-input "libigl"))
+                   (format #f "-DCatch2_DIR=~a/lib/cmake/catch2/"
+                           #$(this-package-input "catch2")))
+           #:phases
+           #~(modify-phases %standard-phases
+               (add-after 'unpack 'fix-include-paths
+                 (lambda _
+                   (substitute* "tests/libslic3r/test_quadric_edge_collapse.cpp"
+                     (("#include <libigl/igl/qslim.h>")
+                      "#include <igl/qslim.h>")))))))
     (native-inputs
-     (list pkg-config))
+     (list pkg-config catch2))
     (inputs
      (list boost
            cereal
@@ -3899,9 +3910,13 @@ (define-public prusa-slicer
            pango
            tbb
            eudev
-           ;; prusa-slicer 2.5 segfaults on startup with wxwidgets 3.2
-           ;; See https://github.com/prusa3d/PrusaSlicer/issues/8299
-           wxwidgets-3.0
+           qhull
+           nanosvg
+           heatshrink
+           ;; XXX: Using Prusa wxWidgets fork as PrusaSlicer segfaults when compiled
+           ;; with regular wxwidgets.
+           prusa-wxwidgets
+           prusa-libbgcode
            zlib))
     (home-page "https://www.prusa3d.com/prusaslicer/")
     (synopsis "G-code generator for 3D printers (RepRap, Makerbot, Ultimaker etc.)")
diff --git a/gnu/packages/patches/prusa-slicer-boost-fixes.patch b/gnu/packages/patches/prusa-slicer-boost-fixes.patch
deleted file mode 100644
index 5bca271625..0000000000
--- a/gnu/packages/patches/prusa-slicer-boost-fixes.patch
+++ /dev/null
@@ -1,97 +0,0 @@
-Fixes for Boost compatibility.
-This patch comes from Gentoo:
- portage/media-gfx/prusaslicer/files/prusaslicer-2.5.0_alpha2-boost-fixes.patch
-
---- a/src/hints/HintsToPot.cpp
-+++ b/src/hints/HintsToPot.cpp
-@@ -1,6 +1,7 @@
- #include <iostream>
- #include <vector>
- #include <string>
-+#include <boost/nowide/fstream.hpp>
- #include <boost/filesystem.hpp>
- #include <boost/dll.hpp>
- #include <boost/property_tree/ini_parser.hpp>
-@@ -9,7 +10,7 @@
- 
- bool write_to_pot(boost::filesystem::path path, const std::vector<std::pair<std::string, std::string>>& data)
- {
--	boost::filesystem::ofstream file(std::move(path), std::ios_base::app);
-+	boost::nowide::ofstream file(std::move(path), std::ios_base::app);
- 	for (const auto& element : data)
- 	{
- 		//Example of .pot element 
---- a/src/libslic3r/Preset.cpp
-+++ b/src/libslic3r/Preset.cpp
-@@ -25,6 +25,7 @@
- #include <stdexcept>
- #include <unordered_map>
- #include <boost/format.hpp>
-+#include <boost/nowide/fstream.hpp>
- #include <boost/filesystem.hpp>
- #include <boost/filesystem/fstream.hpp>
- #include <boost/algorithm/string.hpp>
-@@ -84,7 +85,7 @@ ConfigFileType guess_config_file_type(const ptree &tree)
- VendorProfile VendorProfile::from_ini(const boost::filesystem::path &path, bool load_all)
- {
-     ptree tree;
--    boost::filesystem::ifstream ifs(path);
-+    boost::nowide::ifstream ifs(path);
-     boost::property_tree::read_ini(ifs, tree);
-     return VendorProfile::from_ini(tree, path, load_all);
- }
---- a/src/slic3r/GUI/DesktopIntegrationDialog.cpp
-+++ b/src/slic3r/GUI/DesktopIntegrationDialog.cpp
-@@ -10,6 +10,7 @@
- #include "libslic3r/Platform.hpp"
- #include "libslic3r/Config.hpp"
- 
-+#include <boost/nowide/fstream.hpp>
- #include <boost/filesystem.hpp>
- #include <boost/log/trivial.hpp>
- #include <boost/dll/runtime_symbol_info.hpp>
-@@ -503,4 +504,4 @@ DesktopIntegrationDialog::~DesktopIntegrationDialog()
- 
- } // namespace GUI
- } // namespace Slic3r
--#endif // __linux__
-\ No newline at end of file
-+#endif // __linux__
---- a/src/slic3r/GUI/GUI_App.cpp
-+++ b/src/slic3r/GUI/GUI_App.cpp
-@@ -13,6 +13,7 @@
- #include <cstdlib>
- #include <regex>
- #include <string_view>
-+#include <boost/nowide/fstream.hpp>
- #include <boost/algorithm/string/predicate.hpp>
- #include <boost/algorithm/string.hpp>
- #include <boost/format.hpp>
---- a/src/slic3r/GUI/HintNotification.cpp
-+++ b/src/slic3r/GUI/HintNotification.cpp
-@@ -15,6 +15,7 @@
- #include "libslic3r/PrintConfig.hpp"
- 
- #include <boost/algorithm/string/replace.hpp>
-+#include <boost/nowide/fstream.hpp>
- #include <boost/filesystem.hpp>
- #include <boost/nowide/fstream.hpp>
- #include <boost/log/trivial.hpp>
-@@ -65,7 +66,7 @@ inline void push_style_color(ImGuiCol idx, const ImVec4& col, bool fading_out, f
- 
- void write_used_binary(const std::vector<std::string>& ids)
- {
--	boost::filesystem::ofstream file((boost::filesystem::path(data_dir()) / "cache" / "hints.cereal"), std::ios::binary);
-+	boost::nowide::ofstream file((boost::filesystem::path(data_dir()) / "cache" / "hints.cereal"), std::ios::binary);
- 	cereal::BinaryOutputArchive archive(file);
- 		HintsCerealData cd { ids };
- 	try
-@@ -84,7 +85,7 @@ void read_used_binary(std::vector<std::string>& ids)
- 		BOOST_LOG_TRIVIAL(warning) << "Failed to load to hints.cereal. File does not exists. " << path.string();
- 		return;
- 	}
--	boost::filesystem::ifstream file(path);
-+	boost::nowide::ifstream file(path);
- 	cereal::BinaryInputArchive archive(file);
- 	HintsCerealData cd;
- 	try
diff --git a/gnu/packages/patches/prusa-slicer-with-cereal-1.3.1.patch b/gnu/packages/patches/prusa-slicer-with-cereal-1.3.1.patch
deleted file mode 100644
index affa506b1c..0000000000
--- a/gnu/packages/patches/prusa-slicer-with-cereal-1.3.1.patch
+++ /dev/null
@@ -1,52 +0,0 @@
-Fix for building with cereal>=1.3.1.
-This patch comes from Gentoo:
- portage/media-gfx/prusaslicer/files/prusaslicer-2.5.0_rc1-cereal-1.3.1.patch
-
---- a/src/CMakeLists.txt
-+++ b/src/CMakeLists.txt
-@@ -127,7 +127,7 @@
-     set_target_properties(PrusaSlicer PROPERTIES OUTPUT_NAME "prusa-slicer")
- endif ()
-
--target_link_libraries(PrusaSlicer libslic3r cereal)
-+target_link_libraries(PrusaSlicer libslic3r libcereal)
-
- if (APPLE)
- #    add_compile_options(-stdlib=libc++)
---- a/src/slic3r/CMakeLists.txt
-+++ b/src/slic3r/CMakeLists.txt
-@@ -260,7 +260,7 @@
-
- encoding_check(libslic3r_gui)
-
--target_link_libraries(libslic3r_gui libslic3r avrdude cereal imgui GLEW::GLEW OpenGL::GL hidapi libcurl ${wxWidgets_LIBRARIES})
-+target_link_libraries(libslic3r_gui libslic3r avrdude libcereal imgui GLEW::GLEW OpenGL::GL hidapi libcurl ${wxWidgets_LIBRARIES})
-
- if (MSVC)
-     target_link_libraries(libslic3r_gui Setupapi.lib)
---- a/src/libslic3r/CMakeLists.txt
-+++ b/src/libslic3r/CMakeLists.txt
-@@ -395,7 +395,7 @@
- target_link_libraries(libslic3r
-     libnest2d
-     admesh
--    cereal
-+    libcereal
-     libigl
-     miniz
-     boost_libs
---- a/CMakeLists.txt
-+++ b/CMakeLists.txt
-@@ -446,6 +446,12 @@
-
- # Find the Cereal serialization library
- find_package(cereal REQUIRED)
-+add_library(libcereal INTERFACE)
-+if (NOT TARGET cereal::cereal)
-+    target_link_libraries(libcereal INTERFACE cereal)
-+else()
-+    target_link_libraries(libcereal INTERFACE cereal::cereal)
-+endif()
-
- # l10n
- set(L10N_DIR "${SLIC3R_RESOURCES_DIR}/localization")
-- 
2.41.0