2021-09-18 10:52:07 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
|
|
|
, fetchFromGitHub
|
|
|
|
, buildPackages
|
2020-04-24 23:36:52 +00:00
|
|
|
, version
|
2022-12-28 21:21:41 +00:00
|
|
|
, src
|
2021-09-18 10:52:07 +00:00
|
|
|
, extraMeta ? { }
|
2020-04-24 23:36:52 +00:00
|
|
|
, callPackage
|
|
|
|
, self
|
2021-09-18 10:52:07 +00:00
|
|
|
, packageOverrides ? (final: prev: {})
|
2022-09-30 11:47:45 +00:00
|
|
|
, pkgsBuildBuild
|
|
|
|
, pkgsBuildHost
|
|
|
|
, pkgsBuildTarget
|
|
|
|
, pkgsHostHost
|
|
|
|
, pkgsTargetTarget
|
|
|
|
, passthruFun
|
2020-04-24 23:36:52 +00:00
|
|
|
, enableFFI ? true
|
|
|
|
, enableJIT ? true
|
|
|
|
, enableJITDebugModule ? enableJIT
|
2020-10-07 09:15:18 +00:00
|
|
|
, enableGC64 ? true
|
2020-04-24 23:36:52 +00:00
|
|
|
, enable52Compat ? false
|
|
|
|
, enableValgrindSupport ? false
|
|
|
|
, valgrind ? null
|
|
|
|
, enableGDBJITSupport ? false
|
|
|
|
, enableAPICheck ? false
|
|
|
|
, enableVMAssertions ? false
|
|
|
|
, useSystemMalloc ? false
|
2023-01-11 07:51:40 +00:00
|
|
|
# Upstream generates randomized string id's by default for security reasons
|
|
|
|
# https://github.com/LuaJIT/LuaJIT/issues/626. Deterministic string id's should
|
|
|
|
# never be needed for correctness (that should be fixed in the lua code),
|
|
|
|
# but may be helpful when you want to embed jit-compiled raw lua blobs in
|
|
|
|
# binaries that you want to be reproducible.
|
|
|
|
, deterministicStringIds ? false
|
2022-12-28 21:21:41 +00:00
|
|
|
, luaAttr ? "luajit_${lib.versions.major version}_${lib.versions.minor version}"
|
2022-09-30 11:47:45 +00:00
|
|
|
} @ inputs:
|
2020-04-24 23:36:52 +00:00
|
|
|
assert enableJITDebugModule -> enableJIT;
|
|
|
|
assert enableGDBJITSupport -> enableJIT;
|
|
|
|
assert enableValgrindSupport -> valgrind != null;
|
|
|
|
let
|
2022-09-30 11:47:45 +00:00
|
|
|
|
|
|
|
luaPackages = self.pkgs;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
XCFLAGS = with lib;
|
2021-09-18 10:52:07 +00:00
|
|
|
optional (!enableFFI) "-DLUAJIT_DISABLE_FFI"
|
|
|
|
++ optional (!enableJIT) "-DLUAJIT_DISABLE_JIT"
|
|
|
|
++ optional enable52Compat "-DLUAJIT_ENABLE_LUA52COMPAT"
|
|
|
|
++ optional (!enableGC64) "-DLUAJIT_DISABLE_GC64"
|
|
|
|
++ optional useSystemMalloc "-DLUAJIT_USE_SYSMALLOC"
|
|
|
|
++ optional enableValgrindSupport "-DLUAJIT_USE_VALGRIND"
|
|
|
|
++ optional enableGDBJITSupport "-DLUAJIT_USE_GDBJIT"
|
|
|
|
++ optional enableAPICheck "-DLUAJIT_USE_APICHECK"
|
|
|
|
++ optional enableVMAssertions "-DLUAJIT_USE_ASSERT"
|
2023-01-11 07:51:40 +00:00
|
|
|
++ optional deterministicStringIds "-DLUAJIT_SECURITY_STRID=0"
|
2020-04-24 23:36:52 +00:00
|
|
|
;
|
2023-02-02 18:25:31 +00:00
|
|
|
|
|
|
|
# LuaJIT requires build for 32bit architectures to be build on x86 not x86_64
|
|
|
|
# TODO support also other build architectures. The ideal way would be to use
|
|
|
|
# stdenv_32bit but that doesn't work due to host platform mismatch:
|
|
|
|
# https://github.com/NixOS/nixpkgs/issues/212494
|
|
|
|
buildStdenv = if buildPackages.stdenv.isx86_64 && stdenv.is32bit
|
|
|
|
then buildPackages.pkgsi686Linux.buildPackages.stdenv
|
|
|
|
else buildPackages.stdenv;
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
in
|
|
|
|
stdenv.mkDerivation rec {
|
2022-09-30 11:47:45 +00:00
|
|
|
pname = "luajit";
|
2022-12-28 21:21:41 +00:00
|
|
|
inherit version src;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
luaversion = "5.1";
|
|
|
|
|
|
|
|
postPatch = ''
|
|
|
|
substituteInPlace Makefile --replace ldconfig :
|
|
|
|
if test -n "''${dontStrip-}"; then
|
|
|
|
# CCDEBUG must be non-empty or everything will be stripped, -g being
|
|
|
|
# passed by nixpkgs CC wrapper is insufficient on its own
|
|
|
|
substituteInPlace src/Makefile --replace "#CCDEBUG= -g" "CCDEBUG= -g"
|
|
|
|
fi
|
2021-09-18 10:52:07 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
echo -e '
|
|
|
|
#undef LUA_PATH_DEFAULT
|
|
|
|
#define LUA_PATH_DEFAULT "./share/lua/${luaversion}/?.lua;./?.lua;./?/init.lua"
|
|
|
|
#undef LUA_CPATH_DEFAULT
|
|
|
|
#define LUA_CPATH_DEFAULT "./lib/lua/${luaversion}/?.so;./?.so;./lib/lua/${luaversion}/loadall.so"
|
|
|
|
'
|
|
|
|
} >> src/luaconf.h
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
2023-01-11 07:51:40 +00:00
|
|
|
dontConfigure = true;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
buildInputs = lib.optional enableValgrindSupport valgrind;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
buildFlags = [
|
|
|
|
"amalg" # Build highly optimized version
|
|
|
|
];
|
|
|
|
makeFlags = [
|
|
|
|
"PREFIX=$(out)"
|
|
|
|
"DEFAULT_CC=cc"
|
|
|
|
"CROSS=${stdenv.cc.targetPrefix}"
|
2023-02-02 18:25:31 +00:00
|
|
|
"HOST_CC=${buildStdenv.cc}/bin/cc"
|
2023-07-15 17:15:38 +00:00
|
|
|
] ++ lib.optional enableJITDebugModule "INSTALL_LJLIBD=$(INSTALL_LMOD)"
|
|
|
|
++ lib.optional stdenv.hostPlatform.isStatic "BUILDMODE=static";
|
2020-04-24 23:36:52 +00:00
|
|
|
enableParallelBuilding = true;
|
2023-03-04 12:14:45 +00:00
|
|
|
env.NIX_CFLAGS_COMPILE = toString XCFLAGS;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
postInstall = ''
|
|
|
|
( cd "$out/include"; ln -s luajit-*/* . )
|
|
|
|
ln -s "$out"/bin/luajit-* "$out"/bin/lua
|
2023-01-11 07:51:40 +00:00
|
|
|
if [[ ! -e "$out"/bin/luajit ]]; then
|
|
|
|
ln -s "$out"/bin/luajit* "$out"/bin/luajit
|
|
|
|
fi
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
2022-09-30 11:47:45 +00:00
|
|
|
LuaPathSearchPaths = luaPackages.luaLib.luaPathList;
|
|
|
|
LuaCPathSearchPaths = luaPackages.luaLib.luaCPathList;
|
2021-09-18 10:52:07 +00:00
|
|
|
|
2022-09-30 11:47:45 +00:00
|
|
|
setupHook = luaPackages.lua-setup-hook luaPackages.luaLib.luaPathList luaPackages.luaLib.luaCPathList;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-09-30 11:47:45 +00:00
|
|
|
# copied from python
|
|
|
|
passthru = let
|
|
|
|
# When we override the interpreter we also need to override the spliced versions of the interpreter
|
|
|
|
inputs' = lib.filterAttrs (n: v: ! lib.isDerivation v && n != "passthruFun") inputs;
|
|
|
|
override = attr: let lua = attr.override (inputs' // { self = lua; }); in lua;
|
|
|
|
in passthruFun rec {
|
2022-12-28 21:21:41 +00:00
|
|
|
inherit self luaversion packageOverrides luaAttr;
|
2022-09-30 11:47:45 +00:00
|
|
|
executable = "lua";
|
|
|
|
luaOnBuildForBuild = override pkgsBuildBuild.${luaAttr};
|
|
|
|
luaOnBuildForHost = override pkgsBuildHost.${luaAttr};
|
|
|
|
luaOnBuildForTarget = override pkgsBuildTarget.${luaAttr};
|
|
|
|
luaOnHostForHost = override pkgsHostHost.${luaAttr};
|
2023-07-15 17:15:38 +00:00
|
|
|
luaOnTargetForTarget = lib.optionalAttrs (lib.hasAttr luaAttr pkgsTargetTarget) (override pkgsTargetTarget.${luaAttr});
|
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 = "High-performance JIT compiler for Lua 5.1";
|
2023-01-11 07:51:40 +00:00
|
|
|
homepage = "https://luajit.org/";
|
2021-09-18 10:52:07 +00:00
|
|
|
license = licenses.mit;
|
|
|
|
platforms = platforms.linux ++ platforms.darwin;
|
2023-01-11 07:51:40 +00:00
|
|
|
badPlatforms = [
|
|
|
|
"riscv64-linux" "riscv64-linux" # See https://github.com/LuaJIT/LuaJIT/issues/628
|
|
|
|
"powerpc64le-linux" # `#error "No support for PPC64"`
|
|
|
|
];
|
2022-01-19 23:45:15 +00:00
|
|
|
maintainers = with maintainers; [ thoughtpolice smironov vcunat lblasc ];
|
2020-04-24 23:36:52 +00:00
|
|
|
} // extraMeta;
|
|
|
|
}
|