pkgxdev / pantry

pkg manifests
https://pkgx.dev/pkgs/
161 stars 112 forks source link

Lua can't find libraries #6568

Closed magnusviri closed 1 day ago

magnusviri commented 2 days ago

I'm trying to use luasockets.

> pkgx lua ./lua-stuff.lua
/opt/pkgx/lua.org/v5.4.7/bin/lua: ./lua-stuff.lua:1: module 'socket' not found:
    no field package.preload['socket']
    no file '/usr/local/share/lua/5.4/socket.lua'
    no file '/usr/local/share/lua/5.4/socket/init.lua'
    no file '/usr/local/lib/lua/5.4/socket.lua'
    no file '/usr/local/lib/lua/5.4/socket/init.lua'
    no file './socket.lua'
    no file './socket/init.lua'
    no file '/usr/local/lib/lua/5.4/socket.so'
    no file '/usr/local/lib/lua/5.4/loadall.so'
    no file './socket.so'
stack traceback:
    [C]: in function 'require'
    ./lua-part.lua:1: in main chunk
    [C]: in ?

> pkgx luarocks install luasocket
Installing https://luarocks.org/luasocket-3.1.0-1.src.rock
...
luasocket 3.1.0-1 is now installed in /opt/pkgx/luarocks.org/v3.11.1 (license: MIT)

> pkgx lua ./lua-stuff.lua
/opt/pkgx/lua.org/v5.4.7/bin/lua: ./lua-stuff.lua:1: module 'socket' not found:
    no field package.preload['socket']
    no file '/usr/local/share/lua/5.4/socket.lua'
    no file '/usr/local/share/lua/5.4/socket/init.lua'
    no file '/usr/local/lib/lua/5.4/socket.lua'
    no file '/usr/local/lib/lua/5.4/socket/init.lua'
    no file './socket.lua'
    no file './socket/init.lua'
    no file '/usr/local/lib/lua/5.4/socket.so'
    no file '/usr/local/lib/lua/5.4/loadall.so'
    no file './socket.so'
stack traceback:
    [C]: in function 'require'
    ./lua-part.lua:1: in main chunk
    [C]: in ?

This fixes it. I'm not sure how you want to integrate it. (see https://www.lua.org/manual/5.4/lua.html)

export LUA_PATH="/opt/pkgx/lua.org/v\*/share/lua/5.4/?.lua;/opt/pkgx/lua.org/v\*/share/lua/5.4/?/init.lua;/opt/pkgx/lua.org/v*/lib/lua/5.4/?.lua;/opt/pkgx/lua.org/v*/lib/lua/5.4/?/init.lua;/opt/pkgx/luarocks.org/v*/share/lua/5.4/?.lua;/opt/pkgx/luarocks.org/v*/share/lua/5.4/?/init.lua;/opt/pkgx/luarocks.org/v*/lib/lua/5.4/?.lua;/opt/pkgx/luarocks.org/v*/lib/lua/5.4/?/init.lua;./?.lua;./?/init.lua"
export LUA_CPATH="/opt/pkgx/lua.org/v*/lib/lua/5.4/?.so;/opt/pkgx/lua.org/v*/lib/lua/5.4/loadall.so;/opt/pkgx/luarocks.org/v*/lib/lua/5.4/?.so;/opt/pkgx/luarocks.org/v*/lib/lua/5.4/loadall.so;./?.so"
jhheider commented 1 day ago

So, if i'm reading correctly, both lua should list luarocks as a companion, and both should have runtime variables pointing to the share directories. does it work properly with only the directory paths, and not the specific files listed as well?

export LUA_PATH="/opt/pkgx/lua.org/v\*/share/lua/5.4;/opt/pkgx/lua.org/v*/lib/lua/5.4;;/opt/pkgx/luarocks.org/v*/share/lua/5.4;/opt/pkgx/luarocks.org/v*/lib/lua/5.4"
export LUA_CPATH="/opt/pkgx/lua.org/v*/lib/lua/5.4/;/opt/pkgx/luarocks.org/v*/lib/lua/5.4"
jhheider commented 1 day ago

nope, as always, your fix is perfect. ugly, but that's lua's fault. pr incoming with a test for your specific issue.

magnusviri commented 1 day ago

Ok, I feel dumb because there might be a better solution. Luarocks can specify an install directory like this: luarocks install --tree ~/.local/lua. I'm not sure where you guys install stuff with gems and pip, but this is similar to that. That directory should probably be included in LUA_PATH and LUA_CPATH instead of the luarocks.org pkgx directory. I included the luarocks pkgx directory because that's where luarocks installs stuff by default.

jhheider commented 1 day ago

ooh, good catch. looks like we might be using ~/.gems if i'm reading the patches correctly. i wonder what's considered standard.