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

Linux Native Lua Binaries Needed #16

Closed
tilkinsc opened this issue Jan 24, 2024 · 5 comments
Closed

Linux Native Lua Binaries Needed #16

tilkinsc opened this issue Jan 24, 2024 · 5 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@tilkinsc
Copy link
Owner

Its time we support Linux (I will add x86_64 support)!

If you have a Linux on ARM64 cpu, your assistance is needed (Read Below)!

This is how you download and build lua.

curl -L -R -O https://www.lua.org/ftp/lua-all.tar.gz
tar zxf lua-all.tar.gz
cd lua-all
make -j $(nproc) all

Each sub folder in lua-all will have a .so file associated inside of it resulting from the build.

This is how you download and build luajit.

git clone https://luajit.org/git/luajit.git
cd luajit
make -j $(nproc) all

Collect each minor versions highest patch number (5.4.6, 5.3.6, 5.2.4, 5.1.5) and rename the so appropriately (lua546.so, lua536.so, lua524.so lua515.so) For luajit, retain the name of lua51.so.

Move these so's to runtimes/linux-arm64/native. example About RIDs

@tilkinsc tilkinsc added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Jan 24, 2024
@tilkinsc tilkinsc self-assigned this Jan 24, 2024
@tilkinsc tilkinsc changed the title Linux Native Lua Binaries Linux Native Lua Binaries Needed Jan 24, 2024
@McJazzy
Copy link

McJazzy commented Apr 2, 2024

HI @tilkinsc , is there a branch available where we can test the linux x64 binding?

@tilkinsc
Copy link
Owner Author

tilkinsc commented Apr 3, 2024

When you build luajit, you need to have all the symbols available. I was trying to build these .so's for Linux, but ran into issues with the lua headers themselves. Building .so's is hacked on top of lua when it comes to linux because on linux puc-lua expects you to just suck it up and use .a files instead. If you look at lua.h there is no reference to dlls for anything other than windows. I was going to experiment to see if I could create either a custom configuration or if I could jerry rig the .a (which should have everything necessary) into a dll as the path of least resistance. Missing symbols means things will stop working.

require("socket"). 

I've compiled luasocket with luarocks, but getting following error:

error loading module 'socket.core' from file '/usr/local/lib/lua/5.1/socket/core.so':
        /usr/local/lib/lua/5.1/socket/core.so: undefined symbol: lua_gettop


I've trying loading these modules:
lua_State L = luaL_newstate();
if (L == 0)
{
Console.WriteLine("Unable to create context!");
}
luaopen_base(L);
luaL_openlibs(L);
luaopen_jit(L);
but the same error appears.

I've tried to dlopen luajit, but still the same error appears.
IntPtr moduleHandle = dlopen("lua51.so", RTLD_GLOBAL | RTLD_NOW);
Console.WriteLine($"handle: {moduleHandle}");

As per dlopen api, I think its the fact that the file isn't found 'lua51.so' is not a valid path. This would definitely return a null pointer. LuaRocks is a layer that sits somewhere between lua and lua libraries. You may get around this by manually linking your luajit dll with the luasocket library. Let me know how that goes.

@tilkinsc
Copy link
Owner Author

tilkinsc commented Apr 3, 2024

I am on archlinux. To be transparent, this is the setup I am using for figuring out how to handle this.

yay -Syu
yay -S dotnet-runtime dotnet-sdk
git clone https://github.com/tilkinsc/Lua.NET
cd Lua.NET
git clone https://luajit.org/git/luajit.git
curl -L -R -O https://www.lua.org/ftp/lua-all.tar.gz > lua-all.tar.gz
tar zxf lua-all.tar.gz

Hmm it seems that the .so is building out of the box now. Thats nice.

@tilkinsc
Copy link
Owner Author

tilkinsc commented Apr 3, 2024

luaso.tar.gz

I was able to drive the library with these .so's. However, I had to dump these next to the binary. For some reason, its looking relative to it (makes sense due to windows), rather than from runtimes/** which I expect to always be on the search path as well. This is local testing, however, and I havent been able to test it due to nuget being a required step in this process. Perhaps I should just release a -dev suffixed nuget package for this purpose.

I'll check out getting luarocks support in after this.

You may beta test this through this package reference
<PackageReference Include="Lua.NET" Version="5.0.0" />

@tilkinsc tilkinsc closed this as completed Apr 3, 2024
@tilkinsc
Copy link
Owner Author

tilkinsc commented Apr 3, 2024

Lua.NET works on Linux now.
<PackageReference Include="Lua.NET" Version="5.0.3" />
Moving LuaRocks discussion to #21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants