summaryrefslogtreecommitdiffstats
path: root/pkgs/development/compilers/zig/cc.nix
blob: 1768d17542cd05dcc7e5e8f52a71bb3e861cd6ed (plain)
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
{
  lib,
  runCommand,
  zig,
  stdenv,
  makeWrapper,
}:
let
  targetPrefix = lib.optionalString (
    stdenv.hostPlatform != stdenv.targetPlatform
  ) "${stdenv.targetPlatform.config}-";
in
runCommand "zig-cc-${zig.version}"
  {
    pname = "zig-cc";
    inherit (zig) version;

    nativeBuildInputs = [ makeWrapper ];

    passthru = {
      isZig = true;
      inherit targetPrefix;
    };

    inherit zig;

    meta = zig.meta // {
      mainProgram = "${targetPrefix}clang";
    };
  }
  ''
    mkdir -p $out/bin
    for tool in cc c++ ld.lld; do
      makeWrapper "$zig/bin/zig" "$out/bin/$tool" \
        --add-flags "$tool" \
        --run "export ZIG_GLOBAL_CACHE_DIR=\$TMPDIR/zig-cache"
    done

    ln -s $out/bin/c++ $out/bin/clang++
    ln -s $out/bin/cc $out/bin/clang
    ln -s $out/bin/ld.lld $out/bin/ld
  ''