20 luajitRev = "50936d784474747b4569d988767f1b5bab8bb6d0";
21 luajitBase = "LuaJIT-${luajitRev}";
22 luajitArchive = "${luajitBase}.tar.gz";
23 luajitSrc = fetchFromGitHub {
27 sha256 = "1g87pl014b5v6z2nnhiwn3wf405skawszfr5wdzyfbx00j3kgxd0";
30 llvmPackages = llvmPackages_16;
31 llvmMerged = symlinkJoin {
32 name = "llvmClangMerged";
33 paths = with llvmPackages; [
43 cuda = cudaPackages.cudatoolkit_11;
45 clangVersion = llvmPackages.clang-unwrapped.version;
48 stdenv.mkDerivation rec {
52 src = fetchFromGitHub {
55 rev = "release-${version}";
56 sha256 = "0v9vpxcp9ybwnfljskqn41vjq7c0srdfv7qs890a6480pnk4kavd";
59 nativeBuildInputs = [ cmake ];
67 ++ lib.optionals enableCUDA [ cuda ]
68 ++ lib.optional (!stdenv.hostPlatform.isDarwin) libpfm
69 ++ lib.optionals stdenv.hostPlatform.isDarwin [
78 "${llvmMerged}/lib/clang/"
79 + (if lib.versionOlder clangVersion "16" then clangVersion else lib.versions.major clangVersion);
82 "-DHAS_TERRA_VERSION=0"
83 "-DTERRA_VERSION=${version}"
85 "-DTERRA_SKIP_LUA_DOWNLOAD=ON"
86 "-DCLANG_RESOURCE_DIR=${resourceDir}"
88 ++ lib.optional enableCUDA "-DTERRA_ENABLE_CUDA=ON";
91 hardeningDisable = [ "fortify" ];
99 patches = [ ./nix-cflags.patch ];
102 substituteInPlace src/terralib.lua \
103 --subst-var-by NIX_LIBC_INCLUDE ${lib.getDev stdenv.cc.libc}/include
108 ln -s ${luajitSrc} build/${luajitBase}
109 tar --mode="a+rwX" -chzf build/${luajitArchive} -C build ${luajitBase}
110 rm build/${luajitBase}
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
123 description = "Low-level counterpart to Lua";
124 homepage = "https://terralang.org/";
125 platforms = platforms.all;
126 maintainers = with maintainers; [
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;