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

Create static libraries #264

Closed
wants to merge 5 commits into from
Closed

Conversation

siffiejoe
Copy link
Contributor

Create static libraries (see #262) when using "builtin" build mode. Seems to work on Linux, Windows/MinGW, and Windows/VC (I haven't tested linking to the generated static libraries yet ...).

Currently no include files are generated ...

@hishamhm
Copy link
Member

Cool! Let's merge this when LR3 development starts, early June.

@starius
Copy link

starius commented Oct 19, 2015

Ping.

Can I use this feature to embed Lua modules? There is a program using a rock which uses built-in build mode (e.g., LPeg). I want to get a static binary with no external dependencies. I see the following general solution (probably partly done in this pull request):

  1. Create a static target in LuaRocks to prevent static-shared mixture. For example, for lua-5.1 the static target is lua-5.1-static.
  2. A rock should produce a static library which incorporates C code and Lua code. Lua code can be converted into C code (lua2c) and linked together. This static library has only one function callable from outside: rockopen_<rock>. When Lua creates new lua_State it calls such a function to preload this module. rockopen function uses well known Lua mechanisms to enable require "rock". For example, modify package.preload.
  3. Finally Lua static executable is built. It is linked with all static libraries produced by rocks used. The only difference from normal lua.exe is that it calls functions rockopen_<rock> after creating a Lua state.
  4. When building libs, C sources are changed to replace lua_newstate (and luaL_newstate) with a wrapper calling the original function plus rockopens. This enables using rocks from modules creating additional Lua states (e.g., llthreads).

Current rockspec format has enough information to implement all these cool features in LuaRocks and to build static executables from Lua scripts with just luarocks make --static without modifying rocks.

starius referenced this pull request in starius/luarocks Feb 24, 2016
@hishamhm
Copy link
Member

hishamhm commented May 3, 2016

Current rockspec format has enough information to implement all these cool features in LuaRocks and to build static executables from Lua scripts with just luarocks make --static without modifying rocks.

...if the rockspec uses the builtin type. This is a big "if" (even if 80% of all rocks are builtin). Torch people use build.type="cmake" a lot, for example.

@hishamhm
Copy link
Member

hishamhm commented May 3, 2016

Merged in luarocks-3 branch! As promised in... 2014 :-P

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.

None yet

5 participants