2021-06-28 23:13:55 +00:00
|
|
|
{ lib, stdenv, fetchFromGitHub, llvmPackages, ncurses, cmake, libxml2
|
2022-08-21 13:32:41 +00:00
|
|
|
, symlinkJoin, breakpointHook, cudaPackages, enableCUDA ? false
|
|
|
|
, libobjc, Cocoa, Foundation
|
|
|
|
}:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
let
|
2022-08-21 13:32:41 +00:00
|
|
|
luajitRev = "50936d784474747b4569d988767f1b5bab8bb6d0";
|
2021-06-28 23:13:55 +00:00
|
|
|
luajitBase = "LuaJIT-${luajitRev}";
|
|
|
|
luajitArchive = "${luajitBase}.tar.gz";
|
|
|
|
luajitSrc = fetchFromGitHub {
|
|
|
|
owner = "LuaJIT";
|
|
|
|
repo = "LuaJIT";
|
|
|
|
rev = luajitRev;
|
2022-08-21 13:32:41 +00:00
|
|
|
sha256 = "1g87pl014b5v6z2nnhiwn3wf405skawszfr5wdzyfbx00j3kgxd0";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2021-06-28 23:13:55 +00:00
|
|
|
|
|
|
|
llvmMerged = symlinkJoin {
|
|
|
|
name = "llvmClangMerged";
|
|
|
|
paths = with llvmPackages; [
|
|
|
|
llvm.out
|
|
|
|
llvm.dev
|
|
|
|
llvm.lib
|
|
|
|
clang-unwrapped.out
|
|
|
|
clang-unwrapped.dev
|
|
|
|
clang-unwrapped.lib
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
cuda = cudaPackages.cudatoolkit_11;
|
|
|
|
|
|
|
|
clangVersion = llvmPackages.clang-unwrapped.version;
|
|
|
|
|
|
|
|
in stdenv.mkDerivation rec {
|
2020-04-24 23:36:52 +00:00
|
|
|
pname = "terra";
|
2022-09-09 14:08:57 +00:00
|
|
|
version = "1.0.6";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
2021-06-28 23:13:55 +00:00
|
|
|
owner = "terralang";
|
|
|
|
repo = "terra";
|
2022-07-14 12:49:19 +00:00
|
|
|
rev = "release-${version}";
|
2022-09-09 14:08:57 +00:00
|
|
|
sha256 = "1bs76ibzb469rlqs7slw8pm65csjq1nf0lqh6i9kcvbzavmdfds7";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2021-06-28 23:13:55 +00:00
|
|
|
nativeBuildInputs = [ cmake ];
|
2022-08-21 13:32:41 +00:00
|
|
|
buildInputs = [ llvmMerged ncurses libxml2 ]
|
|
|
|
++ lib.optionals enableCUDA [ cuda ]
|
|
|
|
++ lib.optionals stdenv.isDarwin [ libobjc Cocoa Foundation ];
|
2021-06-28 23:13:55 +00:00
|
|
|
|
|
|
|
cmakeFlags = [
|
|
|
|
"-DHAS_TERRA_VERSION=0"
|
|
|
|
"-DTERRA_VERSION=${version}"
|
|
|
|
"-DTERRA_LUA=luajit"
|
|
|
|
"-DCLANG_RESOURCE_DIR=${llvmMerged}/lib/clang/${clangVersion}"
|
|
|
|
] ++ lib.optional enableCUDA "-DTERRA_ENABLE_CUDA=ON";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
doCheck = true;
|
|
|
|
hardeningDisable = [ "fortify" ];
|
|
|
|
outputs = [ "bin" "dev" "out" "static" ];
|
|
|
|
|
|
|
|
patches = [ ./nix-cflags.patch ];
|
2021-06-28 23:13:55 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
postPatch = ''
|
2021-06-28 23:13:55 +00:00
|
|
|
sed -i '/file(DOWNLOAD "''${LUAJIT_URL}" "''${LUAJIT_TAR}")/d' \
|
|
|
|
cmake/Modules/GetLuaJIT.cmake
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
substituteInPlace src/terralib.lua \
|
2021-02-05 17:12:51 +00:00
|
|
|
--subst-var-by NIX_LIBC_INCLUDE ${lib.getDev stdenv.cc.libc}/include
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
2021-06-28 23:13:55 +00:00
|
|
|
preConfigure = ''
|
2020-04-24 23:36:52 +00:00
|
|
|
mkdir -p build
|
2021-06-28 23:13:55 +00:00
|
|
|
ln -s ${luajitSrc} build/${luajitBase}
|
|
|
|
tar --mode="a+rwX" -chzf build/${luajitArchive} -C build ${luajitBase}
|
|
|
|
rm build/${luajitBase}
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
2021-06-28 23:13:55 +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
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
mkdir -pv $dev/include
|
2021-06-28 23:13:55 +00:00
|
|
|
cp -rv include/terra $dev/include
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
meta = with lib; {
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "A low-level counterpart to Lua";
|
2021-08-05 21:33:18 +00:00
|
|
|
homepage = "https://terralang.org/";
|
2022-09-09 14:08:57 +00:00
|
|
|
platforms = platforms.all;
|
2022-06-16 17:23:12 +00:00
|
|
|
maintainers = with maintainers; [ jb55 seylerius thoughtpolice elliottslaughter ];
|
2021-06-28 23:13:55 +00:00
|
|
|
license = licenses.mit;
|
2022-12-17 10:02:37 +00:00
|
|
|
# never built on aarch64-darwin since first introduction in nixpkgs
|
|
|
|
broken = stdenv.isDarwin && stdenv.isAarch64;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|