-
Notifications
You must be signed in to change notification settings - Fork 3
/
zig-overlay.nix
65 lines (63 loc) · 2.3 KB
/
zig-overlay.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
# provided by the flake
{
# version. can be a release version or a date.
version ? "0.10.0",
# whether the missing ARM header should be downloaded and added to libc headers
patchArmHeader ? true, zig-binaries }:
final: prev:
let
base = zig-binaries.packages.${prev.system}.${version};
zig = base.overrideAttrs (old:
let
macos_sysroot = if prev.stdenv.isDarwin then
"${final.darwin.apple_sdk.MacOSX-SDK}"
else
"";
in {
cc_impl = ''
#!${final.bash}/bin/bash
ADDITIONAL_FLAGS=
if ! [ -z ''${ZIG_TARGET+x} ]; then
ADDITIONAL_FLAGS="$ADDITIONAL_FLAGS -target $ZIG_TARGET"
# don't add the macOS flags when cross-compiling
NIX_COREFOUNDATION_RPATH=
fi
if ! [ -z ''${NIX_COREFOUNDATION_RPATH+x} ]; then
ADDITIONAL_FLAGS="$ADDITIONAL_FLAGS -F$NIX_COREFOUNDATION_RPATH"
ADDITIONAL_FLAGS="$ADDITIONAL_FLAGS -I${macos_sysroot}/usr/include -L${macos_sysroot}/usr/lib -DTARGET_OS_OSX=1 -DTARGET_OS_IPHONE=0"
fi
export ZIG_LOCAL_CACHE_DIR=$TMPDIR/zig-cache
export ZIG_GLOBAL_CACHE_DIR=$ZIG_LOCAL_CACHE_DIR
${
builtins.placeholder "out"
}/bin/zig cc -gline-tables-only $ADDITIONAL_FLAGS $@
'';
installPhase = let
armFeatures = builtins.fetchurl {
url = "https://sourceware.org/git/?p=glibc.git;"
+ "a=blob_plain;f=sysdeps/arm/arm-features.h;"
+ "h=80a1e2272b5b4ee0976a410317341b5ee601b794;"
+ "hb=0281c7a7ec8f3f46d8e6f5f3d7fca548946dbfce";
name = "glibc-2.35_arm-features.h";
sha256 = "1g4yb51srrfbd4289yj0vrpzzp2rlxllxgz8q4a5zw1n654wzs5a";
};
in old.installPhase + ''
${if patchArmHeader then ''
cp ${armFeatures} $out/lib/libc/glibc/sysdeps/arm/arm-features.h
'' else
""}
printenv cc_impl >$out/bin/cc
chmod a+x $out/bin/cc
'';
# mapping from NixOS system names to what zig expects
passthru.systemName = {
"aarch64-darwin" = "aarch64-macos";
"armv7l-hf-multiplatform" = "arm-linux-gnueabihf";
"x86_64-windows" = "x86_64-windows-gnu";
};
});
in {
inherit zig;
zigStdenv = prev.overrideCC prev.clangStdenv zig;
buildZig = final.callPackage (import ./buildZig.nix) { };
}