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

Static linking to vendored Lua #111

Open
atweiden opened this issue May 30, 2023 · 3 comments
Open

Static linking to vendored Lua #111

atweiden opened this issue May 30, 2023 · 3 comments

Comments

@atweiden
Copy link

This module doesn’t build without Lua development libraries installed on the build host. This is a shortcoming compared to the situation in mlua, where users needn’t have Lua pre-installed for static linking to mlua’s vendored copy of Lua to work.

Does Go support this type of build? Would it take a custom Makefile or similar? I’ve forked golua to ~ioiojo/golua to experiment, but I don’t see how to link my vendored copy of Lua. As an example, see the lua-c-api/zig subdirectory of ~ioiojo/export-anytype: https://git.sr.ht/~ioiojo/export-anytype/tree/master/item/lua-c-api/zig/internal/luautils/luautils.go

@aarzilli
Copy link
Owner

I've never looked into lua's build system. It might be that you can just throw all of the source files into a directory and just let cgo do its thing. If it's anything more complicated you can't do it because cmd/go doesn't let you run arbitrary code at install time.

@atweiden
Copy link
Author

One can vendor Lua in their golua-using module, compile Lua with a Makefile or similar, and then link to the vendored Lua library using CGO_CFLAGS + CGO_LDFLAGS.

Enabling this would seem to require patching golua’s lua/lua.go to include a declaration for lua_gc_compat in the Cgo special comments section, e.g.

/*
...
LUA_API int (lua_gc_compat) (lua_State *L, int what, int data);
...
*/
import "C"

... rather than patching Lua’s own lua.h to include this declaration, as I believe lua/lua54/lua.h does currently. Correct me if I’m wrong, but I don’t think lua_gc_compat is part of any Lua 5.4x release.

@aarzilli
Copy link
Owner

It doesn't matter if there's an extra declaration in lua.h or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants