-
-
Save andir/1ee3a7ffa2af086e31dac7cb226fc4e1 to your computer and use it in GitHub Desktop.
luajit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ stdenv, lib, fetchurl, lua5_1, buildPackages }: | |
let | |
inherit (lib.systems.inspect) is64bit is32bit; | |
isCross = stdenv.buildPlatform != stdenv.hostPlatform; | |
# when compiling for a 32bit target on a 64bit machine we need a 32bit native compiler | |
hostCC = builtins.trace ("${buildPackages.pkgsi686Linux.stdenv.cc}") ( | |
if (isCross && stdenv.buildPlatform.system == "x86_64-linux" && stdenv.hostPlatform.is32bit) then | |
"${buildPackages.pkgsi686Linux.stdenv.cc}/bin/${buildPackages.pkgsi686Linux.stdenv.cc.targetPrefix}cc" else null); | |
in rec { | |
luajit = luajit_2_1; | |
luajit_2_0 = generic { | |
version = "2.0.5"; | |
isStable = true; | |
sha256 = "0yg9q4q6v028bgh85317ykc9whgxgysp76qzaqgq55y6jy11yjw7"; | |
meta = genericMeta // { | |
platforms = lib.filter (p: p != "aarch64-linux") genericMeta.platforms; | |
}; | |
}; | |
luajit_2_1 = generic { | |
version = "2.1.0-beta3"; | |
isStable = false; | |
sha256 = "1hyrhpkwjqsv54hnnx4cl8vk44h9d6c9w0fz1jfjz00w255y7lhs"; | |
}; | |
genericMeta = with stdenv.lib; { | |
description = "High-performance JIT compiler for Lua 5.1"; | |
homepage = http://luajit.org; | |
license = licenses.mit; | |
platforms = platforms.linux ++ platforms.darwin; | |
maintainers = with maintainers; [ thoughtpolice smironov vcunat andir ]; | |
}; | |
generic = | |
{ version, sha256 ? null, isStable | |
, name ? "luajit-${version}" | |
, src ? | |
(fetchurl { | |
url = "http://luajit.org/download/LuaJIT-${version}.tar.gz"; | |
inherit sha256; | |
}) | |
, meta ? genericMeta | |
}: | |
stdenv.mkDerivation rec { | |
inherit name version src meta; | |
luaversion = "5.1"; | |
patchPhase = '' | |
substituteInPlace Makefile \ | |
--replace /usr/local "$out" | |
substituteInPlace src/Makefile --replace gcc ${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc | |
'' + stdenv.lib.optionalString (stdenv.cc.libc != null) | |
'' | |
substituteInPlace Makefile \ | |
--replace ldconfig ${stdenv.cc.libc.bin or stdenv.cc.libc}/bin/ldconfig | |
'' + stdenv.lib.optionalString (isCross && stdenv.hostPlatform.is32bit && stdenv.buildPlatform.is64bit) '' | |
mkdir -p src/gnu | |
touch src/gnu/stubs-32.h | |
''; | |
configurePhase = false; | |
buildFlags = [ "amalg" ] # Build highly optimized version | |
++ lib.optionals (isCross) [ # ignore the fact there are other cross compile sources for now... | |
"HOST_CC=${hostCC}" | |
"HOST_CFLAGS=-m32" | |
"HOST_LDFLAGS=-m32" | |
]; | |
enableParallelBuilding = true; | |
nativeBuildInputs = lib.optional isCross lua5_1; | |
installPhase = '' | |
make install PREFIX="$out" | |
( 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 | |
''; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment