Subject: [PATCH v3 7/8] gnu: Add prusa-wxwidgets.

From: "Artyom V. Poptsov" <[email-masked]>
Date: Sat, 13 Jul 2024 14:13:16 +0300

* gnu/packages/engineering.scm (prusa-wxwidgets): New variable.
* gnu/packages/patches/prusa-wxwidgets-makefile-fix.patch: New file.
* gnu/local.mk (dist_patch_DATA): Register
  "prusa-wxwidgets-makefile-fix.patch".

Co-authored-by: Nikita Domnitskii <[email-masked]>
Change-Id: I9043c2acc95986275ee24d9c5d944e5fe2702e99
---
 gnu/local.mk                                  |   1 +
 .../prusa-wxwidgets-makefile-fix.patch        | 112 ++++++++++++++++++
 gnu/packages/wxwidgets.scm                    |  39 ++++++
 3 files changed, 152 insertions(+)
 create mode 100644 gnu/packages/patches/prusa-wxwidgets-makefile-fix.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 4726e2c128..541f636c35 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1847,6 +1847,7 @@ dist_patch_DATA =						\
   %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/prusa-wxwidgets-makefile-fix.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/patches/prusa-wxwidgets-makefile-fix.patch b/gnu/packages/patches/prusa-wxwidgets-makefile-fix.patch
new file mode 100644
index 0000000000..aadf976588
--- /dev/null
+++ b/gnu/packages/patches/prusa-wxwidgets-makefile-fix.patch
@@ -0,0 +1,112 @@
+diff --git a/Makefile.in b/Makefile.in
+index 8f33aa2ff4..39928382da 100644
+--- a/Makefile.in
++++ b/Makefile.in
+@@ -4358,7 +4358,7 @@ COND_PLATFORM_WIN32_1___BASE_PLATFORM_SRC_OBJECTS =  \
+ 	monodll_msw_utils.o \
+ 	monodll_utilsexc.o \
+ 	monodll_fswatcher.o \
+-	monodll_msw_secretstore.o
++	monodll_msw_secretstore.o \
+ 	monodll_msw_uilocale.o
+ @COND_PLATFORM_WIN32_1@__BASE_PLATFORM_SRC_OBJECTS = $(COND_PLATFORM_WIN32_1___BASE_PLATFORM_SRC_OBJECTS)
+ @COND_PLATFORM_WIN32_1@__BASE_AND_GUI_PLATFORM_SRC_OBJECTS \
+@@ -5284,7 +5284,7 @@ COND_TOOLKIT_MSW___LOWLEVEL_SRC_OBJECTS =  \
+ 	monodll_uuid.o \
+ 	monodll_msw_evtloop.o \
+ 	monodll_access.o \
+-	monodll_dark_mode.o
++	monodll_dark_mode.o \
+ 	monodll_msw_bmpbndl.o
+ @COND_TOOLKIT_MSW@__LOWLEVEL_SRC_OBJECTS = $(COND_TOOLKIT_MSW___LOWLEVEL_SRC_OBJECTS)
+ @COND_TOOLKIT_OSX_COCOA@__LOWLEVEL_SRC_OBJECTS = \
+@@ -6196,7 +6196,7 @@ COND_TOOLKIT_MSW___LOWLEVEL_SRC_OBJECTS_1 =  \
+ 	monodll_uuid.o \
+ 	monodll_msw_evtloop.o \
+ 	monodll_access.o \
+-	monodll_dark_mode.o
++	monodll_dark_mode.o \
+ 	monodll_msw_bmpbndl.o
+ @COND_TOOLKIT_MSW@__LOWLEVEL_SRC_OBJECTS_1 = $(COND_TOOLKIT_MSW___LOWLEVEL_SRC_OBJECTS_1)
+ @COND_TOOLKIT_OSX_COCOA@__LOWLEVEL_SRC_OBJECTS_1 = \
+@@ -6371,7 +6371,7 @@ COND_PLATFORM_WIN32_1___BASE_PLATFORM_SRC_OBJECTS_1 =  \
+ 	monolib_msw_utils.o \
+ 	monolib_utilsexc.o \
+ 	monolib_fswatcher.o \
+-	monolib_msw_secretstore.o
++	monolib_msw_secretstore.o \
+ 	monolib_msw_uilocale.o
+ @COND_PLATFORM_WIN32_1@__BASE_PLATFORM_SRC_OBJECTS_1 = $(COND_PLATFORM_WIN32_1___BASE_PLATFORM_SRC_OBJECTS_1)
+ @COND_PLATFORM_WIN32_1@__BASE_AND_GUI_PLATFORM_SRC_OBJECTS_1 \
+@@ -7297,7 +7297,7 @@ COND_TOOLKIT_MSW___LOWLEVEL_SRC_OBJECTS_2 =  \
+ 	monolib_uuid.o \
+ 	monolib_msw_evtloop.o \
+ 	monolib_access.o \
+-	monolib_dark_mode.o
++	monolib_dark_mode.o \
+ 	monolib_msw_bmpbndl.o
+ @COND_TOOLKIT_MSW@__LOWLEVEL_SRC_OBJECTS_2 = $(COND_TOOLKIT_MSW___LOWLEVEL_SRC_OBJECTS_2)
+ @COND_TOOLKIT_OSX_COCOA@__LOWLEVEL_SRC_OBJECTS_2 = \
+@@ -8209,7 +8209,7 @@ COND_TOOLKIT_MSW___LOWLEVEL_SRC_OBJECTS_3 =  \
+ 	monolib_uuid.o \
+ 	monolib_msw_evtloop.o \
+ 	monolib_access.o \
+-	monolib_dark_mode.o
++	monolib_dark_mode.o \
+ 	monolib_msw_bmpbndl.o
+ @COND_TOOLKIT_MSW@__LOWLEVEL_SRC_OBJECTS_3 = $(COND_TOOLKIT_MSW___LOWLEVEL_SRC_OBJECTS_3)
+ @COND_TOOLKIT_OSX_COCOA@__LOWLEVEL_SRC_OBJECTS_3 = \
+@@ -8436,7 +8436,7 @@ COND_PLATFORM_WIN32_1___BASE_PLATFORM_SRC_OBJECTS_2 =  \
+ 	basedll_msw_utils.o \
+ 	basedll_utilsexc.o \
+ 	basedll_fswatcher.o \
+-	basedll_msw_secretstore.o
++	basedll_msw_secretstore.o \
+ 	basedll_msw_uilocale.o
+ @COND_PLATFORM_WIN32_1@__BASE_PLATFORM_SRC_OBJECTS_2 = $(COND_PLATFORM_WIN32_1___BASE_PLATFORM_SRC_OBJECTS_2)
+ @COND_PLATFORM_WIN32_1@__BASE_AND_GUI_PLATFORM_SRC_OBJECTS_2 \
+@@ -8523,7 +8523,7 @@ COND_PLATFORM_WIN32_1___BASE_PLATFORM_SRC_OBJECTS_3 =  \
+ 	baselib_msw_utils.o \
+ 	baselib_utilsexc.o \
+ 	baselib_fswatcher.o \
+-	baselib_msw_secretstore.o
++	baselib_msw_secretstore.o \
+ 	baselib_msw_uilocale.o
+ @COND_PLATFORM_WIN32_1@__BASE_PLATFORM_SRC_OBJECTS_3 = $(COND_PLATFORM_WIN32_1___BASE_PLATFORM_SRC_OBJECTS_3)
+ @COND_PLATFORM_WIN32_1@__BASE_AND_GUI_PLATFORM_SRC_OBJECTS_3 \
+@@ -9464,7 +9464,7 @@ COND_TOOLKIT_MSW___LOWLEVEL_SRC_OBJECTS_4 =  \
+ 	coredll_uuid.o \
+ 	coredll_msw_evtloop.o \
+ 	coredll_access.o \
+-	coredll_dark_mode.o
++	coredll_dark_mode.o \
+ 	coredll_msw_bmpbndl.o
+ @COND_TOOLKIT_MSW@__LOWLEVEL_SRC_OBJECTS_4 = $(COND_TOOLKIT_MSW___LOWLEVEL_SRC_OBJECTS_4)
+ @COND_TOOLKIT_OSX_COCOA@__LOWLEVEL_SRC_OBJECTS_4 = \
+@@ -10376,7 +10376,7 @@ COND_TOOLKIT_MSW___LOWLEVEL_SRC_OBJECTS_5 =  \
+ 	coredll_uuid.o \
+ 	coredll_msw_evtloop.o \
+ 	coredll_access.o \
+-	coredll_dark_mode.o
++	coredll_dark_mode.o \
+ 	coredll_msw_bmpbndl.o
+ @COND_TOOLKIT_MSW@__LOWLEVEL_SRC_OBJECTS_5 = $(COND_TOOLKIT_MSW___LOWLEVEL_SRC_OBJECTS_5)
+ @COND_TOOLKIT_OSX_COCOA@__LOWLEVEL_SRC_OBJECTS_5 = \
+@@ -11204,7 +11204,7 @@ COND_TOOLKIT_MSW___LOWLEVEL_SRC_OBJECTS_6 =  \
+ 	corelib_uuid.o \
+ 	corelib_msw_evtloop.o \
+ 	corelib_access.o \
+-	corelib_dark_mode.o
++	corelib_dark_mode.o \
+ 	corelib_msw_bmpbndl.o
+ @COND_TOOLKIT_MSW@__LOWLEVEL_SRC_OBJECTS_6 = $(COND_TOOLKIT_MSW___LOWLEVEL_SRC_OBJECTS_6)
+ @COND_TOOLKIT_OSX_COCOA@__LOWLEVEL_SRC_OBJECTS_6 = \
+@@ -12116,7 +12116,7 @@ COND_TOOLKIT_MSW___LOWLEVEL_SRC_OBJECTS_7 =  \
+ 	corelib_uuid.o \
+ 	corelib_msw_evtloop.o \
+ 	corelib_access.o \
+-	corelib_dark_mode.o
++	corelib_dark_mode.o \
+ 	corelib_msw_bmpbndl.o
+ @COND_TOOLKIT_MSW@__LOWLEVEL_SRC_OBJECTS_7 = $(COND_TOOLKIT_MSW___LOWLEVEL_SRC_OBJECTS_7)
+ @COND_TOOLKIT_OSX_COCOA@__LOWLEVEL_SRC_OBJECTS_7 = \
diff --git a/gnu/packages/wxwidgets.scm b/gnu/packages/wxwidgets.scm
index 973e962fb1..11c2ac2154 100644
--- a/gnu/packages/wxwidgets.scm
+++ b/gnu/packages/wxwidgets.scm
@@ -46,6 +46,7 @@ (define-module (gnu packages wxwidgets)
   #:use-module (gnu packages freedesktop)
   #:use-module (gnu packages gl)
   #:use-module (gnu packages gnome)
+  #:use-module (gnu packages graphics)
   #:use-module (gnu packages gstreamer)
   #:use-module (gnu packages gtk)
   #:use-module (gnu packages image)
@@ -265,6 +266,44 @@ (define-public wxwidgets-2
                (("-Wall") "-Wall -Wno-narrowing"))
              #t)))))))
 
+(define-public prusa-wxwidgets
+  ;; There is no proper tag/release, all patches are in separate branches based on
+  ;; the wxWidgets release (e.g. this commit is taken from "v3.2.0-patched" branch".)
+  (let ((commit "78aa2dc0ea7ce99dc19adc1140f74c3e2e3f3a26")
+        (revision "0"))
+    (package
+      (inherit wxwidgets)
+      (name "prusa-wxwidgets")
+      (version (git-version "3.2.0" revision commit))
+      (home-page "https://github.com/prusa3d/wxWidgets")
+      (source
+       (origin
+         (method git-fetch)
+         (uri (git-reference
+               (url home-page)
+               (commit commit)))
+         (file-name (git-file-name name version))
+         ;; The patch is taken from the NixOS nixpkgs repository (see
+         ;; <https://github.com/NixOS/nixpkgs/commit/0e724ac89f3dbf6ed31d647290a371b44a85e5ad>.)
+         (patches (search-patches "prusa-wxwidgets-makefile-fix.patch"))
+         (sha256
+          (base32
+           "1xk6w7q4xv4cj906xa5dwam5q51mc8bszbkkz7l8d3wjmsz73rwv"))))
+      (native-inputs (modify-inputs (package-native-inputs wxwidgets)
+                       (prepend nanosvg)))
+      (arguments
+       (substitute-keyword-arguments (package-arguments wxwidgets)
+         ((#:configure-flags flags)
+          ;; To fix 3D rendering in PrusaSlicer, wxWidgets must be compiled with
+          ;; "--disable-glcanvasegl" flag (see
+          ;; <https://github.com/NixOS/nixpkgs/issues/193135>.)
+          #~(cons "--disable-glcanvasegl" #$flags))
+         ((#:phases phases)
+          #~(modify-phases #$phases
+              (add-after 'unpack 'copy-nanosvg-source
+                (lambda _
+                  (copy-recursively #$(package-source nanosvg) "3rdparty/nanosvg/"))))))))))
+
 (define-public python-wxpython
   (package
     (name "python-wxpython")
-- 
2.45.2