about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/compilers/codon/default.nix
blob: 70cd16327299d4ca8f189596e0efb258138b2094 (plain) (blame)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
{ cacert
, cmake
, fetchFromGitHub
, git
, lib
, lld
, ninja
, nix-update-script
, perl
, python3
, stdenv
}:

let
  version = "0.16.1";

  src = fetchFromGitHub {
    owner = "exaloop";
    repo = "codon";
    rev = "v${version}";
    hash = "sha256-s2GqiFcekXRts8BU5CSmTrkFZ9xLqq4A5MybhB1o1Gg=";
  };

  depsDir = "deps";

  codon-llvm = stdenv.mkDerivation {
    pname = "codon-llvm";
    version = "unstable-2022-09-23";

    src = fetchFromGitHub {
      owner = "exaloop";
      repo = "llvm-project";
      rev = "55b0b8fa1c9f9082b535628fc9fa6313280c0b9a";
      hash = "sha256-03SPQgNdrpR6/JZ5aR/ntoh/FnZvCjT/6bTAcZaFafw=";
    };

    nativeBuildInputs = [
      cmake
      git
      lld
      ninja
      python3
    ];

    cmakeFlags = [
      "-DLLVM_ENABLE_RTTI=ON"
      "-DLLVM_ENABLE_TERMINFO=OFF"
      "-DLLVM_ENABLE_ZLIB=OFF"
      "-DLLVM_INCLUDE_TESTS=OFF"
      "-DLLVM_TARGETS_TO_BUILD=all"
      "-DLLVM_USE_LINKER=lld"
      "-S ../llvm"
    ];
  };

  codon-deps = stdenv.mkDerivation {
    name = "codon-deps-${version}.tar.gz";

    inherit src;

    nativeBuildInputs = [
      cacert
      cmake
      git
      perl
      python3
    ];

    dontBuild = true;

    cmakeFlags = [
      "-DCPM_DOWNLOAD_ALL=ON"
      "-DCPM_SOURCE_CACHE=${depsDir}"
      "-DLLVM_DIR=${codon-llvm}/lib/cmake/llvm"
    ];

    installPhase = ''
      # Prune the `.git` directories
      find ${depsDir} -name .git -type d -prune -exec rm -rf {} \;;
      # Build a reproducible tar, per instructions at https://reproducible-builds.org/docs/archives/
      tar --owner=0 --group=0 --numeric-owner --format=gnu \
          --sort=name --mtime="@$SOURCE_DATE_EPOCH" \
          -czf $out \
            ${depsDir} \
            cmake \
            _deps/googletest-subbuild/googletest-populate-prefix/src/*.zip
    '';

    outputHash =
      if stdenv.hostPlatform.isDarwin then
        "sha256-KfemYV42xBAhsPbwTkzdc3GxCVHiWRbyUZORPWxx4vg="
      else
        "sha256-a1zGSpbMjfQBrcgW/aiIdKX8+uI3p/S9pgZjHe2HtWs=";

    outputHashAlgo = "sha256";
  };
in
stdenv.mkDerivation {
  pname = "codon";

  inherit src version;

  patches = [
    # Without the hash, CMake will try to replace the `.zip` file
    ./Add-a-hash-to-the-googletest-binary.patch
  ];

  nativeBuildInputs = [
    cmake
    git
    lld
    ninja
    perl
    python3
  ];

  postUnpack = ''
    mkdir -p $sourceRoot/build
    tar -xf ${codon-deps} -C $sourceRoot/build
  '';

  cmakeFlags = [
    "-DCPM_SOURCE_CACHE=${depsDir}"
    "-DLLVM_DIR=${codon-llvm}/lib/cmake/llvm"
    "-DLLVM_USE_LINKER=lld"
  ];

  postInstall = lib.optionalString stdenv.isDarwin ''
    ln -s $out/lib/codon/*.dylib $out/lib/
  '';

  passthru.updateScript = nix-update-script { };

  meta = {
    description = "A high-performance, zero-overhead, extensible Python compiler using LLVM";
    homepage = "https://docs.exaloop.io/codon";
    maintainers = [ lib.maintainers.paveloom ];
    license = lib.licenses.bsl11;
    platforms = lib.platforms.all;
  };
}