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

Adds support for compiling shared library for Luac #1

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions hererocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,9 @@ def add_options_to_version_suffix(self):
if opts.no_readline:
options.append(("readline", "false"))

if opts.no_shared:
options.append(("shared", "false"))

if options:
self.version_suffix += " (" + (", ".join(
opt + ": " + value for opt, value in options)) + ")"
Expand Down Expand Up @@ -1042,14 +1045,17 @@ def __init__(self, version):

if opts.target == "mingw" or using_cl():
self.dll_file = "lua5" + self.major_version[2] + ".dll"
self.so_file = None
else:
self.dll_file = None
self.so_file = "liblua5" + self.major_version[2] + ".so"

def set_identifiers(self):
super(RioLua, self).set_identifiers()

self.identifiers["readline"] = str(not opts.no_readline).lower()
self.identifiers["patched"] = str(opts.patch).lower()
self.identifiers["shared"] = str(not opts.no_shared).lower()

def major_version_from_version(self):
return self.version[:3]
Expand Down Expand Up @@ -1191,6 +1197,8 @@ def make(self):
cc = ["cl", "/nologo", "/MD", "/O2", "/W3", "/c", "/D_CRT_SECURE_NO_DEPRECATE"]
else:
cflags = ["-O2", "-Wall", "-Wextra"] + cflags
if not opts.no_shared:
cflags = ["-fPIC"] + cflags

lflags.append("-lm")
static_cflags = list(cflags)
Expand Down Expand Up @@ -1230,6 +1238,11 @@ def make(self):
run("ar", "rcu", self.arch_file, lib_objs)
run("ranlib", self.arch_file)
run(cc, "-o", self.luac_file, luac_objs, self.arch_file, lflags)
if not opts.no_shared:
so_lflags = [ "-ldl",
"-Wl,--whole-archive,--soname={}".format(self.so_file),
"-Wl,--no-as-needed"] + lflags + [self.arch_file, "-Wl,--no-whole-archive"]
run(cc, "-o", self.so_file, "-shared", so_lflags)

if opts.target == "mingw":
run(cc, "-shared", "-o", self.dll_file, lib_objs)
Expand Down Expand Up @@ -1265,6 +1278,8 @@ def make_install(self):
"lua.h", "luaconf.h", "lualib.h", "lauxlib.h", lua_hpp)

copy_files(os.path.join(opts.location, "lib"), self.arch_file)
if self.so_file and not opts.no_shared:
copy_files(os.path.join(opts.location, "lib"), self.so_file)

class LuaJIT(Lua):
name = "LuaJIT"
Expand Down Expand Up @@ -1792,6 +1807,8 @@ def main(argv=None):
"vs13_32", "vs13_64", "vs15_32", "vs15_64"
], metavar="{linux,macosx,freebsd,mingw,posix,generic,mingw,vs,vs_XX,vsXX_YY}",
default=get_default_lua_target())
parser.add_argument("--no-shared", help="Don't make a shared library when building standard Lua.",
action="store_true", default=False)
parser.add_argument("--no-readline", help="Don't use readline library when building standard Lua.",
action="store_true", default=False)
parser.add_argument("--downloads",
Expand Down