From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id SAsbKKeFPWG/uwAAgWs5BA (envelope-from ) for ; Sun, 12 Sep 2021 06:44:23 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id yNHJI6eFPWEuWAAA1q6Kng (envelope-from ) for ; Sun, 12 Sep 2021 04:44:23 +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 7C0473100 for ; Sun, 12 Sep 2021 06:44:22 +0200 (CEST) Received: from localhost ([::1]:57648 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mPHLo-0000X3-UN for larch@yhetil.org; Sun, 12 Sep 2021 00:44:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45334) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mPHLW-0000Wl-UZ for guix-patches@gnu.org; Sun, 12 Sep 2021 00:44:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:58540) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mPHLW-0005nj-MF for guix-patches@gnu.org; Sun, 12 Sep 2021 00:44:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mPHLW-0007yc-Er for guix-patches@gnu.org; Sun, 12 Sep 2021 00:44:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#47006] [WIP PATCH v2 2/2] gnu: Add zig. Resent-From: Sarah Morgensen Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 12 Sep 2021 04:44:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47006 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Liliana Marie Prikler Cc: 47006@debbugs.gnu.org, =?UTF-8?Q?Andr=C3=A1s_?= =?UTF-8?Q?V=C3=B6r=C3=B6sk=C5=91i?= , maximedevos@telenet.be, efraim@flashner.co.il Received: via spool by 47006-submit@debbugs.gnu.org id=B47006.163142179430584 (code B ref 47006); Sun, 12 Sep 2021 04:44:02 +0000 Received: (at 47006) by debbugs.gnu.org; 12 Sep 2021 04:43:14 +0000 Received: from localhost ([127.0.0.1]:41853 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mPHKj-0007xD-6Z for submit@debbugs.gnu.org; Sun, 12 Sep 2021 00:43:14 -0400 Received: from out1.migadu.com ([91.121.223.63]:18727) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mPHKf-0007x2-5F for 47006@debbugs.gnu.org; Sun, 12 Sep 2021 00:43:11 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mgsn.dev; s=key1; t=1631421787; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=OhiR6er5vLSpJfPGHedAmzdgZ2NOCkHFBQRwqiTUhW4=; b=J6+cf21ZBE52oWss5Uuny1HnODvvpwqWJkLCCMyIl59WiAMKCCvbl0XTvLf4km3ht6CIto tp9zcF7M9wWecY5cOHInfJSt4rhZMNIXT3NssshUdB1H+LpPPV1XY77xI5p0lwVNoCFcg0 TVACHLptde2BhSqWPm2SvOBYs9LikbM= From: Sarah Morgensen References: <0f6c5b692df8d06a0d7adddc9e5abf93894a366f.1631226695.git.liliana.prikler@gmail.com> <86wnnmnceg.fsf@mgsn.dev> Date: Sat, 11 Sep 2021 21:42:53 -0700 In-Reply-To: (Liliana Marie Prikler's message of "Sat, 11 Sep 2021 22:01:31 +0200 (7 hours, 44 minutes, 50 seconds ago)") Message-ID: <865yv6mmk2.fsf@mgsn.dev> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1631421863; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:resent-cc:resent-from:resent-sender: resent-message-id:in-reply-to:in-reply-to:references:references: list-id:list-help:list-unsubscribe:list-subscribe:list-post: dkim-signature; bh=OhiR6er5vLSpJfPGHedAmzdgZ2NOCkHFBQRwqiTUhW4=; b=MiRj8t1J3QYrOheS7cMnsVAZlrGzocpCeZGSNfF799LaYob8+wJYbF4oawp0NhQTEAeNCy yJ/qpojcN3UYUJkhiokqiR5XTP3T5xIISkk6Yd11U7HspwHrHnzJefTY9MWQodgem4EHih hY2tUL6jCc5UeSwCn6yOAe601HaHaqaY3slIDeFU/nTPxhPe0OoYn6r1bs8J67/dDKSysO kMC+Qe+mSTz7qUMLwkSP9/D5LKKR/2T6/odc8h/QLnDwsBL9e4+GeSP5sgB0WZRSI55GlC Uwz0wZmbwMTsI9XrxOTewut/hESiNmQFO2A0OK5C/qPbaR3yWKhY4r2CZjtHpA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1631421863; a=rsa-sha256; cv=none; b=juDUa7hlNRhgtLDDna1TFC8uHpl9jsqKWjinyWK/VGX4U8Ug5m0UWrzerjW0rcQHy0vrJS aq8tNixtuN099cIgIWOwjsBl0Hfx1a+1WnCW496eysi92Sbz6hVZtaLDP/zkcGTTwPJkOm MB5xqXGSOkKdF/iJCbPyDeLytJ70/SEH1NqhQ0Gih4LnUuX01DAjslJzhcPxs/yIc5a4NC mvabcX8FHOJOAfuMioEQL7jHtcVtj5ZfCb4g4uPIXvaTbAbJy8pdVaUi3uqjXD5VTlLCMS m3FflipnG0cr0PdfFiCtyj2Wk3dcMhu/rrEFna3NEwGaGGBgP3PTJfhh/rj/lw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=mgsn.dev header.s=key1 header.b=J6+cf21Z; dmarc=fail reason="SPF not aligned (relaxed)" header.from=mgsn.dev (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: 0.19 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=mgsn.dev header.s=key1 header.b=J6+cf21Z; dmarc=fail reason="SPF not aligned (relaxed)" header.from=mgsn.dev (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: 7C0473100 X-Spam-Score: 0.19 X-Migadu-Scanner: scn0.migadu.com X-TUID: HznTjCTvH02D --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi, I finally got a chance to run some tests. I've attached a patch below that works. As Andr=C3=A1s pointed out, Andr=C3=A1s V=C3=B6r=C3=B6sk=C5=91i 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=20 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. 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 --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: inline; filename=v3-0002-gnu-Add-zig.patch Content-Transfer-Encoding: quoted-printable Content-Description: [WIP PATCH v3 2/2] gnu: Add zig. >From 06ed65a6f49c290bbf1b773da8874353344a5b55 Mon Sep 17 00:00:00 2001 Message-Id: <06ed65a6f49c290bbf1b773da8874353344a5b55.1631421568.git.iskari= an@mgsn.dev> In-Reply-To: References: From: Liliana Prikler 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.pat= ch 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 =3D \ %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 =3D \ %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 =20 diff --git a/gnu/packages/patches/zig-disable-MIPS-tests.patch b/gnu/packag= es/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 is= sue +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 =3D blk: { + // .link_libc =3D true, + //}, +=20 +- TestTarget{ +- .target =3D .{ +- .cpu_arch =3D .mips, +- .os_tag =3D .linux, +- .abi =3D .none, +- }, +- }, +- +- TestTarget{ +- .target =3D .{ +- .cpu_arch =3D .mips, +- .os_tag =3D .linux, +- .abi =3D .musl, +- }, +- .link_libc =3D true, +- }, ++ // TestTarget{ ++ // .target =3D .{ ++ // .cpu_arch =3D .mips, ++ // .os_tag =3D .linux, ++ // .abi =3D .none, ++ // }, ++ // }, ++ ++ // TestTarget{ ++ // .target =3D .{ ++ // .cpu_arch =3D .mips, ++ // .os_tag =3D .linux, ++ // .abi =3D .musl, ++ // }, ++ // .link_libc =3D true, ++ // }, +=20 + // https://github.com/ziglang/zig/issues/4927 + //TestTarget{ +@@ -180,22 +180,22 @@ const test_targets =3D blk: { + // .link_libc =3D true, + //}, +=20 +- TestTarget{ +- .target =3D .{ +- .cpu_arch =3D .mipsel, +- .os_tag =3D .linux, +- .abi =3D .none, +- }, +- }, +- +- TestTarget{ +- .target =3D .{ +- .cpu_arch =3D .mipsel, +- .os_tag =3D .linux, +- .abi =3D .musl, +- }, +- .link_libc =3D true, +- }, ++ // TestTarget{ ++ // .target =3D .{ ++ // .cpu_arch =3D .mipsel, ++ // .os_tag =3D .linux, ++ // .abi =3D .none, ++ // }, ++ // }, ++ ++ // TestTarget{ ++ // .target =3D .{ ++ // .cpu_arch =3D .mipsel, ++ // .os_tag =3D .linux, ++ // .abi =3D .musl, ++ // }, ++ // .link_libc =3D true, ++ // }, +=20 + // https://github.com/ziglang/zig/issues/4927 + //TestTarget{ diff --git a/gnu/packages/patches/zig-disable-libc-note-test.patch b/gnu/pa= ckages/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 sp= ecified in the build command", + }); +=20 +- cases.addTest("libc headers note", +- \\const c =3D @cImport(@cInclude("stdio.h")); +- \\export fn entry() void { +- \\ _ =3D 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 =3D @cImport(@cInclude("stdio.h")); ++// \\export fn entry() void { ++// \\ _ =3D c.printf("hello, world!\n"); ++// \\} ++// , &[_][]const u8{ ++// "tmp.zig:1:11: error: C import failed", ++// "tmp.zig:1:11: note: libc headers not available; compilatio= n does not link against libc", ++// }); + } +=20 + cases.addTest("comptime vector overflow shows the index", diff --git a/gnu/packages/patches/zig-fix-cross-native-execution.patch b/gn= u/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(); +=20 + if (test_exec_args.len =3D=3D 0) { +- if (!std.Target.current.canExecBinariesOf(target)) { ++ const can_run =3D blk: { ++ if (!std.Target.current.canExecBinariesOf(target.target)) b= reak :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 =3D> { + warn("created {s} but skipping execution because it i= s non-native", .{exe_path}); diff --git a/gnu/packages/patches/zig-use-explicit-paths.patch b/gnu/packag= es/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 environme= nt +variables can be used as search paths in Guix. + +Index: zig-0.8.1/lib/std/zig/system.zig +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +--- 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 =3D struct { + }; + errdefer self.deinit(); +=20 +- var is_nix =3D false; +- if (process.getEnvVarOwned(allocator, "NIX_CFLAGS_COMPILE")) |nix= _cflags_compile| { +- defer allocator.free(nix_cflags_compile); +- +- is_nix =3D true; +- var it =3D mem.tokenize(nix_cflags_compile, " "); ++ // TODO: Support cross-compile paths? ++ if (process.getEnvVarOwned(allocator, "ZIG_INCLUDE_DIRS")) |zig_i= nclude_dirs| { ++ defer allocator.free(zig_include_dirs); ++ var it =3D mem.tokenize(zig_include_dirs, ":"); + while (true) { +- const word =3D it.next() orelse break; +- if (mem.eql(u8, word, "-isystem")) { +- const include_path =3D it.next() orelse { +- try self.addWarning("Expected argument after -isy= stem in NIX_CFLAGS_COMPILE"); +- break; +- }; +- try self.addIncludeDir(include_path); +- } else { +- if (mem.startsWith(u8, word, "-frandom-seed=3D")) { +- continue; +- } +- try self.addWarningFmt("Unrecognized C flag from NIX_= CFLAGS_COMPILE: {s}", .{word}); +- } ++ const dir =3D it.next() orelse break; ++ try self.addIncludeDir(dir); + } + } else |err| switch (err) { + error.InvalidUtf8 =3D> {}, + error.EnvironmentVariableNotFound =3D> {}, + error.OutOfMemory =3D> |e| return e, + } +- if (process.getEnvVarOwned(allocator, "NIX_LDFLAGS")) |nix_ldflag= s| { +- defer allocator.free(nix_ldflags); +=20 +- is_nix =3D true; +- var it =3D mem.tokenize(nix_ldflags, " "); ++ if (process.getEnvVarOwned(allocator, "ZIG_LIB_DIRS")) |zig_lib_d= irs| { ++ defer allocator.free(zig_lib_dirs); ++ var it =3D mem.tokenize(zig_lib_dirs, ":"); + while (true) { +- const word =3D it.next() orelse break; +- if (mem.eql(u8, word, "-rpath")) { +- const rpath =3D it.next() orelse { +- try self.addWarning("Expected argument after -rpa= th in NIX_LDFLAGS"); +- break; +- }; +- try self.addRPath(rpath); +- } else if (word.len > 2 and word[0] =3D=3D '-' and word[1= ] =3D=3D 'L') { +- const lib_path =3D word[2..]; +- try self.addLibDir(lib_path); +- } else { +- try self.addWarningFmt("Unrecognized C flag from NIX_= LDFLAGS: {s}", .{word}); +- break; +- } ++ const dir =3D it.next() orelse break; ++ try self.addLibDir(dir); + } + } else |err| switch (err) { + error.InvalidUtf8 =3D> {}, + error.EnvironmentVariableNotFound =3D> {}, + error.OutOfMemory =3D> |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 !=3D .windows) { +- const triple =3D try native_target.linuxTriple(allocator); +- const qual =3D 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 o= n some systems. audit needed. +=20 +- 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 =3D mem.tokenize(zig_framework_dirs, ":"); ++ while (true) { ++ const dir =3D it.next() orelse break; ++ try self.addFrameworkDir(dir); ++ } ++ } else |err| switch (err) { ++ error.InvalidUtf8 =3D> {}, ++ error.EnvironmentVariableNotFound =3D> {}, ++ error.OutOfMemory =3D> |e| return e, + } +=20 + 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 =C2=A9 2021 Liliana Prikler +;;; Copyright =C2=A9 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" + ;; 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=3D" + (%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, a= nd + ;; will fail if it is OOM-killed. The 'test-toolch= ain' + ;; target skips standard library and doc tests. + "build" "test-toolchain" + ;; Stage 2 is experimental, not what we run with `z= ig', + ;; 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))) --=20 2.33.0 --=-=-=--