-
Notifications
You must be signed in to change notification settings - Fork 0
/
zig.nix
92 lines (78 loc) · 2.26 KB
/
zig.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
{ lib
, stdenv
, fetchFromGitHub
, cmake
, coreutils
, llvmPackages_19
, libgcc
, libxml2
, zlib
, release
}:
let
llvmPackages = llvmPackages_19;
in
stdenv.mkDerivation (finalAttrs: {
pname = "zig";
inherit (release) version;
src = fetchFromGitHub {
owner = "ziglang";
repo = "zig";
rev = release.src.rev;
hash = release.src.hash;
};
# Zig's build looks at /usr/bin/env to detect the dynamic linker (ld-linux).
# This path doesn't exist in the Nix build environment.
postPatch = ''
substituteInPlace lib/std/zig/system.zig \
--replace "/usr/bin/env" "${coreutils}/bin/env"
'';
nativeBuildInputs = [
cmake
];
buildInputs = [
libgcc.lib # Work around https://github.com/ziglang/zig/issues/18612 (libstdc++.so not found in rpath)
libxml2
zlib
] ++ (with llvmPackages; [
libclang
lld
llvm
]);
cmakeFlags = [
# This ensures that the resulting zig binary
# - runs on all CPUs with the same arch (like x86-64)
# - is identical when built on different systems
"-DZIG_TARGET_MCPU=baseline"
# To optimize for recent x86_64 CPUs, you can set the following:
# "-DZIG_TARGET_MCPU=x86_64_v4"
## Other useful options
#
# Statically link LLVM
# This increases the zig binary size, but reduces the total derivation closure size.
# "-DZIG_STATIC_LLVM=ON"
];
# Silence some warnings when building stage2
# ("_FORTIFY_SOURCE requires compiling with optimization").
# This setting has no effect on the final Zig binary (stage3).
hardeningDisable = [ "all" ];
preConfigure = ''
export ZIG_GLOBAL_CACHE_DIR=$TMP/zig-cache;
'';
doInstallCheck = true;
installCheckPhase = ''
runHook preInstallCheck
srcDir=$TMP/$sourceRoot
$out/bin/zig test --cache-dir "$TMP/zig-test-cache" -I $srcDir/test $srcDir/test/behavior.zig
runHook postInstallCheck
'';
passthru = { inherit llvmPackages; };
meta = {
description = "General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software";
homepage = "https://ziglang.org/";
changelog = "https://ziglang.org/download/${finalAttrs.version}/release-notes.html";
license = lib.licenses.mit;
mainProgram = "zig";
platforms = lib.platforms.unix;
};
})