2021-08-25 10:35:49 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
|
|
|
, fetchFromGitHub
|
|
|
|
, buildPackages
|
2019-01-30 14:13:15 +00:00
|
|
|
, version
|
2022-12-19 07:27:58 +00:00
|
|
|
, src
|
2021-08-25 10:35:49 +00:00
|
|
|
, extraMeta ? { }
|
2019-01-30 14:13:15 +00:00
|
|
|
, callPackage
|
|
|
|
, self
|
2021-09-11 22:01:49 +00:00
|
|
|
, packageOverrides ? (final: prev: {})
|
2022-08-26 03:17:06 +00:00
|
|
|
, pkgsBuildBuild
|
|
|
|
, pkgsBuildHost
|
|
|
|
, pkgsBuildTarget
|
|
|
|
, pkgsHostHost
|
|
|
|
, pkgsTargetTarget
|
|
|
|
, passthruFun
|
2019-03-23 05:21:37 +00:00
|
|
|
, enableFFI ? true
|
|
|
|
, enableJIT ? true
|
|
|
|
, enableJITDebugModule ? enableJIT
|
2020-10-01 04:41:13 +00:00
|
|
|
, enableGC64 ? true
|
2019-03-23 05:21:37 +00:00
|
|
|
, enable52Compat ? false
|
|
|
|
, enableValgrindSupport ? false
|
|
|
|
, valgrind ? null
|
|
|
|
, enableGDBJITSupport ? false
|
|
|
|
, enableAPICheck ? false
|
|
|
|
, enableVMAssertions ? false
|
|
|
|
, useSystemMalloc ? false
|
neovim: make the build reproducible
This introduces a patch that improves binary reproducibility since changes in
ordering of the generated code indeed cause changes in the compiled code.
Additionally, since neovim embeds luajit-compiled bytecode into the nvim binary,
we are impacted by https://github.com/LuaJIT/LuaJIT/issues/626 . It is possible
to switch to lua 5.1, but that'd be a regression (luajit has much better
performance and some plugins depend on it, like for example Noice and Lazy).
Disabling `COMPILE_LUA` at build time would cause a runtime penalty each time
neovim starts. Instead, we run luagit with those security settings disabled for
the build-time code generation.
(Note to self: for a minimized testcase this seemed to help at
975ec13f5d5aefcac1dbb15fa867e660e07c93a1 but no longer at
03080b795aa3496ed62d4a0697c9f4767e7ca7e5 of luajit, which is surprising since
that commit doesn't look super relevant. _Also_ surprisingly it does seem to
work in the context of the neovim code generation, though, so that might be
good enough...)
Also, some of the code generation (using mpack and tables) still relies on
stable table ordering. This should eventually be fixed, but as a workaround
we use the luajit-with-stable-string-ids for those generators as well.
Fixes #207841
2022-12-28 13:04:18 +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-19 07:27:58 +00:00
|
|
|
, luaAttr ? "luajit_${lib.versions.major version}_${lib.versions.minor version}"
|
2022-08-26 03:17:06 +00:00
|
|
|
} @ inputs:
|
2019-03-23 05:21:37 +00:00
|
|
|
assert enableJITDebugModule -> enableJIT;
|
|
|
|
assert enableGDBJITSupport -> enableJIT;
|
|
|
|
assert enableValgrindSupport -> valgrind != null;
|
2019-01-30 14:13:15 +00:00
|
|
|
let
|
2022-08-26 03:17:06 +00:00
|
|
|
|
|
|
|
luaPackages = self.pkgs;
|
2019-03-23 05:21:37 +00:00
|
|
|
|
2021-01-23 13:15:07 +00:00
|
|
|
XCFLAGS = with lib;
|
2021-08-25 10:35:49 +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"
|
neovim: make the build reproducible
This introduces a patch that improves binary reproducibility since changes in
ordering of the generated code indeed cause changes in the compiled code.
Additionally, since neovim embeds luajit-compiled bytecode into the nvim binary,
we are impacted by https://github.com/LuaJIT/LuaJIT/issues/626 . It is possible
to switch to lua 5.1, but that'd be a regression (luajit has much better
performance and some plugins depend on it, like for example Noice and Lazy).
Disabling `COMPILE_LUA` at build time would cause a runtime penalty each time
neovim starts. Instead, we run luagit with those security settings disabled for
the build-time code generation.
(Note to self: for a minimized testcase this seemed to help at
975ec13f5d5aefcac1dbb15fa867e660e07c93a1 but no longer at
03080b795aa3496ed62d4a0697c9f4767e7ca7e5 of luajit, which is surprising since
that commit doesn't look super relevant. _Also_ surprisingly it does seem to
work in the context of the neovim code generation, though, so that might be
good enough...)
Also, some of the code generation (using mpack and tables) still relies on
stable table ordering. This should eventually be fixed, but as a workaround
we use the luajit-with-stable-string-ids for those generators as well.
Fixes #207841
2022-12-28 13:04:18 +00:00
|
|
|
++ optional deterministicStringIds "-DLUAJIT_SECURITY_STRID=0"
|
2019-03-23 05:21:37 +00:00
|
|
|
;
|
2023-01-26 10:31:01 +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;
|
|
|
|
|
2019-01-30 14:13:15 +00:00
|
|
|
in
|
|
|
|
stdenv.mkDerivation rec {
|
2022-08-26 03:17:06 +00:00
|
|
|
pname = "luajit";
|
2022-12-19 07:27:58 +00:00
|
|
|
inherit version src;
|
2013-11-15 16:20:29 +00:00
|
|
|
|
2019-01-30 14:13:15 +00:00
|
|
|
luaversion = "5.1";
|
2013-11-15 16:20:29 +00:00
|
|
|
|
2019-02-21 09:35:42 +00:00
|
|
|
postPatch = ''
|
|
|
|
substituteInPlace Makefile --replace ldconfig :
|
2019-03-23 05:21:37 +00:00
|
|
|
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-11 22:01:49 +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
|
2019-01-30 14:13:15 +00:00
|
|
|
'';
|
|
|
|
|
2022-12-19 07:40:49 +00:00
|
|
|
dontConfigure = true;
|
2013-11-15 16:20:29 +00:00
|
|
|
|
2021-01-23 13:15:07 +00:00
|
|
|
buildInputs = lib.optional enableValgrindSupport valgrind;
|
2019-03-23 05:21:37 +00:00
|
|
|
|
|
|
|
buildFlags = [
|
|
|
|
"amalg" # Build highly optimized version
|
|
|
|
];
|
2019-02-21 09:35:42 +00:00
|
|
|
makeFlags = [
|
|
|
|
"PREFIX=$(out)"
|
|
|
|
"DEFAULT_CC=cc"
|
|
|
|
"CROSS=${stdenv.cc.targetPrefix}"
|
2023-01-26 10:31:01 +00:00
|
|
|
"HOST_CC=${buildStdenv.cc}/bin/cc"
|
2021-01-23 13:15:07 +00:00
|
|
|
] ++ lib.optional enableJITDebugModule "INSTALL_LJLIBD=$(INSTALL_LMOD)";
|
2019-01-30 14:13:15 +00:00
|
|
|
enableParallelBuilding = true;
|
2023-02-19 19:23:32 +00:00
|
|
|
env.NIX_CFLAGS_COMPILE = toString XCFLAGS;
|
2019-01-30 14:13:15 +00:00
|
|
|
|
2019-02-21 09:35:42 +00:00
|
|
|
postInstall = ''
|
2019-03-23 05:21:37 +00:00
|
|
|
( cd "$out/include"; ln -s luajit-*/* . )
|
|
|
|
ln -s "$out"/bin/luajit-* "$out"/bin/lua
|
2022-12-19 07:40:49 +00:00
|
|
|
if [[ ! -e "$out"/bin/luajit ]]; then
|
|
|
|
ln -s "$out"/bin/luajit* "$out"/bin/luajit
|
|
|
|
fi
|
2019-03-23 05:21:37 +00:00
|
|
|
'';
|
2019-01-30 14:13:15 +00:00
|
|
|
|
2022-08-22 22:45:37 +00:00
|
|
|
LuaPathSearchPaths = luaPackages.luaLib.luaPathList;
|
|
|
|
LuaCPathSearchPaths = luaPackages.luaLib.luaCPathList;
|
2021-09-11 22:01:49 +00:00
|
|
|
|
2022-08-22 22:45:37 +00:00
|
|
|
setupHook = luaPackages.lua-setup-hook luaPackages.luaLib.luaPathList luaPackages.luaLib.luaCPathList;
|
2019-01-30 14:13:15 +00:00
|
|
|
|
2022-08-26 03:17:06 +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-19 07:27:58 +00:00
|
|
|
inherit self luaversion packageOverrides luaAttr;
|
2022-08-26 03:17:06 +00:00
|
|
|
executable = "lua";
|
|
|
|
luaOnBuildForBuild = override pkgsBuildBuild.${luaAttr};
|
|
|
|
luaOnBuildForHost = override pkgsBuildHost.${luaAttr};
|
|
|
|
luaOnBuildForTarget = override pkgsBuildTarget.${luaAttr};
|
|
|
|
luaOnHostForHost = override pkgsHostHost.${luaAttr};
|
|
|
|
luaOnTargetForTarget = if lib.hasAttr luaAttr pkgsTargetTarget then (override pkgsTargetTarget.${luaAttr}) else {};
|
2014-04-09 02:15:55 +00:00
|
|
|
};
|
2017-07-07 08:44:33 +00:00
|
|
|
|
2021-01-23 13:15:07 +00:00
|
|
|
meta = with lib; {
|
2017-07-10 12:07:54 +00:00
|
|
|
description = "High-performance JIT compiler for Lua 5.1";
|
2022-12-19 07:40:49 +00:00
|
|
|
homepage = "https://luajit.org/";
|
2021-08-25 10:35:49 +00:00
|
|
|
license = licenses.mit;
|
|
|
|
platforms = platforms.linux ++ platforms.darwin;
|
2023-01-05 08:50:27 +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:24:52 +00:00
|
|
|
maintainers = with maintainers; [ thoughtpolice smironov vcunat lblasc ];
|
2019-10-13 11:57:48 +00:00
|
|
|
} // extraMeta;
|
2013-11-15 16:20:29 +00:00
|
|
|
}
|