nvim-lua-plugin-template icon indicating copy to clipboard operation
nvim-lua-plugin-template copied to clipboard

Specify Lua version to install in testing docs

Open clorl opened this issue 1 year ago • 4 comments

Spent a whole lot of time banging my head on why testing errored. This is because you need to install Lua 5.1 system-wide even if in the end you use nlua to make neovim your interpreter. This is because when luarocks installs some rocks, it may compile some of them to shared objects against the lua version you have installed globally on your system. This means that if you have luarocks + lua > 5.1 on your system, buster can't even run.

The error I got was on pl/path.lua where it couldn't require luafilesystem, even though the .so file was present. lfs.so failed because it was using undefined symbols that aren't available in Lua 5.1.

clorl avatar Aug 09 '24 01:08 clorl

I have lua 5.4.6 and get this trying to run the tests with luarocks test --local

E5113: Error while calling lua chunk: ...uarocks/lib/luarocks/rocks-5.4/busted/2.2.0-1/bin/busted:3: module 'busted.runner' not found:
	no field package.preload['busted.runner']
	no file './busted/runner.lua'
	no file '/opt/homebrew/share/luajit-2.1/busted/runner.lua'
	no file '/usr/local/share/lua/5.1/busted/runner.lua'
	no file '/usr/local/share/lua/5.1/busted/runner/init.lua'
	no file '/opt/homebrew/share/lua/5.1/busted/runner.lua'
	no file '/opt/homebrew/share/lua/5.1/busted/runner/init.lua'
	no file './busted/runner.so'
	no file '/usr/local/lib/lua/5.1/busted/runner.so'
	no file '/opt/homebrew/lib/lua/5.1/busted/runner.so'
	no file '/usr/local/lib/lua/5.1/loadall.so'
	no file './busted.so'
	no file '/usr/local/lib/lua/5.1/busted.so'
	no file '/opt/homebrew/lib/lua/5.1/busted.so'
	no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
	[C]: in function 'require'
	...uarocks/lib/luarocks/rocks-5.4/busted/2.2.0-1/bin/busted:3: in function 'fn'
	/Users/aaron/.luarocks/bin/nlua:79: in main chunk

@clorl do you think this is related to the same thing?

aaronik avatar Aug 10 '24 17:08 aaronik

Yes, this is the exact same error. So first busted.runner isn't found because you have to set the LUA_PATH and LUA_CPATH. Add this to your .bashrc, .zshrc or wherever.

eval "$(luarocks path)"

This will automatically set those variables. Ofc you can just run them, but you will have to do it everytime you want to run luarocks test.

Now rerun the test command, you should get a different error. The next step is to uninstall lua and luarocks and clean all the lua related files. This is because luarocks really badly handles the case where there are multiple lua versions and may still compile shared objects against the wrong one. (Related issue)

Here are example commands for Debian which is what I use, you have to change them to fit your package manager. Here is a simple command to find related lua files.

# This should list lua related files in /usr/share lib and include
# It removes errors
find /usr/{share,lib,include} -name "*lua*" 2>/dev/null

I'd advise against directly piping this into rm, you may have programs who have an embedded lua version, make sure you only delete the ones installed by lua package. For safety, since you're deleting files as root, I advise you do something like this

sudo -s # Become root
alias rm='rm -i' # Always ask for confirmation
# Then do your thing

Once it's done, install the following packages (names may vary depending on your distro)

  • lua5.1
  • luajit
  • liblua5.1-0
  • luarocks

And now your tests should work fine!

Note: I don't know if manually deleting lua related files is necessary or safe. I'm pretty sure it is, especially the /usr/include file which is the one luarocks shared objects use. Maybe using apt purge to uninstall the packages would have deleted those, I don't know

clorl avatar Aug 12 '24 07:08 clorl

@clorl this is profoundly helpful - I'd given up on getting this to work. Thank you so much!

aaronik avatar Aug 12 '24 14:08 aaronik

I found that what fixed my issue was reading nvim-busted-action's .busted file. There was a difference between the busted file set in this template and their example in their repo was the following.

This template:

_all = {
    coverage = false,
    lpath = "lua/?.lua;lua/?/init.lua",
    lua = "nlua",
  },

nvim-busted-action's example:

_all = {
   coverage = false,
   lpath = "lua/?.lua;lua/?/init.lua",
   lua = "~/.luarocks/bin/nlua",
},

Once I changed it to nvim-busted-action's example, it worked for me. I've been recently informed that issue #19 discusses the exact reason for this change, and its not because the .busted file is outdated. For anyone reading this, please refer to that issue to know exactly why nlua is a hard path reference.

PLAZMAMA avatar Jan 04 '25 07:01 PLAZMAMA