-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.lua
More file actions
56 lines (48 loc) · 1.58 KB
/
Copy pathbuild.lua
File metadata and controls
56 lines (48 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
-- build.lua — Compiles the C bridge module for lua-sys.
--
-- Linux/macOS: bridge.so/.dylib leaves lua* symbols unresolved at link time;
-- they are satisfied at load time from the host process image.
--
-- Windows: PE executables do not export symbols to DLLs, so we download a
-- pre-built libluajit and link it directly into bridge.dll. Guest states
-- use this embedded runtime — safe because lua-sys communicates with the
-- host exclusively through the Lua C API (push/pop, registry refs).
local build = require("lde-build")
local out = assert(os.getenv("LDE_OUTPUT_DIR"), "LDE_OUTPUT_DIR not set")
local ext, args
if jit.os == "Windows" then
ext = "dll"
local arch = jit.arch == "arm64" and "aarch64" or "x86-64"
local tarName = "libluajit-windows-" .. arch .. "-gnu.tar.gz"
local tarUrl = "https://github.com/lde-org/luajit/releases/download/latest/" .. tarName
build:write(tarName, build:fetch(tarUrl))
build:extract(tarName, "luajit")
build:delete(tarName)
local ljDir = out .. "/luajit/libluajit-windows-" .. arch .. "-gnu"
args = {
"-shared", "-O2",
"-I", out,
"-I", ljDir .. "/include",
"-o", out .. "/bridge." .. ext,
out .. "/bridge.c",
"-Wl,--whole-archive", ljDir .. "/lib/libluajit.a", "-Wl,--no-whole-archive",
"-lm",
}
elseif jit.os == "OSX" then
ext = "dylib"
args = {
"-dynamiclib", "-undefined", "dynamic_lookup", "-O2",
"-I", out,
"-o", out .. "/bridge." .. ext,
out .. "/bridge.c",
}
else
ext = "so"
args = {
"-shared", "-fPIC", "-O2",
"-I", out,
"-o", out .. "/bridge." .. ext,
out .. "/bridge.c",
}
end
build:cc(args)