From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id EBdsJkGETWGeEwEAgWs5BA (envelope-from ) for ; Fri, 24 Sep 2021 09:54:41 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id GFweIkGETWELPwAAB5/wlQ (envelope-from ) for ; Fri, 24 Sep 2021 07:54:41 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 4ADBE312B5 for ; Fri, 24 Sep 2021 09:54:41 +0200 (CEST) Received: from localhost ([::1]:48696 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mTg2a-0007bU-Di for larch@yhetil.org; Fri, 24 Sep 2021 03:54:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48286) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mTftH-0006fV-CA for guix-patches@gnu.org; Fri, 24 Sep 2021 03:45:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:45106) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mTftH-0000fX-37 for guix-patches@gnu.org; Fri, 24 Sep 2021 03:45:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mTftH-0005Bi-1Q for guix-patches@gnu.org; Fri, 24 Sep 2021 03:45:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#50449] [PATCH v5] gnu: Add zig. Resent-From: Liliana Prikler Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 24 Sep 2021 07:45:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50449 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Sarah Morgensen Cc: 47006@debbugs.gnu.org, =?UTF-8?Q?Andr=C3=A1s_?= =?UTF-8?Q?V=C3=B6r=C3=B6sk=C5=91i?= , 50449@debbugs.gnu.org, maximedevos@telenet.be, efraim@flashner.co.il Received: via spool by 50449-submit@debbugs.gnu.org id=B50449.163246946419850 (code B ref 50449); Fri, 24 Sep 2021 07:45:02 +0000 Received: (at 50449) by debbugs.gnu.org; 24 Sep 2021 07:44:24 +0000 Received: from localhost ([127.0.0.1]:56648 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mTfsd-0005A4-JR for submit@debbugs.gnu.org; Fri, 24 Sep 2021 03:44:24 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:37468) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mTfsb-00059l-Ml; Fri, 24 Sep 2021 03:44:22 -0400 Received: by mail-wr1-f68.google.com with SMTP id t8so24568260wrq.4; Fri, 24 Sep 2021 00:44:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:references:from:date:subject:to:cc :content-transfer-encoding:message-id:mime-version; bh=dmKkhf8yDjYxIiGtajWAczR1wL2ouID7J6hvR9Vzdyg=; b=NunEyT+Ssqvoz1PzBogBR2KsT2vgaVoGT5jk98YxSowPRhU51h4JYCy1cqix7FKxJE Ht57+jMD5rVJUwq7LRwsdcfpe6AupyRV8QRa7w9E0r0fHPzsbqbDfdWGFsm56gf31joB E1/prqGDNYhX7S8uOGit0a5AdwuQwRzpKvMydd8LY8rAlT9ee0IDyQKxyHNXSWYJHlJd 7nOrVh/Zw/BGOCOBHIUmyhoZl/5VhVk00MtZFyVog9rKOfhRbwcc6a3bBAbgobH4/B08 LaJkP64OHMIH5aeD9w/Cdn22e8sl+kkS/L9w/21Ze+OGZSQKOQVmKyf7Iy7Kbwtzr5wa 8Qug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:in-reply-to:references:from:date:subject:to:cc :content-transfer-encoding:message-id:mime-version; bh=dmKkhf8yDjYxIiGtajWAczR1wL2ouID7J6hvR9Vzdyg=; b=RIf7hn8nJvnj8gFpgSBNVlxTp/WGGQejRcbJIBJA0QdXxeE7ea3e5YiENo0hYXmYPe uyON5NmRSFfMLk4uaWl4gTrIWk5AVpBiVNEiBi/a4E7KIQv0L9FQ62tJQcQbgGekxks3 xo2f6Q2wBPiM0bWqHrQzssq5YS3cabJhozELUwhR4+g+3zWfT3XHTLa92EU9lPKdmshA 3j88ZjzZcln3Myu3H5H5lcEayIAfzkB+sg4o4zXiYHzOJUjnGlr5QEkX9U2onnsn8VBU J/p7eOiyeXewuLk5qcXUuYSzieFjAZx/iJW37kTz3glYc3pNfbW8kiR28teMJ6AyNVLh 4vtQ== X-Gm-Message-State: AOAM533sG1yWaY/O9Fd9CTVV/kw3Kf9PVhjAmswRkukne3cGjsuRpG1z 06KG8mImXa4jAyCoMEFEcNU= X-Google-Smtp-Source: ABdhPJyD23HOqp7HUN/bo16Z6j0fx6PkbsHnorIielFza2CZ0fd/vKFoZH1cfolj84BfTg7FRqfhUg== X-Received: by 2002:a05:600c:21c8:: with SMTP id x8mr528287wmj.163.1632469454693; Fri, 24 Sep 2021 00:44:14 -0700 (PDT) Received: from nijino.fritz.box (85-127-52-93.dsl.dynamic.surfer.at. [85.127.52.93]) by smtp.gmail.com with ESMTPSA id q7sm7896897wrc.55.2021.09.24.00.44.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Sep 2021 00:44:14 -0700 (PDT) In-Reply-To: <867df6kesn.fsf@mgsn.dev> References: <867df6kesn.fsf@mgsn.dev> From: Liliana Prikler Date: Thu, 9 Sep 2021 15:32:22 +0200 Content-Transfer-Encoding: 8bit Message-ID: <5ab728b993bf511df7d71cb6781fc10c58aaff6d.camel@gmail.com> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -4.00 Authentication-Results: aspmx1.migadu.com; none X-Migadu-Queue-Id: 4ADBE312B5 X-Spam-Score: -4.00 X-Migadu-Scanner: scn1.migadu.com X-TUID: h2JpDJWLzepY * 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 +;;; Copyright © 2021 Sarah Morgensen +;;; +;;; 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 . + +(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