Subject: [bug#78233] [PATCH v2 2/2] gnu: nextpnr-ice40: Update to 0.8.

From: Cayetano Santos <[email-masked]>
Date: Sun, 11 May 2025 11:18:39 +0200

* gnu/packages/fpga.scm (nextpnr-ice40): Update to 0.8.

Change-Id: I8d1c3528679f38ec4593f90aec0f1c4321dc7e44
---
 gnu/packages/fpga.scm | 128 +++++++++++-------------------------------
 1 file changed, 33 insertions(+), 95 deletions(-)

diff --git a/gnu/packages/fpga.scm b/gnu/packages/fpga.scm
index 083faf7d7a..77f39559cf 100644
--- a/gnu/packages/fpga.scm
+++ b/gnu/packages/fpga.scm
@@ -436,102 +436,39 @@ (define nextpnr
     (license license:asl2.0)))
 
 (define-public nextpnr-ice40
-  (let* ((version "0.7")
-         (tag (string-append "nextpnr-" version)))
-    (package
-      (name "nextpnr-ice40")
-      (version version)
-      (source
-       (origin
-         (method git-fetch)
-         (uri (git-reference
-               (url "https://github.com/YosysHQ/nextpnr")
-               (commit tag)
-               (recursive? #t)))
-         (file-name (git-file-name name version))
-         (sha256
-          (base32
-           "0sbhqscgmlk4q2207rsqsw99qx4fyrxx1hsd669lrk42gmk3s9lm"))
-         (modules '((guix build utils)))
-         (snippet
-          #~(begin
-              ;; Remove bundled source code for which Guix has packages.
-              ;; Note the bundled copies of json11 and python-console contain
-              ;; modifications, while QtPropertyBrowser appears to be
-              ;; abandoned and without an official source.
-              ;; fpga-interchange-schema is used only by the
-              ;; "fpga_interchange" architecture target, which this package
-              ;; doesn't build.
-              (with-directory-excursion "3rdparty"
-                (for-each delete-file-recursively
-                          '("googletest" "imgui" "pybind11" "qtimgui"
-                            "sanitizers-cmake")))
-
-              ;; Remove references to unbundled code and link against external
-              ;; libraries instead.
-              (substitute* "CMakeLists.txt"
-                (("^\\s+add_subdirectory\\(3rdparty/googletest.*") "")
-                (("^(\\s+target_link_libraries.*)( gtest_main\\))"
-                  _ prefix suffix)
-                 (string-append prefix " gtest" suffix)))
-              (substitute* "gui/CMakeLists.txt"
-                (("^\\s+../3rdparty/(qt)?imgui.*") "")
-                (("^(target_link_libraries.*)\\)" _ prefix)
-                 (string-append prefix " imgui qt_imgui_widgets)")))))))
-      (native-inputs
-       (list googletest sanitizers-cmake))
-      (inputs
-       (list boost
-             eigen
-             icestorm
-             imgui-1.86
-             pybind11
-             python
-             qtbase-5
-             qtwayland-5
-             qtimgui
-             yosys))
-      (build-system qt-build-system)
-      (arguments
-       (list
-        #:configure-flags
-        #~(list "-DARCH=ice40"
-                "-DBUILD_GUI=ON"
-                "-DBUILD_TESTS=ON"
-                (string-append "-DCURRENT_GIT_VERSION=" #$tag)
-                (string-append "-DICESTORM_INSTALL_PREFIX="
-                               #$(this-package-input "icestorm"))
-                "-DUSE_IPO=OFF")
-        #:phases
-        #~(modify-phases %standard-phases
-            (add-after 'unpack 'patch-source
-              (lambda* (#:key inputs #:allow-other-keys)
-                (substitute* "CMakeLists.txt"
-                  ;; Use the system sanitizers-cmake module.
-                  (("\\$\\{CMAKE_SOURCE_DIR\\}/3rdparty/sanitizers-cmake/cmake")
-                   (string-append
-                    #$(this-package-native-input "sanitizers-cmake")
-                    "/share/sanitizers-cmake/cmake")))
-                (substitute* "gui/CMakeLists.txt"
-                  ;; Compile with system imgui and qtimgui headers.
-                  (("^(target_include_directories.*)../3rdparty/imgui(.*)$"
-                    _ prefix suffix)
-                   (string-append prefix
-                                  (search-input-directory inputs
-                                                          "include/imgui")
-                                  suffix))
-                  (("^(target_include_directories.*)../3rdparty/qtimgui/(.*)$"
-                    _ prefix suffix)
-                   (string-append prefix
-                                  (search-input-directory inputs
-                                                          "include/qtimgui")
-                                  suffix))))))))
-      (synopsis "Place-and-Route tool for FPGAs")
-      (description "Nextpnr aims to be a vendor neutral, timing driven, FOSS
-FPGA place and route tool.")
-      (home-page "https://github.com/YosysHQ/nextpnr")
-      (license license:expat))))
+  (package
+    (inherit nextpnr)
+    (name "nextpnr-ice40")
+    (arguments
+     (substitute-keyword-arguments (package-arguments nextpnr)
+       ((#:phases phases #~%standard-phases)
+        #~(modify-phases #$phases
+            (add-after 'unpack 'get-icestorm
+              (lambda _
+                (copy-recursively #$(package-source icestorm) "icestorm")))
+            ;; Run examples included in icestorm backend.
+            (add-after 'compress-documentation 'run-icestorm-examples
+              (lambda _
+                (let* ((examples "../source/icestorm/examples/")
+                       (dir (opendir examples))
+                       (path-env (getenv "PATH")))
+                  (setenv "PATH" (string-append #$output "/bin" ":" path-env))
+                  (do ((entry (readdir dir) (readdir dir)))
+                      ((eof-object? entry))
+                    (unless (member entry '("." ".."))
+                      (invoke "make" "-C" (string-append examples entry))))
+                  (closedir dir))))))
+       ((#:configure-flags original-flags #~(list))
+        #~(append #$original-flags
+                  `("-DARCH=ice40"
+                    ,(string-append "-DICESTORM_INSTALL_PREFIX="
+                                    #$(this-package-input "icestorm")))))))
+    (propagated-inputs
+     (modify-inputs (package-propagated-inputs nextpnr)
+       (prepend icestorm)))
+    (native-inputs
+     (modify-inputs (package-native-inputs nextpnr)
+       (prepend yosys)))))
 
 (define-public gtkwave
   (package
--
2.49.0