2024-05-11 09:04:43 +00:00
|
|
|
{ lib, stdenv, fetchFromGitHub, llvmPackages_16, ncurses, cmake, libxml2
|
2024-07-31 23:59:21 +00:00
|
|
|
, symlinkJoin, cudaPackages, enableCUDA ? false
|
2024-01-24 19:46:21 +00:00
|
|
|
, libffi, libobjc, libpfm, Cocoa, Foundation
|
2022-08-21 01:10:19 +00:00
|
|
|
}:
|
2016-06-14 23:37:37 +00:00
|
|
|
|
|
|
|
let
|
2022-08-21 01:10:19 +00:00
|
|
|
luajitRev = "50936d784474747b4569d988767f1b5bab8bb6d0";
|
2021-06-17 17:54:22 +00:00
|
|
|
luajitBase = "LuaJIT-${luajitRev}";
|
|
|
|
luajitArchive = "${luajitBase}.tar.gz";
|
|
|
|
luajitSrc = fetchFromGitHub {
|
|
|
|
owner = "LuaJIT";
|
|
|
|
repo = "LuaJIT";
|
|
|
|
rev = luajitRev;
|
2022-08-21 01:10:19 +00:00
|
|
|
sha256 = "1g87pl014b5v6z2nnhiwn3wf405skawszfr5wdzyfbx00j3kgxd0";
|
2016-06-14 23:37:37 +00:00
|
|
|
};
|
2021-06-13 08:15:16 +00:00
|
|
|
|
2024-05-11 09:04:43 +00:00
|
|
|
llvmPackages = llvmPackages_16;
|
2021-06-05 23:48:45 +00:00
|
|
|
llvmMerged = symlinkJoin {
|
|
|
|
name = "llvmClangMerged";
|
|
|
|
paths = with llvmPackages; [
|
|
|
|
llvm.out
|
|
|
|
llvm.dev
|
|
|
|
llvm.lib
|
|
|
|
clang-unwrapped.out
|
|
|
|
clang-unwrapped.dev
|
|
|
|
clang-unwrapped.lib
|
|
|
|
];
|
|
|
|
};
|
2021-06-13 08:15:16 +00:00
|
|
|
|
2021-06-06 02:11:02 +00:00
|
|
|
cuda = cudaPackages.cudatoolkit_11;
|
2021-06-13 08:15:16 +00:00
|
|
|
|
|
|
|
clangVersion = llvmPackages.clang-unwrapped.version;
|
|
|
|
|
2021-06-05 23:48:45 +00:00
|
|
|
in stdenv.mkDerivation rec {
|
2019-09-19 03:13:18 +00:00
|
|
|
pname = "terra";
|
2023-05-05 21:07:08 +00:00
|
|
|
version = "1.1.0";
|
2016-01-18 00:50:10 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
2021-06-05 23:48:45 +00:00
|
|
|
owner = "terralang";
|
|
|
|
repo = "terra";
|
2022-07-08 23:22:45 +00:00
|
|
|
rev = "release-${version}";
|
2023-05-05 21:07:08 +00:00
|
|
|
sha256 = "0v9vpxcp9ybwnfljskqn41vjq7c0srdfv7qs890a6480pnk4kavd";
|
2016-01-18 00:50:10 +00:00
|
|
|
};
|
|
|
|
|
2021-05-16 06:02:00 +00:00
|
|
|
nativeBuildInputs = [ cmake ];
|
2024-01-24 19:46:21 +00:00
|
|
|
buildInputs = [ llvmMerged ncurses libffi libxml2 ]
|
2022-08-21 01:10:19 +00:00
|
|
|
++ lib.optionals enableCUDA [ cuda ]
|
2024-01-24 19:46:21 +00:00
|
|
|
++ lib.optional (!stdenv.hostPlatform.isDarwin) libpfm
|
2022-08-21 01:10:19 +00:00
|
|
|
++ lib.optionals stdenv.hostPlatform.isDarwin [ libobjc Cocoa Foundation ];
|
2021-05-16 06:02:00 +00:00
|
|
|
|
2024-01-24 19:46:21 +00:00
|
|
|
cmakeFlags = let
|
|
|
|
resourceDir = "${llvmMerged}/lib/clang/" + (
|
|
|
|
if lib.versionOlder clangVersion "16"
|
|
|
|
then
|
|
|
|
clangVersion
|
|
|
|
else
|
|
|
|
lib.versions.major clangVersion
|
|
|
|
);
|
|
|
|
in [
|
2021-05-16 06:02:00 +00:00
|
|
|
"-DHAS_TERRA_VERSION=0"
|
2021-06-17 17:54:22 +00:00
|
|
|
"-DTERRA_VERSION=${version}"
|
2021-05-16 06:02:00 +00:00
|
|
|
"-DTERRA_LUA=luajit"
|
2023-05-05 21:07:08 +00:00
|
|
|
"-DTERRA_SKIP_LUA_DOWNLOAD=ON"
|
2024-01-24 19:46:21 +00:00
|
|
|
"-DCLANG_RESOURCE_DIR=${resourceDir}"
|
2021-06-06 02:11:02 +00:00
|
|
|
] ++ lib.optional enableCUDA "-DTERRA_ENABLE_CUDA=ON";
|
2019-09-19 03:13:18 +00:00
|
|
|
|
2019-09-19 05:26:48 +00:00
|
|
|
doCheck = true;
|
|
|
|
hardeningDisable = [ "fortify" ];
|
2016-08-29 00:30:01 +00:00
|
|
|
outputs = [ "bin" "dev" "out" "static" ];
|
2016-06-14 23:37:37 +00:00
|
|
|
|
2021-06-17 17:54:22 +00:00
|
|
|
patches = [ ./nix-cflags.patch ];
|
2021-06-05 23:48:45 +00:00
|
|
|
|
2016-06-14 23:37:37 +00:00
|
|
|
postPatch = ''
|
2019-09-19 05:26:48 +00:00
|
|
|
substituteInPlace src/terralib.lua \
|
2021-01-22 11:25:31 +00:00
|
|
|
--subst-var-by NIX_LIBC_INCLUDE ${lib.getDev stdenv.cc.libc}/include
|
2016-01-18 00:50:10 +00:00
|
|
|
'';
|
|
|
|
|
2021-05-16 06:02:00 +00:00
|
|
|
preConfigure = ''
|
2016-01-18 00:50:10 +00:00
|
|
|
mkdir -p build
|
2021-06-17 17:54:22 +00:00
|
|
|
ln -s ${luajitSrc} build/${luajitBase}
|
|
|
|
tar --mode="a+rwX" -chzf build/${luajitArchive} -C build ${luajitBase}
|
|
|
|
rm build/${luajitBase}
|
2016-01-18 00:50:10 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
2021-05-16 06:02:00 +00:00
|
|
|
install -Dm755 -t $bin/bin bin/terra
|
|
|
|
install -Dm755 -t $out/lib lib/terra${stdenv.hostPlatform.extensions.sharedLibrary}
|
|
|
|
install -Dm644 -t $static/lib lib/libterra_s.a
|
2016-06-14 23:37:37 +00:00
|
|
|
|
|
|
|
mkdir -pv $dev/include
|
2021-05-16 06:02:00 +00:00
|
|
|
cp -rv include/terra $dev/include
|
2019-04-27 13:47:19 +00:00
|
|
|
'';
|
2016-01-18 00:50:10 +00:00
|
|
|
|
2021-01-22 11:25:31 +00:00
|
|
|
meta = with lib; {
|
2016-01-18 00:50:10 +00:00
|
|
|
description = "Low-level counterpart to Lua";
|
2021-07-31 17:01:50 +00:00
|
|
|
homepage = "https://terralang.org/";
|
2022-09-08 04:31:12 +00:00
|
|
|
platforms = platforms.all;
|
2022-06-01 17:16:09 +00:00
|
|
|
maintainers = with maintainers; [ jb55 seylerius thoughtpolice elliottslaughter ];
|
2021-06-05 23:48:45 +00:00
|
|
|
license = licenses.mit;
|
2022-12-06 20:47:40 +00:00
|
|
|
# never built on aarch64-darwin since first introduction in nixpkgs
|
2024-01-24 19:46:21 +00:00
|
|
|
# Linux Aarch64 broken above LLVM11
|
|
|
|
# https://github.com/terralang/terra/issues/597
|
|
|
|
broken = stdenv.hostPlatform.isAarch64;
|
2016-01-18 00:50:10 +00:00
|
|
|
};
|
|
|
|
}
|