Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

luaPackages.luv: cleanup build #80528

Closed
wants to merge 11 commits into from
7 changes: 2 additions & 5 deletions pkgs/applications/editors/neovim/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let
neovimLuaEnv = lua.withPackages(ps:
(with ps; [ lpeg luabitop mpack ]
++ optionals doCheck [
nvim-client luv coxpcall busted luafilesystem penlight inspect
nvim-client libluv coxpcall busted luafilesystem penlight inspect
]
));
in
Expand Down Expand Up @@ -44,7 +44,7 @@ in
libtermkey
libuv
libvterm-neovim
lua.pkgs.luv.libluv
lua.pkgs.libluv
msgpack
ncurses
neovimLuaEnv
Expand Down Expand Up @@ -79,9 +79,6 @@ in
"-DGPERF_PRG=${gperf}/bin/gperf"
"-DLUA_PRG=${neovimLuaEnv.interpreter}"
]
# FIXME: this is verry messy and strange.
++ optional (!stdenv.isDarwin) "-DLIBLUV_LIBRARY=${lua.pkgs.luv}/lib/lua/${lua.luaversion}/luv.so"
++ optional (stdenv.isDarwin) "-DLIBLUV_LIBRARY=${lua.pkgs.luv.libluv}/lib/lua/${lua.luaversion}/libluv.dylib"
++ optional doCheck "-DBUSTED_PRG=${neovimLuaEnv}/bin/busted"
++ optional (!lua.pkgs.isLuaJIT) "-DPREFER_LUA=ON"
;
Expand Down
6 changes: 3 additions & 3 deletions pkgs/development/lua-modules/generated-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1326,11 +1326,11 @@ luuid = buildLuarocksPackage {
};
luv = buildLuarocksPackage {
pname = "luv";
version = "1.34.1-1";
version = "1.34.2-0";

src = fetchurl {
url = https://luarocks.org/luv-1.34.1-1.src.rock;
sha256 = "044cyp25xn35nj5qp1hx04lfkzrpa6adhqjshq2g7wvbga77p1q0";
url = https://luarocks.org/luv-1.34.2-0.src.rock;
sha256 = "05c0s1a897yvk0qp31hra2b2qg6kr9fd4cib9hbrpxvzzn9a9cwc";
};
disabled = (luaOlder "5.1");
propagatedBuildInputs = [ lua ];
Expand Down
49 changes: 25 additions & 24 deletions pkgs/development/lua-modules/overrides.nix
Original file line number Diff line number Diff line change
Expand Up @@ -264,37 +264,38 @@ with super;
disabled = luaOlder "5.1" || (luaAtLeast "5.4");
});

compat53 = super.compat53.override (old: {
# needed for luv build
postInstall = ''
cp -r c-api $out/c-api
'';
});

luv = super.luv.override({
# Use system libuv instead of building local and statically linking
# This is a hacky way to specify -DWITH_SHARED_LIBUV=ON which
# is not possible with luarocks and the current luv rockspec
# While at it, remove bundled libuv source entirely to be sure.
# We may wish to drop bundled lua submodules too...
preBuild = ''
sed -i 's,\(option(WITH_SHARED_LIBUV.*\)OFF,\1ON,' CMakeLists.txt
rm -rf deps/libuv
# So we can be sure no internal dependency is used from the repo and that
# everything is provided by us
preConfigure = ''
rm -rf deps
''
# See the following issues:
# - https://github.com/luarocks/luarocks/issues/1160
# - https://github.com/luarocks/luarocks/issues/509
# - https://github.com/luarocks/luarocks/issues/339
+ ''
sed -i 's,\(option(WITH_SHARED_LIBUV.*\)OFF,\1ON,' CMakeLists.txt
Comment on lines +278 to +285
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rm -rf deps
''
# See the following issues:
# - https://github.com/luarocks/luarocks/issues/1160
# - https://github.com/luarocks/luarocks/issues/509
# - https://github.com/luarocks/luarocks/issues/339
+ ''
sed -i 's,\(option(WITH_SHARED_LIBUV.*\)OFF,\1ON,' CMakeLists.txt
rm -r deps
# See the following issues:
# - https://github.com/luarocks/luarocks/issues/1160
# - https://github.com/luarocks/luarocks/issues/509
# - https://github.com/luarocks/luarocks/issues/339
sed -i 's,\(option(WITH_SHARED_LIBUV.*\)OFF,\1ON,' CMakeLists.txt

'';
LUA_COMPAT53_DIR="${lua.pkgs.compat53}";

buildInputs = [ pkgs.libuv ];

passthru = {
libluv = self.luv.override ({
preBuild = self.luv.preBuild + ''
sed -i 's,\(option(BUILD_MODULE.*\)ON,\1OFF,' CMakeLists.txt
sed -i 's,\(option(BUILD_SHARED_LIBS.*\)OFF,\1ON,' CMakeLists.txt
sed -i 's,${"\${INSTALL_INC_DIR}"},${placeholder "out"}/include/luv,' CMakeLists.txt
'';

nativeBuildInputs = [ pkgs.fixDarwinDylibNames ];

# Fixup linking libluv.dylib, for some reason it's not linked against lua correctly.
NIX_LDFLAGS = pkgs.lib.optionalString pkgs.stdenv.isDarwin
(if isLuaJIT then "-lluajit-${lua.luaversion}" else "-llua");
});
};
nativeBuildInputs = [
lua.pkgs.compat53
];
# Fixup linking libluv.dylib, for some reason it's not linked against lua correctly.
NIX_LDFLAGS = pkgs.lib.optionalString pkgs.stdenv.isDarwin
(if isLuaJIT then "-lluajit-${lua.luaversion}" else "-llua");
Comment on lines +295 to +296
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
NIX_LDFLAGS = pkgs.lib.optionalString pkgs.stdenv.isDarwin
(if isLuaJIT then "-lluajit-${lua.luaversion}" else "-llua");
NIX_LDFLAGS = pkgs.lib.optionalString pkgs.stdenv.isDarwin (if isLuaJIT then "-lluajit-${lua.luaversion}" else "-llua");

});


rapidjson = super.rapidjson.override({
preBuild = ''
sed -i '/set(CMAKE_CXX_FLAGS/d' CMakeLists.txt
Expand Down
57 changes: 57 additions & 0 deletions pkgs/top-level/lua-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,63 @@ with self; {

luarocks-nix = callPackage ../development/tools/misc/luarocks/luarocks-nix.nix { };

# This package is very much like `lua.pkgs.luv`, but it's not defined as a
# module because it fails to install some files if we use
# `buildLuarocksPackage` instead of `mkDerivation`. However, if another
# package (e.g lua.pkgs.nvim-client) would require `luv =
# stdenv.mkDerivation`, it would not detect it and hence it would fail to
# build.

# The workaround implemented here is to create 2 versions of `libluv` while
# `luv` is still defined by lua's generated packages and still overriden as
# necessary in lua's overrides. This version is used in neovim and every
# other package that needs luv as a shared library (not as a mere lua
# module).
libluv = pkgs.stdenv.mkDerivation rec {
pname = "luv";
version = "1.34.2-0";

src = pkgs.fetchFromGitHub {
owner = "luvit";
repo = pname;
rev = version;
sha256 = "0iq272n7p0wkll4a7d880qyhdp65582cwc3b2zzrirpli93x3v87";
};
disabled = (luaOlder "5.1");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
disabled = (luaOlder "5.1");
disabled = luaOlder "5.1";


# So we can be sure no internal dependency is used from the repo and that
# everything is provided by us
postUnpack = ''
rm -rf deps
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rm -rf deps
rm -r deps

'';

cmakeFlags = [
"-DWITH_SHARED_LIBUV=ON"
"-DLUA_BUILD_TYPE=System"
"-DBUILD_MODULE=ON"
"-DBUILD_SHARED_LIBS=ON"
"-DLUA_COMPAT53_DIR=${lua.pkgs.compat53}"
];

buildInputs = [ pkgs.libuv ];

nativeBuildInputs = [
pkgs.cmake
lua.pkgs.compat53
];
# Fixup linking libluv.dylib, for some reason it's not linked against lua correctly.
NIX_LDFLAGS = pkgs.lib.optionalString pkgs.stdenv.isDarwin
(if isLuaJIT then "-lluajit-${lua.luaversion}" else "-llua");
Comment on lines +147 to +148
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
NIX_LDFLAGS = pkgs.lib.optionalString pkgs.stdenv.isDarwin
(if isLuaJIT then "-lluajit-${lua.luaversion}" else "-llua");
NIX_LDFLAGS = pkgs.lib.optionalString pkgs.stdenv.isDarwin (if isLuaJIT then "-lluajit-${lua.luaversion}" else "-llua");

propagatedBuildInputs = [ lua ];

meta = with stdenv.lib; {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
meta = with stdenv.lib; {
meta = with lib; {

homepage = "https://github.com/luvit/luv";
description = "Bare libuv bindings for lua";
license = {
fullName = "Apache 2.0";
};
Comment on lines +154 to +156
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
license = {
fullName = "Apache 2.0";
};
license = licenses.asl20;

};
};
luxio = buildLuaPackage rec {
name = "luxio-${version}";
version = "13";
Expand Down