Skip to content

Commit

Permalink
luajit: Expose build options, enable JIT debug module
Browse files Browse the repository at this point in the history
  • Loading branch information
Shados authored and teto committed Feb 15, 2020
1 parent bbb4a1b commit e34db5a
Showing 1 changed file with 41 additions and 9 deletions.
50 changes: 41 additions & 9 deletions pkgs/development/interpreters/luajit/default.nix
Expand Up @@ -7,9 +7,33 @@
, callPackage
, self
, packageOverrides ? (self: super: {})
, enableFFI ? true
, enableJIT ? true
, enableJITDebugModule ? enableJIT
, enable52Compat ? false
, enableValgrindSupport ? false
, valgrind ? null
, enableGDBJITSupport ? false
, enableAPICheck ? false
, enableVMAssertions ? false
, useSystemMalloc ? false
}:
assert enableJITDebugModule -> enableJIT;
assert enableGDBJITSupport -> enableJIT;
assert enableValgrindSupport -> valgrind != null;
let
luaPackages = callPackage ../../lua-modules {lua=self; overrides=packageOverrides;};

XCFLAGS = with stdenv.lib;
optional (!enableFFI) "-DLUAJIT_DISABLE_FFI"
++ optional (!enableJIT) "-DLUAJIT_DISABLE_JIT"
++ optional enable52Compat "-DLUAJIT_ENABLE_LUA52COMPAT"
++ 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"
;
in
stdenv.mkDerivation rec {
inherit name version;
Expand All @@ -22,27 +46,36 @@ stdenv.mkDerivation rec {

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
'';

configurePhase = false;

buildInputs = stdenv.lib.optional enableValgrindSupport valgrind;

buildFlags = [
"amalg" # Build highly optimized version
];
makeFlags = [
"PREFIX=$(out)"
"DEFAULT_CC=cc"
"CROSS=${stdenv.cc.targetPrefix}"
# TODO: when pointer size differs, we would need e.g. -m32
"HOST_CC=${buildPackages.stdenv.cc}/bin/cc"
];
buildFlags = [ "amalg" ]; # Build highly optimized version
] ++ stdenv.lib.optional enableJITDebugModule "INSTALL_LJLIBD=$(INSTALL_LMOD)";
enableParallelBuilding = true;
NIX_CFLAGS_COMPILE = XCFLAGS;

postInstall = ''
( cd "$out/include"; ln -s luajit-*/* . )
ln -s "$out"/bin/luajit-* "$out"/bin/lua
''
+ stdenv.lib.optionalString (!isStable) ''
ln -s "$out"/bin/luajit-* "$out"/bin/luajit
'';
( cd "$out/include"; ln -s luajit-*/* . )
ln -s "$out"/bin/luajit-* "$out"/bin/lua
'' + stdenv.lib.optionalString (!isStable) ''
ln -s "$out"/bin/luajit-* "$out"/bin/luajit
'';

LuaPathSearchPaths = [
"lib/lua/${luaversion}/?.lua" "share/lua/${luaversion}/?.lua"
Expand Down Expand Up @@ -70,4 +103,3 @@ stdenv.mkDerivation rec {
maintainers = with maintainers; [ thoughtpolice smironov vcunat andir ];
} // extraMeta;
}

0 comments on commit e34db5a

Please sign in to comment.