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

    nativeBuildInputs = [ makeWrapper ];

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

    inherit zig;
  }
  ''
    mkdir -p $out/bin
    for tool in ar objcopy ranlib 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/ld.lld $out/bin/ld
  ''