gnu: Add zig.
[jackhill/guix/guix.git] / gnu / packages / zig.scm
CommitLineData
9f2c5e90
LMP
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2021 Liliana Prikler <liliana.prikler@gmail.com>
3;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
4;;;
5;;; This file is part of GNU Guix.
6;;;
7;;; GNU Guix is free software; you can redistribute it and/or modify it
8;;; under the terms of the GNU General Public License as published by
9;;; the Free Software Foundation; either version 3 of the License, or (at
10;;; your option) any later version.
11;;;
12;;; GNU Guix is distributed in the hope that it will be useful, but
13;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;;; GNU General Public License for more details.
16;;;
17;;; You should have received a copy of the GNU General Public License
18;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19
20(define-module (gnu packages zig)
21 #:use-module (guix packages)
22 #:use-module (guix git-download)
23 #:use-module ((guix licenses) #:prefix license:)
24 #:use-module (guix build-system cmake)
25 #:use-module (gnu packages)
26 #:use-module (gnu packages llvm))
27
28(define-public zig
29 (package
30 (name "zig")
31 (version "0.8.1")
32 (source
33 (origin
34 (method git-fetch)
35 (uri (git-reference
36 (url "https://github.com/ziglang/zig.git")
37 (commit version)))
38 (file-name (git-file-name name version))
39 (sha256
40 (base32 "147qx7xgj0r353wh5ragzn6kmm1vrf31i8038z3zqwjnqqgqxi6c"))
41 (patches
42 (search-patches
43 "zig-disable-libc-note-test.patch"
44 "zig-use-system-paths.patch"))))
45 (build-system cmake-build-system)
46 (inputs
47 `(("clang" ,clang-12) ; Clang propagates llvm.
48 ("lld" ,lld)))
49 ;; Zig compiles fine with GCC, but also needs native LLVM libraries.
50 (native-inputs
51 `(("llvm" ,llvm-12)))
52 (arguments
53 `(#:configure-flags
54 (list ,@(if (%current-target-system)
55 (string-append "-DZIG_TARGET_TRIPLE="
56 (%current-target-system))
57 '()))
58 #:out-of-source? #f ; for tests
59 #:phases
60 (modify-phases %standard-phases
61 (add-after 'configure 'set-cache-dir
62 (lambda _
63 ;; Set cache dir, otherwise Zig looks for `$HOME/.cache'.
64 (setenv "ZIG_GLOBAL_CACHE_DIR"
65 (string-append (getcwd) "/zig-cache"))))
66 (delete 'check)
67 (add-after 'install 'check
68 (lambda* (#:key outputs tests? #:allow-other-keys)
69 (when tests?
70 (invoke (string-append (assoc-ref outputs "out") "/bin/zig")
71 ;; Testing the standard library takes >7.5GB RAM, and
72 ;; will fail if it is OOM-killed. The 'test-toolchain'
73 ;; target skips standard library and doc tests.
74 "build" "test-toolchain"
75 ;; Stage 2 is experimental, not what we run with `zig',
76 ;; and stage 2 tests require a lot of RAM.
77 "-Dskip-stage2-tests"
78 ;; Non-native tests try to link and execute non-native
79 ;; binaries.
80 "-Dskip-non-native")))))))
81 (native-search-paths
82 (list
83 (search-path-specification
84 (variable "C_INCLUDE_PATH")
85 (files '("include")))
86 (search-path-specification
87 (variable "CPLUS_INCLUDE_PATH")
88 (files '("include/c++" "include")))
89 (search-path-specification
90 (variable "LIBRARY_PATH")
91 (files '("lib" "lib64")))))
92 (synopsis "General purpose programming language and toolchain")
93 (description "Zig is a general-purpose programming language and
94toolchain. Among other features it provides
95@itemize
96@item an Optional type instead of null pointers,
97@item manual memory management,
98@item generic data structures and functions,
99@item compile-time reflection and compile-time code execution,
100@item integration with C using zig as a C compiler, and
101@item concurrency via async functions.
102@end itemize")
103 (home-page "https://github.com/ziglang/zig")
104 (license license:expat)))