1
0
mirror of https://git.savannah.gnu.org/git/guix.git synced 2026-04-06 21:20:33 +02:00

gnu: zig: Default to zig-0.13.

* guix/build-system/zig.scm (#:parallel-build?,#:parallel-tests?):
New arguments.
* guix/build/zig-build-system.scm (zig-arguments): New procedure.
(bulid): Use it and honor #:parallel-build?.
(check): Use it and honor #:parallel-tests?.
* gnu/packages/zig.scm (zig): Define as zig-0.13.
* gnu/packages/ncdu.scm (ncdu)[arguments]<#:zig>: Unset.
<#:zig-release-type>: Set to "safe".
<#:zig-build-flags>: Add "-Dpie".
* gnu/packages/zig-xyz.scm (river)[arguments]<#:zig>: Use zig-0.10.
(zig-zls)[arguments]<#:zig>: Use zig-0.10.
<#:zig-release-type>: Set to "safe".

Change-Id: I1f0087ff39ea9fecb2ad911019d0525f1e6285f6
This commit is contained in:
Hilton Chain
2024-11-20 08:00:54 +08:00
parent 5ce59e0413
commit bdff1941e5
5 changed files with 70 additions and 16 deletions

View File

@@ -72,8 +72,10 @@ ncurses installed.")
"01g5mpvsm78lkd0yin82gyancrl23npy69qcp3d60vmm72yiwirz"))))
(build-system zig-build-system)
(arguments
(list #:zig zig-0.12
#:install-source? #f))
(list #:install-source? #f
#:zig-release-type "safe"
#:zig-build-flags
#~(list "-Dpie")))
(inputs (list ncurses `(,zstd "lib")))
(native-inputs (list pkg-config))
(properties `((tunable? . #t)))))

View File

@@ -53,6 +53,7 @@
(build-system zig-build-system)
(arguments
(list
#:zig zig-0.10
#:install-source? #f
#:phases
#~(modify-phases %standard-phases
@@ -124,7 +125,9 @@ mission-critical safety and performance for financial services.")
(build-system zig-build-system)
(inputs (list zig-0.10 python))
(arguments
(list #:install-source? #f
(list #:zig zig-0.10
#:install-source? #f
#:zig-release-type "safe"
;; The tests fail with memory leaks.
#:tests? #f))
(synopsis "Zig language server")

View File

@@ -1639,4 +1639,4 @@ toolchain. Among other features it provides
(properties `((max-silent-time . 9600)
,@(clang-compiler-cpu-architectures "18")))))
(define-public zig zig-0.10)
(define-public zig zig-0.13)

View File

@@ -48,6 +48,8 @@
source
(tests? #t)
(test-target #f)
(parallel-build? #t)
(parallel-tests? #t)
(install-source? #t)
(skip-build? #f)
(zig-build-flags ''())
@@ -70,6 +72,8 @@
#:source #+source
#:system #$system
#:test-target #$test-target
#:parallel-build? #$parallel-build?
#:parallel-tests? #$parallel-tests?
#:install-source? #$install-source?
#:skip-build? #$skip-build?
#:zig-build-flags #$zig-build-flags
@@ -102,6 +106,8 @@
(native-search-paths '())
(tests? #t)
(test-target #f)
(parallel-build? #t)
(parallel-tests? #t)
(install-source? #t)
(skip-build? #f)
(zig-build-flags ''())
@@ -140,6 +146,8 @@
#:outputs %outputs
#:target #$target
#:test-target #$test-target
#:parallel-build? #$parallel-build?
#:parallel-tests? #$parallel-tests?
#:inputs %build-target-inputs
#:native-inputs %build-host-inputs
#:search-paths '#$(map search-path-specification->sexp

View File

@@ -41,6 +41,32 @@
(zig-source-install-path
(dirname (dirname (dirname (canonicalize-path input))))))
(define (zig-arguments)
(define version-major+minor
(let* ((port (open-input-pipe "zig version"))
(str (read-line port)))
(close-pipe port)
(take (string-split str #\.) 2)))
(define (version>=? a b-major b-minor)
(let ((a-major (string->number (first a)))
(a-minor (string->number (second a))))
(or (> a-major b-major)
(and (= a-major b-major)
(>= a-minor b-minor)))))
`(("parallel-jobs" .
,(lambda (jobs)
(cond
((version>=? version-major+minor 0 11)
(list (string-append "-j" (number->string jobs))))
(else '()))))
("release-type" .
,(lambda (type)
(cond
((version>=? version-major+minor 0 11)
(list (string-append "--release=" type)))
(else
(list (string-append "-Drelease-" type))))))))
;; Notes on Zig package manager (`build.zig.zon')
;; 1. Dependency definition (name -> URL + hash)
;; - Dependency names are not necessarily consistent across packages.
@@ -114,34 +140,49 @@
zig-build-target
;; "safe", "fast" or "small", empty for a "debug" build.
zig-release-type
parallel-build?
skip-build?
#:allow-other-keys)
"Build a given Zig package."
(when (not skip-build?)
(setenv "DESTDIR" "out")
(let ((call `("zig" "build"
"--prefix" "" ;; Don't add /usr
"--prefix-lib-dir" "lib"
"--prefix-exe-dir" "bin"
"--prefix-include-dir" "include"
,(string-append "-Dtarget=" (zig-target zig-build-target))
,@(if zig-release-type
(list (string-append "-Drelease-" zig-release-type))
'())
,@zig-build-flags)))
(let* ((arguments (zig-arguments))
(call `("zig" "build"
"--prefix" "" ;; Don't add /usr
"--prefix-lib-dir" "lib"
"--prefix-exe-dir" "bin"
"--prefix-include-dir" "include"
,(string-append "-Dtarget=" (zig-target zig-build-target))
,@(if parallel-build?
((assoc-ref arguments "parallel-jobs")
(parallel-job-count))
((assoc-ref arguments "parallel-jobs")
1))
,@(if zig-release-type
((assoc-ref arguments "release-type")
zig-release-type)
'())
,@zig-build-flags)))
(format #t "running: ~s~%" call)
(apply invoke call))))
(define* (check #:key tests?
zig-test-flags
target
parallel-tests?
#:allow-other-keys)
"Run all the tests"
(when (and tests? (not target))
(let ((old-destdir (getenv "DESTDIR")))
(setenv "DESTDIR" "test-out") ;; Avoid colisions with the build output
(let ((call `("zig" "build" "test"
,@zig-test-flags)))
(let* ((arguments (zig-arguments))
(call `("zig" "build" "test"
,@(if parallel-tests?
((assoc-ref arguments "parallel-jobs")
(parallel-job-count))
((assoc-ref arguments "parallel-jobs")
1))
,@zig-test-flags)))
(format #t "running: ~s~%" call)
(apply invoke call))
(if old-destdir