diff --git a/gnu/local.mk b/gnu/local.mk index a4024c3d2c..e0b88d612d 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -1905,6 +1905,8 @@ dist_patch_DATA = \ %D%/packages/patches/netsurf-system-utf8proc.patch \ %D%/packages/patches/netsurf-y2038-tests.patch \ %D%/packages/patches/netsurf-longer-test-timeout.patch \ + %D%/packages/patches/nextpnr-gtest.patch \ + %D%/packages/patches/nextpnr-imgui.patch \ %D%/packages/patches/nhc98-c-update.patch \ %D%/packages/patches/nix-dont-build-html-doc.diff \ %D%/packages/patches/nfs4-acl-tools-0.3.7-fixpaths.patch \ diff --git a/gnu/packages/fpga.scm b/gnu/packages/fpga.scm index 2298dde595..22f38b7886 100644 --- a/gnu/packages/fpga.scm +++ b/gnu/packages/fpga.scm @@ -357,101 +357,92 @@ files.") (license license:isc)))) (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. + (package + (name "nextpnr-ice40") + (version "0.8") + (source + (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/YosysHQ/nextpnr/") + (commit (string-append "nextpnr-" version)) + ;; XXX: Fetch some bundled libraries such as QtPropertyBrowser, + ;; json11 and python-console, which have custom modifications or + ;; no longer have their original upstream. + (recursive? #t))) + (file-name (git-file-name name version)) + (modules '((guix build utils) + (ice-9 ftw) + (srfi srfi-26))) + (snippet + '(begin + ;; XXX: 'delete-all-but' is copied from the turbovnc package. + (define (delete-all-but directory . preserve) + (define (directory? x) + (and=> (stat x #f) + (compose (cut eq? 'directory <>) stat:type))) + (with-directory-excursion directory + (let* ((pred + (negate (cut member <> (append '("." "..") preserve)))) + (items (scandir "." pred))) + (for-each (lambda (item) + (if (directory? item) + (delete-file-recursively item) + (delete-file item))) + items)))) + (delete-all-but "3rdparty" + ;; The following sources have all been patched, so + ;; cannot easily be unbundled. + "QtPropertyBrowser" + "json11" + "python-console" + "oourafft"))) + (patches (search-patches "nextpnr-gtest.patch" + "nextpnr-imgui.patch")) + (sha256 + (base32 "0p53a2gl89hf3hfwdxs6pykxyrk82j4lqpwd1fqia2y0c9r2gjlm")))) + (build-system qt-build-system) + (arguments + (list + #:cmake cmake ;CMake 3.25 or higher is required. + #:configure-flags + #~(list "-DARCH=ice40" + "-DBUILD_GUI=ON" + "-DUSE_OPENMP=ON" + "-DBUILD_TESTS=ON" + (string-append "-DCURRENT_GIT_VERSION=nextpnr-" #$version) + (string-append "-DICESTORM_INSTALL_PREFIX=" + #$(this-package-input "icestorm")) + "-DUSE_IPO=OFF") + #:phases + #~(modify-phases %standard-phases + (add-after 'unpack 'unbundle-sanitizers-cmake + (lambda* (#:key inputs #:allow-other-keys) (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)))) + ;; Use the system sanitizers-cmake module. This is made + ;; necessary 'sanitizers-cmake' installing a FindPackage + ;; module but no CMake config file. + (("\\$\\{CMAKE_SOURCE_DIR}/3rdparty/sanitizers-cmake/cmake") + (string-append + #$(this-package-native-input "sanitizers-cmake") + "/share/sanitizers-cmake/cmake")))))))) + (native-inputs + (list googletest + sanitizers-cmake)) + (inputs + (list boost + eigen + icestorm + pybind11 + python + qtbase-5 + qtwayland-5 + qtimgui + yosys)) + (synopsis "Place-and-Route tool for FPGAs") + (description "Nextpnr is a portable FPGA place and route tool.") + (home-page "https://github.com/YosysHQ/nextpnr/") + (license license:isc))) (define-public gtkwave (package diff --git a/gnu/packages/patches/nextpnr-gtest.patch b/gnu/packages/patches/nextpnr-gtest.patch new file mode 100644 index 0000000000..e940bd51c5 --- /dev/null +++ b/gnu/packages/patches/nextpnr-gtest.patch @@ -0,0 +1,30 @@ +Upstream-status: https://github.com/YosysHQ/nextpnr/pull/1478 + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 47d60330..88463984 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -217,7 +217,13 @@ set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/3rdparty/sanitizers-cmake/cmake" ${CM + find_package(Sanitizers) + + if (BUILD_TESTS) +- add_subdirectory(3rdparty/googletest/googletest EXCLUDE_FROM_ALL) ++ find_package(GTest) ++ if(GTest_FOUND) ++ add_library(gtest_main ALIAS GTest::gtest_main) ++ else() ++ add_subdirectory(3rdparty/googletest/googletest EXCLUDE_FROM_ALL) ++ set(gtest_include_dir ${CMAKE_SOURCE_DIR}/3rdparty/googletest/googletest/include) ++ endif() + enable_testing() + endif() + +@@ -366,7 +372,7 @@ function(add_nextpnr_architecture target) + add_executable(nextpnr-${target}-test ${arg_TEST_SOURCES}) + set_property(TARGET nextpnr-${target}-test PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) + +- target_include_directories(nextpnr-${target}-test PRIVATE ${CMAKE_SOURCE_DIR}/3rdparty/googletest/googletest/include) ++ target_include_directories(nextpnr-${target}-test PRIVATE gtest_include_dir) + + target_link_libraries(nextpnr-${target}-test PRIVATE gtest_main nextpnr-${target}-core) + if (BUILD_GUI) diff --git a/gnu/packages/patches/nextpnr-imgui.patch b/gnu/packages/patches/nextpnr-imgui.patch new file mode 100644 index 0000000000..0d9d316d15 --- /dev/null +++ b/gnu/packages/patches/nextpnr-imgui.patch @@ -0,0 +1,75 @@ +Uptream-status: https://github.com/YosysHQ/nextpnr/pull/1480 + +diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt +index ff5d9208..c554cc96 100644 +--- a/gui/CMakeLists.txt ++++ b/gui/CMakeLists.txt +@@ -46,12 +46,42 @@ target_include_directories(nextpnr-${target}-gui PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + ) + ++# Detect whether imgui/qtimgui packages are available from the system. ++find_path(IMGUI_INCLUDE_DIR NAMES imgui.h PATH_SUFFIXES imgui) ++find_path(QTIMGUI_INCLUDE_DIR NAMES QtImGui.h PATH_SUFFIXES qtimgui) ++find_library(IMGUI_LIB NAMES imgui) ++find_library(QTIMGUI_LIB NAMES qt_imgui_widgets) ++if (IMGUI_INCLUDE_DIR AND IMGUI_LIB) ++ message("Using system imgui library: ++ IMGUI_INCLUDE_DIR=${IMGUI_INCLUDE_DIR} ++ IMGUI_LIB=${IMGUI_LIB}") ++else() ++ message("Using bundled imgui library") ++ set(IMGUI_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/3rdparty/imgui) ++ set(IMGUI_SOURCES ++ ../3rdparty/imgui/imgui_widgets.cpp ++ ../3rdparty/imgui/imgui_draw.cpp ++ ../3rdparty/imgui/imgui.cpp ++ ../3rdparty/imgui/imgui_demo.cpp) ++endif() ++if (QTIMGUI_INCLUDE_DIR AND QTIMGUI_LIB) ++ message("Using system qtimgui library: ++ QTIMGUI_INCLUDE_DIR=${QTIMGUI_INCLUDE_DIR} ++ QTIMGUI_LIB=${QTIMGUI_LIB}") ++else() ++ message("Using bundled qtimgui library") ++ set(QTIMGUI_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/3rdparty/qtimgui) ++ set(QTIMGUI_SOURCES ++ ../3rdparty/qtimgui/ImGuiRenderer.cpp ++ ../3rdparty/qtimgui/QtImGui.cpp) ++endif() ++ + target_include_directories(nextpnr-${target}-gui PRIVATE + ${CMAKE_SOURCE_DIR}/frontend + ${CMAKE_SOURCE_DIR}/json + ${CMAKE_SOURCE_DIR}/3rdparty/QtPropertyBrowser/src +- ${CMAKE_SOURCE_DIR}/3rdparty/imgui +- ${CMAKE_SOURCE_DIR}/3rdparty/qtimgui ++ ${IMGUI_INCLUDE_DIR} ++ ${QTIMGUI_INCLUDE_DIR} + ) + + target_link_libraries(nextpnr-${target}-gui PUBLIC +@@ -77,14 +107,17 @@ if (BUILD_PYTHON) + ../3rdparty/python-console/ParseMessage.cpp + ../3rdparty/python-console/modified/pyredirector.cc + ../3rdparty/python-console/modified/pyinterpreter.cc +- ../3rdparty/imgui/imgui_widgets.cpp +- ../3rdparty/imgui/imgui_draw.cpp +- ../3rdparty/imgui/imgui.cpp +- ../3rdparty/imgui/imgui_demo.cpp +- ../3rdparty/qtimgui/ImGuiRenderer.cpp +- ../3rdparty/qtimgui/QtImGui.cpp ++ ${IMGUI_SOURCES} ++ ${QTIMGUI_SOURCES} + ) + ++ if (IMGUI_LIB) ++ target_link_libraries(nextpnr-${target}-gui PRIVATE ${IMGUI_LIB}) ++ endif() ++ if (QTIMGUI_LIB) ++ target_link_libraries(nextpnr-${target}-gui PRIVATE ${QTIMGUI_LIB}) ++ endif() ++ + target_include_directories(nextpnr-${target}-gui PRIVATE + ../3rdparty/python-console + ../3rdparty/python-console/modified