summaryrefslogtreecommitdiff
path: root/gnu/packages/zig.scm
diff options
context:
space:
mode:
authorHilton Chain <hako@ultrarare.space>2024-11-19 20:27:49 +0800
committerHilton Chain <hako@ultrarare.space>2024-12-31 10:56:34 +0800
commit3ef8c9307ce10ca59af9bcf84161a88fd08310e7 (patch)
treee778ed993ab65c9112bb45672dcd79fe018fb0a2 /gnu/packages/zig.scm
parent05bbf0ec43abcc8c49e1e49e95baca24f6fea950 (diff)
gnu: zig: Build reproducibly.
* guix/build/zig-utils.scm: New file. * Makefile.am (MODULES): Add it. * guix/build-system/zig.scm (%zig-build-system-modules): Add it. (zig-build,zig-cross-build): Add #:zig-build-target. * guix/build/zig-build-system.scm (zig-target): Move to (guix build zig-utils). (configure): Move to (guix build zig-utils) as zig-configure. (build): Replace target with zig-build-target. (%standard-phases): Adjust accordingly. * gnu/packages/zig.scm (zig-0.9)[arguments]<#:imported-modules,#:modules>: Add zig-build-system modules. <#:configure-flags>: Set ZIG_TARGET_TRIPLE for native builds too. Move applicable flags from zig-0.10 here. <#:phases>: Apply 'zig-configure. Unset ZIG_LIBC in 'check. Remove 'set-cache-dir. (zig-0.10)[arguments]<#:configure-flags>: Adjust accordingly. (zig-0.10.0-610)[arguments]<#:configure-flags>: Remove ZIG_TARGET_TRIPLE.
Diffstat (limited to 'gnu/packages/zig.scm')
-rw-r--r--gnu/packages/zig.scm52
1 files changed, 34 insertions, 18 deletions
diff --git a/gnu/packages/zig.scm b/gnu/packages/zig.scm
index 62e224b760a..99335c54048 100644
--- a/gnu/packages/zig.scm
+++ b/gnu/packages/zig.scm
@@ -23,6 +23,7 @@
23(define-module (gnu packages zig) 23(define-module (gnu packages zig)
24 #:use-module (guix gexp) 24 #:use-module (guix gexp)
25 #:use-module (guix packages) 25 #:use-module (guix packages)
26 #:use-module (guix platform)
26 #:use-module (guix utils) 27 #:use-module (guix utils)
27 #:use-module (guix download) 28 #:use-module (guix download)
28 #:use-module (guix git-download) 29 #:use-module (guix git-download)
@@ -87,11 +88,24 @@
87 (build-system cmake-build-system) 88 (build-system cmake-build-system)
88 (arguments 89 (arguments
89 (list 90 (list
91 #:imported-modules
92 (cons '(guix build zig-utils)
93 %cmake-build-system-modules)
94 #:modules
95 (cons '(guix build zig-utils)
96 '((guix build cmake-build-system)
97 (guix build utils)))
90 #:configure-flags 98 #:configure-flags
91 #~(list #$@(if (%current-target-system) 99 #~(list (string-append "-DZIG_LIB_DIR=" #$output "/lib/zig")
92 (list (string-append "-DZIG_TARGET_TRIPLE=" 100 "-DZIG_TARGET_MCPU=baseline"
93 (%current-target-system))) 101 (string-append
94 '())) 102 "-DZIG_TARGET_TRIPLE="
103 (zig-target
104 #$(platform-target
105 (lookup-platform-by-target-or-system
106 (or (%current-target-system)
107 (%current-system))))))
108 "-DZIG_USE_LLVM_CONFIG=ON")
95 #:out-of-source? #f ; for tests 109 #:out-of-source? #f ; for tests
96 ;; There are too many unclear test failures. 110 ;; There are too many unclear test failures.
97 #:tests? (not (or (target-riscv64?) 111 #:tests? (not (or (target-riscv64?)
@@ -114,15 +128,14 @@
114 ;; Is this symbol x86 only in glibc? 128 ;; Is this symbol x86 only in glibc?
115 ((".*link_static_lib_as_system_lib.*") ""))))) 129 ((".*link_static_lib_as_system_lib.*") "")))))
116 '()) 130 '())
117 (add-after 'configure 'set-cache-dir 131 (add-before 'configure 'zig-configure zig-configure)
118 (lambda _
119 ;; Set cache dir, otherwise Zig looks for `$HOME/.cache'.
120 (setenv "ZIG_GLOBAL_CACHE_DIR"
121 (string-append (getcwd) "/zig-cache"))))
122 (delete 'check) 132 (delete 'check)
123 (add-after 'install 'check 133 (add-after 'install 'check
124 (lambda* (#:key tests? #:allow-other-keys) 134 (lambda* (#:key tests? #:allow-other-keys)
125 (when tests? 135 (when tests?
136 ;; error(libc_installation): msvc_lib_dir may not be empty for
137 ;; windows-msvc.
138 (unsetenv "ZIG_LIBC")
126 (invoke (string-append #$output "/bin/zig") 139 (invoke (string-append #$output "/bin/zig")
127 ;; Testing the standard library takes >7.5GB RAM, and 140 ;; Testing the standard library takes >7.5GB RAM, and
128 ;; will fail if it is OOM-killed. The 'test-toolchain' 141 ;; will fail if it is OOM-killed. The 'test-toolchain'
@@ -222,20 +235,13 @@ toolchain. Among other features it provides
222 ((#:tests? _ #t) 235 ((#:tests? _ #t)
223 (not (%current-target-system))) 236 (not (%current-target-system)))
224 ((#:configure-flags flags ''()) 237 ((#:configure-flags flags ''())
225 #~(cons* "-DZIG_TARGET_MCPU=baseline" 238 #~(cons "-DZIG_SHARED_LLVM=ON"
226 "-DZIG_SHARED_LLVM=ON" 239 #$flags))
227 (string-append "-DZIG_LIB_DIR=" #$output "/lib/zig")
228 #$flags))
229 ((#:phases phases '%standard-phases) 240 ((#:phases phases '%standard-phases)
230 #~(modify-phases #$phases 241 #~(modify-phases #$phases
231 #$@(if (target-riscv64?) 242 #$@(if (target-riscv64?)
232 `((delete 'adjust-tests)) 243 `((delete 'adjust-tests))
233 '()) 244 '())
234 (add-after 'unpack 'set-CC
235 (lambda _
236 ;; Set CC, since the stage 2 zig relies on it to find the libc
237 ;; installation, and otherwise silently links against its own.
238 (setenv "CC" #$(cc-for-target))))
239 (add-after 'patch-source-shebangs 'patch-more-shebangs 245 (add-after 'patch-source-shebangs 'patch-more-shebangs
240 (lambda* (#:key inputs #:allow-other-keys) 246 (lambda* (#:key inputs #:allow-other-keys)
241 ;; Zig uses information about an ELF file to determine the 247 ;; Zig uses information about an ELF file to determine the
@@ -245,6 +251,9 @@ toolchain. Among other features it provides
245 (replace 'check 251 (replace 'check
246 (lambda* (#:key tests? #:allow-other-keys) 252 (lambda* (#:key tests? #:allow-other-keys)
247 (when tests? 253 (when tests?
254 ;; error(libc_installation): msvc_lib_dir may not be empty for
255 ;; windows-msvc.
256 (unsetenv "ZIG_LIBC")
248 (invoke (string-append #$output "/bin/zig") 257 (invoke (string-append #$output "/bin/zig")
249 "build" "test" 258 "build" "test"
250 ;; We're not testing the compiler bootstrap chain. 259 ;; We're not testing the compiler bootstrap chain.
@@ -314,6 +323,13 @@ toolchain. Among other features it provides
314 (substitute-keyword-arguments (package-arguments base) 323 (substitute-keyword-arguments (package-arguments base)
315 ;; Patch for fixing RUNPATH not applied to intermediate versions. 324 ;; Patch for fixing RUNPATH not applied to intermediate versions.
316 ((#:validate-runpath? _ #t) #f) 325 ((#:validate-runpath? _ #t) #f)
326 ;; Patch for cross-compilation not applied to intermediate versions.
327 ((#:modules modules '())
328 (cons '(srfi srfi-1) modules))
329 ((#:configure-flags flags ''())
330 #~(filter (lambda (flag)
331 (not (string-contains flag "ZIG_TARGET_TRIPLE")))
332 #$flags))
317 ;; Disable tests for intermediate versions. 333 ;; Disable tests for intermediate versions.
318 ((#:tests? _ #t) #f) 334 ((#:tests? _ #t) #f)
319 ((#:phases phases '%standard-phases) 335 ((#:phases phases '%standard-phases)