diff options
Diffstat (limited to 'guix')
-rw-r--r-- | guix/build-system/cmake.scm | 32 | ||||
-rw-r--r-- | guix/build-system/meson.scm | 2 | ||||
-rw-r--r-- | guix/build-system/qt.scm | 31 | ||||
-rw-r--r-- | guix/build/cmake-build-system.scm | 120 |
4 files changed, 141 insertions, 44 deletions
diff --git a/guix/build-system/cmake.scm b/guix/build-system/cmake.scm index 8b1889e36b..b0587fddf0 100644 --- a/guix/build-system/cmake.scm +++ b/guix/build-system/cmake.scm @@ -31,7 +31,9 @@ #:use-module (guix packages) #:export (%cmake-build-system-modules cmake-build - cmake-build-system)) + cmake-build-system + default-cmake + default-ninja)) ;; Commentary: ;; @@ -64,10 +66,17 @@ 'cmake-minimal-cross 'cmake-minimal)))) +(define (default-ninja) + "Return the default ninja package." + ;; Lazily resolve the binding to avoid a circular dependency. + (let ((module (resolve-interface '(gnu packages ninja)))) + (module-ref module 'ninja/pinned))) + (define* (lower name #:key source inputs native-inputs outputs system target (implicit-inputs? #t) (implicit-cross-inputs? #t) (cmake (default-cmake target)) + (ninja (default-ninja)) #:allow-other-keys #:rest arguments) "Return a bag for NAME." @@ -84,6 +93,7 @@ `(("source" ,source)) '()) ,@`(("cmake" ,cmake)) + ,@`(("ninja" ,ninja)) ,@native-inputs ,@(if target '() inputs) ,@(if (and target implicit-cross-inputs?) @@ -115,9 +125,12 @@ (search-paths '()) (make-flags ''()) (out-of-source? #t) + (generator "Unix Makefiles") (build-type "RelWithDebInfo") (tests? #t) - (test-target "test") + (test-exclude "") + (test-repeat-until-pass? #t) + (test-repeat-until-pass-count 5) (parallel-build? #t) (parallel-tests? #t) (validate-runpath? #t) (patch-shebangs? #t) @@ -155,9 +168,12 @@ provides a 'CMakeLists.txt' file as its build system." configure-flags) #:make-flags #$make-flags #:out-of-source? #$out-of-source? + #:generator #$generator #:build-type #$build-type #:tests? #$tests? - #:test-target #$test-target + #:test-exclude #$test-exclude + #:test-repeat-until-pass? #$test-repeat-until-pass? + #:test-repeat-until-pass-count #$test-repeat-until-pass-count #:parallel-build? #$parallel-build? #:parallel-tests? #$parallel-tests? #:validate-runpath? #$validate-runpath? @@ -193,9 +209,12 @@ provides a 'CMakeLists.txt' file as its build system." (native-search-paths '()) (make-flags ''()) (out-of-source? #t) + (generator "Unix Makefiles") (build-type "RelWithDebInfo") (tests? #f) ; nothing can be done - (test-target "test") + (test-exclude "") + (test-repeat-until-pass? #t) + (test-repeat-until-pass-count 5) (parallel-build? #t) (parallel-tests? #t) (validate-runpath? #t) (patch-shebangs? #t) @@ -256,9 +275,12 @@ build system." configure-flags)) #:make-flags #$make-flags #:out-of-source? #$out-of-source? + #:generator #$generator #:build-type #$build-type #:tests? #$tests? - #:test-target #$test-target + #:test-exclude #$test-exclude + #:test-repeat-until-pass? #$test-repeat-until-pass? + #:test-repeat-until-pass-count #$test-repeat-until-pass-count #:parallel-build? #$parallel-build? #:parallel-tests? #$parallel-tests? #:validate-runpath? #$validate-runpath? diff --git a/guix/build-system/meson.scm b/guix/build-system/meson.scm index 5eeeb59e65..612e148fb6 100644 --- a/guix/build-system/meson.scm +++ b/guix/build-system/meson.scm @@ -137,7 +137,7 @@ TRIPLET." "Return the default ninja package." ;; Lazily resolve the binding to avoid a circular dependency. (let ((module (resolve-interface '(gnu packages ninja)))) - (module-ref module 'ninja))) + (module-ref module 'ninja/pinned))) (define (default-meson) "Return the default meson package." diff --git a/guix/build-system/qt.scm b/guix/build-system/qt.scm index d1f721c54e..84e008bfe7 100644 --- a/guix/build-system/qt.scm +++ b/guix/build-system/qt.scm @@ -61,13 +61,6 @@ (guix build qt-utils) ,@%cmake-build-system-modules)) -(define (default-cmake) - "Return the default CMake package." - - ;; Do not use `@' to avoid introducing circular dependencies. - (let ((module (resolve-interface '(gnu packages cmake)))) - (module-ref module 'cmake-minimal))) - (define (default-qtbase) "Return the default qtbase package." @@ -79,7 +72,8 @@ ;; the variables defined here. (define* (lower name #:key source inputs native-inputs outputs system target - (cmake (default-cmake)) + (cmake (default-cmake target)) + (ninja (default-ninja)) (qtbase (default-qtbase)) #:allow-other-keys #:rest arguments) @@ -96,6 +90,7 @@ `(("source" ,source)) '()) ,@`(("cmake" ,cmake)) + ,@`(("ninja" ,ninja)) ,@`(("qtbase" ,qtbase)) ,@native-inputs ,@(if target @@ -128,9 +123,12 @@ (search-paths '()) (make-flags ''()) (out-of-source? #t) + (generator "Unix Makefiles") (build-type "RelWithDebInfo") (tests? #t) - (test-target "test") + (test-exclude "") + (test-repeat-until-pass? #t) + (test-repeat-until-pass-count 5) (parallel-build? #t) (parallel-tests? #t) (validate-runpath? #t) (patch-shebangs? #t) @@ -168,9 +166,12 @@ provides a 'CMakeLists.txt' file as its build system." #:configure-flags #$configure-flags #:make-flags #$make-flags #:out-of-source? #$out-of-source? + #:generator #$generator #:build-type #$build-type #:tests? #$tests? - #:test-target #$test-target + #:test-exclude #$test-exclude + #:test-repeat-until-pass? #$test-repeat-until-pass? + #:test-repeat-until-pass-count #$test-repeat-until-pass-count #:parallel-build? #$parallel-build? #:parallel-tests? #$parallel-tests? #:validate-runpath? #$validate-runpath? @@ -205,9 +206,12 @@ provides a 'CMakeLists.txt' file as its build system." (native-search-paths '()) (make-flags ''()) (out-of-source? #t) + (generator "Unix Makefiles") (build-type "RelWithDebInfo") (tests? #f) ; nothing can be done - (test-target "test") + (test-exclude "") + (test-repeat-until-pass? #t) + (test-repeat-until-pass-count 5) (parallel-build? #t) (parallel-tests? #f) (validate-runpath? #t) (patch-shebangs? #t) @@ -258,9 +262,12 @@ build system." #:configure-flags #$configure-flags #:make-flags #$make-flags #:out-of-source? #$out-of-source? + #:generator #$generator #:build-type #$build-type #:tests? #$tests? - #:test-target #$test-target + #:test-exclude #$test-exclude + #:test-repeat-until-pass? #$test-repeat-until-pass? + #:test-repeat-until-pass-count #$test-repeat-until-pass-count #:parallel-build? #$parallel-build? #:parallel-tests? #$parallel-tests? #:validate-runpath? #$validate-runpath? diff --git a/guix/build/cmake-build-system.scm b/guix/build/cmake-build-system.scm index 61033061c6..6d62b870ed 100644 --- a/guix/build/cmake-build-system.scm +++ b/guix/build/cmake-build-system.scm @@ -3,6 +3,7 @@ ;;; Copyright © 2013 Cyril Roelandt <tipecaml@gmail.com> ;;; Copyright © 2014, 2015 Andreas Enge <andreas@enge.fr> ;;; Copyright © 2017 Efraim Flashner <efraim@flashner.co.il> +;;; Copyright © 2024 Greg Hogan <code@greghogan.com> ;;; ;;; This file is part of GNU Guix. ;;; @@ -23,6 +24,8 @@ #:use-module ((guix build gnu-build-system) #:prefix gnu:) #:use-module (guix build utils) #:use-module (ice-9 match) + #:use-module (ice-9 threads) + #:use-module (srfi srfi-34) #:export (%standard-phases cmake-build)) @@ -33,7 +36,7 @@ ;; Code: (define* (configure #:key outputs (configure-flags '()) (out-of-source? #t) - build-type target + build-type target generator (tests? #t) #:allow-other-keys) "Configure the given package." (let* ((out (assoc-ref outputs "out")) @@ -48,38 +51,103 @@ (chdir "../build")) (format #t "build directory: ~s~%" (getcwd)) - (let ((args `(,srcdir - ,@(if build-type - (list (string-append "-DCMAKE_BUILD_TYPE=" - build-type)) - '()) - ,(string-append "-DCMAKE_INSTALL_PREFIX=" out) - ;; ensure that the libraries are installed into /lib - "-DCMAKE_INSTALL_LIBDIR=lib" - ;; add input libraries to rpath - "-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE" - ;; add (other) libraries of the project itself to rpath - ,(string-append "-DCMAKE_INSTALL_RPATH=" out "/lib") - ;; enable verbose output from builds - "-DCMAKE_VERBOSE_MAKEFILE=ON" - ,@configure-flags))) - (format #t "running 'cmake' with arguments ~s~%" args) - (apply invoke "cmake" args)))) + (call-with-temporary-output-file + (lambda (temp port) + (let ((args `(,srcdir + ;; Load variables into the the cache to prevent + ;; warnings about unused manually-specified variables. + ,(string-append "-C " temp) + ,@(if generator + (list (string-append "-G" generator)) + '()) + ,@configure-flags))) -(define* (check #:key (tests? #t) (parallel-tests? #t) (test-target "test") + (define save-to-cache + (lambda* (name value) + ;; <type> and <docstring> arguments are used only by CMake GUIs. + (format port "set(~a \"~a\" CACHE STRING \"\")~%" name value))) + + (if build-type + (save-to-cache "CMAKE_BUILD_TYPE" build-type)) + (save-to-cache "CMAKE_INSTALL_PREFIX" out) + ;; Ensure that the libraries are installed into /lib. + (save-to-cache "CMAKE_INSTALL_LIBDIR" "lib") + ;; Add input libraries to rpath. + (save-to-cache "CMAKE_INSTALL_RPATH_USE_LINK_PATH" "TRUE") + ;; Add (other) libraries of the project itself to rpath. + (save-to-cache "CMAKE_INSTALL_RPATH" (string-append out "/lib")) + ;; Enable verbose output from builds. + (save-to-cache "CMAKE_VERBOSE_MAKEFILE" "ON") + ;; Enable colored compiler diagnostics. + (save-to-cache "CMAKE_COLOR_DIAGNOSTICS" "ON") + ;; BUILD_TESTING in an option of CMake's CTest module. + (save-to-cache "BUILD_TESTING" (if tests? "ON" "OFF")) + + (close-port port) + (format #t "running 'cmake' with arguments ~s~%" args) + (apply invoke "cmake" args)))))) + +(define* (build #:key (make-flags '()) (parallel-build? #t) #:allow-other-keys) - (let ((gnu-check (assoc-ref gnu:%standard-phases 'check))) - (setenv "CTEST_OUTPUT_ON_FAILURE" "1") - (gnu-check #:tests? tests? #:test-target test-target - #:parallel-tests? parallel-tests?))) + (apply invoke "cmake" + `("--build" + "." + ,@(if parallel-build? + `("-j" ,(number->string (parallel-job-count))) + ;; When unset CMake defers to the build system. + '("-j" "1")) + ;; Pass the following options to the native tool. + "--" + ,@(if parallel-build? + ;; Set load average limit for Make and Ninja. + `("-l" ,(number->string (total-processor-count))) + '()) + ,@make-flags))) + +(define %test-suite-log-regexp + ;; Name of test suite log files as commonly found in CMake. + "^LastTest\\.log$") + +(define* (check #:key (tests? #t) (test-exclude "") + (parallel-tests? #t) + (test-repeat-until-pass? #t) + (test-repeat-until-pass-count 5) + (test-suite-log-regexp %test-suite-log-regexp) + #:allow-other-keys) + (if tests? + (guard (c ((invoke-error? c) + ;; Dump the test suite log to facilitate debugging. + (display "\nTest suite failed, dumping logs.\n" + (current-error-port)) + (gnu:dump-file-contents "." test-suite-log-regexp) + (raise c))) + (apply invoke "ctest" "--output-on-failure" "--no-tests=error" + `(,@(if (string-null? test-exclude) + '() + `("--exclude-regex" ,test-exclude)) + ,@(if parallel-tests? + `("-j" ,(number->string (parallel-job-count)) + "--test-load" + ,(number->string (total-processor-count))) + ;; When unset CMake defers to the build system. + '("-j" "1")) + ,@(if test-repeat-until-pass? + `("--repeat" + ,(string-append "until-pass:" + (number->string test-repeat-until-pass-count))) + '())))) + (format #t "test suite not run~%"))) + +(define* (install #:rest args) + (invoke "cmake" "--install" ".")) (define %standard-phases - ;; Everything is as with the GNU Build System except for the `configure' - ;; and 'check' phases. (modify-phases gnu:%standard-phases (delete 'bootstrap) + (replace 'build build) (replace 'check check) - (replace 'configure configure))) + (replace 'configure configure) + (replace 'install install))) (define* (cmake-build #:key inputs (phases %standard-phases) #:allow-other-keys #:rest args) |