nvim-lua / nvim-lua-plugin-template

A starter template for a Neovim plugin written in Lua
136 stars 13 forks source link

Specify Lua version to install in testing docs #17

Open clorl opened 1 month ago

clorl commented 1 month ago

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.

aaronik commented 1 month ago

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?

clorl commented 1 month ago

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)

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

aaronik commented 1 month ago

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