Yuescript
Yuescript copied to clipboard
Add static compilation mode (for linux)
I'd like to compile moonplus on alpine (which uses muslc instead of glibc) and get a fully static binary that I can take on any Linux system. Please add a make target that produces a static binary.
MoonPlus is written with C++. Building C++ codes with muslc seems not to be an easy task. The official musl FAQ suggests rebuilding libstdc++ against musl to support C++. And this repo is using luarocks to locating native Lua libs for building compatible MoonPlus lib for local environment. You can change the line in CMakeLists.txt of add_library( moonp MODULE ... to add_library( moonp STATIC ... to get a static binary for MoonPlus.
Thanks, I'll investigate on my own :)
I managed to do it using the unix makefile and adding -static -static-libstdc++ -static-libgcc while building inside of an alpine container (which has a muslc based libstdc++).
The only problem is that because of Lua's module system, ldl is also linked. That works on muslc systems but will break on glibc. This is fine as long as no Lua module loading features are used.
It would be great to have a compilation mode of moonplus that doesn't include any Lua libraries. What I basically need is a compiler that just takes moonplus code and spits out Lua, with no minification or running of any Lua code. Maybe a compiler flag that builds without Lua - that would be great.
For now, anyone who wants it, here's a static build from the latest master. It's 2MB and should work on any Linux system without any other dependencies (kernel 4.x and up): moonp.zip
The moonp uses an embedded Lua to provide macro functions that run some Lua codes to generate Lua codes when compiling. You can build embedded Lua part without -DLUA_USE_DLOPEN and -DLUA_USE_LINUX flags and then link without ldl.
Add compiler flags MOONP_NO_MACRO and MOONP_COMPILER_ONLY to disable macro feature and build moonp without Lua. See 02b6afeb2b92c4471cb954209c4ac9195150ea23 bf39ea1dbbe6184c62cafc0249402f4082331de4
MoonPlus tool can now be build with command make install NO_LUA=true. f6e603cc5bef133e5e368a81f677bea92bc405b5