Skip to content
This repository was archived by the owner on Dec 29, 2024. It is now read-only.

Commit 392bb28

Browse files
authored
Cleanup build system some, Add cdb alias for extension builds (#181)
1 parent e9129f2 commit 392bb28

4 files changed

Lines changed: 84 additions & 147 deletions

File tree

SConstruct

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ import os
33
import sys
44
import fnmatch
55

6+
from config import configure
7+
8+
Export('configure')
69
env = SConscript("external/SConscript")
7-
env.tools=['mingw']
10+
env.Tool('compilation_db')
811

912
env.Append(CPPDEFINES = ['LAPI_GDEXTENSION'])
1013
env.Append(CPPPATH = [Dir('src').abspath, Dir('external').abspath])
@@ -23,6 +26,9 @@ if env["luaapi_luaver"] == 'jit':
2326
elif env["luaapi_luaver"] == '5.1':
2427
env.Append(CPPDEFINES=['LAPI_51'])
2528

29+
cdb = env.CompilationDatabase('compile_commands.json')
30+
Alias('cdb', cdb)
31+
2632
library = env.SharedLibrary(
2733
"project/addons/luaAPI/bin/libluaapi{}{}".format(env["suffix"], env["SHLIBSUFFIX"]),
2834
source=sources,

external/SConscript

Lines changed: 7 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,17 @@
1-
# Used for extension builds
2-
import sys
3-
import os
4-
import platform
5-
6-
def configure(env):
7-
from SCons.Script import BoolVariable, EnumVariable, Variables, Help
8-
9-
env_vars = Variables()
10-
11-
env_vars.Add(BoolVariable("luaapi_luajit_build",
12-
"When LuaAPI is using luaJIT, be default it will attempt to build it automatically. if you prefer you can build it manually and disable auto building with this flag. Make sure to build statically and that the libs are in external/luaJIT/src",
13-
True))
14-
15-
env_vars.Add(EnumVariable("luaapi_host_cc",
16-
"LuaJIT builds some tools to assist with the rest of the build. You can set the host CC to be used here in the case of cross compilation.", "gcc", ("gcc", "clang")))
17-
18-
env_vars.Add(EnumVariable("luaapi_luaver",
19-
"Build the LuaAPI module with the following lua VM", "5.4", ("5.4", "5.1", "jit")))
20-
21-
env_vars.Update(env)
22-
Help(env_vars.GenerateHelpText(env))
23-
24-
def run(cmd):
25-
print("Running: %s" % cmd)
26-
res = os.system(cmd)
27-
code = 0
28-
if (os.name == 'nt'):
29-
code = res
30-
else:
31-
code = os.WEXITSTATUS(res)
32-
if code != 0:
33-
print("Error: return code: " + str(code))
34-
sys.exit(code)
35-
36-
def build_luajit():
37-
os.chdir("luaJIT")
38-
# cross compile linux->windows
39-
if env['platform'] == 'windows':
40-
host_arch = platform.machine()
41-
run("make clean")
42-
if (host_arch != env['arch']):
43-
if (host_arch == 'x86_64' and env['arch'] == 'x86_32'):
44-
host_cc = env['luaapi_host_cc'] + ' -m32'
45-
run('make HOST_CC="%s" CROSS="%s" BUILDMODE="static" TARGET_SYS=Windows TARGET_CFLAGS="-fPIC"' % (host_cc, env['CC'].replace("-gcc", "-").replace("-clang", "-")))
46-
47-
else:
48-
print("ERROR: Unsupported cross compile!")
49-
sys.exit(-1)
50-
else:
51-
run('make HOST_CC="%s" CROSS="%s" BUILDMODE="static" TARGET_SYS=Windows TARGET_CFLAGS="-fPIC"' % (env['luaapi_host_cc'], env['CC'].replace("-gcc", "-").replace("-clang", "-")))
52-
53-
elif env['platform']=='macos':
54-
run("make clean MACOSX_DEPLOYMENT_TARGET=10.12")
55-
arch = env['arch']
56-
if arch == "universal":
57-
run('make CC="%s" TARGET_FLAGS="-arch x86_64" MACOSX_DEPLOYMENT_TARGET=10.12' % (env['CC']))
58-
run('mv src/libluajit.a src/libluajit64.a')
59-
run('make clean MACOSX_DEPLOYMENT_TARGET=10.12')
60-
run('make CC="%s" TARGET_FLAGS="-arch arm64" MACOSX_DEPLOYMENT_TARGET=10.12' % (env['CC']))
61-
run('lipo -create src/libluajit.a src/libluajit64.a -output src/libluajit.a')
62-
run('rm src/libluajit64.a')
63-
else:
64-
run('make CC="%s" TARGET_FLAGS="-arch %s" MACOSX_DEPLOYMENT_TARGET=10.12' % (env['CC'], arch))
65-
66-
elif env['platform']=='linux':
67-
host_arch = platform.machine()
68-
run("make clean")
69-
if (host_arch != env['arch']):
70-
if (host_arch == 'x86_64' and env['arch'] == 'x86_32'):
71-
host_cc = env['luaapi_host_cc'] + ' -m32'
72-
run('make HOST_CC="%s" CROSS="%s" BUILDMODE="static" TARGET_CFLAGS="-fPIC"' % (host_cc, env['CC'].replace("-gcc", "-").replace("-clang", "-")))
73-
74-
else:
75-
print("ERROR: Unsupported cross compile!")
76-
sys.exit(-1)
77-
78-
else:
79-
run('make CC="%s" BUILDMODE="static" TARGET_CFLAGS="-fPIC"' % env['CC'])
80-
81-
else:
82-
print("ERROR: Unsupported platform '%s'." % env['platform'])
83-
sys.exit(-1)
1+
# Used for extension builds
2+
from build_luajit import build_luajit
843

854
env = SConscript("godot-cpp/SConstruct")
5+
6+
Import('configure')
867
configure(env)
87-
env_lua = env.Clone()
888

9+
env_lua = env.Clone()
8910
luaver = env["luaapi_luaver"]
9011

9112
if luaver == "jit":
9213
if env["luaapi_luajit_build"]:
93-
build_luajit()
14+
build_luajit(env)
9415

9516
env.Append(LIBPATH=[Dir("luaJIT/src").abspath])
9617
env.Append(LIBS=['libluajit'])
@@ -127,4 +48,4 @@ else:
12748
env.Append(LIBPATH=[Dir("bin").abspath])
12849
env.Append(LIBS=[library_name])
12950

130-
Return('env')
51+
Return('env')

external/SCsub

Lines changed: 2 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,13 @@
11
Import('env')
22
Import('env_lua')
33

4-
import sys
5-
import os
6-
import platform
7-
8-
def run(cmd):
9-
print("Running: %s" % cmd)
10-
res = os.system(cmd)
11-
code = 0
12-
if (os.name == 'nt'):
13-
code = res
14-
else:
15-
code = os.WEXITSTATUS(res)
16-
if code != 0:
17-
print("Error: return code: " + str(code))
18-
sys.exit(code)
19-
20-
def build_luajit():
21-
if not env_lua.msvc:
22-
os.chdir("luaJIT")
23-
# cross compile linux->windows
24-
if env['PLATFORM'] == 'posix' and env['platform'] == 'windows':
25-
host_arch = platform.machine()
26-
run("make clean")
27-
if (host_arch != env['arch']):
28-
if (host_arch == 'x86_64' and env['arch'] == 'x86_32'):
29-
host_cc = env['luaapi_host_cc'] + ' -m32'
30-
run('make HOST_CC="%s" CROSS="%s" BUILDMODE="static" TARGET_SYS=Windows' % (host_cc, env['CC'].replace("-gcc", "-").replace("-clang", "-")))
31-
32-
else:
33-
print("ERROR: Unsupported cross compile!")
34-
sys.exit(-1)
35-
else:
36-
run('make HOST_CC="%s" CROSS="%s" BUILDMODE="static" TARGET_SYS=Windows' % (env['luaapi_host_cc'], env['CC'].replace("-gcc", "-").replace("-clang", "-")))
37-
38-
elif env['platform']=='macos':
39-
run("make clean MACOSX_DEPLOYMENT_TARGET=10.12")
40-
run('make CC="%s" TARGET_FLAGS="-arch %s" MACOSX_DEPLOYMENT_TARGET=10.12' % (env['CC'], env['arch']))
41-
42-
elif env['platform']=='linuxbsd':
43-
host_arch = platform.machine()
44-
run("make clean")
45-
if (host_arch != env['arch']):
46-
if (host_arch == 'x86_64' and env['arch'] == 'x86_32'):
47-
host_cc = env['luaapi_host_cc'] + ' -m32'
48-
run('make HOST_CC="%s" CROSS="%s" BUILDMODE="static"' % (host_cc, env['CC'].replace("-gcc", "-").replace("-clang", "-")))
49-
50-
else:
51-
print("ERROR: Unsupported cross compile!")
52-
sys.exit(-1)
53-
54-
else:
55-
run('make CC="%s" BUILDMODE="static"' % env['CC'])
56-
57-
else:
58-
print("ERROR: Unsupported platform '%s'." % env['platform'])
59-
sys.exit(-1)
60-
else:
61-
os.chdir("luaJIT/src")
62-
run("msvcbuild static")
4+
from build_luajit import build_luajit
635

646
luaver = env["luaapi_luaver"]
657

668
if luaver == "jit":
679
if env["luaapi_luajit_build"]:
68-
build_luajit()
10+
build_luajit(env)
6911
if env_lua.msvc:
7012
# hack for msvc builds. See https://github.com/godotengine/godot/issues/23687
7113
env.Append(LIBS=[File('luaJIT/src/luajit.lib')])

external/build_luajit.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import sys
2+
import os
3+
import platform
4+
5+
def run(cmd):
6+
print("Running: %s" % cmd)
7+
res = os.system(cmd)
8+
code = 0
9+
if (os.name == 'nt'):
10+
code = res
11+
else:
12+
code = os.WEXITSTATUS(res)
13+
if code != 0:
14+
print("Error: return code: " + str(code))
15+
sys.exit(code)
16+
17+
def build_luajit(env):
18+
if not env.msvc:
19+
os.chdir("luaJIT")
20+
21+
# cross compile posix->windows
22+
if (os.name == 'posix') and env['platform'] == 'windows':
23+
host_arch = platform.machine()
24+
run("make clean")
25+
if (host_arch != env['arch']):
26+
if (host_arch == 'x86_64' and env['arch'] == 'x86_32'):
27+
host_cc = env['luaapi_host_cc'] + ' -m32'
28+
run('make HOST_CC="%s" CROSS="%s" BUILDMODE="static" TARGET_SYS=Windows' % (host_cc, env['CC'].replace("-gcc", "-").replace("-clang", "-")))
29+
30+
else:
31+
print("ERROR: Unsupported cross compile!")
32+
sys.exit(-1)
33+
else:
34+
run('make HOST_CC="%s" CROSS="%s" BUILDMODE="static" TARGET_SYS=Windows' % (env['luaapi_host_cc'], env['CC'].replace("-gcc", "-").replace("-clang", "-")))
35+
36+
elif env['platform']=='macos':
37+
run("make clean MACOSX_DEPLOYMENT_TARGET=10.12")
38+
arch = env['arch']
39+
if arch == "universal":
40+
run('make CC="%s" TARGET_FLAGS="-arch x86_64" MACOSX_DEPLOYMENT_TARGET=10.12' % (env['CC']))
41+
run('mv src/libluajit.a src/libluajit64.a')
42+
run('make clean MACOSX_DEPLOYMENT_TARGET=10.12')
43+
run('make CC="%s" TARGET_FLAGS="-arch arm64" MACOSX_DEPLOYMENT_TARGET=10.12' % (env['CC']))
44+
run('lipo -create src/libluajit.a src/libluajit64.a -output src/libluajit.a')
45+
run('rm src/libluajit64.a')
46+
else:
47+
run('make CC="%s" TARGET_FLAGS="-arch %s" MACOSX_DEPLOYMENT_TARGET=10.12' % (env['CC'], arch))
48+
elif env['platform']=='linuxbsd' or env['platform']=='linux':
49+
host_arch = platform.machine()
50+
run("make clean")
51+
if (host_arch != env['arch']):
52+
if (host_arch == 'x86_64' and env['arch'] == 'x86_32'):
53+
host_cc = env['luaapi_host_cc'] + ' -m32'
54+
run('make HOST_CC="%s" CROSS="%s" BUILDMODE="static"' % (host_cc, env['CC'].replace("-gcc", "-").replace("-clang", "-")))
55+
56+
else:
57+
print("ERROR: Unsupported cross compile!")
58+
sys.exit(-1)
59+
60+
else:
61+
run('make CC="%s" BUILDMODE="static"' % env['CC'])
62+
63+
else:
64+
print("ERROR: Unsupported platform '%s'." % env['platform'])
65+
sys.exit(-1)
66+
else:
67+
os.chdir("luaJIT/src")
68+
run("msvcbuild static")

0 commit comments

Comments
 (0)