# LuaRocks Integration
LRocket supports integration with the [luarocks](https://luarocks.org) module manager and build system.
In order to enable compilation via lrocket, luarocks projects may add the '[luarocks-build-lrocket](https://luarocks.org/modules/sewbacca/luarocks-build-lrocket)' module in the `dependencies` of their rockspec file. The module provides the `lrocket` build type, which invokes `lrc` to bundle and compile the project:
**Example rockspec:**
```lua
build = {
type = 'lrocket',
entrypoint = 'main.lua',
output = 'bin/program' -- compiles into ./bin/program or 'bin/program.exe' on windows
},
dependencies = {
'luarocks-build-lrocket'
}
```
Running the `luarocks build` command will now bundle and compile all code contained in the entrypoint `main.lua` and produce `./bin/program` (or `bin/program.exe` on windows).
Naturally this will also include the code of all additional lua files and c modules required by the file:
```
> luarocks build
```
**What about C-based rocks and static linking?**
luarocks-build-lrocket configures the luarocks package manager to compile all newly installed packages or dependencies that contain C code into both, a shared library (.dll/.so) and a static archive (.a/.lib)!
This means any native package available on [luarocks.org](https://luarocks.org) and supported by the mechanism\* can be statically linked into the executable with no .dll/.so required.
If a native package is not supported, `lrc` will automatically fallback to using the .dll/.so instead. This can also be configured using the `prefer_c_module_type` rockspec build option (see the section below for a [full list](#rockspec-build-options) of available build options).
\* The method is based on the [lr-hooks](https://codeberg.org/leso-kn/lr-hooks) framework and works on any package that uses the luarocks 'builtin' build system and is likely to work on packages using a Makefile.
## rockspec Build Options
luarocks-build-lrocket generally translates all flags supported by `lrc` to rockspec options.
The current list of available build options can be found below:
| Option | Description |
| ------ | ----------- |
| `entrypoint` | **required:** Main lua file |
| `c_header_out` | Output filename of the companion C header |
| `c_module_name` | Name of the target C module (luaopen_) |
| `cflags` | Extra arguments to the C compiler |
| `debug`
- `'all'`
- `'project'`
- `'module'`
| Add debugging information to the output file |
| `exclude` | Exclude given modules from search |
| `extra_modules` | Explicitly include the specified module |
| `fuzzy`
default: `true` | Examine complex require statements when resolving modules |
| `keep_intermediate`
default: `false` | Do not remove intermediate C code after compilation |
| `liblua_shared`
default: `false` | Link against the dynamic variant of the Lua library |
| `link_sibling_deps`
default: `true` | Resolve dynamic dependencies of statically linked lua modules by scanning equally named dynamic modules |
| `log_level`
- `'none'`
- `'error'`
- `'warn'`
- `'info'`
- `'debug'`
| lrocket compiler: level of verbosity |
| `no_std_paths`
default: `false` | Ignore standard Lua paths |
| `optimize`
- `'none'`
- `'speed'`
- `'size'`
| Enable optimizations |
| `otype`
- `'executable'`
- `'shared'`
- `'lua'`
- `'executable-c'`
- `'shared-c'`
| Output file format |
| `output` | Output filename |
| `prefer_c_module_type`
default: `'static'` | Choose preferred variant of Lua C modules |
| `windows_gui`
default: `false` | Link with /SUBSYSTEM:WINDOWS (or -mwindows for MinGW) |
_The Luarocks logo was created by [Hisham Muhammad](https://hisham.hm/projects)._