blade-formatter: 1.42.0 -> 1.42.1 (#376873)
[NixPkgs.git] / pkgs / development / compilers / terra / default.nix
blob0a455d45ce0fc2e4fc5c856645702e891b3962ac
2   lib,
3   stdenv,
4   fetchFromGitHub,
5   llvmPackages_16,
6   ncurses,
7   cmake,
8   libxml2,
9   symlinkJoin,
10   cudaPackages,
11   enableCUDA ? false,
12   libffi,
13   libobjc,
14   libpfm,
15   Cocoa,
16   Foundation,
19 let
20   luajitRev = "50936d784474747b4569d988767f1b5bab8bb6d0";
21   luajitBase = "LuaJIT-${luajitRev}";
22   luajitArchive = "${luajitBase}.tar.gz";
23   luajitSrc = fetchFromGitHub {
24     owner = "LuaJIT";
25     repo = "LuaJIT";
26     rev = luajitRev;
27     sha256 = "1g87pl014b5v6z2nnhiwn3wf405skawszfr5wdzyfbx00j3kgxd0";
28   };
30   llvmPackages = llvmPackages_16;
31   llvmMerged = symlinkJoin {
32     name = "llvmClangMerged";
33     paths = with llvmPackages; [
34       llvm.out
35       llvm.dev
36       llvm.lib
37       clang-unwrapped.out
38       clang-unwrapped.dev
39       clang-unwrapped.lib
40     ];
41   };
43   cuda = cudaPackages.cudatoolkit_11;
45   clangVersion = llvmPackages.clang-unwrapped.version;
48 stdenv.mkDerivation rec {
49   pname = "terra";
50   version = "1.1.0";
52   src = fetchFromGitHub {
53     owner = "terralang";
54     repo = "terra";
55     rev = "release-${version}";
56     sha256 = "0v9vpxcp9ybwnfljskqn41vjq7c0srdfv7qs890a6480pnk4kavd";
57   };
59   nativeBuildInputs = [ cmake ];
60   buildInputs =
61     [
62       llvmMerged
63       ncurses
64       libffi
65       libxml2
66     ]
67     ++ lib.optionals enableCUDA [ cuda ]
68     ++ lib.optional (!stdenv.hostPlatform.isDarwin) libpfm
69     ++ lib.optionals stdenv.hostPlatform.isDarwin [
70       libobjc
71       Cocoa
72       Foundation
73     ];
75   cmakeFlags =
76     let
77       resourceDir =
78         "${llvmMerged}/lib/clang/"
79         + (if lib.versionOlder clangVersion "16" then clangVersion else lib.versions.major clangVersion);
80     in
81     [
82       "-DHAS_TERRA_VERSION=0"
83       "-DTERRA_VERSION=${version}"
84       "-DTERRA_LUA=luajit"
85       "-DTERRA_SKIP_LUA_DOWNLOAD=ON"
86       "-DCLANG_RESOURCE_DIR=${resourceDir}"
87     ]
88     ++ lib.optional enableCUDA "-DTERRA_ENABLE_CUDA=ON";
90   doCheck = true;
91   hardeningDisable = [ "fortify" ];
92   outputs = [
93     "bin"
94     "dev"
95     "out"
96     "static"
97   ];
99   patches = [ ./nix-cflags.patch ];
101   postPatch = ''
102     substituteInPlace src/terralib.lua \
103       --subst-var-by NIX_LIBC_INCLUDE ${lib.getDev stdenv.cc.libc}/include
104   '';
106   preConfigure = ''
107     mkdir -p build
108     ln -s ${luajitSrc} build/${luajitBase}
109     tar --mode="a+rwX" -chzf build/${luajitArchive} -C build ${luajitBase}
110     rm build/${luajitBase}
111   '';
113   installPhase = ''
114     install -Dm755 -t $bin/bin bin/terra
115     install -Dm755 -t $out/lib lib/terra${stdenv.hostPlatform.extensions.sharedLibrary}
116     install -Dm644 -t $static/lib lib/libterra_s.a
118     mkdir -pv $dev/include
119     cp -rv include/terra $dev/include
120   '';
122   meta = with lib; {
123     description = "Low-level counterpart to Lua";
124     homepage = "https://terralang.org/";
125     platforms = platforms.all;
126     maintainers = with maintainers; [
127       jb55
128       seylerius
129       thoughtpolice
130       elliottslaughter
131     ];
132     license = licenses.mit;
133     # never built on aarch64-darwin since first introduction in nixpkgs
134     # Linux Aarch64 broken above LLVM11
135     # https://github.com/terralang/terra/issues/597
136     broken = stdenv.hostPlatform.isAarch64;
137   };