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

feat: Allow external build scripts to link Lua libraries #529

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Sculas
Copy link

@Sculas Sculas commented Feb 15, 2025

This PR makes a small change to mlua-sys (and mlua to propagate the feature) that allows external crates and build scripts to do the compilation and linking part of the Lua libraries.

For my use case, I'm working on Pluto bindings for mlua (which I'll release very soon). Pluto allows for many sandboxing options, which is why I created a separate build script for it. In this script, you can configure each of those options to suit your needs.

In this case, the Pluto build script also handles the compilation and linking of the static library. This PR allows this system to work.
This is also useful for any future Lua forks/derivatives since you're no longer bound to what mlua can compile, instead you just need to confirm that the ABIs match.

@khvzak
Copy link
Member

khvzak commented Feb 24, 2025

Thanks for the PR!
I'm probably okay to add external feature flag to mlua-sys, but could we leave mlua feature flags unchanged.
For anyone who need the external feature flag, can just include mlua-sys to their dependencies with desired flags.

@khvzak
Copy link
Member

khvzak commented Feb 24, 2025

Also to note, Pluto support will be added to a next mlua v0.11

@Sculas
Copy link
Author

Sculas commented Feb 24, 2025

Oh, nice! Will it also support configuring the sandboxing options in Pluto's luaconf.h? (either via build script or feature flags)

@khvzak
Copy link
Member

khvzak commented Feb 24, 2025

Will it also support configuring the sandboxing options in Pluto's luaconf.h?

Did not think about it yet. From the doc seems this option just disable loading binary modules?
Will it make any difference between the current approach in mlua (to remove the loader)?

Also, for proper sandboxing, modules that provide access to OS/FS/etc should be disabled too, which is still aligned with mlua basic capabilities to enable only specific modules.

@Sculas
Copy link
Author

Sculas commented Feb 24, 2025

The Pluto docs unfortunately don't show all the options, and some are even outdated (such as ContmodOnLoad having an outdated signature in the docs). I've just published my Pluto build script to GitHub: https://github.com/Sculas/pluto-build-rs

It's under the same MIT license so feel free to take anything from there that you need :)
You can find all the Pluto-specific options in src/options.rs with proper documentation (there are quite a lot!) and tests in the testcrate directory.

I hadn't published it yet because I still needed to find out a way how I can load Pluto's standard libraries (and required STL code!) without loading ALL libraries, which is what patches/libwrapper.hpp was for (although I haven't worked on it further yet).

In my opinion, besides the language features, the sandboxing capabilities from Pluto are what make it so good. So not having them would be really unfortunate.

Also, if you need any help with implementing Pluto for mlua, feel free to ping me! I'd love to help :)

@Sculas
Copy link
Author

Sculas commented Feb 24, 2025

I hadn't published it yet because I still needed to find out a way how I can load Pluto's standard libraries (and required STL code!) without loading ALL libraries, which is what patches/libwrapper.hpp was for (although I haven't worked on it further yet).

Took a bit longer than I expected (half of the time was spent debugging linker issues, great), but I was finally able to fix this issue in the following commit: Sculas/pluto-build-rs@7626f5a
I'm personally not the biggest fan of how it's done (using macros to work around linker ordering), but it's the only way I could get it working.

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

Successfully merging this pull request may close these issues.

2 participants