GNU bug report logs - #47006
[PATCH] gnu: Add zig.

Previous Next

Package: guix-patches;

Reported by: Leo Prikler <leo.prikler <at> student.tugraz.at>

Date: Mon, 8 Mar 2021 13:15:02 UTC

Severity: normal

Tags: patch

Merged with 39480, 50449

Done: Liliana Marie Prikler <liliana.prikler <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 47006 in the body.
You can then email your comments to 47006 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to guix-patches <at> gnu.org:
bug#47006; Package guix-patches. (Mon, 08 Mar 2021 13:15:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Leo Prikler <leo.prikler <at> student.tugraz.at>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Mon, 08 Mar 2021 13:15:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Leo Prikler <leo.prikler <at> student.tugraz.at>
To: guix-patches <at> gnu.org
Subject: [PATCH] gnu: Add zig.
Date: Mon,  8 Mar 2021 14:11:56 +0100
* gnu/packages/zig.scm: New file.
* gnu/local.mk (GNU_SYSTEM_MODULES): Add it here.
---
 gnu/local.mk         |  1 +
 gnu/packages/zig.scm | 65 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+)
 create mode 100644 gnu/packages/zig.scm

diff --git a/gnu/local.mk b/gnu/local.mk
index fb3b395852..abcf86fb7e 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -586,6 +586,7 @@ GNU_SYSTEM_MODULES =				\
   %D%/packages/xdisorg.scm			\
   %D%/packages/xorg.scm				\
   %D%/packages/xfce.scm				\
+  %D%/packages/zig.scm				\
   %D%/packages/zile.scm				\
   %D%/packages/zwave.scm			\
 						\
diff --git a/gnu/packages/zig.scm b/gnu/packages/zig.scm
new file mode 100644
index 0000000000..caf0a5e21a
--- /dev/null
+++ b/gnu/packages/zig.scm
@@ -0,0 +1,65 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2021 Leo Prikler <leo.prikler <at> student.tugraz.at>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (gnu packages zig)
+  #:use-module (guix packages)
+  #:use-module (guix git-download)
+  #:use-module ((guix licenses) #:prefix license:)
+  #:use-module (guix build-system cmake)
+  #:use-module (gnu packages)
+  #:use-module (gnu packages llvm))
+
+(define-public zig
+  (package
+    (name "zig")
+    (version "0.7.1")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/ziglang/zig.git")
+             (commit version)))
+       (file-name (git-file-name name version))
+       (sha256
+        (base32 "1z6c4ym9jmga46cw2arn7zv2drcpmrf3vw139gscxp27n7q2z5md"))))
+    (build-system cmake-build-system)
+    (native-inputs
+     `(("clang" ,clang-11)
+       ("lld" ,lld)
+       ("llvm" ,llvm-11)))
+    (arguments
+     `(#:tests? #f                       ; no check target
+       #:phases
+       (modify-phases %standard-phases
+         (add-after 'configure 'set-home
+           (lambda _
+             (setenv "HOME" (getcwd))    ; zig writes to $HOME/.cache
+             #t)))))
+    (synopsis "General purpose programming language and toolchain")
+    (description "Zig is a general-purpose programming language and
+toolchain.  Among other features it provides
+@itemize
+@item an Optional type instead of null pointers,
+@item manual memory management,
+@item generic data structures and functions,
+@item compile-time reflection and compile-time code execution,
+@item integration with C using zig as a C compiler, and
+@item concurrency via async functions.
+@end itemize")
+    (home-page "https://github.com/ziglang/zig")
+    (license license:expat)))
-- 
2.30.1





Information forwarded to guix-patches <at> gnu.org:
bug#47006; Package guix-patches. (Mon, 15 Mar 2021 14:22:01 GMT) Full text and rfc822 format available.

Message #8 received at 47006 <at> debbugs.gnu.org (full text, mbox):

From: Léo Le Bouter <lle-bout <at> zaclys.net>
To: 47006 <at> debbugs.gnu.org
Cc: Léo Le Bouter <lle-bout <at> zaclys.net>
Subject: [PATCH v2 0/1] gnu: Add zig.
Date: Mon, 15 Mar 2021 15:20:44 +0100
I attempted to add tests, Zig has an unconventional way of requiring tests to be
run after installation so I added a 'check phase after the 'install phase which
works but then after lots of tests succeeded there is a FileNotFound error cause
by some 'test' binary failing to run.

I found out by running:

$ ./pre-inst-env guix build --keep-failed zig
$ cd /tmp/guix-build-zig-0.7.1.drv-0/source
$ env -i $(which bash)
$ source ../environment-variables
$ /run/current-system/profile/bin/strace -f -e trace=file /gnu/store/1cmjgdiim452bqkzgp53d0kw4fi4gfar-zig-0.7.1/bin/zig build test
...
[pid 25896] execve("/tmp/guix-build-zig-0.7.1.drv-0/source/zig-cache/o/25718f52ae311b1dafdba7de4a338f12/test", ["/tmp/guix-build-zig-0.7.1.drv-0/"...], 0x4e42bb0 /* 27 vars */) = -1 ENOENT (No such file or directory)
[pid 25896] +++ exited with 1 +++
[pid 25885] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=25896, si_uid=1000, si_status=1, si_utime=0, si_stime=0} ---
error: FileNotFound
...
$ ldd /tmp/guix-build-zig-0.7.1.drv-0/source/zig-cache/o/25718f52ae311b1dafdba7de4a338f12/test
        linux-vdso.so.1 (0x00007ffd22d1d000)
        libc.so.6 => /gnu/store/fa6wj5bxkj5ll1d7292a70knmyl7a0cr-glibc-2.31/lib/libc.so.6 (0x00007fea82162000)
        libm.so.6 => /gnu/store/fa6wj5bxkj5ll1d7292a70knmyl7a0cr-glibc-2.31/lib/libm.so.6 (0x00007fea82021000)
        libpthread.so.0 => /gnu/store/fa6wj5bxkj5ll1d7292a70knmyl7a0cr-glibc-2.31/lib/libpthread.so.0 (0x00007fea82000000)
        libdl.so.2 => /gnu/store/fa6wj5bxkj5ll1d7292a70knmyl7a0cr-glibc-2.31/lib/libdl.so.2 (0x00007fea81ffb000)
        librt.so.1 => /gnu/store/fa6wj5bxkj5ll1d7292a70knmyl7a0cr-glibc-2.31/lib/librt.so.1 (0x00007fea81ff1000)
        /lib64/ld-linux-x86-64.so.2 => /gnu/store/fa6wj5bxkj5ll1d7292a70knmyl7a0cr-glibc-2.31/lib/ld-linux-x86-64.so.2 (0x00007fea82321000)
        libutil.so.1 => /gnu/store/fa6wj5bxkj5ll1d7292a70knmyl7a0cr-glibc-2.31/lib/libutil.so.1 (0x00007fea81fec000)
$ file /tmp/guix-build-zig-0.7.1.drv-0/source/zig-cache/o/25718f52ae311b1dafdba7de4a338f12/test
/tmp/guix-build-zig-0.7.1.drv-0/source/zig-cache/o/25718f52ae311b1dafdba7de4a338f12/test: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.0.0, with debug_info, not stripped

The issue here is that this binary should work fine already according to the
output of ldd and file. We would need a way to get verbose debugging errors of
execve somehow.

Leo Prikler (1):
  gnu: Add zig.

 gnu/local.mk         |  1 +
 gnu/packages/zig.scm | 76 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 77 insertions(+)
 create mode 100644 gnu/packages/zig.scm

-- 
2.30.2





Information forwarded to guix-patches <at> gnu.org:
bug#47006; Package guix-patches. (Mon, 15 Mar 2021 14:22:02 GMT) Full text and rfc822 format available.

Message #11 received at 47006 <at> debbugs.gnu.org (full text, mbox):

From: Léo Le Bouter <lle-bout <at> zaclys.net>
To: 47006 <at> debbugs.gnu.org
Cc: Léo Le Bouter <lle-bout <at> zaclys.net>,
 Leo Prikler <leo.prikler <at> student.tugraz.at>
Subject: [PATCH v2 1/1] gnu: Add zig.
Date: Mon, 15 Mar 2021 15:20:45 +0100
From: Leo Prikler <leo.prikler <at> student.tugraz.at>

* gnu/packages/zig.scm: New file.
* gnu/local.mk (GNU_SYSTEM_MODULES): Add it here.

Co-authored-by: Léo Le Bouter <lle-bout <at> zaclys.net>
---
 gnu/local.mk         |  1 +
 gnu/packages/zig.scm | 76 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 77 insertions(+)
 create mode 100644 gnu/packages/zig.scm

diff --git a/gnu/local.mk b/gnu/local.mk
index cf8849cf59..ffa8005533 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -586,6 +586,7 @@ GNU_SYSTEM_MODULES =				\
   %D%/packages/xdisorg.scm			\
   %D%/packages/xorg.scm				\
   %D%/packages/xfce.scm				\
+  %D%/packages/zig.scm				\
   %D%/packages/zile.scm				\
   %D%/packages/zwave.scm			\
 						\
diff --git a/gnu/packages/zig.scm b/gnu/packages/zig.scm
new file mode 100644
index 0000000000..adc4c3e1e0
--- /dev/null
+++ b/gnu/packages/zig.scm
@@ -0,0 +1,76 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2021 Leo Prikler <leo.prikler <at> student.tugraz.at>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (gnu packages zig)
+  #:use-module (guix packages)
+  #:use-module (guix git-download)
+  #:use-module ((guix licenses) #:prefix license:)
+  #:use-module (guix build-system cmake)
+  #:use-module (gnu packages)
+  #:use-module (gnu packages llvm))
+
+(define-public zig
+  (package
+    (name "zig")
+    (version "0.7.1")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/ziglang/zig.git")
+             (commit version)))
+       (file-name (git-file-name name version))
+       (sha256
+        (base32 "1z6c4ym9jmga46cw2arn7zv2drcpmrf3vw139gscxp27n7q2z5md"))))
+    (build-system cmake-build-system)
+    (native-inputs
+     `(("clang" ,clang-11)
+       ("lld" ,lld)
+       ("llvm" ,llvm-11)))
+    (arguments
+     `(#:phases
+       (modify-phases %standard-phases
+         (add-after 'unpack 'save-unpack-dir
+           (lambda _
+             ;; HACK: Passing unpacked source directory to 'check phase.
+             (setenv "ZIG_UNPACK_DIR" (getcwd))
+             #t))
+         (add-after 'configure 'set-home
+           (lambda _
+             (setenv "HOME" (getcwd))    ; zig writes to $HOME/.cache
+             #t))
+         (delete 'check)
+         (add-after 'install 'check
+           (lambda* (#:key outputs #:allow-other-keys)
+             (with-directory-excursion (getenv "ZIG_UNPACK_DIR")
+               (invoke (string-append (assoc-ref outputs "out") "/bin/zig")
+                       "build" "test"))
+             #t)))))
+    (synopsis "General purpose programming language and toolchain")
+    (description "Zig is a general-purpose programming language and
+toolchain.  Among other features it provides
+@itemize
+@item an Optional type instead of null pointers,
+@item manual memory management,
+@item generic data structures and functions,
+@item compile-time reflection and compile-time code execution,
+@item integration with C using zig as a C compiler, and
+@item concurrency via async functions.
+@end itemize")
+    (home-page "https://github.com/ziglang/zig")
+    (license license:expat)))
-- 
2.30.2





Information forwarded to guix-patches <at> gnu.org:
bug#47006; Package guix-patches. (Tue, 16 Mar 2021 12:59:03 GMT) Full text and rfc822 format available.

Message #14 received at 47006 <at> debbugs.gnu.org (full text, mbox):

From: Efraim Flashner <efraim <at> flashner.co.il>
To: Leo Prikler <leo.prikler <at> student.tugraz.at>
Cc: 47006 <at> debbugs.gnu.org
Subject: Re: [bug#47006] [PATCH] gnu: Add zig.
Date: Tue, 16 Mar 2021 14:57:32 +0200
[Message part 1 (text/plain, inline)]
On Mon, Mar 08, 2021 at 02:11:56PM +0100, Leo Prikler wrote:
> * gnu/packages/zig.scm: New file.
> * gnu/local.mk (GNU_SYSTEM_MODULES): Add it here.
> ---
>  gnu/local.mk         |  1 +
>  gnu/packages/zig.scm | 65 ++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 66 insertions(+)
>  create mode 100644 gnu/packages/zig.scm
> 
> diff --git a/gnu/local.mk b/gnu/local.mk
> index fb3b395852..abcf86fb7e 100644
> --- a/gnu/local.mk
> +++ b/gnu/local.mk
> @@ -586,6 +586,7 @@ GNU_SYSTEM_MODULES =				\
>    %D%/packages/xdisorg.scm			\
>    %D%/packages/xorg.scm				\
>    %D%/packages/xfce.scm				\
> +  %D%/packages/zig.scm				\
>    %D%/packages/zile.scm				\
>    %D%/packages/zwave.scm			\
>  						\
> diff --git a/gnu/packages/zig.scm b/gnu/packages/zig.scm
> new file mode 100644
> index 0000000000..caf0a5e21a
> --- /dev/null
> +++ b/gnu/packages/zig.scm
> @@ -0,0 +1,65 @@
> +;;; GNU Guix --- Functional package management for GNU
> +;;; Copyright © 2021 Leo Prikler <leo.prikler <at> student.tugraz.at>
> +;;;
> +;;; This file is part of GNU Guix.
> +;;;
> +;;; GNU Guix is free software; you can redistribute it and/or modify it
> +;;; under the terms of the GNU General Public License as published by
> +;;; the Free Software Foundation; either version 3 of the License, or (at
> +;;; your option) any later version.
> +;;;
> +;;; GNU Guix is distributed in the hope that it will be useful, but
> +;;; WITHOUT ANY WARRANTY; without even the implied warranty of
> +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +;;; GNU General Public License for more details.
> +;;;
> +;;; You should have received a copy of the GNU General Public License
> +;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
> +
> +(define-module (gnu packages zig)
> +  #:use-module (guix packages)
> +  #:use-module (guix git-download)
> +  #:use-module ((guix licenses) #:prefix license:)
> +  #:use-module (guix build-system cmake)
> +  #:use-module (gnu packages)
> +  #:use-module (gnu packages llvm))
> +
> +(define-public zig
> +  (package
> +    (name "zig")
> +    (version "0.7.1")
> +    (source
> +     (origin
> +       (method git-fetch)
> +       (uri (git-reference
> +             (url "https://github.com/ziglang/zig.git")
> +             (commit version)))
> +       (file-name (git-file-name name version))
> +       (sha256
> +        (base32 "1z6c4ym9jmga46cw2arn7zv2drcpmrf3vw139gscxp27n7q2z5md"))))
> +    (build-system cmake-build-system)
> +    (native-inputs
> +     `(("clang" ,clang-11)
> +       ("lld" ,lld)
> +       ("llvm" ,llvm-11)))

Does it work to replace these three with clang-toolchain-11?

> +    (arguments
> +     `(#:tests? #f                       ; no check target
> +       #:phases
> +       (modify-phases %standard-phases
> +         (add-after 'configure 'set-home
> +           (lambda _
> +             (setenv "HOME" (getcwd))    ; zig writes to $HOME/.cache
> +             #t)))))
> +    (synopsis "General purpose programming language and toolchain")
> +    (description "Zig is a general-purpose programming language and
> +toolchain.  Among other features it provides
> +@itemize
> +@item an Optional type instead of null pointers,
> +@item manual memory management,
> +@item generic data structures and functions,
> +@item compile-time reflection and compile-time code execution,
> +@item integration with C using zig as a C compiler, and
> +@item concurrency via async functions.
> +@end itemize")
> +    (home-page "https://github.com/ziglang/zig")
> +    (license license:expat)))
> -- 
> 2.30.1
> 
> 
> 
> 

-- 
Efraim Flashner   <efraim <at> flashner.co.il>   אפרים פלשנר
GPG key = A28B F40C 3E55 1372 662D  14F7 41AA E7DC CA3D 8351
Confidentiality cannot be guaranteed on emails sent or received unencrypted
[signature.asc (application/pgp-signature, inline)]

Information forwarded to guix-patches <at> gnu.org:
bug#47006; Package guix-patches. (Tue, 16 Mar 2021 13:10:02 GMT) Full text and rfc822 format available.

Message #17 received at 47006 <at> debbugs.gnu.org (full text, mbox):

From: Leo Prikler <leo.prikler <at> student.tugraz.at>
To: Efraim Flashner <efraim <at> flashner.co.il>
Cc: 47006 <at> debbugs.gnu.org
Subject: Re: [bug#47006] [PATCH] gnu: Add zig.
Date: Tue, 16 Mar 2021 14:09:34 +0100
Am Dienstag, den 16.03.2021, 14:57 +0200 schrieb Efraim Flashner:
> On Mon, Mar 08, 2021 at 02:11:56PM +0100, Leo Prikler wrote:
> > +    (native-inputs
> > +     `(("clang" ,clang-11)
> > +       ("lld" ,lld)
> > +       ("llvm" ,llvm-11)))
> 
> Does it work to replace these three with clang-toolchain-11?
You can replace clang+llvm by clang-toolchain, but IIUC we prefer the
explicit style in Guix.  Correct me if I'm wrong.

Regards,
Leo





Information forwarded to guix-patches <at> gnu.org:
bug#47006; Package guix-patches. (Wed, 17 Mar 2021 07:06:02 GMT) Full text and rfc822 format available.

Message #20 received at 47006 <at> debbugs.gnu.org (full text, mbox):

From: Léo Le Bouter <lle-bout <at> zaclys.net>
To: 47006 <at> debbugs.gnu.org
Subject: [PATCH] gnu: Add zig.
Date: Wed, 17 Mar 2021 08:05:32 +0100
[Message part 1 (text/plain, inline)]
Another patch submission for Zig was sent: 
https://issues.guix.gnu.org/47206 (I closed and directed them here for
cooperation instead). But still have a look there for any improvements
to the current patch.
[signature.asc (application/pgp-signature, inline)]

Information forwarded to guix-patches <at> gnu.org:
bug#47006; Package guix-patches. (Fri, 09 Apr 2021 22:22:02 GMT) Full text and rfc822 format available.

Message #23 received at 47006 <at> debbugs.gnu.org (full text, mbox):

From: terramorpha <at> protonmail.com
To: "47006 <at> debbugs.gnu.org" <47006 <at> debbugs.gnu.org>
Subject: (No Subject)
Date: Fri, 09 Apr 2021 22:17:32 +0000
[Message part 1 (text/plain, inline)]
Hi, are there any issues left preventing this patch from being merged? If so, I can help. I would love to see Zig packaged in guix.
[Message part 2 (text/html, inline)]

Information forwarded to guix-patches <at> gnu.org:
bug#47006; Package guix-patches. (Sun, 11 Apr 2021 21:05:01 GMT) Full text and rfc822 format available.

Message #26 received at 47006 <at> debbugs.gnu.org (full text, mbox):

From: Maxime Devos <maximedevos <at> telenet.be>
To: 47006 <at> debbugs.gnu.org
Subject: Re: [PATCH] gnu: Add zig.
Date: Sun, 11 Apr 2021 23:04:15 +0200
[Message part 1 (text/plain, inline)]
One comment below.

> +    (native-inputs
> +     `(("clang" ,clang-11)
> +       ("lld" ,lld)
> +       ("llvm" ,llvm-11)))

This looks rather suspicious from a cross-compilation perspective.
IIUC, lld and llvm are used for two purposes:

* for compiling the "zig" compiler  --> native-inputs is ok
  (or is GCC used to compile the zig compiler?)
* as a run-time dependency of "zig" --> should be 'inputs'

Therefore, shouldn't "lld" and "llvm" be added to "inputs" as well?

TODO to self: define a variant of disallowed-references
disallowed-references/native that refers to the package in 'native-inputs'
instead of 'inputs'.

Perhaps explicitely whitelist some inputs (llvm, lld, maybe some implicit
libc inputs?).

Note: according to me, *all* inputs in native-inputs should be added
to disallowed-references *by default* when cross-compiling.

Alternatively, I guess ‘we’ could simply add a comment
;; Cross-compilation is currently unsupported.
and leave cross-compilation for later.  My comments are mostly about
‘giving the good example’ on how to use inputs & native-inputs and avoid
giving ‘bad examples’ of package definitions without marking them as such.

Greetings,
Maxime.
[signature.asc (application/pgp-signature, inline)]

Information forwarded to guix-patches <at> gnu.org:
bug#47006; Package guix-patches. (Sun, 30 May 2021 09:33:02 GMT) Full text and rfc822 format available.

Message #29 received at 47006 <at> debbugs.gnu.org (full text, mbox):

From: Sharlatan Hellseher <sharlatanus <at> gmail.com>
To: 47006 <at> debbugs.gnu.org
Subject: Zig question
Date: Sun, 30 May 2021 10:32:33 +0100
[Message part 1 (text/plain, inline)]
Hi Guix team.


There is an open issue from 2020 adding zig

 https://issues.guix.gnu.org/39480

it probably could be linked to this one #47006

Zig has it's own build system:

 zig build

it will be usefully to have a guix native build system as well when
compiler is merged.

https://ziglang.org/learn/overview/#zig-build-system

It also has a language server https://github.com/zigtools/zls
[Message part 2 (text/html, inline)]

Merged 39480 47006. Request was from Leo Prikler <leo.prikler <at> student.tugraz.at> to control <at> debbugs.gnu.org. (Mon, 31 May 2021 07:02:01 GMT) Full text and rfc822 format available.

Merged 39480 47006 50449. Request was from Liliana Marie Prikler <liliana.prikler <at> gmail.com> to control <at> debbugs.gnu.org. (Wed, 08 Sep 2021 22:17:01 GMT) Full text and rfc822 format available.

Information forwarded to guix-patches <at> gnu.org:
bug#47006; Package guix-patches. (Thu, 09 Sep 2021 13:51:02 GMT) Full text and rfc822 format available.

Message #36 received at 47006 <at> debbugs.gnu.org (full text, mbox):

From: Liliana Prikler <liliana.prikler <at> gmail.com>
To: 47006 <at> debbugs.gnu.org
Cc: maximedevos <at> telenet.be, efraim <at> flashner.co.il
Subject: [PATCH 2/2] gnu: Add zig.
Date: Thu, 9 Sep 2021 15:32:22 +0200
* gnu/packages/zig.scm: New file.
* gnu/local.mk (GNU_SYSTEM_MODULES): Add it here.
---
 gnu/local.mk         |  1 +
 gnu/packages/zig.scm | 83 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+)
 create mode 100644 gnu/packages/zig.scm

diff --git a/gnu/local.mk b/gnu/local.mk
index 2a56c4a9e2..710e5bd9df 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -598,6 +598,7 @@ GNU_SYSTEM_MODULES =				\
   %D%/packages/xdisorg.scm			\
   %D%/packages/xorg.scm				\
   %D%/packages/xfce.scm				\
+  %D%/packages/zig.scm				\
   %D%/packages/zile.scm				\
   %D%/packages/zwave.scm			\
 						\
diff --git a/gnu/packages/zig.scm b/gnu/packages/zig.scm
new file mode 100644
index 0000000000..8b9a863b4d
--- /dev/null
+++ b/gnu/packages/zig.scm
@@ -0,0 +1,83 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2021 Leo Prikler <leo.prikler <at> student.tugraz.at>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (gnu packages zig)
+  #:use-module (guix packages)
+  #:use-module (guix git-download)
+  #:use-module ((guix licenses) #:prefix license:)
+  #:use-module (guix build-system cmake)
+  #:use-module (gnu packages)
+  #:use-module (gnu packages llvm))
+
+(define-public zig
+  (package
+    (name "zig")
+    (version "0.8.1")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/ziglang/zig.git")
+             (commit version)))
+       (file-name (git-file-name name version))
+       (sha256
+        (base32 "147qx7xgj0r353wh5ragzn6kmm1vrf31i8038z3zqwjnqqgqxi6c"))))
+    (build-system cmake-build-system)
+    ;; Zig is based on and builds itself using the Clang toolchain,
+    ;; so add it both as inputs and native-inputs.
+    (inputs
+     `(("clang" ,clang-12)
+       ("lld" ,lld-12)
+       ("llvm" ,llvm-12)))
+    (native-inputs
+     `(("clang" ,clang-12)
+       ("lld" ,lld-12)
+       ("llvm" ,llvm-12)))
+    (arguments
+     `(#:tests? #f                       ; no check target
+       #:phases
+       (modify-phases %standard-phases
+         (add-after 'unpack 'save-unpack-dir
+           (lambda _
+             ;; HACK: Passing unpacked source directory to 'check phase.
+             (setenv "ZIG_SOURCE_DIR" (getcwd))
+             #t))
+         (add-after 'configure 'set-home
+           (lambda _
+             (setenv "HOME" (getcwd))    ; zig writes to $HOME/.cache
+             #t))
+         (delete 'check)
+         (add-after 'install 'check
+           (lambda* (#:key outputs tests? #:allow-other-keys)
+             (when tests?
+               (with-directory-excursion (getenv "ZIG_SOURCE_DIR")
+                 (invoke (string-append (assoc-ref outputs) "out") "/bin/zig"
+                         "build" "test"))))))))
+    (synopsis "General purpose programming language and toolchain")
+    (description "Zig is a general-purpose programming language and
+toolchain.  Among other features it provides
+@itemize
+@item an Optional type instead of null pointers,
+@item manual memory management,
+@item generic data structures and functions,
+@item compile-time reflection and compile-time code execution,
+@item integration with C using zig as a C compiler, and
+@item concurrency via async functions.
+@end itemize")
+    (home-page "https://github.com/ziglang/zig")
+    (license license:expat)))
-- 
2.33.0






Information forwarded to guix-patches <at> gnu.org:
bug#47006; Package guix-patches. (Thu, 09 Sep 2021 13:51:02 GMT) Full text and rfc822 format available.

Message #39 received at 47006 <at> debbugs.gnu.org (full text, mbox):

From: Liliana Prikler <liliana.prikler <at> gmail.com>
To: 47006 <at> debbugs.gnu.org
Cc: maximedevos <at> telenet.be, efraim <at> flashner.co.il
Subject: [PATCH 1/2] gnu: lld: Update to 12.0.0.
Date: Thu, 9 Sep 2021 15:32:20 +0200
* gnu/packages/llvm.scm (llvm-subprojects-origin, %llvm-project-12.0.0-hash):
New variables.
(lld-11, lld-12): New variables.
(lld): Point to lld-11.
---
 gnu/packages/llvm.scm | 44 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 43 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/llvm.scm b/gnu/packages/llvm.scm
index 4394194939..220116cbfb 100644
--- a/gnu/packages/llvm.scm
+++ b/gnu/packages/llvm.scm
@@ -92,6 +92,22 @@ as \"x86_64-linux\"."
   (string-append "https://github.com/llvm/llvm-project/releases/download"
                  "/llvmorg-" version "/" component "-" version ".src.tar.xz"))
 
+(define* (llvm-subprojects-origin components version base32-hash
+                                  #:optional (patches '()))
+  (origin
+    (method url-fetch)
+    (uri (llvm-uri "llvm-project" version))
+    (sha256 base32-hash)
+    (patches (map search-patch patches))
+    (modules '((guix build utils)
+               (ice-9 ftw)))
+    (snippet
+     `(for-each
+       (lambda (file)
+         (unless (member file '("." ".." ,@components))
+           (delete-file-recursively file)))
+       (scandir ".")))))
+
 (define* (clang-runtime-from-llvm llvm hash
                                   #:optional (patches '()))
   (package
@@ -882,7 +898,7 @@ of programming tools as well as libraries with equivalent functionality.")
 (define-public clang clang-9)
 (define-public clang-toolchain clang-toolchain-9)
 
-(define-public lld
+(define-public lld-11
   (package
     (name "lld")
     (version "11.0.0")
@@ -906,6 +922,32 @@ of programming tools as well as libraries with equivalent functionality.")
 components which highly leverage existing libraries in the larger LLVM Project.")
     (license license:asl2.0))) ; With LLVM exception
 
+(define %llvm-project-12.0.0-hash
+  (base32 "0a1n88dmbwp1ww7h3ykf0s001cndk1bm3i2cj1y2sh548f4nilcy"))
+
+(define-public lld-12
+  (package
+    (inherit lld-11)
+    (version "12.0.0")
+    (source (llvm-subprojects-origin '("lld" "libunwind") version
+                                     %llvm-project-12.0.0-hash))
+    (arguments
+     `(,@(package-arguments lld-11)
+       #:phases
+       (modify-phases %standard-phases
+         (add-after 'unpack 'dissect
+           (lambda _
+             ;; Find libunwind in unpacked sources
+             (substitute* "lld/MachO/CMakeLists.txt"
+               (("\\$\\{LLVM_MAIN_SRC_DIR\\}/\\.\\./libunwind")
+                (string-append (getcwd) "/libunwind")))
+             ;; chdir to actual source folder
+             (chdir "lld"))))))
+    (inputs
+     `(("llvm" ,llvm-12)))))
+
+(define-public lld lld-11)
+
 (define-public lldb
   (package
     (name "lldb")
-- 
2.33.0






Information forwarded to guix-patches <at> gnu.org:
bug#47006; Package guix-patches. (Thu, 09 Sep 2021 16:32:02 GMT) Full text and rfc822 format available.

Message #42 received at 47006 <at> debbugs.gnu.org (full text, mbox):

From: Sarah Morgensen <iskarian <at> mgsn.dev>
To: Liliana Prikler <liliana.prikler <at> gmail.com>
Cc: 47006 <at> debbugs.gnu.org, 50449 <at> debbugs.gnu.org, maximedevos <at> telenet.be,
 efraim <at> flashner.co.il
Subject: Re: [bug#47006] [PATCH 2/2] gnu: Add zig.
Date: Thu, 09 Sep 2021 09:31:13 -0700
Hi Liliana,

Thanks for taking a look at the recent patch and sending an updated
one.  I've been tinkering with the recent zig patch as well, so I have a
few comments.

Liliana Prikler <liliana.prikler <at> gmail.com> writes:

> * gnu/packages/zig.scm: New file.
> * gnu/local.mk (GNU_SYSTEM_MODULES): Add it here.
> ---
>  gnu/local.mk         |  1 +
>  gnu/packages/zig.scm | 83 ++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 84 insertions(+)
>  create mode 100644 gnu/packages/zig.scm
>
> diff --git a/gnu/local.mk b/gnu/local.mk
> index 2a56c4a9e2..710e5bd9df 100644
> --- a/gnu/local.mk
> +++ b/gnu/local.mk
> @@ -598,6 +598,7 @@ GNU_SYSTEM_MODULES =				\
>    %D%/packages/xdisorg.scm			\
>    %D%/packages/xorg.scm				\
>    %D%/packages/xfce.scm				\
> +  %D%/packages/zig.scm				\
>    %D%/packages/zile.scm				\
>    %D%/packages/zwave.scm			\
>  						\
> diff --git a/gnu/packages/zig.scm b/gnu/packages/zig.scm
> new file mode 100644
> index 0000000000..8b9a863b4d
> --- /dev/null
> +++ b/gnu/packages/zig.scm
> @@ -0,0 +1,83 @@
> +;;; GNU Guix --- Functional package management for GNU
> +;;; Copyright © 2021 Leo Prikler <leo.prikler <at> student.tugraz.at>
> +;;;
> +;;; This file is part of GNU Guix.
> +;;;
> +;;; GNU Guix is free software; you can redistribute it and/or modify it
> +;;; under the terms of the GNU General Public License as published by
> +;;; the Free Software Foundation; either version 3 of the License, or (at
> +;;; your option) any later version.
> +;;;
> +;;; GNU Guix is distributed in the hope that it will be useful, but
> +;;; WITHOUT ANY WARRANTY; without even the implied warranty of
> +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +;;; GNU General Public License for more details.
> +;;;
> +;;; You should have received a copy of the GNU General Public License
> +;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
> +
> +(define-module (gnu packages zig)
> +  #:use-module (guix packages)
> +  #:use-module (guix git-download)
> +  #:use-module ((guix licenses) #:prefix license:)
> +  #:use-module (guix build-system cmake)
> +  #:use-module (gnu packages)
> +  #:use-module (gnu packages llvm))
> +
> +(define-public zig
> +  (package
> +    (name "zig")
> +    (version "0.8.1")
> +    (source
> +     (origin
> +       (method git-fetch)
> +       (uri (git-reference
> +             (url "https://github.com/ziglang/zig.git")
> +             (commit version)))
> +       (file-name (git-file-name name version))
> +       (sha256
> +        (base32 "147qx7xgj0r353wh5ragzn6kmm1vrf31i8038z3zqwjnqqgqxi6c"))))
> +    (build-system cmake-build-system)
> +    ;; Zig is based on and builds itself using the Clang toolchain,
> +    ;; so add it both as inputs and native-inputs.
> +    (inputs
> +     `(("clang" ,clang-12)
> +       ("lld" ,lld-12)
> +       ("llvm" ,llvm-12)))
> +    (native-inputs
> +     `(("clang" ,clang-12)
> +       ("lld" ,lld-12)
> +       ("llvm" ,llvm-12)))

Zig is perfectly happy compiling itself with GCC, and I believe it's the
default.  I'm pretty sure it either needs no native tools, or only llvm,
but I wasn't able to test without compiling a whole GCC cross-toolchain.

For cross compiling, you will also need to add "-DZIG_TARGET_TRIPLE=" to
configure flags, and you might want to look into adding
"-DZIG_TARGET_MCPU" (should take the same values as LLVM's -mcpu) to
change the baseline CPU for ARM systems since we build for ARM7 by
default.

> +    (arguments
> +     `(#:tests? #f                       ; no check target

Did you mean to leave this in? ;)

> +       #:phases
> +       (modify-phases %standard-phases
> +         (add-after 'unpack 'save-unpack-dir
> +           (lambda _
> +             ;; HACK: Passing unpacked source directory to 'check phase.
> +             (setenv "ZIG_SOURCE_DIR" (getcwd))
> +             #t))
> +         (add-after 'configure 'set-home
> +           (lambda _
> +             (setenv "HOME" (getcwd))    ; zig writes to $HOME/.cache
> +             #t))
> +         (delete 'check)
> +         (add-after 'install 'check
> +           (lambda* (#:key outputs tests? #:allow-other-keys)
> +             (when tests?
> +               (with-directory-excursion (getenv "ZIG_SOURCE_DIR")
> +                 (invoke (string-append (assoc-ref outputs) "out") "/bin/zig"
> +                         "build" "test"))))))))

Full tests take quite a while, (it's supposed to be "an hour or two") so
it may eventually be a good idea to limit what we test, such as using
"-Dskip-release", which tests without optimization.  IMO that should be
enough for catching any Guix-based issues with Zig.

> +    (synopsis "General purpose programming language and toolchain")
> +    (description "Zig is a general-purpose programming language and
> +toolchain.  Among other features it provides
> +@itemize
> +@item an Optional type instead of null pointers,
> +@item manual memory management,
> +@item generic data structures and functions,
> +@item compile-time reflection and compile-time code execution,
> +@item integration with C using zig as a C compiler, and
> +@item concurrency via async functions.
> +@end itemize")
> +    (home-page "https://github.com/ziglang/zig")
> +    (license license:expat)))

I don't know if it affects the license, but Zig bundles the source for
*many* components, such as glibc, musl, mingw, wasi, and from LLVM:
libcxx, libcxxabi, libunwind, and tsan.

Zig doesn't seem to honor LIBRARY_PATH, but oddly enough it honors
NIX_LDFLAGS and NIX_CFLAGS_COMPILE, so if we want it to see external
libraries, something like this is needed:

--8<---------------cut here---------------start------------->8---
         (add-after 'check 'wrap-binary
           (lambda* (#:key outputs #:allow-other-keys)
             ;; TODO: test with 'zig cc'
             (wrap-program (string-append (assoc-ref outputs "out") "/bin/zig")
               `("NIX_LDFLAGS" prefix
                 ("${LIBRARY_PATH:+-L${LIBRARY_PATH//:/ -L}}"))
               `("NIX_CFLAGS_COMPILE" prefix
                 (,(string-append
                    "${CPLUS_INCLUDE_PATH:+-isystem "
                    "${CPLUS_INCLUDE_PATH//:/ -isystem }}"))))))
--8<---------------cut here---------------end--------------->8---

I haven't tested this with 'zig cc', but this worked for compiling [0].

[0] https://github.com/andrewrk/tetris

Hope that helps,

--
Sarah




Information forwarded to guix-patches <at> gnu.org:
bug#47006; Package guix-patches. (Thu, 09 Sep 2021 18:19:01 GMT) Full text and rfc822 format available.

Message #45 received at 47006 <at> debbugs.gnu.org (full text, mbox):

From: Liliana Marie Prikler <liliana.prikler <at> gmail.com>
To: Sarah Morgensen <iskarian <at> mgsn.dev>
Cc: 47006 <at> debbugs.gnu.org, 50449 <at> debbugs.gnu.org, maximedevos <at> telenet.be,
 efraim <at> flashner.co.il
Subject: Re: [bug#47006] [PATCH 2/2] gnu: Add zig.
Date: Thu, 09 Sep 2021 20:18:20 +0200
Hi Sarah,

Am Donnerstag, den 09.09.2021, 09:31 -0700 schrieb Sarah Morgensen:
> Liliana Prikler <liliana.prikler <at> gmail.com> writes:
> 
> > * gnu/packages/zig.scm: New file.
> > * gnu/local.mk (GNU_SYSTEM_MODULES): Add it here.
> > ---
> >  gnu/local.mk         |  1 +
> >  gnu/packages/zig.scm | 83
> > ++++++++++++++++++++++++++++++++++++++++++++
> >  2 files changed, 84 insertions(+)
> >  create mode 100644 gnu/packages/zig.scm
> > 
> > diff --git a/gnu/local.mk b/gnu/local.mk
> > index 2a56c4a9e2..710e5bd9df 100644
> > --- a/gnu/local.mk
> > +++ b/gnu/local.mk
> > @@ -598,6 +598,7 @@ GNU_SYSTEM_MODULES =				
> > \
> >    %D%/packages/xdisorg.scm			\
> >    %D%/packages/xorg.scm				\
> >    %D%/packages/xfce.scm				\
> > +  %D%/packages/zig.scm				\
> >    %D%/packages/zile.scm				\
> >    %D%/packages/zwave.scm			\
> >  						\
> > diff --git a/gnu/packages/zig.scm b/gnu/packages/zig.scm
> > new file mode 100644
> > index 0000000000..8b9a863b4d
> > --- /dev/null
> > +++ b/gnu/packages/zig.scm
> > @@ -0,0 +1,83 @@
> > +;;; GNU Guix --- Functional package management for GNU
> > +;;; Copyright © 2021 Leo Prikler <leo.prikler <at> student.tugraz.at>
> > +;;;
> > +;;; This file is part of GNU Guix.
> > +;;;
> > +;;; GNU Guix is free software; you can redistribute it and/or
> > modify it
> > +;;; under the terms of the GNU General Public License as published
> > by
> > +;;; the Free Software Foundation; either version 3 of the License,
> > or (at
> > +;;; your option) any later version.
> > +;;;
> > +;;; GNU Guix is distributed in the hope that it will be useful,
> > but
> > +;;; WITHOUT ANY WARRANTY; without even the implied warranty of
> > +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > +;;; GNU General Public License for more details.
> > +;;;
> > +;;; You should have received a copy of the GNU General Public
> > License
> > +;;; along with GNU Guix.  If not, see <
> > http://www.gnu.org/licenses/>;.
> > +
> > +(define-module (gnu packages zig)
> > +  #:use-module (guix packages)
> > +  #:use-module (guix git-download)
> > +  #:use-module ((guix licenses) #:prefix license:)
> > +  #:use-module (guix build-system cmake)
> > +  #:use-module (gnu packages)
> > +  #:use-module (gnu packages llvm))
> > +
> > +(define-public zig
> > +  (package
> > +    (name "zig")
> > +    (version "0.8.1")
> > +    (source
> > +     (origin
> > +       (method git-fetch)
> > +       (uri (git-reference
> > +             (url "https://github.com/ziglang/zig.git")
> > +             (commit version)))
> > +       (file-name (git-file-name name version))
> > +       (sha256
> > +        (base32
> > "147qx7xgj0r353wh5ragzn6kmm1vrf31i8038z3zqwjnqqgqxi6c"))))
> > +    (build-system cmake-build-system)
> > +    ;; Zig is based on and builds itself using the Clang
> > toolchain,
> > +    ;; so add it both as inputs and native-inputs.
> > +    (inputs
> > +     `(("clang" ,clang-12)
> > +       ("lld" ,lld-12)
> > +       ("llvm" ,llvm-12)))
> > +    (native-inputs
> > +     `(("clang" ,clang-12)
> > +       ("lld" ,lld-12)
> > +       ("llvm" ,llvm-12)))
> 
> Zig is perfectly happy compiling itself with GCC, and I believe it's
> the default.  I'm pretty sure it either needs no native tools, or
> only llvm, but I wasn't able to test without compiling a whole GCC
> cross-toolchain.
> 
> For cross compiling, you will also need to add "-DZIG_TARGET_TRIPLE=" 
> to configure flags, and you might want to look into adding
> "-DZIG_TARGET_MCPU" (should take the same values as LLVM's -mcpu) to
> change the baseline CPU for ARM systems since we build for ARM7 by
> default.
I don't think we set mcpu for LLVM or Clang, so that one should be
fine.  As for ZIG_TARGET_TRIPLET and the native inputs, do you have an
amended patch already lying around?

> > +    (arguments
> > +     `(#:tests? #f                       ; no check target
> 
> Did you mean to leave this in? ;)
Pretty sure that was a copypaste error at some point, good catch.

> > +       #:phases
> > +       (modify-phases %standard-phases
> > +         (add-after 'unpack 'save-unpack-dir
> > +           (lambda _
> > +             ;; HACK: Passing unpacked source directory to 'check
> > phase.
> > +             (setenv "ZIG_SOURCE_DIR" (getcwd))
> > +             #t))
> > +         (add-after 'configure 'set-home
> > +           (lambda _
> > +             (setenv "HOME" (getcwd))    ; zig writes to
> > $HOME/.cache
> > +             #t))
> > +         (delete 'check)
> > +         (add-after 'install 'check
> > +           (lambda* (#:key outputs tests? #:allow-other-keys)
> > +             (when tests?
> > +               (with-directory-excursion (getenv "ZIG_SOURCE_DIR")
> > +                 (invoke (string-append (assoc-ref outputs) "out")
> > "/bin/zig"
> > +                         "build" "test"))))))))
> 
> Full tests take quite a while, (it's supposed to be "an hour or two")
> so it may eventually be a good idea to limit what we test, such as
> using "-Dskip-release", which tests without optimization.  IMO that
> should be enough for catching any Guix-based issues with Zig.
Is that a configure flag or a test flag?

> > +    (synopsis "General purpose programming language and
> > toolchain")
> > +    (description "Zig is a general-purpose programming language
> > and
> > +toolchain.  Among other features it provides
> > +@itemize
> > +@item an Optional type instead of null pointers,
> > +@item manual memory management,
> > +@item generic data structures and functions,
> > +@item compile-time reflection and compile-time code execution,
> > +@item integration with C using zig as a C compiler, and
> > +@item concurrency via async functions.
> > +@end itemize")
> > +    (home-page "https://github.com/ziglang/zig")
> > +    (license license:expat)))
> 
> I don't know if it affects the license, but Zig bundles the source
> for *many* components, such as glibc, musl, mingw, wasi, and from
> LLVM: libcxx, libcxxabi, libunwind, and tsan.
Good catch, could we unbundle some/all of those?

> Zig doesn't seem to honor LIBRARY_PATH, but oddly enough it honors
> NIX_LDFLAGS and NIX_CFLAGS_COMPILE, so if we want it to see external
> libraries, something like this is needed:
> 
> --8<---------------cut here---------------start------------->8---
>          (add-after 'check 'wrap-binary
>            (lambda* (#:key outputs #:allow-other-keys)
>              ;; TODO: test with 'zig cc'
>              (wrap-program (string-append (assoc-ref outputs "out")
> "/bin/zig")
>                `("NIX_LDFLAGS" prefix
>                  ("${LIBRARY_PATH:+-L${LIBRARY_PATH//:/ -L}}"))
>                `("NIX_CFLAGS_COMPILE" prefix
>                  (,(string-append
>                     "${CPLUS_INCLUDE_PATH:+-isystem "
>                     "${CPLUS_INCLUDE_PATH//:/ -isystem }}"))))))
> --8<---------------cut here---------------end--------------->8---
That is rather inelegant.  I'd prefer we patch zig to honor
LIBRARY_PATH, CPLUS_INCLUDE_FLAGS and what other important environment
variables we find.

Thanks





Information forwarded to guix-patches <at> gnu.org:
bug#47006; Package guix-patches. (Thu, 09 Sep 2021 18:50:01 GMT) Full text and rfc822 format available.

Message #48 received at 47006 <at> debbugs.gnu.org (full text, mbox):

From: Sarah Morgensen <iskarian <at> mgsn.dev>
To: Liliana Marie Prikler <liliana.prikler <at> gmail.com>
Cc: 47006 <at> debbugs.gnu.org, maximedevos <at> telenet.be, efraim <at> flashner.co.il
Subject: Re: [bug#50449] [bug#47006] [PATCH 2/2] gnu: Add zig.
Date: Thu, 09 Sep 2021 11:49:42 -0700
[Message part 1 (text/plain, inline)]
Liliana Marie Prikler <liliana.prikler <at> gmail.com> writes:

>> Zig is perfectly happy compiling itself with GCC, and I believe it's
>> the default.  I'm pretty sure it either needs no native tools, or
>> only llvm, but I wasn't able to test without compiling a whole GCC
>> cross-toolchain.
>> 
>> For cross compiling, you will also need to add "-DZIG_TARGET_TRIPLE=" 
>> to configure flags, and you might want to look into adding
>> "-DZIG_TARGET_MCPU" (should take the same values as LLVM's -mcpu) to
>> change the baseline CPU for ARM systems since we build for ARM7 by
>> default.
> I don't think we set mcpu for LLVM or Clang, so that one should be
> fine.  As for ZIG_TARGET_TRIPLET and the native inputs, do you have an
> amended patch already lying around?

Sure, I'll attach it.

>> Full tests take quite a while, (it's supposed to be "an hour or two")
>> so it may eventually be a good idea to limit what we test, such as
>> using "-Dskip-release", which tests without optimization.  IMO that
>> should be enough for catching any Guix-based issues with Zig.
> Is that a configure flag or a test flag?

It's a test flag.  You can check out build.zig for all the flags.

>> I don't know if it affects the license, but Zig bundles the source
>> for *many* components, such as glibc, musl, mingw, wasi, and from
>> LLVM: libcxx, libcxxabi, libunwind, and tsan.
> Good catch, could we unbundle some/all of those?

I know they do modify some of them, so it would require some care.

>> Zig doesn't seem to honor LIBRARY_PATH, but oddly enough it honors
>> NIX_LDFLAGS and NIX_CFLAGS_COMPILE, so if we want it to see external
>> libraries, something like this is needed:
>> 
>> --8<---------------cut here---------------start------------->8---
>>          (add-after 'check 'wrap-binary
>>            (lambda* (#:key outputs #:allow-other-keys)
>>              ;; TODO: test with 'zig cc'
>>              (wrap-program (string-append (assoc-ref outputs "out")
>> "/bin/zig")
>>                `("NIX_LDFLAGS" prefix
>>                  ("${LIBRARY_PATH:+-L${LIBRARY_PATH//:/ -L}}"))
>>                `("NIX_CFLAGS_COMPILE" prefix
>>                  (,(string-append
>>                     "${CPLUS_INCLUDE_PATH:+-isystem "
>>                     "${CPLUS_INCLUDE_PATH//:/ -isystem }}"))))))
>> --8<---------------cut here---------------end--------------->8---
> That is rather inelegant.  I'd prefer we patch zig to honor
> LIBRARY_PATH, CPLUS_INCLUDE_FLAGS and what other important environment
> variables we find.

Yeah, it's inelegant.  I've never written Zig, so I didn't want to
accidentally introduce any bugs.  If you want to take a stab at it, take
a look at lib/std/zig/system.zig, lines 30-140.

--
Sarah

[0001-gnu-Add-zig.patch (text/x-patch, inline)]
From 3cfaaf2023bf5a9915d625963140039c711207ae Mon Sep 17 00:00:00 2001
Message-Id: <3cfaaf2023bf5a9915d625963140039c711207ae.1631213249.git.iskarian <at> mgsn.dev>
From: Liliana Prikler <liliana.prikler <at> gmail.com>
Date: Thu, 9 Sep 2021 15:32:22 +0200
Subject: [PATCH] gnu: Add zig.

* gnu/packages/zig.scm: New file.
* gnu/local.mk (GNU_SYSTEM_MODULES): Add it here.
---
 gnu/local.mk         |  1 +
 gnu/packages/zig.scm | 96 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 97 insertions(+)
 create mode 100644 gnu/packages/zig.scm

diff --git a/gnu/local.mk b/gnu/local.mk
index 2a56c4a9e2..710e5bd9df 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -598,6 +598,7 @@ GNU_SYSTEM_MODULES =				\
   %D%/packages/xdisorg.scm			\
   %D%/packages/xorg.scm				\
   %D%/packages/xfce.scm				\
+  %D%/packages/zig.scm				\
   %D%/packages/zile.scm				\
   %D%/packages/zwave.scm			\
 						\
diff --git a/gnu/packages/zig.scm b/gnu/packages/zig.scm
new file mode 100644
index 0000000000..5f64c8367d
--- /dev/null
+++ b/gnu/packages/zig.scm
@@ -0,0 +1,96 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2021 Liliana Prikler <liliana.prikler <at> gmail.com>
+;;; Copyright © 2021 Sarah Morgensen <iskarian <at> mgsn.dev>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (gnu packages zig)
+  #:use-module (guix packages)
+  #:use-module (guix git-download)
+  #:use-module ((guix licenses) #:prefix license:)
+  #:use-module (guix build-system cmake)
+  #:use-module (gnu packages)
+  #:use-module (gnu packages llvm))
+
+(define-public zig
+  (package
+    (name "zig")
+    (version "0.8.1")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/ziglang/zig.git")
+             (commit version)))
+       (file-name (git-file-name name version))
+       (sha256
+        (base32 "147qx7xgj0r353wh5ragzn6kmm1vrf31i8038z3zqwjnqqgqxi6c"))))
+    (build-system cmake-build-system)
+    ;; Zig uses Clang and LLVM libraries, and (may) use LLVM to compile along
+    ;; with GCC.
+    (inputs
+     `(("clang" ,clang-12)
+       ("lld" ,lld-12)
+       ("llvm" ,llvm-12)))
+    (native-inputs
+     `(("llvm" ,llvm-12)))
+    (arguments
+     `(,@(if (%current-target-system)
+             ;; TODO: set -DZIG_TARGET_CPU for aarch64/armhf
+             `(#:configure-flags (,(string-append "-DZIG_TARGET_TRIPLE="
+                                                  (%current-target-system))))
+             '())
+       #:phases
+       (modify-phases %standard-phases
+         (add-after 'unpack 'save-unpack-dir
+           (lambda _
+             ;; HACK: Passing unpacked source directory to 'check phase.
+             (setenv "ZIG_SOURCE_DIR" (getcwd))
+             #t))
+         (add-after 'configure 'set-home
+           (lambda _
+             (setenv "HOME" (getcwd))    ; zig writes to $HOME/.cache
+             #t))
+         (delete 'check)
+         (add-after 'install 'check
+           (lambda* (#:key outputs tests? #:allow-other-keys)
+             (when tests?
+               (with-directory-excursion (getenv "ZIG_SOURCE_DIR")
+                 (invoke (string-append (assoc-ref outputs) "out") "/bin/zig"
+                         "build" "test"))))))))
+    (native-search-paths
+     ;; XXX: I don't think Zig can distinguishes between C/C++ includes,
+     ;; so just include both.
+     (list
+      (search-path-specification
+       (variable "CPLUS_INCLUDE_PATH")
+       (files '("include/c++" "include")))
+      (search-path-specification
+       (variable "LIBRARY_PATH")
+       (files '("lib" "lib64")))))
+    (synopsis "General purpose programming language and toolchain")
+    (description "Zig is a general-purpose programming language and
+toolchain.  Among other features it provides
+@itemize
+@item an Optional type instead of null pointers,
+@item manual memory management,
+@item generic data structures and functions,
+@item compile-time reflection and compile-time code execution,
+@item integration with C using zig as a C compiler, and
+@item concurrency via async functions.
+@end itemize")
+    (home-page "https://github.com/ziglang/zig")
+    (license license:expat)))

base-commit: a8555e01740d04e714fa9d70008f469f0db55d9a
-- 
2.33.0


Information forwarded to guix-patches <at> gnu.org:
bug#47006; Package guix-patches. (Thu, 09 Sep 2021 22:48:02 GMT) Full text and rfc822 format available.

Message #51 received at 47006 <at> debbugs.gnu.org (full text, mbox):

From: Liliana Prikler <liliana.prikler <at> gmail.com>
To: iskarian <at> mgsn.dev
Cc: 47006 <at> debbugs.gnu.org, maximedevos <at> telenet.be, efraim <at> flashner.co.il
Subject: [WIP PATCH v2 2/2] gnu: Add zig.
Date: Thu, 9 Sep 2021 15:32:22 +0200
* gnu/packages/patches/zig-use-explicit-paths.patch: New file.
* gnu/packages/zig.scm: New file.
* gnu/local.mk (GNU_SYSTEM_MODULES, dist_patch_DATA): Adjust accordingly.
---
I've added a patch to use explicit search paths rather than whatever Zig used
before and tried fixing some (syntactic) errors with the tests, but was
unsuccesful, as there appear to be failing tests in the suite itself.  Could
you have a look at the revised patch and check what flags you could add to
the check phase to make it meaningful?

Btw. I haven't checked whether my cosmetic changes to #:configure-flags break
things or not.  The end of the build phase puts a large amount of stress onto
my system that I'd like to avoid at this hour.

 gnu/local.mk                                  |   2 +
 .../patches/zig-use-explicit-paths.patch      | 132 ++++++++++++++++++
 gnu/packages/zig.scm                          | 100 +++++++++++++
 3 files changed, 234 insertions(+)
 create mode 100644 gnu/packages/patches/zig-use-explicit-paths.patch
 create mode 100644 gnu/packages/zig.scm

diff --git a/gnu/local.mk b/gnu/local.mk
index 2a56c4a9e2..4503b4b2e2 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -598,6 +598,7 @@ GNU_SYSTEM_MODULES =				\
   %D%/packages/xdisorg.scm			\
   %D%/packages/xorg.scm				\
   %D%/packages/xfce.scm				\
+  %D%/packages/zig.scm				\
   %D%/packages/zile.scm				\
   %D%/packages/zwave.scm			\
 						\
@@ -1903,6 +1904,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/ytfzf-updates.patch        \
   %D%/packages/patches/ytnef-CVE-2021-3403.patch	\
   %D%/packages/patches/ytnef-CVE-2021-3404.patch	\
+  %D%/packages/patches/zig-use-explicit-paths.patch	\
   %D%/packages/patches/zstd-CVE-2021-24031_CVE-2021-24032.patch	\
   %D%/packages/patches/zziplib-CVE-2018-16548.patch
 
diff --git a/gnu/packages/patches/zig-use-explicit-paths.patch b/gnu/packages/patches/zig-use-explicit-paths.patch
new file mode 100644
index 0000000000..ab0d2c7f8b
--- /dev/null
+++ b/gnu/packages/patches/zig-use-explicit-paths.patch
@@ -0,0 +1,132 @@
+This patch replaces the OS-specific detection mechanism by one that solely
+relies on environment variables.  This has the benefit that said environment
+variables can be used as search paths in Guix.
+
+Index: zig-0.8.1/lib/std/zig/system.zig
+===================================================================
+--- zig-0.8.1.orig/lib/std/zig/system.zig
++++ zig-0.8.1/lib/std/zig/system.zig
+@@ -39,101 +39,44 @@ pub const NativePaths = struct {
+         };
+         errdefer self.deinit();
+ 
+-        var is_nix = false;
+-        if (process.getEnvVarOwned(allocator, "NIX_CFLAGS_COMPILE")) |nix_cflags_compile| {
+-            defer allocator.free(nix_cflags_compile);
+-
+-            is_nix = true;
+-            var it = mem.tokenize(nix_cflags_compile, " ");
++        // TODO: Support cross-compile paths?
++        if (process.getEnvVarOwned(allocator, "ZIG_INCLUDE_DIRS")) |zig_include_dirs| {
++            defer allocator.free(zig_include_dirs);
++            var it = mem.tokenize(zig_include_dirs, ":");
+             while (true) {
+-                const word = it.next() orelse break;
+-                if (mem.eql(u8, word, "-isystem")) {
+-                    const include_path = it.next() orelse {
+-                        try self.addWarning("Expected argument after -isystem in NIX_CFLAGS_COMPILE");
+-                        break;
+-                    };
+-                    try self.addIncludeDir(include_path);
+-                } else {
+-                    if (mem.startsWith(u8, word, "-frandom-seed=")) {
+-                        continue;
+-                    }
+-                    try self.addWarningFmt("Unrecognized C flag from NIX_CFLAGS_COMPILE: {s}", .{word});
+-                }
++                const dir = it.next() orelse break;
++                try self.addIncludeDir(dir);
+             }
+         } else |err| switch (err) {
+             error.InvalidUtf8 => {},
+             error.EnvironmentVariableNotFound => {},
+             error.OutOfMemory => |e| return e,
+         }
+-        if (process.getEnvVarOwned(allocator, "NIX_LDFLAGS")) |nix_ldflags| {
+-            defer allocator.free(nix_ldflags);
+ 
+-            is_nix = true;
+-            var it = mem.tokenize(nix_ldflags, " ");
++        if (process.getEnvVarOwned(allocator, "ZIG_LIB_DIRS")) |zig_lib_dirs| {
++            defer allocator.free(zig_lib_dirs);
++            var it = mem.tokenize(zig_lib_dirs, ":");
+             while (true) {
+-                const word = it.next() orelse break;
+-                if (mem.eql(u8, word, "-rpath")) {
+-                    const rpath = it.next() orelse {
+-                        try self.addWarning("Expected argument after -rpath in NIX_LDFLAGS");
+-                        break;
+-                    };
+-                    try self.addRPath(rpath);
+-                } else if (word.len > 2 and word[0] == '-' and word[1] == 'L') {
+-                    const lib_path = word[2..];
+-                    try self.addLibDir(lib_path);
+-                } else {
+-                    try self.addWarningFmt("Unrecognized C flag from NIX_LDFLAGS: {s}", .{word});
+-                    break;
+-                }
++                const dir = it.next() orelse break;
++                try self.addLibDir(dir);
+             }
+         } else |err| switch (err) {
+             error.InvalidUtf8 => {},
+             error.EnvironmentVariableNotFound => {},
+             error.OutOfMemory => |e| return e,
+         }
+-        if (is_nix) {
+-            return self;
+-        }
+-
+-        if (comptime Target.current.isDarwin()) {
+-            try self.addIncludeDir("/usr/include");
+-            try self.addIncludeDir("/usr/local/include");
+-
+-            try self.addLibDir("/usr/lib");
+-            try self.addLibDir("/usr/local/lib");
+-
+-            try self.addFrameworkDir("/Library/Frameworks");
+-            try self.addFrameworkDir("/System/Library/Frameworks");
+-
+-            return self;
+-        }
+-
+-        if (native_target.os.tag != .windows) {
+-            const triple = try native_target.linuxTriple(allocator);
+-            const qual = native_target.cpu.arch.ptrBitWidth();
+-
+-            // TODO: $ ld --verbose | grep SEARCH_DIR
+-            // the output contains some paths that end with lib64, maybe include them too?
+-            // TODO: what is the best possible order of things?
+-            // TODO: some of these are suspect and should only be added on some systems. audit needed.
+ 
+-            try self.addIncludeDir("/usr/local/include");
+-            try self.addLibDirFmt("/usr/local/lib{d}", .{qual});
+-            try self.addLibDir("/usr/local/lib");
+-
+-            try self.addIncludeDirFmt("/usr/include/{s}", .{triple});
+-            try self.addLibDirFmt("/usr/lib/{s}", .{triple});
+-
+-            try self.addIncludeDir("/usr/include");
+-            try self.addLibDirFmt("/lib{d}", .{qual});
+-            try self.addLibDir("/lib");
+-            try self.addLibDirFmt("/usr/lib{d}", .{qual});
+-            try self.addLibDir("/usr/lib");
+-
+-            // example: on a 64-bit debian-based linux distro, with zlib installed from apt:
+-            // zlib.h is in /usr/include (added above)
+-            // libz.so.1 is in /lib/x86_64-linux-gnu (added here)
+-            try self.addLibDirFmt("/lib/{s}", .{triple});
++        if (process.getEnvVarOwned(allocator, "ZIG_FRAMEWORK_DIRS")) |zig_framework_dirs| {
++            defer allocator.free(zig_framework_dirs);
++            var it = mem.tokenize(zig_framework_dirs, ":");
++            while (true) {
++                const dir = it.next() orelse break;
++                try self.addFrameworkDir(dir);
++            }
++        } else |err| switch (err) {
++            error.InvalidUtf8 => {},
++            error.EnvironmentVariableNotFound => {},
++            error.OutOfMemory => |e| return e,
+         }
+ 
+         return self;
diff --git a/gnu/packages/zig.scm b/gnu/packages/zig.scm
new file mode 100644
index 0000000000..aae095b747
--- /dev/null
+++ b/gnu/packages/zig.scm
@@ -0,0 +1,100 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2021 Liliana Prikler <liliana.prikler <at> gmail.com>
+;;; Copyright © 2021 Sarah Morgensen <iskarian <at> mgsn.dev>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (gnu packages zig)
+  #:use-module (guix packages)
+  #:use-module (guix git-download)
+  #:use-module ((guix licenses) #:prefix license:)
+  #:use-module (guix build-system cmake)
+  #:use-module (gnu packages)
+  #:use-module (gnu packages llvm))
+
+(define-public zig
+  (package
+    (name "zig")
+    (version "0.8.1")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/ziglang/zig.git")
+             (commit version)))
+       (file-name (git-file-name name version))
+       (sha256
+        (base32 "147qx7xgj0r353wh5ragzn6kmm1vrf31i8038z3zqwjnqqgqxi6c"))
+       (patches
+        (search-patches
+         "zig-use-explicit-paths.patch"))))
+    (build-system cmake-build-system)
+    ;; Zig uses Clang and LLVM libraries, and (may) use LLVM to compile along
+    ;; with GCC.
+    (inputs
+     `(("clang" ,clang-12)
+       ("lld" ,lld-12)
+       ("llvm" ,llvm-12)))
+    (native-inputs
+     `(("llvm" ,llvm-12)))
+    (arguments
+     `(#:configure-flags
+       (list ,@(if (%current-target-system)
+                   (string-append "-DZIG_TARGET_TRIPLE="
+                                  (%current-target-system))
+                   '()))
+       #:tests? #f ;;; XXX: tests result in a FileNotFound
+       #:phases
+       (modify-phases %standard-phases
+         (add-after 'unpack 'save-unpack-dir
+           (lambda _
+             ;; HACK: Passing unpacked source directory to 'check phase.
+             (setenv "ZIG_SOURCE_DIR" (getcwd))
+             #t))
+         (add-after 'configure 'set-home
+           (lambda _
+             (setenv "HOME" (getcwd))    ; zig writes to $HOME/.cache
+             #t))
+         (delete 'check)
+         (add-after 'install 'check
+           (lambda* (#:key outputs tests? #:allow-other-keys)
+             (when tests?
+               (with-directory-excursion (getenv "ZIG_SOURCE_DIR")
+                 (invoke (string-append (assoc-ref outputs "out") "/bin/zig")
+                         "build" "test"))))))))
+    (native-search-paths
+     (list
+      (search-path-specification
+       (variable "ZIG_INCLUDE_DIRS")
+       ;; XXX: It doesn't seem as though Zig can distinguish between C and C++
+       ;;      include paths, so provide both.
+       (files '("include/c++" "include")))
+      (search-path-specification
+       (variable "ZIG_LIB_DIRS")
+       (files '("lib" "lib64")))))
+    (synopsis "General purpose programming language and toolchain")
+    (description "Zig is a general-purpose programming language and
+toolchain.  Among other features it provides
+@itemize
+@item an Optional type instead of null pointers,
+@item manual memory management,
+@item generic data structures and functions,
+@item compile-time reflection and compile-time code execution,
+@item integration with C using zig as a C compiler, and
+@item concurrency via async functions.
+@end itemize")
+    (home-page "https://github.com/ziglang/zig")
+    (license license:expat)))
-- 
2.33.0






Information forwarded to guix-patches <at> gnu.org:
bug#47006; Package guix-patches. (Sat, 11 Sep 2021 00:02:02 GMT) Full text and rfc822 format available.

Message #54 received at 47006 <at> debbugs.gnu.org (full text, mbox):

From: András Vöröskői <voroskoi <at> gmail.com>
To: 47006 <at> debbugs.gnu.org
Subject: [PATCH] gnu: Add zig.
Date: Sat, 11 Sep 2021 02:01:06 +0200
Hi,

I have also spent some time with zig, having hard time with tests too.

I can reproduce the "FileNotFound" error :-) I have a rpi4 running
guix on top of Alpine and the failing test was aarch64-linux-gnu.
After disabling it I got an other LLD related error and gave up.

Now, I am trying -Dskip-non-native=true, so far so good, but I also
want to try if -Dskip-libc.

BTW I would not recommend skipping ReleaseFast builds, maybe
ReleaseSmall is the least interesting one.




Information forwarded to guix-patches <at> gnu.org:
bug#47006; Package guix-patches. (Sat, 11 Sep 2021 09:54:01 GMT) Full text and rfc822 format available.

Message #57 received at 47006 <at> debbugs.gnu.org (full text, mbox):

From: iskarian <at> mgsn.dev
To: "Liliana Prikler" <liliana.prikler <at> gmail.com>
Cc: 47006 <at> debbugs.gnu.org, maximedevos <at> telenet.be, efraim <at> flashner.co.il
Subject: Re: [WIP PATCH v2 2/2] gnu: Add zig.
Date: Sat, 11 Sep 2021 09:52:57 +0000
Hi Liliana,

September 9, 2021 6:32 AM, "Liliana Prikler" <liliana.prikler <at> gmail.com> wrote:

> I've added a patch to use explicit search paths rather than whatever Zig used
> before and tried fixing some (syntactic) errors with the tests, but was
> unsuccesful, as there appear to be failing tests in the suite itself. Could
> you have a look at the revised patch and check what flags you could add to
> the check phase to make it meaningful?

I'm

> Btw. I haven't checked whether my cosmetic changes to #:configure-flags break
> things or not. The end of the build phase puts a large amount of stress onto
> my system that I'd like to avoid at this hour.
> 
> gnu/local.mk | 2 +
> .../patches/zig-use-explicit-paths.patch | 132 ++++++++++++++++++
> gnu/packages/zig.scm | 100 +++++++++++++
> 3 files changed, 234 insertions(+)
> create mode 100644 gnu/packages/patches/zig-use-explicit-paths.patch
> create mode 100644 gnu/packages/zig.scm
> 
> diff --git a/gnu/local.mk b/gnu/local.mk
> index 2a56c4a9e2..4503b4b2e2 100644
> --- a/gnu/local.mk
> +++ b/gnu/local.mk
> @@ -598,6 +598,7 @@ GNU_SYSTEM_MODULES = \
> %D%/packages/xdisorg.scm \
> %D%/packages/xorg.scm \
> %D%/packages/xfce.scm \
> + %D%/packages/zig.scm \
> %D%/packages/zile.scm \
> %D%/packages/zwave.scm \
> \
> @@ -1903,6 +1904,7 @@ dist_patch_DATA = \
> %D%/packages/patches/ytfzf-updates.patch \
> %D%/packages/patches/ytnef-CVE-2021-3403.patch \
> %D%/packages/patches/ytnef-CVE-2021-3404.patch \
> + %D%/packages/patches/zig-use-explicit-paths.patch \
> %D%/packages/patches/zstd-CVE-2021-24031_CVE-2021-24032.patch \
> %D%/packages/patches/zziplib-CVE-2018-16548.patch
> 
> diff --git a/gnu/packages/patches/zig-use-explicit-paths.patch
> b/gnu/packages/patches/zig-use-explicit-paths.patch
> new file mode 100644
> index 0000000000..ab0d2c7f8b
> --- /dev/null
> +++ b/gnu/packages/patches/zig-use-explicit-paths.patch
> @@ -0,0 +1,132 @@
> +This patch replaces the OS-specific detection mechanism by one that solely
> +relies on environment variables. This has the benefit that said environment
> +variables can be used as search paths in Guix.
> +
> +Index: zig-0.8.1/lib/std/zig/system.zig
> +===================================================================
> +--- zig-0.8.1.orig/lib/std/zig/system.zig
> ++++ zig-0.8.1/lib/std/zig/system.zig
> +@@ -39,101 +39,44 @@ pub const NativePaths = struct {
> + };
> + errdefer self.deinit();
> +
> +- var is_nix = false;
> +- if (process.getEnvVarOwned(allocator, "NIX_CFLAGS_COMPILE")) |nix_cflags_compile| {
> +- defer allocator.free(nix_cflags_compile);
> +-
> +- is_nix = true;
> +- var it = mem.tokenize(nix_cflags_compile, " ");
> ++ // TODO: Support cross-compile paths?
> ++ if (process.getEnvVarOwned(allocator, "ZIG_INCLUDE_DIRS")) |zig_include_dirs| {
> ++ defer allocator.free(zig_include_dirs);
> ++ var it = mem.tokenize(zig_include_dirs, ":");
> + while (true) {
> +- const word = it.next() orelse break;
> +- if (mem.eql(u8, word, "-isystem")) {
> +- const include_path = it.next() orelse {
> +- try self.addWarning("Expected argument after -isystem in NIX_CFLAGS_COMPILE");
> +- break;
> +- };
> +- try self.addIncludeDir(include_path);
> +- } else {
> +- if (mem.startsWith(u8, word, "-frandom-seed=")) {
> +- continue;
> +- }
> +- try self.addWarningFmt("Unrecognized C flag from NIX_CFLAGS_COMPILE: {s}", .{word});
> +- }
> ++ const dir = it.next() orelse break;
> ++ try self.addIncludeDir(dir);
> + }
> + } else |err| switch (err) {
> + error.InvalidUtf8 => {},
> + error.EnvironmentVariableNotFound => {},
> + error.OutOfMemory => |e| return e,
> + }
> +- if (process.getEnvVarOwned(allocator, "NIX_LDFLAGS")) |nix_ldflags| {
> +- defer allocator.free(nix_ldflags);
> +
> +- is_nix = true;
> +- var it = mem.tokenize(nix_ldflags, " ");
> ++ if (process.getEnvVarOwned(allocator, "ZIG_LIB_DIRS")) |zig_lib_dirs| {
> ++ defer allocator.free(zig_lib_dirs);
> ++ var it = mem.tokenize(zig_lib_dirs, ":");
> + while (true) {
> +- const word = it.next() orelse break;
> +- if (mem.eql(u8, word, "-rpath")) {
> +- const rpath = it.next() orelse {
> +- try self.addWarning("Expected argument after -rpath in NIX_LDFLAGS");
> +- break;
> +- };
> +- try self.addRPath(rpath);
> +- } else if (word.len > 2 and word[0] == '-' and word[1] == 'L') {
> +- const lib_path = word[2..];
> +- try self.addLibDir(lib_path);
> +- } else {
> +- try self.addWarningFmt("Unrecognized C flag from NIX_LDFLAGS: {s}", .{word});
> +- break;
> +- }
> ++ const dir = it.next() orelse break;
> ++ try self.addLibDir(dir);
> + }
> + } else |err| switch (err) {
> + error.InvalidUtf8 => {},
> + error.EnvironmentVariableNotFound => {},
> + error.OutOfMemory => |e| return e,
> + }
> +- if (is_nix) {
> +- return self;
> +- }
> +-
> +- if (comptime Target.current.isDarwin()) {
> +- try self.addIncludeDir("/usr/include");
> +- try self.addIncludeDir("/usr/local/include");
> +-
> +- try self.addLibDir("/usr/lib");
> +- try self.addLibDir("/usr/local/lib");
> +-
> +- try self.addFrameworkDir("/Library/Frameworks");
> +- try self.addFrameworkDir("/System/Library/Frameworks");
> +-
> +- return self;
> +- }
> +-
> +- if (native_target.os.tag != .windows) {
> +- const triple = try native_target.linuxTriple(allocator);
> +- const qual = native_target.cpu.arch.ptrBitWidth();
> +-
> +- // TODO: $ ld --verbose | grep SEARCH_DIR
> +- // the output contains some paths that end with lib64, maybe include them too?
> +- // TODO: what is the best possible order of things?
> +- // TODO: some of these are suspect and should only be added on some systems. audit needed.
> +
> +- try self.addIncludeDir("/usr/local/include");
> +- try self.addLibDirFmt("/usr/local/lib{d}", .{qual});
> +- try self.addLibDir("/usr/local/lib");
> +-
> +- try self.addIncludeDirFmt("/usr/include/{s}", .{triple});
> +- try self.addLibDirFmt("/usr/lib/{s}", .{triple});
> +-
> +- try self.addIncludeDir("/usr/include");
> +- try self.addLibDirFmt("/lib{d}", .{qual});
> +- try self.addLibDir("/lib");
> +- try self.addLibDirFmt("/usr/lib{d}", .{qual});
> +- try self.addLibDir("/usr/lib");
> +-
> +- // example: on a 64-bit debian-based linux distro, with zlib installed from apt:
> +- // zlib.h is in /usr/include (added above)
> +- // libz.so.1 is in /lib/x86_64-linux-gnu (added here)
> +- try self.addLibDirFmt("/lib/{s}", .{triple});
> ++ if (process.getEnvVarOwned(allocator, "ZIG_FRAMEWORK_DIRS")) |zig_framework_dirs| {
> ++ defer allocator.free(zig_framework_dirs);
> ++ var it = mem.tokenize(zig_framework_dirs, ":");
> ++ while (true) {
> ++ const dir = it.next() orelse break;
> ++ try self.addFrameworkDir(dir);
> ++ }
> ++ } else |err| switch (err) {
> ++ error.InvalidUtf8 => {},
> ++ error.EnvironmentVariableNotFound => {},
> ++ error.OutOfMemory => |e| return e,
> + }
> +
> + return self;
> diff --git a/gnu/packages/zig.scm b/gnu/packages/zig.scm
> new file mode 100644
> index 0000000000..aae095b747
> --- /dev/null
> +++ b/gnu/packages/zig.scm
> @@ -0,0 +1,100 @@
> +;;; GNU Guix --- Functional package management for GNU
> +;;; Copyright © 2021 Liliana Prikler <liliana.prikler <at> gmail.com>
> +;;; Copyright © 2021 Sarah Morgensen <iskarian <at> mgsn.dev>
> +;;;
> +;;; This file is part of GNU Guix.
> +;;;
> +;;; GNU Guix is free software; you can redistribute it and/or modify it
> +;;; under the terms of the GNU General Public License as published by
> +;;; the Free Software Foundation; either version 3 of the License, or (at
> +;;; your option) any later version.
> +;;;
> +;;; GNU Guix is distributed in the hope that it will be useful, but
> +;;; WITHOUT ANY WARRANTY; without even the implied warranty of
> +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> +;;; GNU General Public License for more details.
> +;;;
> +;;; You should have received a copy of the GNU General Public License
> +;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses>.
> +
> +(define-module (gnu packages zig)
> + #:use-module (guix packages)
> + #:use-module (guix git-download)
> + #:use-module ((guix licenses) #:prefix license:)
> + #:use-module (guix build-system cmake)
> + #:use-module (gnu packages)
> + #:use-module (gnu packages llvm))
> +
> +(define-public zig
> + (package
> + (name "zig")
> + (version "0.8.1")
> + (source
> + (origin
> + (method git-fetch)
> + (uri (git-reference
> + (url "https://github.com/ziglang/zig.git")
> + (commit version)))
> + (file-name (git-file-name name version))
> + (sha256
> + (base32 "147qx7xgj0r353wh5ragzn6kmm1vrf31i8038z3zqwjnqqgqxi6c"))
> + (patches
> + (search-patches
> + "zig-use-explicit-paths.patch"))))
> + (build-system cmake-build-system)
> + ;; Zig uses Clang and LLVM libraries, and (may) use LLVM to compile along
> + ;; with GCC.
> + (inputs
> + `(("clang" ,clang-12)
> + ("lld" ,lld-12)
> + ("llvm" ,llvm-12)))
> + (native-inputs
> + `(("llvm" ,llvm-12)))
> + (arguments
> + `(#:configure-flags
> + (list ,@(if (%current-target-system)
> + (string-append "-DZIG_TARGET_TRIPLE="
> + (%current-target-system))
> + '()))
> + #:tests? #f ;;; XXX: tests result in a FileNotFound
> + #:phases
> + (modify-phases %standard-phases
> + (add-after 'unpack 'save-unpack-dir
> + (lambda _
> + ;; HACK: Passing unpacked source directory to 'check phase.
> + (setenv "ZIG_SOURCE_DIR" (getcwd))
> + #t))
> + (add-after 'configure 'set-home
> + (lambda _
> + (setenv "HOME" (getcwd)) ; zig writes to $HOME/.cache
> + #t))
> + (delete 'check)
> + (add-after 'install 'check
> + (lambda* (#:key outputs tests? #:allow-other-keys)
> + (when tests?
> + (with-directory-excursion (getenv "ZIG_SOURCE_DIR")
> + (invoke (string-append (assoc-ref outputs "out") "/bin/zig")
> + "build" "test"))))))))
> + (native-search-paths
> + (list
> + (search-path-specification
> + (variable "ZIG_INCLUDE_DIRS")
> + ;; XXX: It doesn't seem as though Zig can distinguish between C and C++
> + ;; include paths, so provide both.
> + (files '("include/c++" "include")))
> + (search-path-specification
> + (variable "ZIG_LIB_DIRS")
> + (files '("lib" "lib64")))))
> + (synopsis "General purpose programming language and toolchain")
> + (description "Zig is a general-purpose programming language and
> +toolchain. Among other features it provides
> +@itemize
> +@item an Optional type instead of null pointers,
> +@item manual memory management,
> +@item generic data structures and functions,
> +@item compile-time reflection and compile-time code execution,
> +@item integration with C using zig as a C compiler, and
> +@item concurrency via async functions.
> +@end itemize")
> + (home-page "https://github.com/ziglang/zig")
> + (license license:expat)))
> --
> 2.33.0




Information forwarded to guix-patches <at> gnu.org:
bug#47006; Package guix-patches. (Sat, 11 Sep 2021 18:47:02 GMT) Full text and rfc822 format available.

Message #60 received at 47006 <at> debbugs.gnu.org (full text, mbox):

From: András Vöröskői <voroskoi <at> gmail.com>
To: 47006 <at> debbugs.gnu.org
Subject: Re: [PATCH] gnu: Add zig.
Date: Sat, 11 Sep 2021 20:45:58 +0200
Hi,

So zig testing result is the following:
-Dskip-libc does not work, my best result is with -Dskip-non-native.

-Dskip-non-native fails with "libc headers note" test from
`compile_errors.zig` (I had to comment it around line 2750) and std
library tests also fails instantaneously.

So I suggest the following test command for now: `zig build
-Dskip-non-native test-toolchain` with a patch to disable that failing
test. This will test everything except the std library and docs.




Information forwarded to guix-patches <at> gnu.org:
bug#47006; Package guix-patches. (Sat, 11 Sep 2021 19:25:02 GMT) Full text and rfc822 format available.

Message #63 received at 47006 <at> debbugs.gnu.org (full text, mbox):

From: Sarah Morgensen <iskarian <at> mgsn.dev>
To: Liliana Prikler <liliana.prikler <at> gmail.com>
Cc: 47006 <at> debbugs.gnu.org, 39480 <at> debbugs.gnu.org, maximedevos <at> telenet.be,
 efraim <at> flashner.co.il
Subject: Re: [bug#47006] [WIP PATCH v2 2/2] gnu: Add zig.
Date: Sat, 11 Sep 2021 12:24:39 -0700
[Message part 1 (text/plain, inline)]
All,

Apologies for the empty email earlier.  That shows me for trying to send
from mobile!

Liliana,

Liliana Prikler <liliana.prikler <at> gmail.com> writes:

> I've added a patch to use explicit search paths rather than whatever Zig used
> before and tried fixing some (syntactic) errors with the tests, but was
> unsuccesful, as there appear to be failing tests in the suite itself.  Could
> you have a look at the revised patch and check what flags you could add to
> the check phase to make it meaningful?
>
> Btw. I haven't checked whether my cosmetic changes to #:configure-flags break
> things or not.  The end of the build phase puts a large amount of stress onto
> my system that I'd like to avoid at this hour.

I'm still working through the tests, but I did find one issue that has
cropped up either from your patch or from the 0.7.1 -> 0.8.1 upgrade.
This is from attempting to build tetris [0] (though I had to make a few
syntax fixes, attached below, to build with 0.8.1):

--8<---------------cut here---------------start------------->8---
Zig attempted to find the path to native system libc headers by executing this command:
cc -E -Wp,-v -xc /dev/null
error: unable to create compilation: UnableToSpawnCCompiler
--8<---------------cut here---------------end--------------->8---

No combination of ZIG_LIB_DIRS and ZIG_INCLUDE_DIRS seems to fix
it.  Neither does --search-prefix.

If I set CC=gcc, it works fine.  But I think something changed such that
it now has to fall back to this method of detection.  I have no idea
why.

[0] https://github.com/andrewrk/tetris

--
Sarah

[build-tetris.patch (text/x-patch, inline)]
diff --git a/src/all_shaders.zig b/src/all_shaders.zig
index a855bba..fb7eac8 100644
--- a/src/all_shaders.zig
+++ b/src/all_shaders.zig
@@ -107,7 +107,7 @@ pub const ShaderProgram = struct {
     pub fn attribLocation(sp: ShaderProgram, name: [*]const u8) c.GLint {
         const id = c.glGetAttribLocation(sp.program_id, name);
         if (id == -1) {
-            panic("invalid attrib: {}\n", .{name});
+            panic("invalid attrib: {*}\n", .{name});
         }
         return id;
     }
@@ -115,7 +115,7 @@ pub const ShaderProgram = struct {
     pub fn uniformLocation(sp: ShaderProgram, name: [*]const u8) c.GLint {
         const id = c.glGetUniformLocation(sp.program_id, name);
         if (id == -1) {
-            panic("invalid uniform: {}\n", .{name});
+            panic("invalid uniform: {*}\n", .{name});
         }
         return id;
     }
@@ -169,7 +169,7 @@ pub const ShaderProgram = struct {
         c.glGetProgramiv(sp.program_id, c.GL_INFO_LOG_LENGTH, &error_size);
         const message = try c_allocator.alloc(u8, @intCast(usize, error_size));
         c.glGetProgramInfoLog(sp.program_id, error_size, &error_size, message.ptr);
-        panic("Error linking shader program: {}\n", .{message.ptr});
+        panic("Error linking shader program: {*}\n", .{message.ptr});
     }
 
     pub fn destroy(sp: *ShaderProgram) void {
@@ -205,5 +205,5 @@ fn initGlShader(source: []const u8, name: [*]const u8, kind: c.GLenum) !c.GLuint
 
     const message = try c_allocator.alloc(u8, @intCast(usize, error_size));
     c.glGetShaderInfoLog(shader_id, error_size, &error_size, message.ptr);
-    panic("Error compiling {} shader:\n{}\n", .{ name, message.ptr });
+    panic("Error compiling {*} shader:\n{*}\n", .{ name, message.ptr });
 }
diff --git a/src/debug_gl.zig b/src/debug_gl.zig
index 2fdcda0..543202b 100644
--- a/src/debug_gl.zig
+++ b/src/debug_gl.zig
@@ -2,7 +2,7 @@ const c = @import("c.zig");
 const std = @import("std");
 const os = std.os;
 const panic = std.debug.panic;
-const builtin = @import("builtin");
+const builtin = std.builtin;
 
 pub const is_on = if (builtin.mode == builtin.Mode.ReleaseFast) c.GL_FALSE else c.GL_TRUE;
 
diff --git a/src/main.zig b/src/main.zig
index fd83f8a..fa5f264 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -19,7 +19,7 @@ var static_geometry: StaticGeometry = undefined;
 var font: Spritesheet = undefined;
 
 fn errorCallback(err: c_int, description: [*c]const u8) callconv(.C) void {
-    panic("Error: {}\n", .{@as([*:0]const u8, description)});
+    panic("Error: {s}\n", .{@as([*:0]const u8, description)});
 }
 
 fn keyCallback(win: ?*c.GLFWwindow, key: c_int, scancode: c_int, action: c_int, mods: c_int) callconv(.C) void {
@@ -95,9 +95,10 @@ pub fn main() !void {
     defer font.deinit();
 
     var seed_bytes: [@sizeOf(u64)]u8 = undefined;
-    std.crypto.randomBytes(seed_bytes[0..]) catch |err| {
-        panic("unable to seed random number generator: {}", .{err});
-    };
+    std.crypto.random.bytes(seed_bytes[0..]);
+// catch {
+//        panic("unable to seed random number generator", .{});
+//    };
     t.prng = std.rand.DefaultPrng.init(std.mem.readIntNative(u64, &seed_bytes));
     t.rand = &t.prng.random;
 

Information forwarded to guix-patches <at> gnu.org:
bug#47006; Package guix-patches. (Sat, 11 Sep 2021 20:02:02 GMT) Full text and rfc822 format available.

Message #66 received at 47006 <at> debbugs.gnu.org (full text, mbox):

From: Liliana Marie Prikler <liliana.prikler <at> gmail.com>
To: Sarah Morgensen <iskarian <at> mgsn.dev>
Cc: 47006 <at> debbugs.gnu.org, 39480 <at> debbugs.gnu.org, maximedevos <at> telenet.be,
 efraim <at> flashner.co.il
Subject: Re: [bug#47006] [WIP PATCH v2 2/2] gnu: Add zig.
Date: Sat, 11 Sep 2021 22:01:31 +0200
Hi Sarah,

Am Samstag, den 11.09.2021, 12:24 -0700 schrieb Sarah Morgensen:
> All,
> 
> Apologies for the empty email earlier.  That shows me for trying to
> send from mobile!
Curse those mobile applications with their small buttons amirite? :P

> Liliana,
> 
> Liliana Prikler <liliana.prikler <at> gmail.com> writes:
> 
> > I've added a patch to use explicit search paths rather than
> > whatever Zig used
> > before and tried fixing some (syntactic) errors with the tests, but
> > was
> > unsuccesful, as there appear to be failing tests in the suite
> > itself.  Could
> > you have a look at the revised patch and check what flags you could
> > add to
> > the check phase to make it meaningful?
> > 
> > Btw. I haven't checked whether my cosmetic changes to #:configure-
> > flags break
> > things or not.  The end of the build phase puts a large amount of
> > stress onto
> > my system that I'd like to avoid at this hour.
> 
> I'm still working through the tests, but I did find one issue that
> has cropped up either from your patch or from the 0.7.1 -> 0.8.1
> upgrade.  This is from attempting to build tetris [0] (though I had
> to make a few syntax fixes, attached below, to build with 0.8.1):
W.r.t. the syntax fixes, that is probably an upstream issue or perhaps
an incompatibility introduced by zig itself.  (Maybe already from 0.7.1
to 0.8.0?)

> --8<---------------cut here---------------start------------->8---
> Zig attempted to find the path to native system libc headers by
> executing this command:
> cc -E -Wp,-v -xc /dev/null
> error: unable to create compilation: UnableToSpawnCCompiler
> --8<---------------cut here---------------end--------------->8---
It appears zig tries to execute @command{cc}.  Note, that this command
does not exist in Guix unless you install a symlink, so it will always
fail.  We might want to investigate the source of this error to check
whether spawning a C compiler is indeed the right choice for what
they're claiming to try or whether our hard coding already takes care
of that.

> No combination of ZIG_LIB_DIRS and ZIG_INCLUDE_DIRS seems to fix
> it.  Neither does --search-prefix.
> 
> If I set CC=gcc, it works fine.  But I think something changed such
> that it now has to fall back to this method of detection.  I have no
> idea why.
Thanks for the info.  I'll let you know once I find out more. 





Information forwarded to guix-patches <at> gnu.org:
bug#47006; Package guix-patches. (Sun, 12 Sep 2021 04:44:02 GMT) Full text and rfc822 format available.

Message #69 received at 47006 <at> debbugs.gnu.org (full text, mbox):

From: Sarah Morgensen <iskarian <at> mgsn.dev>
To: Liliana Marie Prikler <liliana.prikler <at> gmail.com>
Cc: 47006 <at> debbugs.gnu.org,
 András Vöröskői <voroskoi <at> gmail.com>,
 maximedevos <at> telenet.be, efraim <at> flashner.co.il
Subject: Re: [bug#47006] [WIP PATCH v2 2/2] gnu: Add zig.
Date: Sat, 11 Sep 2021 21:42:53 -0700
[Message part 1 (text/plain, inline)]
Hi,

I finally got a chance to run some tests.  I've attached a patch below
that works.  As András pointed out,

András Vöröskői <voroskoi <at> gmail.com> writes:

> Hi,
>
> So zig testing result is the following:
> -Dskip-libc does not work, my best result is with -Dskip-non-native.
>
> -Dskip-non-native fails with "libc headers note" test from
> `compile_errors.zig` (I had to comment it around line 2750) and std
> library tests also fails instantaneously.
>
> So I suggest the following test command for now: `zig build
> -Dskip-non-native test-toolchain` with a patch to disable that failing
> test. This will test everything except the std library and docs.

'test-toolchain' is probably a good choice because it skips standard
library tests, which I found out can take a lot of memory (>7.5GB)!  I
also disabled stage 2 tests since stage 2 is experimental and isn't
actually installed.

Now that I have an output:

--8<---------------cut here---------------start------------->8---
$ ./pre-inst-env guix size zig 
store item                                                       total    self
/gnu/store/kwjw55f4syys5gg8a9lr6bk6a3jdqw0i-zig-0.8.1              576.6   177.4  30.8%
/gnu/store/rmc131fpy2hv408a1awd2wm7kiwyf7d7-llvm-12.0.0            234.1   162.7  28.2%
/gnu/store/rn75fm7adgx3pw5j8pg3bczfqq1y17lk-gcc-7.5.0              178.5   107.3  18.6%
/gnu/store/fa6wj5bxkj5ll1d7292a70knmyl7a0cr-glibc-2.31              38.4    36.7   6.4%
/gnu/store/f0ca0lf64bw08srv1bj7gkg6ag0sbdb2-gcc-7.5.0-lib           71.0    32.6   5.7%
/gnu/store/01b4w3m6mp55y531kyi1g8shh722kwqm-gcc-7.5.0-lib           71.0    32.6   5.7%
/gnu/store/nzfhh1rm85lx2p5plbx45qqj82pcv5hp-clang-runtime-12.0.0    95.9    24.9   4.3%
/gnu/store/mmhimfwmmidf09jw1plw3aw1g1zn2nkh-bash-static-5.0.16       1.6     1.6   0.3%
/gnu/store/g2s5jfkfd4k973wb58476b1bbv9zpm6m-zlib-1.2.11             38.6     0.2   0.0%
/gnu/store/rykm237xkmq7rl1p0nwass01p090p88x-zlib-1.2.11             71.2     0.2   0.0%
/gnu/store/bw15z9kh9c65ycc2vbhl2izwfwfva7p1-libffi-3.3              71.2     0.2   0.0%
total: 576.6 MiB
--8<---------------cut here---------------end--------------->8---

It looks like we're retaining references to the main gcc-7.5.0 output,
but only to its "include/c++" directory, as a single reference in the
zig binary.  I expect this would cause issues if another GCC version
were later used with Zig.

We're retaining double direct references to gcc-7.5.0-lib, and double
indirect references to zlib-1.2.11.  This seems to come from clang.
(Wow, clang is big. Maybe it should have a separate "lib" output?  Zig,
for example, only needs libclang to build, not the binaries.)

Other than those items, it looks good!

I've asked on their ML about exactly which dependencies are needed for
the host and target architectures, so hopefully that will solve that.

--
Sarah

[v3-0002-gnu-Add-zig.patch (text/x-patch, inline)]
From 06ed65a6f49c290bbf1b773da8874353344a5b55 Mon Sep 17 00:00:00 2001
Message-Id: <06ed65a6f49c290bbf1b773da8874353344a5b55.1631421568.git.iskarian <at> mgsn.dev>
In-Reply-To: <de7531db2e27b002cc4ba4d6347baa35cece0264.1631421568.git.iskarian <at> mgsn.dev>
References: <de7531db2e27b002cc4ba4d6347baa35cece0264.1631421568.git.iskarian <at> mgsn.dev>
From: Liliana Prikler <liliana.prikler <at> gmail.com>
Date: Thu, 9 Sep 2021 15:32:22 +0200
Subject: [WIP PATCH v3 2/2] gnu: Add zig.

* gnu/packages/patches/zig-disable-libc-note-test.patch,
gnu/packages/patches/zig-disable-MIPS-tests.patch,
gnu/packages/patches/zig-fix-cross-native-execution.patch,
gnu/packages/patches/zig-use-explicit-paths.patch: New files.
* gnu/packages/zig.scm: New file.
* gnu/local.mk (GNU_SYSTEM_MODULES, dist_patch_DATA): Adjust accordingly.
---
 gnu/local.mk                                  |   5 +
 .../patches/zig-disable-MIPS-tests.patch      |  87 ++++++++++++
 .../patches/zig-disable-libc-note-test.patch  |  31 ++++
 .../zig-fix-cross-native-execution.patch      |  64 +++++++++
 .../patches/zig-use-explicit-paths.patch      | 132 ++++++++++++++++++
 gnu/packages/zig.scm                          | 109 +++++++++++++++
 6 files changed, 428 insertions(+)
 create mode 100644 gnu/packages/patches/zig-disable-MIPS-tests.patch
 create mode 100644 gnu/packages/patches/zig-disable-libc-note-test.patch
 create mode 100644 gnu/packages/patches/zig-fix-cross-native-execution.patch
 create mode 100644 gnu/packages/patches/zig-use-explicit-paths.patch
 create mode 100644 gnu/packages/zig.scm

diff --git a/gnu/local.mk b/gnu/local.mk
index 2a56c4a9e2..dab959845c 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -598,6 +598,7 @@ GNU_SYSTEM_MODULES =				\
   %D%/packages/xdisorg.scm			\
   %D%/packages/xorg.scm				\
   %D%/packages/xfce.scm				\
+  %D%/packages/zig.scm				\
   %D%/packages/zile.scm				\
   %D%/packages/zwave.scm			\
 						\
@@ -1903,6 +1904,10 @@ dist_patch_DATA =						\
   %D%/packages/patches/ytfzf-updates.patch        \
   %D%/packages/patches/ytnef-CVE-2021-3403.patch	\
   %D%/packages/patches/ytnef-CVE-2021-3404.patch	\
+  %D%/packages/patches/zig-disable-libc-note-test.patch         \
+  %D%/packages/patches/zig-disable-MIPS-tests.patch             \
+  %D%/packages/patches/zig-fix-cross-native-execution.patch     \
+  %D%/packages/patches/zig-use-explicit-paths.patch	        \
   %D%/packages/patches/zstd-CVE-2021-24031_CVE-2021-24032.patch	\
   %D%/packages/patches/zziplib-CVE-2018-16548.patch
 
diff --git a/gnu/packages/patches/zig-disable-MIPS-tests.patch b/gnu/packages/patches/zig-disable-MIPS-tests.patch
new file mode 100644
index 0000000000..80d72f1b9c
--- /dev/null
+++ b/gnu/packages/patches/zig-disable-MIPS-tests.patch
@@ -0,0 +1,87 @@
+Upstream issue: https://github.com/ziglang/zig/issues/8155
+
+Zig fails to cross-compile to MIPS architectures with LLVM 12.0.0.  The issue
+is fixed in LLVM 12.0.1.
+
+diff --git a/test/tests.zig b/test/tests.zig
+index b80c082fb..cd0c24fc9 100644
+--- a/test/tests.zig
++++ b/test/tests.zig
+@@ -153,22 +153,22 @@ const test_targets = blk: {
+         //    .link_libc = true,
+         //},
+ 
+-        TestTarget{
+-            .target = .{
+-                .cpu_arch = .mips,
+-                .os_tag = .linux,
+-                .abi = .none,
+-            },
+-        },
+-
+-        TestTarget{
+-            .target = .{
+-                .cpu_arch = .mips,
+-                .os_tag = .linux,
+-                .abi = .musl,
+-            },
+-            .link_libc = true,
+-        },
++        // TestTarget{
++        //     .target = .{
++        //         .cpu_arch = .mips,
++        //         .os_tag = .linux,
++        //         .abi = .none,
++        //     },
++        // },
++
++        // TestTarget{
++        //     .target = .{
++        //         .cpu_arch = .mips,
++        //         .os_tag = .linux,
++        //         .abi = .musl,
++        //     },
++        //     .link_libc = true,
++        // },
+ 
+         // https://github.com/ziglang/zig/issues/4927
+         //TestTarget{
+@@ -180,22 +180,22 @@ const test_targets = blk: {
+         //    .link_libc = true,
+         //},
+ 
+-        TestTarget{
+-            .target = .{
+-                .cpu_arch = .mipsel,
+-                .os_tag = .linux,
+-                .abi = .none,
+-            },
+-        },
+-
+-        TestTarget{
+-            .target = .{
+-                .cpu_arch = .mipsel,
+-                .os_tag = .linux,
+-                .abi = .musl,
+-            },
+-            .link_libc = true,
+-        },
++        // TestTarget{
++        //     .target = .{
++        //         .cpu_arch = .mipsel,
++        //         .os_tag = .linux,
++        //         .abi = .none,
++        //     },
++        // },
++
++        // TestTarget{
++        //     .target = .{
++        //         .cpu_arch = .mipsel,
++        //         .os_tag = .linux,
++        //         .abi = .musl,
++        //     },
++        //     .link_libc = true,
++        // },
+ 
+         // https://github.com/ziglang/zig/issues/4927
+         //TestTarget{
diff --git a/gnu/packages/patches/zig-disable-libc-note-test.patch b/gnu/packages/patches/zig-disable-libc-note-test.patch
new file mode 100644
index 0000000000..971ae53912
--- /dev/null
+++ b/gnu/packages/patches/zig-disable-libc-note-test.patch
@@ -0,0 +1,31 @@
+This test fails with "error.CompilationIncorrectlySucceeded".
+
+diff --git a/test/compile_errors.zig b/test/compile_errors.zig
+index fd1255c..20d5548 100644
+--- a/test/compile_errors.zig
++++ b/test/compile_errors.zig
+@@ -2751,15 +2751,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
+             "tmp.zig:3:5: error: dependency on libc must be explicitly specified in the build command",
+         });
+ 
+-        cases.addTest("libc headers note",
+-            \\const c = @cImport(@cInclude("stdio.h"));
+-            \\export fn entry() void {
+-            \\    _ = c.printf("hello, world!\n");
+-            \\}
+-        , &[_][]const u8{
+-            "tmp.zig:1:11: error: C import failed",
+-            "tmp.zig:1:11: note: libc headers not available; compilation does not link against libc",
+-        });
++//        cases.addTest("libc headers note",
++//            \\const c = @cImport(@cInclude("stdio.h"));
++//            \\export fn entry() void {
++//            \\    _ = c.printf("hello, world!\n");
++//            \\}
++//        , &[_][]const u8{
++//            "tmp.zig:1:11: error: C import failed",
++//            "tmp.zig:1:11: note: libc headers not available; compilation does not link against libc",
++//        });
+     }
+ 
+     cases.addTest("comptime vector overflow shows the index",
diff --git a/gnu/packages/patches/zig-fix-cross-native-execution.patch b/gnu/packages/patches/zig-fix-cross-native-execution.patch
new file mode 100644
index 0000000000..1952c6b867
--- /dev/null
+++ b/gnu/packages/patches/zig-fix-cross-native-execution.patch
@@ -0,0 +1,64 @@
+Upstream issue: https://github.com/ziglang/zig/issues/9738
+
+Without this patch, 'zig run' or 'zig test' attempts to run cross-native
+binaries even if their dynamic loader isn't present, which causes a crash
+with "error: FileNotFound".
+
+---
+diff --git a/src/main.zig b/src/main.zig
+index c1d12fcba..9b1bee0d6 100644
+--- a/src/main.zig
++++ b/src/main.zig
+@@ -2040,7 +2040,7 @@ fn buildOutputType(
+             test_exec_args.items,
+             self_exe_path,
+             arg_mode,
+-            target_info.target,
++            target_info,
+             watch,
+             &comp_destroyed,
+             all_args,
+@@ -2110,7 +2110,7 @@ fn buildOutputType(
+                         test_exec_args.items,
+                         self_exe_path,
+                         arg_mode,
+-                        target_info.target,
++                        target_info,
+                         watch,
+                         &comp_destroyed,
+                         all_args,
+@@ -2134,7 +2134,7 @@ fn buildOutputType(
+                         test_exec_args.items,
+                         self_exe_path,
+                         arg_mode,
+-                        target_info.target,
++                        target_info,
+                         watch,
+                         &comp_destroyed,
+                         all_args,
+@@ -2158,7 +2158,7 @@ fn runOrTest(
+     test_exec_args: []const ?[]const u8,
+     self_exe_path: []const u8,
+     arg_mode: ArgMode,
+-    target: std.Target,
++    target: std.zig.system.NativeTargetInfo,
+     watch: bool,
+     comp_destroyed: *bool,
+     all_args: []const []const u8,
+@@ -2174,7 +2174,15 @@ fn runOrTest(
+     defer argv.deinit();
+ 
+     if (test_exec_args.len == 0) {
+-        if (!std.Target.current.canExecBinariesOf(target)) {
++        const can_run = blk: {
++              if (!std.Target.current.canExecBinariesOf(target.target)) break :blk false;
++              if (target.dynamic_linker.get()) |dl| {
++                  std.fs.cwd().access(dl, .{}) catch break :blk false;
++                  break :blk true;
++              }
++              break :blk false;
++        };
++        if (!can_run) {
+             switch (arg_mode) {
+                 .zig_test => {
+                     warn("created {s} but skipping execution because it is non-native", .{exe_path});
diff --git a/gnu/packages/patches/zig-use-explicit-paths.patch b/gnu/packages/patches/zig-use-explicit-paths.patch
new file mode 100644
index 0000000000..ab0d2c7f8b
--- /dev/null
+++ b/gnu/packages/patches/zig-use-explicit-paths.patch
@@ -0,0 +1,132 @@
+This patch replaces the OS-specific detection mechanism by one that solely
+relies on environment variables.  This has the benefit that said environment
+variables can be used as search paths in Guix.
+
+Index: zig-0.8.1/lib/std/zig/system.zig
+===================================================================
+--- zig-0.8.1.orig/lib/std/zig/system.zig
++++ zig-0.8.1/lib/std/zig/system.zig
+@@ -39,101 +39,44 @@ pub const NativePaths = struct {
+         };
+         errdefer self.deinit();
+ 
+-        var is_nix = false;
+-        if (process.getEnvVarOwned(allocator, "NIX_CFLAGS_COMPILE")) |nix_cflags_compile| {
+-            defer allocator.free(nix_cflags_compile);
+-
+-            is_nix = true;
+-            var it = mem.tokenize(nix_cflags_compile, " ");
++        // TODO: Support cross-compile paths?
++        if (process.getEnvVarOwned(allocator, "ZIG_INCLUDE_DIRS")) |zig_include_dirs| {
++            defer allocator.free(zig_include_dirs);
++            var it = mem.tokenize(zig_include_dirs, ":");
+             while (true) {
+-                const word = it.next() orelse break;
+-                if (mem.eql(u8, word, "-isystem")) {
+-                    const include_path = it.next() orelse {
+-                        try self.addWarning("Expected argument after -isystem in NIX_CFLAGS_COMPILE");
+-                        break;
+-                    };
+-                    try self.addIncludeDir(include_path);
+-                } else {
+-                    if (mem.startsWith(u8, word, "-frandom-seed=")) {
+-                        continue;
+-                    }
+-                    try self.addWarningFmt("Unrecognized C flag from NIX_CFLAGS_COMPILE: {s}", .{word});
+-                }
++                const dir = it.next() orelse break;
++                try self.addIncludeDir(dir);
+             }
+         } else |err| switch (err) {
+             error.InvalidUtf8 => {},
+             error.EnvironmentVariableNotFound => {},
+             error.OutOfMemory => |e| return e,
+         }
+-        if (process.getEnvVarOwned(allocator, "NIX_LDFLAGS")) |nix_ldflags| {
+-            defer allocator.free(nix_ldflags);
+ 
+-            is_nix = true;
+-            var it = mem.tokenize(nix_ldflags, " ");
++        if (process.getEnvVarOwned(allocator, "ZIG_LIB_DIRS")) |zig_lib_dirs| {
++            defer allocator.free(zig_lib_dirs);
++            var it = mem.tokenize(zig_lib_dirs, ":");
+             while (true) {
+-                const word = it.next() orelse break;
+-                if (mem.eql(u8, word, "-rpath")) {
+-                    const rpath = it.next() orelse {
+-                        try self.addWarning("Expected argument after -rpath in NIX_LDFLAGS");
+-                        break;
+-                    };
+-                    try self.addRPath(rpath);
+-                } else if (word.len > 2 and word[0] == '-' and word[1] == 'L') {
+-                    const lib_path = word[2..];
+-                    try self.addLibDir(lib_path);
+-                } else {
+-                    try self.addWarningFmt("Unrecognized C flag from NIX_LDFLAGS: {s}", .{word});
+-                    break;
+-                }
++                const dir = it.next() orelse break;
++                try self.addLibDir(dir);
+             }
+         } else |err| switch (err) {
+             error.InvalidUtf8 => {},
+             error.EnvironmentVariableNotFound => {},
+             error.OutOfMemory => |e| return e,
+         }
+-        if (is_nix) {
+-            return self;
+-        }
+-
+-        if (comptime Target.current.isDarwin()) {
+-            try self.addIncludeDir("/usr/include");
+-            try self.addIncludeDir("/usr/local/include");
+-
+-            try self.addLibDir("/usr/lib");
+-            try self.addLibDir("/usr/local/lib");
+-
+-            try self.addFrameworkDir("/Library/Frameworks");
+-            try self.addFrameworkDir("/System/Library/Frameworks");
+-
+-            return self;
+-        }
+-
+-        if (native_target.os.tag != .windows) {
+-            const triple = try native_target.linuxTriple(allocator);
+-            const qual = native_target.cpu.arch.ptrBitWidth();
+-
+-            // TODO: $ ld --verbose | grep SEARCH_DIR
+-            // the output contains some paths that end with lib64, maybe include them too?
+-            // TODO: what is the best possible order of things?
+-            // TODO: some of these are suspect and should only be added on some systems. audit needed.
+ 
+-            try self.addIncludeDir("/usr/local/include");
+-            try self.addLibDirFmt("/usr/local/lib{d}", .{qual});
+-            try self.addLibDir("/usr/local/lib");
+-
+-            try self.addIncludeDirFmt("/usr/include/{s}", .{triple});
+-            try self.addLibDirFmt("/usr/lib/{s}", .{triple});
+-
+-            try self.addIncludeDir("/usr/include");
+-            try self.addLibDirFmt("/lib{d}", .{qual});
+-            try self.addLibDir("/lib");
+-            try self.addLibDirFmt("/usr/lib{d}", .{qual});
+-            try self.addLibDir("/usr/lib");
+-
+-            // example: on a 64-bit debian-based linux distro, with zlib installed from apt:
+-            // zlib.h is in /usr/include (added above)
+-            // libz.so.1 is in /lib/x86_64-linux-gnu (added here)
+-            try self.addLibDirFmt("/lib/{s}", .{triple});
++        if (process.getEnvVarOwned(allocator, "ZIG_FRAMEWORK_DIRS")) |zig_framework_dirs| {
++            defer allocator.free(zig_framework_dirs);
++            var it = mem.tokenize(zig_framework_dirs, ":");
++            while (true) {
++                const dir = it.next() orelse break;
++                try self.addFrameworkDir(dir);
++            }
++        } else |err| switch (err) {
++            error.InvalidUtf8 => {},
++            error.EnvironmentVariableNotFound => {},
++            error.OutOfMemory => |e| return e,
+         }
+ 
+         return self;
diff --git a/gnu/packages/zig.scm b/gnu/packages/zig.scm
new file mode 100644
index 0000000000..639cc937e6
--- /dev/null
+++ b/gnu/packages/zig.scm
@@ -0,0 +1,109 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2021 Liliana Prikler <liliana.prikler <at> gmail.com>
+;;; Copyright © 2021 Sarah Morgensen <iskarian <at> mgsn.dev>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (gnu packages zig)
+  #:use-module (guix packages)
+  #:use-module (guix git-download)
+  #:use-module ((guix licenses) #:prefix license:)
+  #:use-module (guix build-system cmake)
+  #:use-module (gnu packages)
+  #:use-module (gnu packages llvm))
+
+(define-public zig
+  (package
+    (name "zig")
+    (version "0.8.1")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/ziglang/zig.git")
+             (commit version)))
+       (file-name (git-file-name name version))
+       (sha256
+        (base32 "147qx7xgj0r353wh5ragzn6kmm1vrf31i8038z3zqwjnqqgqxi6c"))
+       (patches
+        (search-patches
+         "zig-disable-libc-note-test.patch"
+         ;; XXX: Remove the following patch when updating LLVM to 12.0.1.
+         "zig-disable-MIPS-tests.patch"
+         "zig-fix-cross-native-execution.patch"
+         "zig-use-explicit-paths.patch"))))
+    (build-system cmake-build-system)
+    (inputs
+     `(("clang" ,clang-12) ; Clang propagates llvm.
+       ("lld" ,lld-12)))
+    ;; Zig compiles fine with GCC, but also needs native LLVM libraries.
+    (native-inputs
+     `(("llvm" ,llvm-12)))
+    (arguments
+     `(#:configure-flags
+       (list ,@(if (%current-target-system)
+                   (string-append "-DZIG_TARGET_TRIPLE="
+                                  (%current-target-system))
+                   '()))
+       #:out-of-source? #f ; for tests
+       #:phases
+       (modify-phases %standard-phases
+         (add-after 'configure 'set-cache-dir
+           (lambda _
+             ;; Set cache dir, otherwise Zig looks for `$HOME/.cache'.
+             (setenv "ZIG_GLOBAL_CACHE_DIR"
+                     (string-append (getcwd) "/zig-cache"))))
+         (delete 'check)
+         (add-after 'install 'check
+           (lambda* (#:key outputs tests? #:allow-other-keys)
+             (when tests?
+               (invoke (string-append (assoc-ref outputs "out") "/bin/zig")
+                       ;; Testing the standard library takes >7.5GB RAM, and
+                       ;; will fail if it is OOM-killed.  The 'test-toolchain'
+                       ;; target skips standard library and doc tests.
+                       "build" "test-toolchain"
+                       ;; Stage 2 is experimental, not what we run with `zig',
+                       ;; and stage 2 tests require a lot of RAM.
+                       "-Dskip-stage2-tests"
+                       ;; Options to drop some test configurations.
+                       ;;"-Dskip-non-native" "-Dskip-release-small"
+                       ;;"-Dskip-release-fast" "-Dskip-release-safe"
+                       )))))))
+    (native-search-paths
+     (list
+      (search-path-specification
+       (variable "ZIG_INCLUDE_DIRS")
+       ;; XXX: It doesn't seem as though Zig can distinguish between C and C++
+       ;;      include paths, so provide both.
+       (files '("include/c++" "include")))
+      (search-path-specification
+       ;; TODO: Might be confused with "ZIG_LIB_DIR"... Maybe use
+       ;;       "ZIG_INCLUDE_PATH" and "ZIG_LIBRARY_PATH"?
+       (variable "ZIG_LIB_DIRS")
+       (files '("lib" "lib64")))))
+    (synopsis "General purpose programming language and toolchain")
+    (description "Zig is a general-purpose programming language and
+toolchain.  Among other features it provides
+@itemize
+@item an Optional type instead of null pointers,
+@item manual memory management,
+@item generic data structures and functions,
+@item compile-time reflection and compile-time code execution,
+@item integration with C using zig as a C compiler, and
+@item concurrency via async functions.
+@end itemize")
+    (home-page "https://github.com/ziglang/zig")
+    (license license:expat)))
-- 
2.33.0


Information forwarded to guix-patches <at> gnu.org:
bug#47006; Package guix-patches. (Sun, 12 Sep 2021 07:33:02 GMT) Full text and rfc822 format available.

Message #72 received at 47006 <at> debbugs.gnu.org (full text, mbox):

From: Liliana Marie Prikler <liliana.prikler <at> gmail.com>
To: Sarah Morgensen <iskarian <at> mgsn.dev>
Cc: 47006 <at> debbugs.gnu.org,
 András Vöröskői <voroskoi <at> gmail.com>,
 maximedevos <at> telenet.be, efraim <at> flashner.co.il
Subject: Re: [bug#47006] [WIP PATCH v2 2/2] gnu: Add zig.
Date: Sun, 12 Sep 2021 09:32:15 +0200
Hi,

Am Samstag, den 11.09.2021, 21:42 -0700 schrieb Sarah Morgensen:
> Hi,
> 
> I finally got a chance to run some tests.  I've attached a patch
> below
> that works.  As András pointed out,
> 
> András Vöröskői <voroskoi <at> gmail.com> writes:
> 
> > Hi,
> > 
> > So zig testing result is the following:
> > -Dskip-libc does not work, my best result is with -Dskip-non-
> > native.
> > 
> > -Dskip-non-native fails with "libc headers note" test from
> > `compile_errors.zig` (I had to comment it around line 2750) and std
> > library tests also fails instantaneously.
> > 
> > So I suggest the following test command for now: `zig build
> > -Dskip-non-native test-toolchain` with a patch to disable that
> > failing
> > test. This will test everything except the std library and docs.
> 
> 'test-toolchain' is probably a good choice because it skips standard
> library tests, which I found out can take a lot of memory
> (>7.5GB)!  I also disabled stage 2 tests since stage 2 is
> experimental and isn't actually installed.
So far, so good.

> Now that I have an output:
> 
> --8<---------------cut here---------------start------------->8---
> $ ./pre-inst-env guix size zig 
> store
> item                                                       total    s
> elf
> /gnu/store/kwjw55f4syys5gg8a9lr6bk6a3jdqw0i-zig-
> 0.8.1              576.6   177.4  30.8%
> /gnu/store/rmc131fpy2hv408a1awd2wm7kiwyf7d7-llvm-
> 12.0.0            234.1   162.7  28.2%
> /gnu/store/rn75fm7adgx3pw5j8pg3bczfqq1y17lk-gcc-
> 7.5.0              178.5   107.3  18.6%
> /gnu/store/fa6wj5bxkj5ll1d7292a70knmyl7a0cr-glibc-
> 2.31              38.4    36.7   6.4%
> /gnu/store/f0ca0lf64bw08srv1bj7gkg6ag0sbdb2-gcc-7.5.0-
> lib           71.0    32.6   5.7%
> /gnu/store/01b4w3m6mp55y531kyi1g8shh722kwqm-gcc-7.5.0-
> lib           71.0    32.6   5.7%
> /gnu/store/nzfhh1rm85lx2p5plbx45qqj82pcv5hp-clang-runtime-
> 12.0.0    95.9    24.9   4.3%
> /gnu/store/mmhimfwmmidf09jw1plw3aw1g1zn2nkh-bash-static-
> 5.0.16       1.6     1.6   0.3%
> /gnu/store/g2s5jfkfd4k973wb58476b1bbv9zpm6m-zlib-
> 1.2.11             38.6     0.2   0.0%
> /gnu/store/rykm237xkmq7rl1p0nwass01p090p88x-zlib-
> 1.2.11             71.2     0.2   0.0%
> /gnu/store/bw15z9kh9c65ycc2vbhl2izwfwfva7p1-libffi-
> 3.3              71.2     0.2   0.0%
> total: 576.6 MiB
> --8<---------------cut here---------------end--------------->8---
> 
> It looks like we're retaining references to the main gcc-7.5.0
> output, but only to its "include/c++" directory, as a single
> reference in the zig binary.  I expect this would cause issues if
> another GCC version were later used with Zig.
Where does that include/c++ come from?  Could it be related to the libc
header thing we talked about in IRC?  I don't see any substitution for
that going on either.

> We're retaining double direct references to gcc-7.5.0-lib, and double
> indirect references to zlib-1.2.11.  This seems to come from clang.
> (Wow, clang is big. Maybe it should have a separate "lib"
> output?  Zig, for example, only needs libclang to build, not the
> binaries.)
> 
> Other than those items, it looks good!
According to `guix refresh', there's only two dependents of Clang 12,
but since we'd have to rebuild all clangs, that might go into core-
updates territory.  We might also want to check with an expert on
X/Mesa, since that seems to be one of our biggest clang dependents.

> +       (patches
> +        (search-patches
> +         "zig-disable-libc-note-test.patch"
Is this test really necessary to skip that test?  If not, let's try to
use the command line for that.
> +         ;; XXX: Remove the following patch when updating LLVM to
> 12.0.1.
> +         "zig-disable-MIPS-tests.patch"
There's a patch for LLVM 12.0.1 waiting in the ML and we could
potentially bump lld to 12.0.1 regardless.  (Can LLVM components be
mix-matched like that?)
> +         "zig-fix-cross-native-execution.patch"
IIUC this is weaker than "-Dskip-non-native".  Is there a reason to
include specifically these non-native tests?
> +         "zig-use-explicit-paths.patch"))))

> +    (native-search-paths
> +     (list
> +      (search-path-specification
> +       (variable "ZIG_INCLUDE_DIRS")
> +       ;; XXX: It doesn't seem as though Zig can distinguish between
> C and C++
> +       ;;      include paths, so provide both.
> +       (files '("include/c++" "include")))
> +      (search-path-specification
> +       ;; TODO: Might be confused with "ZIG_LIB_DIR"... Maybe use
> +       ;;       "ZIG_INCLUDE_PATH" and "ZIG_LIBRARY_PATH"?
> +       (variable "ZIG_LIB_DIRS")
> +       (files '("lib" "lib64")))))
You can rewrite "zig-use-explicit-paths.patch" in-place with Emacs'
query-replace and/or sed (or even just manually, there are no lines to
add or remove) if you disagree with my environment variable naming
choice.  Just make sure you don't accidentally break diff by deleting
trailing space.

Regards





Information forwarded to guix-patches <at> gnu.org:
bug#47006; Package guix-patches. (Sun, 12 Sep 2021 07:40:02 GMT) Full text and rfc822 format available.

Message #75 received at 47006 <at> debbugs.gnu.org (full text, mbox):

From: Liliana Marie Prikler <liliana.prikler <at> gmail.com>
To: Sarah Morgensen <iskarian <at> mgsn.dev>
Cc: 47006 <at> debbugs.gnu.org,
 András Vöröskői <voroskoi <at> gmail.com>,
 maximedevos <at> telenet.be, efraim <at> flashner.co.il
Subject: Re: [bug#47006] [WIP PATCH v2 2/2] gnu: Add zig.
Date: Sun, 12 Sep 2021 09:39:11 +0200
Hi,

Am Sonntag, den 12.09.2021, 09:32 +0200 schrieb Liliana Marie Prikler:
> > +    (native-search-paths
> > +     (list
> > +      (search-path-specification
> > +       (variable "ZIG_INCLUDE_DIRS")
> > +       ;; XXX: It doesn't seem as though Zig can distinguish
> > between
> > C and C++
> > +       ;;      include paths, so provide both.
> > +       (files '("include/c++" "include")))
> > +      (search-path-specification
> > +       ;; TODO: Might be confused with "ZIG_LIB_DIR"... Maybe use
> > +       ;;       "ZIG_INCLUDE_PATH" and "ZIG_LIBRARY_PATH"?
> > +       (variable "ZIG_LIB_DIRS")
> > +       (files '("lib" "lib64")))))
> You can rewrite "zig-use-explicit-paths.patch" in-place with Emacs'
> query-replace and/or sed (or even just manually, there are no lines
> to add or remove) if you disagree with my environment variable naming
> choice.  Just make sure you don't accidentally break diff by deleting
> trailing space.
Another potential naming choice would be to prefix everything with
ZIG_LIBC_ rather than simply ZIG_.  Of course I thought about that only
after sending my previous mail ^^"





Information forwarded to guix-patches <at> gnu.org:
bug#47006; Package guix-patches. (Sun, 12 Sep 2021 22:41:01 GMT) Full text and rfc822 format available.

Message #78 received at 47006 <at> debbugs.gnu.org (full text, mbox):

From: Sarah Morgensen <iskarian <at> mgsn.dev>
To: Liliana Marie Prikler <liliana.prikler <at> gmail.com>
Cc: 47006 <at> debbugs.gnu.org,
 András Vöröskői <voroskoi <at> gmail.com>,
 maximedevos <at> telenet.be, efraim <at> flashner.co.il
Subject: Re: [bug#47006] [WIP PATCH v2 2/2] gnu: Add zig.
Date: Sun, 12 Sep 2021 15:40:39 -0700
Liliana Marie Prikler <liliana.prikler <at> gmail.com> writes:

>> It looks like we're retaining references to the main gcc-7.5.0
>> output, but only to its "include/c++" directory, as a single
>> reference in the zig binary.  I expect this would cause issues if
>> another GCC version were later used with Zig.
> Where does that include/c++ come from?  Could it be related to the libc
> header thing we talked about in IRC?  I don't see any substitution for
> that going on either.

I think the build process for Zig might save it after auto-detecting it
as a default include path or something? In the binary, here's where it
appears:

--8<---------------cut here---------------start------------->8---
-gpsize=
GNU::Linker
/lib/i386-gnu
/../lib/
/usr/lib/
/usr/lib/../
static-lib-linker
GNU::StaticLibTool
/../../../../
/libc
/gnu/store/rn75fm7adgx3pw5j8pg3bczfqq1y17lk-gcc-7.5.0/include/c++
/../include/g++
ld-uClibc-mipsn8.so.0
ld-uClibc.so.0
ld-musl-mipsel.so.1
ld-musl-mips.so.1
/system/bin/linker
/system/bin/linker64
/lib/ld-musl-
ld-linux-riscv32-
ld-linux-riscv64-
--8<---------------cut here---------------end--------------->8---

Searching the Clang source yields a const reference in
'lib/Driver/ToolChains/Linux.cpp' at line 406:

--8<---------------cut here---------------start------------->8---
  const StringRef InstallDir = GCCInstallation.getInstallPath();
  const StringRef TripleStr = GCCInstallation.getTriple().str();
  const Multilib &Multilib = GCCInstallation.getMultilib();

  std::string Path =
      (InstallDir + "/../../../../" + TripleStr + "/libc" + Multilib.osSuffix())
          .str();
--8<---------------cut here---------------end--------------->8---

And I just searched the Clang input for this reference--that exact path
with the exact same context as above is present in libclang,
libclangDriver, and everything that gets linked to them.  So it looks
like this one we can blame on Clang as well.

>> We're retaining double direct references to gcc-7.5.0-lib, and double
>> indirect references to zlib-1.2.11.  This seems to come from clang.
>> (Wow, clang is big. Maybe it should have a separate "lib"
>> output?  Zig, for example, only needs libclang to build, not the
>> binaries.)
>> 
>> Other than those items, it looks good!
> According to `guix refresh', there's only two dependents of Clang 12,
> but since we'd have to rebuild all clangs, that might go into core-
> updates territory.  We might also want to check with an expert on
> X/Mesa, since that seems to be one of our biggest clang dependents.

Yeah, Clang is an absolute beast to mess with, so I don't think we
should let this be a blocker for Zig.  I'll submit a bug report to see
if I can summon the experts, though.

>> +       (patches
>> +        (search-patches
>> +         "zig-disable-libc-note-test.patch"
> Is this test really necessary to skip that test?  If not, let's try to
> use the command line for that.

We could use "-Dskip-compile-errors", but that also skips ~600 other
test cases.

>> +         ;; XXX: Remove the following patch when updating LLVM to
>> 12.0.1.
>> +         "zig-disable-MIPS-tests.patch"
> There's a patch for LLVM 12.0.1 waiting in the ML and we could
> potentially bump lld to 12.0.1 regardless.  (Can LLVM components be
> mix-matched like that?)

I have no idea if they *can*, but I'm pretty sure they're not intended
to be, as LLVM wants you to build everything together in one big blob.

>> +         "zig-fix-cross-native-execution.patch"
> IIUC this is weaker than "-Dskip-non-native".  Is there a reason to
> include specifically these non-native tests?

Yes, as I wrote in the patch header, it fixes the behavior of 'zig run'
and 'zig test' when the target is cross-native.  Would we want to stick
to upstream, even if it's buggy?

We might want to add "-Dskip-non-native" anyway as it speeds up tests by
an order of magnitude, in which case tests will succeed without the
patch.  It looks their CI uses it "-Dskip-non-native" as well, and I
suppose there's not a whole lot Guix can do to mess up Zig's
cross-compiling anyway, since it's pretty self-contained...

>> +    (native-search-paths
>> +     (list
>> +      (search-path-specification
>> +       (variable "ZIG_INCLUDE_DIRS")
>> +       ;; XXX: It doesn't seem as though Zig can distinguish between
>> C and C++
>> +       ;;      include paths, so provide both.
>> +       (files '("include/c++" "include")))
>> +      (search-path-specification
>> +       ;; TODO: Might be confused with "ZIG_LIB_DIR"... Maybe use
>> +       ;;       "ZIG_INCLUDE_PATH" and "ZIG_LIBRARY_PATH"?
>> +       (variable "ZIG_LIB_DIRS")
>> +       (files '("lib" "lib64")))))
> You can rewrite "zig-use-explicit-paths.patch" in-place with Emacs'
> query-replace and/or sed (or even just manually, there are no lines to
> add or remove) if you disagree with my environment variable naming
> choice.  Just make sure you don't accidentally break diff by deleting
> trailing space.

> Another potential naming choice would be to prefix everything with
> ZIG_LIBC_ rather than simply ZIG_.  Of course I thought about that only
> after sending my previous mail ^^"

Ah, I meant to mention it in my last e-mail but I forgot.  I didn't want
to just go changing it on you without discussing it.

As far as I can tell, there's no such thing as a "Zig library" or a "Zig
header"; these are for including system C headers and libraries.  So, I
would just go with LIBRARY_PATH and CPLUS_INCLUDE_PATH unless we
anticipate needing to tell Zig something different than what we tell
GCC/Clang.  Furthermore, the in-development 'zig cc' command is intended
to be a drop-in replacement for GCC/Clang, so it should probably honor
the same environment variables.

--
Sarah




Information forwarded to guix-patches <at> gnu.org:
bug#47006; Package guix-patches. (Tue, 14 Sep 2021 16:18:01 GMT) Full text and rfc822 format available.

Message #81 received at 47006 <at> debbugs.gnu.org (full text, mbox):

From: Liliana Marie Prikler <liliana.prikler <at> gmail.com>
To: Sarah Morgensen <iskarian <at> mgsn.dev>
Cc: 47006 <at> debbugs.gnu.org,
 András Vöröskői <voroskoi <at> gmail.com>,
 maximedevos <at> telenet.be, efraim <at> flashner.co.il
Subject: Re: [bug#47006] [WIP PATCH v2 2/2] gnu: Add zig.
Date: Tue, 14 Sep 2021 18:17:14 +0200
[Message part 1 (text/plain, inline)]
Hi,

Am Sonntag, den 12.09.2021, 15:40 -0700 schrieb Sarah Morgensen:
> > > +       (patches
> > > +        (search-patches
> > > +         "zig-disable-libc-note-test.patch"
> > Is this test really necessary to skip that test?  If not, let's try
> > to use the command line for that.
> 
> We could use "-Dskip-compile-errors", but that also skips ~600 other
> test cases.
Point taken, let's keep it then.

> > > +         ;; XXX: Remove the following patch when updating LLVM
> > > to 12.0.1.
> > > +         "zig-disable-MIPS-tests.patch"
> > There's a patch for LLVM 12.0.1 waiting in the ML and we could
> > potentially bump lld to 12.0.1 regardless.  (Can LLVM components be
> > mix-matched like that?)
> 
> I have no idea if they *can*, but I'm pretty sure they're not
> intended to be, as LLVM wants you to build everything together in one
> big blob.
Fair enough, I've tried to rebase this based on András patch
regardless.  In some sense this counts as a review of #50486, but I
obviously haven't tested all the problematic packages that would keep
it from being merged, like mesa.

> > > +         "zig-fix-cross-native-execution.patch"
> > IIUC this is weaker than "-Dskip-non-native".  Is there a reason to
> > include specifically these non-native tests?
> 
> Yes, as I wrote in the patch header, it fixes the behavior of 'zig
> run' and 'zig test' when the target is cross-native.  Would we want
> to stick to upstream, even if it's buggy?
I'm not particularly sure about 'zig run', but imo we should simply
supply the correct linker in cross-native and not worry about upstream
bugs in the negative case.

> We might want to add "-Dskip-non-native" anyway as it speeds up tests
> by an order of magnitude, in which case tests will succeed without
> the patch.  It looks their CI uses it "-Dskip-non-native" as well,
> and I suppose there's not a whole lot Guix can do to mess up Zig's
> cross-compiling anyway, since it's pretty self-contained...
Did that.

> > > +    (native-search-paths
> > > +     (list
> > > +      (search-path-specification
> > > +       (variable "ZIG_INCLUDE_DIRS")
> > > +       ;; XXX: It doesn't seem as though Zig can distinguish
> > > between
> > > C and C++
> > > +       ;;      include paths, so provide both.
> > > +       (files '("include/c++" "include")))
> > > +      (search-path-specification
> > > +       ;; TODO: Might be confused with "ZIG_LIB_DIR"... Maybe
> > > use
> > > +       ;;       "ZIG_INCLUDE_PATH" and "ZIG_LIBRARY_PATH"?
> > > +       (variable "ZIG_LIB_DIRS")
> > > +       (files '("lib" "lib64")))))
> > You can rewrite "zig-use-explicit-paths.patch" in-place with Emacs'
> > query-replace and/or sed (or even just manually, there are no lines
> > to add or remove) if you disagree with my environment variable
> > naming choice.  Just make sure you don't accidentally break diff by
> > deleting trailing space.
> > Another potential naming choice would be to prefix everything with
> > ZIG_LIBC_ rather than simply ZIG_.  Of course I thought about that
> > only after sending my previous mail ^^"
> 
> Ah, I meant to mention it in my last e-mail but I forgot.  I didn't
> want to just go changing it on you without discussing it.
> 
> As far as I can tell, there's no such thing as a "Zig library" or a
> "Zig header"; these are for including system C headers and
> libraries.  So, I would just go with LIBRARY_PATH and
> CPLUS_INCLUDE_PATH unless we anticipate needing to tell Zig something
> different than what we tell GCC/Clang.  Furthermore, the in-
> development 'zig cc' command is intended to be a drop-in replacement
> for GCC/Clang, so it should probably honor the same environment
> variables.
Fair enough, I now have zig search the paths that would normally be
expected to be accordingly set.  This leads to doubly adding
"/include", but I suppose that's fine as we risk not including the
right things in a C only context otherwise.

Regards
[v4-0001-gnu-lld-Update-to-12.0.1.patch (text/x-patch, attachment)]
[v4-0002-gnu-Add-zig.patch (text/x-patch, attachment)]

Information forwarded to guix-patches <at> gnu.org:
bug#47006; Package guix-patches. (Fri, 24 Sep 2021 07:45:02 GMT) Full text and rfc822 format available.

Message #84 received at 47006 <at> debbugs.gnu.org (full text, mbox):

From: Liliana Prikler <liliana.prikler <at> gmail.com>
To: Sarah Morgensen <iskarian <at> mgsn.dev>
Cc: 47006 <at> debbugs.gnu.org,
 András Vöröskői <voroskoi <at> gmail.com>,
 50449 <at> debbugs.gnu.org, maximedevos <at> telenet.be, efraim <at> flashner.co.il
Subject: [PATCH v5] gnu: Add zig.
Date: Thu, 9 Sep 2021 15:32:22 +0200
* gnu/packages/patches/zig-disable-libc-note-test.patch,
gnu/packages/patches/zig-use-system-paths.patch: New files.
* gnu/packages/zig.scm: New file.
* gnu/local.mk (GNU_SYSTEM_MODULES, dist_patch_DATA): Adjust accordingly.
---
 gnu/local.mk                                  |   3 +
 .../patches/zig-disable-libc-note-test.patch  |  31 ++++
 .../patches/zig-use-system-paths.patch        | 143 ++++++++++++++++++
 gnu/packages/zig.scm                          | 104 +++++++++++++
 4 files changed, 281 insertions(+)
 create mode 100644 gnu/packages/patches/zig-disable-libc-note-test.patch
 create mode 100644 gnu/packages/patches/zig-use-system-paths.patch
 create mode 100644 gnu/packages/zig.scm

diff --git a/gnu/local.mk b/gnu/local.mk
index ba87264948..e8df88d7fe 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -598,6 +598,7 @@ GNU_SYSTEM_MODULES =				\
   %D%/packages/xdisorg.scm			\
   %D%/packages/xorg.scm				\
   %D%/packages/xfce.scm				\
+  %D%/packages/zig.scm				\
   %D%/packages/zile.scm				\
   %D%/packages/zwave.scm			\
 						\
@@ -1904,6 +1905,8 @@ dist_patch_DATA =						\
   %D%/packages/patches/ytfzf-updates.patch        \
   %D%/packages/patches/ytnef-CVE-2021-3403.patch	\
   %D%/packages/patches/ytnef-CVE-2021-3404.patch	\
+  %D%/packages/patches/zig-disable-libc-note-test.patch         \
+  %D%/packages/patches/zig-use-system-paths.patch	        \
   %D%/packages/patches/zstd-CVE-2021-24031_CVE-2021-24032.patch	\
   %D%/packages/patches/zziplib-CVE-2018-16548.patch
 
diff --git a/gnu/packages/patches/zig-disable-libc-note-test.patch b/gnu/packages/patches/zig-disable-libc-note-test.patch
new file mode 100644
index 0000000000..971ae53912
--- /dev/null
+++ b/gnu/packages/patches/zig-disable-libc-note-test.patch
@@ -0,0 +1,31 @@
+This test fails with "error.CompilationIncorrectlySucceeded".
+
+diff --git a/test/compile_errors.zig b/test/compile_errors.zig
+index fd1255c..20d5548 100644
+--- a/test/compile_errors.zig
++++ b/test/compile_errors.zig
+@@ -2751,15 +2751,15 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
+             "tmp.zig:3:5: error: dependency on libc must be explicitly specified in the build command",
+         });
+ 
+-        cases.addTest("libc headers note",
+-            \\const c = @cImport(@cInclude("stdio.h"));
+-            \\export fn entry() void {
+-            \\    _ = c.printf("hello, world!\n");
+-            \\}
+-        , &[_][]const u8{
+-            "tmp.zig:1:11: error: C import failed",
+-            "tmp.zig:1:11: note: libc headers not available; compilation does not link against libc",
+-        });
++//        cases.addTest("libc headers note",
++//            \\const c = @cImport(@cInclude("stdio.h"));
++//            \\export fn entry() void {
++//            \\    _ = c.printf("hello, world!\n");
++//            \\}
++//        , &[_][]const u8{
++//            "tmp.zig:1:11: error: C import failed",
++//            "tmp.zig:1:11: note: libc headers not available; compilation does not link against libc",
++//        });
+     }
+ 
+     cases.addTest("comptime vector overflow shows the index",
diff --git a/gnu/packages/patches/zig-use-system-paths.patch b/gnu/packages/patches/zig-use-system-paths.patch
new file mode 100644
index 0000000000..ed122dac22
--- /dev/null
+++ b/gnu/packages/patches/zig-use-system-paths.patch
@@ -0,0 +1,143 @@
+This patch replaces the OS-specific detection mechanism by one that solely
+relies on environment variables.  This has the benefit that said environment
+variables can be used as search paths in Guix.
+
+Index: zig-0.8.1/lib/std/zig/system.zig
+===================================================================
+--- zig-0.8.1.orig/lib/std/zig/system.zig
++++ zig-0.8.1/lib/std/zig/system.zig
+@@ -39,101 +39,57 @@ pub const NativePaths = struct {
+         };
+         errdefer self.deinit();
+ 
+-        var is_nix = false;
+-        if (process.getEnvVarOwned(allocator, "NIX_CFLAGS_COMPILE")) |nix_cflags_compile| {
+-            defer allocator.free(nix_cflags_compile);
+-
+-            is_nix = true;
+-            var it = mem.tokenize(nix_cflags_compile, " ");
++        // TODO: Support cross-compile paths?
++        if (process.getEnvVarOwned(allocator, "C_INCLUDE_PATH")) |c_include_path| {
++            defer allocator.free(c_include_path);
++            var it = mem.tokenize(c_include_path, ":");
+             while (true) {
+-                const word = it.next() orelse break;
+-                if (mem.eql(u8, word, "-isystem")) {
+-                    const include_path = it.next() orelse {
+-                        try self.addWarning("Expected argument after -isystem in NIX_CFLAGS_COMPILE");
+-                        break;
+-                    };
+-                    try self.addIncludeDir(include_path);
+-                } else {
+-                    if (mem.startsWith(u8, word, "-frandom-seed=")) {
+-                        continue;
+-                    }
+-                    try self.addWarningFmt("Unrecognized C flag from NIX_CFLAGS_COMPILE: {s}", .{word});
+-                }
++                const dir = it.next() orelse break;
++                try self.addIncludeDir(dir);
+             }
+         } else |err| switch (err) {
+             error.InvalidUtf8 => {},
+             error.EnvironmentVariableNotFound => {},
+             error.OutOfMemory => |e| return e,
+         }
+-        if (process.getEnvVarOwned(allocator, "NIX_LDFLAGS")) |nix_ldflags| {
+-            defer allocator.free(nix_ldflags);
+ 
+-            is_nix = true;
+-            var it = mem.tokenize(nix_ldflags, " ");
++        if (process.getEnvVarOwned(allocator, "CPLUS_INCLUDE_PATH")) |cplus_include_path| {
++            defer allocator.free(cplus_include_path);
++            var it = mem.tokenize(cplus_include_path, ":");
+             while (true) {
+-                const word = it.next() orelse break;
+-                if (mem.eql(u8, word, "-rpath")) {
+-                    const rpath = it.next() orelse {
+-                        try self.addWarning("Expected argument after -rpath in NIX_LDFLAGS");
+-                        break;
+-                    };
+-                    try self.addRPath(rpath);
+-                } else if (word.len > 2 and word[0] == '-' and word[1] == 'L') {
+-                    const lib_path = word[2..];
+-                    try self.addLibDir(lib_path);
+-                } else {
+-                    try self.addWarningFmt("Unrecognized C flag from NIX_LDFLAGS: {s}", .{word});
+-                    break;
+-                }
++                const dir = it.next() orelse break;
++                try self.addIncludeDir(dir);
+             }
+         } else |err| switch (err) {
+             error.InvalidUtf8 => {},
+             error.EnvironmentVariableNotFound => {},
+             error.OutOfMemory => |e| return e,
+         }
+-        if (is_nix) {
+-            return self;
+-        }
+-
+-        if (comptime Target.current.isDarwin()) {
+-            try self.addIncludeDir("/usr/include");
+-            try self.addIncludeDir("/usr/local/include");
+ 
+-            try self.addLibDir("/usr/lib");
+-            try self.addLibDir("/usr/local/lib");
+-
+-            try self.addFrameworkDir("/Library/Frameworks");
+-            try self.addFrameworkDir("/System/Library/Frameworks");
+-
+-            return self;
++        if (process.getEnvVarOwned(allocator, "LIBRARY_PATH")) |library_path| {
++            defer allocator.free(library_path);
++            var it = mem.tokenize(library_path, ":");
++            while (true) {
++                const dir = it.next() orelse break;
++                try self.addLibDir(dir);
++            }
++        } else |err| switch (err) {
++            error.InvalidUtf8 => {},
++            error.EnvironmentVariableNotFound => {},
++            error.OutOfMemory => |e| return e,
+         }
+ 
+-        if (native_target.os.tag != .windows) {
+-            const triple = try native_target.linuxTriple(allocator);
+-            const qual = native_target.cpu.arch.ptrBitWidth();
+-
+-            // TODO: $ ld --verbose | grep SEARCH_DIR
+-            // the output contains some paths that end with lib64, maybe include them too?
+-            // TODO: what is the best possible order of things?
+-            // TODO: some of these are suspect and should only be added on some systems. audit needed.
+-
+-            try self.addIncludeDir("/usr/local/include");
+-            try self.addLibDirFmt("/usr/local/lib{d}", .{qual});
+-            try self.addLibDir("/usr/local/lib");
+-
+-            try self.addIncludeDirFmt("/usr/include/{s}", .{triple});
+-            try self.addLibDirFmt("/usr/lib/{s}", .{triple});
+-
+-            try self.addIncludeDir("/usr/include");
+-            try self.addLibDirFmt("/lib{d}", .{qual});
+-            try self.addLibDir("/lib");
+-            try self.addLibDirFmt("/usr/lib{d}", .{qual});
+-            try self.addLibDir("/usr/lib");
+-
+-            // example: on a 64-bit debian-based linux distro, with zlib installed from apt:
+-            // zlib.h is in /usr/include (added above)
+-            // libz.so.1 is in /lib/x86_64-linux-gnu (added here)
+-            try self.addLibDirFmt("/lib/{s}", .{triple});
++        if (process.getEnvVarOwned(allocator, "DYLD_FRAMEWORK_PATH")) |dyld_framework_path| {
++            defer allocator.free(dyld_framework_path);
++            var it = mem.tokenize(dyld_framework_path, ":");
++            while (true) {
++                const dir = it.next() orelse break;
++                try self.addFrameworkDir(dir);
++            }
++        } else |err| switch (err) {
++            error.InvalidUtf8 => {},
++            error.EnvironmentVariableNotFound => {},
++            error.OutOfMemory => |e| return e,
+         }
+ 
+         return self;
diff --git a/gnu/packages/zig.scm b/gnu/packages/zig.scm
new file mode 100644
index 0000000000..ef5fe04c86
--- /dev/null
+++ b/gnu/packages/zig.scm
@@ -0,0 +1,104 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2021 Liliana Prikler <liliana.prikler <at> gmail.com>
+;;; Copyright © 2021 Sarah Morgensen <iskarian <at> mgsn.dev>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (gnu packages zig)
+  #:use-module (guix packages)
+  #:use-module (guix git-download)
+  #:use-module ((guix licenses) #:prefix license:)
+  #:use-module (guix build-system cmake)
+  #:use-module (gnu packages)
+  #:use-module (gnu packages llvm))
+
+(define-public zig
+  (package
+    (name "zig")
+    (version "0.8.1")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/ziglang/zig.git")
+             (commit version)))
+       (file-name (git-file-name name version))
+       (sha256
+        (base32 "147qx7xgj0r353wh5ragzn6kmm1vrf31i8038z3zqwjnqqgqxi6c"))
+       (patches
+        (search-patches
+         "zig-disable-libc-note-test.patch"
+         "zig-use-system-paths.patch"))))
+    (build-system cmake-build-system)
+    (inputs
+     `(("clang" ,clang-12) ; Clang propagates llvm.
+       ("lld" ,lld-12)))
+    ;; Zig compiles fine with GCC, but also needs native LLVM libraries.
+    (native-inputs
+     `(("llvm" ,llvm-12)))
+    (arguments
+     `(#:configure-flags
+       (list ,@(if (%current-target-system)
+                   (string-append "-DZIG_TARGET_TRIPLE="
+                                  (%current-target-system))
+                   '()))
+       #:out-of-source? #f ; for tests
+       #:phases
+       (modify-phases %standard-phases
+         (add-after 'configure 'set-cache-dir
+           (lambda _
+             ;; Set cache dir, otherwise Zig looks for `$HOME/.cache'.
+             (setenv "ZIG_GLOBAL_CACHE_DIR"
+                     (string-append (getcwd) "/zig-cache"))))
+         (delete 'check)
+         (add-after 'install 'check
+           (lambda* (#:key outputs tests? #:allow-other-keys)
+             (when tests?
+               (invoke (string-append (assoc-ref outputs "out") "/bin/zig")
+                       ;; Testing the standard library takes >7.5GB RAM, and
+                       ;; will fail if it is OOM-killed.  The 'test-toolchain'
+                       ;; target skips standard library and doc tests.
+                       "build" "test-toolchain"
+                       ;; Stage 2 is experimental, not what we run with `zig',
+                       ;; and stage 2 tests require a lot of RAM.
+                       "-Dskip-stage2-tests"
+                       ;; Non-native tests try to link and execute non-native
+                       ;; binaries.
+                       "-Dskip-non-native")))))))
+    (native-search-paths
+     (list
+      (search-path-specification
+       (variable "C_INCLUDE_PATH")
+       (files '("include")))
+      (search-path-specification
+       (variable "CPLUS_INCLUDE_PATH")
+       (files '("include/c++" "include")))
+      (search-path-specification
+       (variable "LIBRARY_PATH")
+       (files '("lib" "lib64")))))
+    (synopsis "General purpose programming language and toolchain")
+    (description "Zig is a general-purpose programming language and
+toolchain.  Among other features it provides
+@itemize
+@item an Optional type instead of null pointers,
+@item manual memory management,
+@item generic data structures and functions,
+@item compile-time reflection and compile-time code execution,
+@item integration with C using zig as a C compiler, and
+@item concurrency via async functions.
+@end itemize")
+    (home-page "https://github.com/ziglang/zig")
+    (license license:expat)))
-- 
2.33.0






Information forwarded to guix-patches <at> gnu.org:
bug#47006; Package guix-patches. (Sun, 31 Oct 2021 08:08:02 GMT) Full text and rfc822 format available.

Message #87 received at 47006 <at> debbugs.gnu.org (full text, mbox):

From: Liliana Marie Prikler <liliana.prikler <at> gmail.com>
To: Sarah Morgensen <iskarian <at> mgsn.dev>
Cc: 47006 <at> debbugs.gnu.org,
 András Vöröskői <voroskoi <at> gmail.com>,
 50449 <at> debbugs.gnu.org, maximedevos <at> telenet.be, efraim <at> flashner.co.il
Subject: Re: [PATCH v5] gnu: Add zig.
Date: Sun, 31 Oct 2021 09:06:59 +0100
I've now pushed this with the following change:

Am Donnerstag, den 09.09.2021, 15:32 +0200 schrieb Liliana Prikler:
> +       ("lld" ,lld-12)))
lld is lld.

Thanks, everyone, and enjoy your zig.





bug closed, send any further explanations to 47006 <at> debbugs.gnu.org and Leo Prikler <leo.prikler <at> student.tugraz.at> Request was from Liliana Marie Prikler <liliana.prikler <at> gmail.com> to control <at> debbugs.gnu.org. (Sun, 31 Oct 2021 08:21:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 28 Nov 2021 12:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 141 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.