• Stars
    star
    175
  • Rank 218,059 (Top 5 %)
  • Language
    Lua
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Easily build a standalone executable for any Lua program

Luapak

Build Status Windows Build Status LDoc

Luapak is a command-line tool that offers complete, multi-platform (Linux, macOS, and Windows), adjustable, all-in-one (yet modular) solution for building a standalone, zero-dependencies, possibly statically linked (only on Linux) executable for (almost) any Lua program. It Just Works!

  1. Resolves, builds and installs project’s Lua dependencies (declared in rockspec) from LuaRocks. Lua/C modules (aka native extensions) are built as static libraries (.a archive files), so they can be statically linked into resulting executable.[1]

  2. Resolves actually required Lua and Lua/C modules (.lua and .a files) using static code analysis of the project and its dependencies (recursively).

  3. Merges all required Lua modules into a single Lua script.

  4. Minifies the Lua script (i.e. removes unnecessary characters to shrink its size) using LuaSrcDiet.

  5. Compresses the Lua script using BriefLZ algorithm.

  6. Embeds the Lua script into a generated C wrapper.

  7. Compiles the C wrapper and links it with Lua interpreter (PUC Lua 5.1–5.3 and LuaJIT supported) and Lua/C libraries (aka native extensions) into a standalone executable.

All these steps can be run with single command luapak make <rockspec>, or separately if you need more control. You can discover available commands and their options in section Commands.

Table of Contents

Commands

luapak make

Click here to expand…
Usage: luapak make [options] [PACKAGE...]
       luapak make --help

Makes a standalone executable from Lua package(s). This is the main Luapak
command that handles entire process from installing dependencies to
compiling executable.
Arguments:
  PACKAGE                         Lua package to build specified as <source-dir>:<rockspec>.
                                  :<rockspec> may be omitted if the <source-dir> or
                                  <source-dir>/rockspec(s) contains single rockspec, or multiple
                                  rockspecs for the same package (i.e. with different version).
                                  In the further case rockspec with the highest version is used.
                                  <source-dir>: may be omitted if the <rockspec> is in the
                                  project's source directory or rockspec(s) subdirectory.
                                  If no argument is given, the current directory is used as
                                  <source-dir>.

Options:
  -s, --entry-script=FILE         The entry point of your program, i.e. the main Lua script. If not
                                  specified and the last PACKAGE defines exactly one CLI script,
                                  then it's used.

  -e, --exclude-modules=PATTERNS  Module(s) to exclude from dependencies analysis and the
                                  generated binary. PATTERNS is one or more glob patterns matching
                                  module name in dot notation (e.g. "pl.*"). Patterns may be
                                  delimited by comma or space. This option can be also specified
                                  multiple times.

  -g, --debug                     Enable debug mode, i.e. preserve line numbers, module names and
                                  local variable names for error messages and backtraces.

  -i, --include-modules=PATTERNS  Extra module(s) to include in dependencies analysis and add to
                                  the generated binary. PATTERNS has the same format as in
                                  "--exclude-module".

      --lua-impl=NAME             The Lua implementation that should be used - "PUC" (default),
                                  or "LuaJIT". This is currently used only as a hint to find the
                                  correct library and headers when auto-detection is used
                                  (i.e. --lua-incdir or --lua-lib is not specified).

      --lua-incdir=DIR            The directory that contains Lua (or LuaJIT) headers. If not
                                  specified, luapak will look for the lua.h (and luajit.h) file
                                  inside: Luarock's LUA_INCDIR, ./vendor/lua, ./deps/lua,
                                  /usr/local/include, and /usr/include. If --lua-version is
                                  specified, then it will also try subdirectories lua<version> and
                                  lua-<version> of each of the named directories and verify that
                                  the found lua.h (or luajit.h) is for the specified Lua
                                  (or LuaJIT) version.

      --lua-lib=FILE              The library of Lua interpreter to include in the binary. If not
                                  specified, luapak will try to find library with version
                                  corresponding to the headers inside Luarock's LUA_LIBDIR,
                                  ./vendor/lua, ./deps/lua, /usr/local/lib, /usr/local/lib64,
                                  /usr/lib, and /usr/lib64.

      --lua-version=VERSION       The version number of Lua (or LuaJIT) headers and library to try
                                  to find (e.g. "5.3", "2.0").

  -o, --output=FILE               Output file name or path. Defaults to base name of the main
                                  script with stripped .lua extension.

  -C, --no-compress               Disable BriefLZ compression of Lua sources.

  -M, --no-minify                 Disable minification of Lua sources.

  -t, --rocks-tree=DIR            The prefix where to install required modules. Default is
                                  ".luapak" in the current directory.
  -q, --quiet                     Be quiet, i.e. print only errors.

  -v, --verbose                   Be verbose, i.e. print debug messages.

  -h, --help                      Display this help message and exit.

Environment Variables:
  AR          Archive-maintaining program; default is "ar".
  CC          Command for compiling C; default is "gcc".
  CMAKE       Command for processing CMakeLists.txt files; default is "cmake".
  CFLAGS      Extra flags to give to the C compiler; default is "-Os -fPIC".
  LD          Command for linking object files and archive files; default is "ld".
  LDFLAGS     Extra flags to give to compiler when they are supposed to invoke the linker;
              default on macOS is "-pagezero_size 10000 -image_base 100000000".
  MAKE        Command for executing Makefile; default is "make".
  RANLIB      Command for generating index to the contents of an archive; default is "ranlib".
  STRIP       Command for discarding symbols from an object file; default is "strip".

luapak analyse-deps

Click here to expand…
Usage: luapak analyse-deps [-a|-f|-m|-g] [options] FILE...
       luapak analyse-deps --help

Analyses dependency graph of Lua module(s) using static code analysis (looks
for "require" expressions).
Arguments:
  FILE                        The entry point(s); path(s) to Lua script(s) to analyse.

Options:
  -a, --all                   Print all information (default).
  -f, --found                 Print only found modules.
  -m, --missing               Print only missing modules.
  -g, --ignored               Print only excluded/ignored modules.

  -e, --excludes=PATTERNS     Module(s) to exclude from the dependencies analysis. PATTERNS is one
                              or more glob patterns matching module name in dot notation
                              (e.g. "pl.*"). Patterns may be delimited by comma or space. This
                              option can be also specified multiple times.

  -n, --ignore-errors         Ignore errors from dependencies resolution (like unredable or unparseable files).

  -P, --no-pcalls             Do not analyse pcall requires.

  -W, --no-wildcards          Do not expand "wildcard" requires.

  -p, --pkg-path=PATH         The path pattern where to search for Lua and C/Lua modules instead of
                              the default path.

  -v, --verbose               Be verbose, i.e. print debug messages.

  -h, --help                  Display this help message and exit.

luapak build-rock

Click here to expand…
Usage: luapak build-rock [options] ROCKSPEC...
       luapak build-rock --help

Builds Lua/C module as a library archive suitable for static linking
and installs it into rocks tree.
Arguments:
  ROCKSPEC                    Path of the rockspec file to build and install.

Options:
  -C, --directory=DIR         Change directory before doing anything.

  -i, --lua-impl=NAME         The Lua implementation that should be used - "PUC" (default), or
                              "LuaJIT". This is currently used only as a hint to find the correct
                              headers when auto-detection is used (i.e. --lua-incdir unspecified).

  -I, --lua-incdir=DIR        The directory that contains Lua (or LuaJIT) headers. If not
                              specified, luapak will look for the lua.h (and luajit.h) file inside:
                              Luarock's LUA_INCDIR, ./vendor/lua, ./deps/lua, /usr/local/include,
                              and /usr/include. If --lua-version is specified, then it will also
                              try subdirectories lua<version> and lua-<version> of each of the
                              named directories and verify that the found lua.h (or luajit.h) is
                              for the specified Lua (or LuaJIT) version.

  -l, --lua-version=VERSION   The version number of Lua (or LuaJIT) headers and library to try
                              to find (e.g. "5.3", "2.0").

  -t, --rocks-tree=DIR        The prefix where to install Lua/C modules Default is ".luapak" in
                              the current directory.

  -v, --verbose               Be verbose, i.e. print debug messages.

  -h, --help                  Display this help message and exit.

Environment Variables:
  AR          Archive-maintaining program; default is "ar".
  CC          Command for compiling C; default is "gcc".
  CMAKE       Command for processing CMakeLists.txt files; default is "cmake".
  CFLAGS      Extra flags to give to the C compiler; default is "-Os -fPIC".
  LD          Command for linking object files and archive files; default is "ld".
  LDFLAGS     Extra flags to give to compiler when they are supposed to invoke the linker;
              default on macOS is "-pagezero_size 10000 -image_base 100000000".
  MAKE        Command for executing Makefile; default is "make".
  RANLIB      Command for generating index to the contents of an archive; default is "ranlib".

luapak merge

Click here to expand…
Usage: luapak merge [options] MODULE...
       luapak merge --help

Combines multiple Lua modules into a single file. Each module is be wrapped in
a function, or string loaded by "load" (--debug), and assigned to
"package.preload" table.
Arguments:
  MODULE                    Name and path of Lua module delimited with "="
                            (e.g. "luapak.utils=luapak/utils.lua") or just path of module.

Options:
  -g, --debug               Preserve module names and line numbers in error backtraces?
  -o, --output=FILE         Where to write the generated code. Use "-" for stdout. Default is "-".
  -v, --verbose             Be verbose, i.e. print debug messages.
  -h, --help                Display this help message and exit.

luapak minify

Click here to expand…
Usage: luapak minify [options] [FILE]
       luapak minify --help

Minifies Lua source code - removes comments, unnecessary white spaces and
empty lines, shortens numbers and names of local variables.
Arguments:
  FILE                        Path of the Lua source file, or "-" for stdin.

Options:
  -l, --keep-lno              Do not affect line numbers.
  -n, --keep-names            Do not rename local variables.
  -o, --output=FILE           Where to write the output. Use "-" for stdout. Default is "-".
  -v, --verbose               Be verbose, i.e. print debug messages.
  -h, --help                  Display this help message and exit.

luapak wrapper

Click here to expand…
Usage: luapak wrapper [options] FILE [MODULE_NAME...]
       luapak wrapper --help

Wraps Lua script into a generated C file that can be compiled and linked with
Lua interpreter and Lua/C native extensions into a standalone executable.
Arguments:
  FILE                        The Lua file to embed into the wrapper.
  MODULE_NAME                 Name of native module to preload (e.g. "cjson").

Options:
  -C, --no-compress           Do not compress FILE using BriefLZ algorithm.
  -o, --output=FILE           Where to write the generated code; "-" for stdout. Default is "-".
  -v, --verbose               Be verbose, i.e. print debug messages.
  -h, --help                  Display this help message and exit.

What Luapak Is Not?

  • Luapak is not a transpiler from Lua to C, nor compiler to a native code. It does not save you from runtime errors in your Lua code, nor increase its performance.

Installation

Note: If you want to bootstrap development environment for running tests, read the next section.

Using LuaRocks

You can install luapak using LuaRocks (the Lua package manager):

luarocks install luapak

or to get the latest development version:

luarocks install --server=http://luarocks.org/dev luapak

Download Standalone Binary

You can also download standalone Luapak binaries for Linux, macOS and Windows from Releases.

Note: Linux binaries are statically linked with musl libc, so they should work on any Linux system.

Set Up Development Environment

  1. Clone this repository:

    git clone https://github.com/jirutka/luapak.git
    cd luapak
  2. Source file .envrc into your shell (or manually add $(pwd)/.venv/bin to your PATH):

    source .envrc
  3. Install Lua and modules for running tests into directory .venv:

    ./script/bootstrap
  4. Start hacking!

  5. Run linters:

    ./script/test

TODO

  • Write documentation into README.

  • Write integration tests.

  • Analyse usage of Lua standard modules and exclude unused from the binary.

Similar Projects

Luapak is not the first tool for packing Lua code into standalone executable, but it’s the most complete. Here’s a list of similar projects I know about, some of them served as an inspiration for Luapak.

License

This project is licensed under MIT License. For the full text of the license, see the LICENSE file.


1. Luapak includes LuaRocks package manager with rewritten builtin build backend and modified settings to build Lua/C modules as static libraries. Other backends (make, cmake, …) are not supported in the sense that Luapak cannot alter build process to produce static libraries; it’s up to the user to ensure that.

More Repositories

1

rsql-parser

Parser for RSQL / FIQL – query language for RESTful APIs
Java
685
star
2

spring-rest-exception-handler

A convenient Spring MVC exception handler for RESTful APIs.
Java
354
star
3

maven-badges

Badge for Maven Central
Ruby
240
star
4

ssh-ldap-pubkey

Utility to manage SSH public keys stored in LDAP.
Python
217
star
5

ldap-passwd-webui

Very simple web interface for changing password stored in LDAP or Active Directory (Samba 4 AD).
Python
198
star
6

esh

Simple templating engine based on shell.
Shell
172
star
7

ngx-oauth

OAuth 2.0 proxy for nginx written in Lua.
Lua
156
star
8

validator-collection

The easiest way to validate collections of basic types using Bean Validation.
Java
120
star
9

smlar

PostgreSQL extension for an effective similarity search || mirror of git://sigaev.ru/smlar.git || see https://www.pgcon.org/2012/schedule/track/Hacking/443.en.html
C
110
star
10

zsh-shift-select

Select text in Zsh command line using Shift, as in many text editors and GUI programs
Shell
107
star
11

setup-alpine

Easily use Alpine Linux on GitHub Actions, with support for QEMU user emulator
Shell
105
star
12

tty-copy

Copy content to system clipboard via TTY and terminal using ANSI OSC52 sequence
C
94
star
13

validator-spring

Bean Validator utilizing Spring Expression Language (SpEL)
Java
84
star
14

asciidoctor-html5s

Semantic HTML5 converter (backend) for Asciidoctor
HTML
79
star
15

luasrcdiet

Compresses Lua source code by removing unnecessary characters (updated fork of http://luasrcdiet.luaforge.net/)
Lua
64
star
16

apk-autoupdate

Automatic updates for Alpine Linux and other systems using apk-tools
Shell
45
star
17

embedmongo-spring

Spring Factory Bean for “Embedded” MongoDB
Java
44
star
18

nginx-binaries

Nginx and njs binaries for Linux (x86_64, aarch64, ppc64le), macOS and Windows. Linux binaries are static so works on every Linux.
TypeScript
44
star
19

otf2bdf

OpenType to BDF Converter (unofficial mirror)
C
42
star
20

njs-typescript-starter

A starting template for developing njs (NGINX JavaScript) scripts for NGINX server in TypeScript.
JavaScript
42
star
21

apcupsd-snmp

Apcupsd module for Net-SNMP
Perl
41
star
22

doas-sudo-shim

sudo shim for doas
Shell
39
star
23

qemu-openrc

OpenRC init script for QEMU/KVM (for Gentoo and Alpine Linux)
Shell
30
star
24

rake-jekyll

Rake tasks for Jekyll as a gem.
Ruby
30
star
25

akms

Alpine Kernel Module Support – aka DKMS for Alpine Linux
Shell
29
star
26

corefines

💎 A collection of refinements for Ruby core classes with a compatibility mode for older Rubies and a convenient syntactic sugar.
Ruby
26
star
27

user-aports

My Alpine Linux aports that are not in official repository yet or don’t adhere to Alpine polices (bundles)
Shell
26
star
28

ipynb2html

Convert Jupyter (IPython) Notebooks to static HTML
TypeScript
26
star
29

sh-parser

Parser of POSIX Shell Command Language
Lua
25
star
30

zzz

A simple program to suspend or hibernate your computer 💤
C
22
star
31

nginx-testing

Support for integration/acceptance testing of nginx configuration in TypeScript/JavaScript.
TypeScript
21
star
32

asciidoctor-highlight.js

Asciidoctor.js extension for highlighting code in build time using Highlight.js
JavaScript
21
star
33

opensmtpd-filter-rewrite-from

OpenSMTPD 6.6+ filter for rewriting From address
Awk
18
star
34

asciidoctor-rouge

Rouge code highlighter support for Asciidoctor (OBSOLETE)
Ruby
18
star
35

efi-mkuki

EFI Unified Kernel Image Maker
Shell
17
star
36

asciidoctor-katex

Asciidoctor extension for converting latexmath using KaTeX at build time
Ruby
17
star
37

babel-preset-njs

A Babel preset for njs - NGINX JavaScript
JavaScript
17
star
38

ssh-getkey-gitlab

A simple script to be used as AuthorizedKeysCommand in OpenSSH server to look up user’s public keys in GitLab or GitHub.
Shell
17
star
39

unidecode

Transliteration from Unicode to US-ASCII and ISO 8859-2.
Java
14
star
40

alpine-zsh-config

A sensible system-wide Zsh configuration for Alpine Linux
Shell
14
star
41

haste-client

CLI client for haste-server (hastebin.com) written in Python
Python
13
star
42

ts-transformer-inline-file

A TypeScript custom transformer for inlining files
TypeScript
12
star
43

argp

Rust derive-based argument parsing optimized for code size and flexibility
Rust
12
star
44

stunnel-static

stunnel built as a fully static binary
Shell
11
star
45

swaylockd

A dumb launcher to spawn swaylock and ensure it runs no matter what
C
11
star
46

ssh-getkey-ldap

A simple script to be used as AuthorizedKeysCommand in OpenSSH server to look up user’s public keys in LDAP.
Lua
11
star
47

ansible-gentoo-roles

A curated list of Ansible roles for Gentoo Linux.
10
star
48

asciidoctor-include-ext

Asciidoctor’s standard include processor reimplemented as an extension
Ruby
9
star
49

muacme

A convenient wrapper for the ACMEv2 client uacme
Shell
8
star
50

rsql-hibernate

This project is outdated. Use https://github.com/tennaito/rsql-jpa instead.
Java
8
star
51

github-pr-closer

GitHub webhook handler for closing pull requests that have been merged using rebase etc.
Python
8
star
52

dokuwiki2adoc

Converter from DokuWiki to AsciiDoc formatted text files.
Shell
8
star
53

sloci-image

Simple script for creating single-layer OCI images.
Shell
8
star
54

brieflz.lua

Lua binding for BriefLZ compression library
C
7
star
55

asciidoctor-interdoc-reftext

Asciidoctor extension providing implicit (automatic) reference text (label) for inter-document cross references
Ruby
7
star
56

spring-boot-openrc

OpenRC init script for Java applications based on Spring Boot
Shell
7
star
57

efi-mkkeys

Script to easily generate self-signed UEFI keys for Secure Boot
Shell
7
star
58

rsub-client

Open and edit files from a remote machine in your local Sublime Text or TextMate 2.
Python
6
star
59

git-metafile

Store and restore files metadata (mode, owner, group) in a git repository
Rust
6
star
60

unboundid-spring

Spring Factory Beans for UnboundID LDAP SDK
Java
6
star
61

alpkit

Rust library and CLI tool for reading Alpine Linux’s apk package format and APKBUILD
Rust
5
star
62

emscripten-travis-example

How to easily use Emscripten on Travis CI or any other CI
C
5
star
63

cesnet-tcs-cli

CLI client utility for CESNET TCS API
Shell
5
star
64

slava-ukrajine

Слава Україні! / Sláva Ukrajině! – grafika
4
star
65

asciidoctor-templates-compiler

Compile templates-based Asciidoctor converter (backend) into a single Ruby file
Ruby
4
star
66

spring-http-client-cache

A very simple HTTP cache for the Spring’s RestTemplate.
4
star
67

one-context

OpenNebula contextualization scripts for Alpine Linux and Gentoo
Shell
4
star
68

uidmapshift

Shift UIDs/GIDs of directory entries recursively by some offset
Lua
4
star
69

yaml-env-tag

Custom YAML tag for referring environment variables in YAML documents
Ruby
3
star
70

mtype

An enhanced Lua type() function that looks for __type metafield
Lua
3
star
71

CSFD-parser

Parser for movie pages and search on CSFD.cz
Python
3
star
72

commons-hibernate

My collection of reusable Java classes for Hibernate.
Java
3
star
73

virt-init

Provisioning scripts for Alpine Linux VMs
Shell
3
star
74

keycloak-json-schema

JSON schemas for Keycloak realm configuration
JavaScript
3
star
75

redmine_agile

Archive of redmine_agile plugin downloaded from https://www.redmineup.com/pages/plugins/agile
Ruby
3
star
76

apk-deploy-tool

Tool for easily deploying applications or configuration packaged in APK packages via SSH
Shell
3
star
77

collectd-apk

Collectd plugin for apk-tools
C
2
star
78

tash

WIP
Shell
2
star
79

acpi-utils

ACPI utilities for use in scripts and one-liners
Shell
2
star
80

gversion.lua

Lua library for Gentoo-style versioning format
Lua
2
star
81

nginx-oidc-njs

OpenID Connect and OAuth 2.0 module for NGINX written in njs.
TypeScript
2
star
82

jabber-migrate

Tool for migration of a roster from one Jabber server to another.
Java
2
star
83

alpine-git-mirror-syncd

Lua script that listens on MQTT and synchronizes Git mirrors when notified about changes
Lua
2
star
84

spring-modular

Modularize Spring applications simply!
Java
2
star
85

spring-security-oauth-samples

Modified samples from Spring Security OAuth project
Java
2
star
86

collectd-openrc

Collectd plugin for OpenRC
C
2
star
87

hass-smarwi

Home Assistant integration for Vektiva SMARWI window opener
Python
2
star
88

macos-init

Simplified cloud-init for macOS
Shell
2
star
89

com.meetfranz.Franz

Flatpak for Franz
1
star
90

prebackup

Pre/post backup scripts
Shell
1
star
91

slim-htag

Slim filter providing a heading tag with parametrized (dynamic) level (h1-h6)
Ruby
1
star
92

beuri-parser

Parser of Boolean Expressions in URI
Java
1
star
93

my-void-packages

My package templates for Void Linux
Shell
1
star
94

ts-transformer-export-default-name

TypeScript AST transformer that assigns name to anonymous functions and classes exported as default
TypeScript
1
star
95

ansible-modules

Some unofficial Ansible modules.
Python
1
star
96

roundcube-virtuser_ldap

A Roundcube plugin for LDAP based User-to-Email and Email-to-User lookup
PHP
1
star
97

sublimedsl

Simple pythonic DSL for generating Sublime Text configs.
Python
1
star
98

shaj

C
1
star
99

atom-jaxb

Custom JAXB classes for Atom Syndication Format
Java
1
star
100

nginx-jsconf

JS library and a CLI tool to convert nginx configuration from YAML or JSON to nginx config format
TypeScript
1
star