Skip to content

Commit deb8621

Browse files
authored
Merge pull request #133 from cortex-command-community/luajit-meson
Linux build LuaJIT from external sources
2 parents d616222 + 725a986 commit deb8621

File tree

10 files changed

+99
-121
lines changed

10 files changed

+99
-121
lines changed

external/include/meson.build

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ external_inc_dirs = [include_directories('boost_1_75',
66
'thread-pool-3.5.0/include',
77
'hopscotch-map-2.3.1/include',)]
88
if host_machine.system() in ['linux', 'darwin']
9-
luajit_proj = subproject('LuaJIT-2.1', default_options: ['header_only=true'])
10-
external_inc_dirs += luajit_proj.get_variable('luajit_source_dir')
119
endif
1210
if host_machine.system() == 'windows'
1311
external_inc_dirs += include_directories('LZ4-1.9.3/LZ4',)

external/sources/LuaJIT-2.1/meson.build

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
# Meson files from github.com/franko/luajit
22
project('luajit', 'c', version : '2.0.5', default_options : ['c_winlibs='])
3-
if get_option('header_only')
4-
luajit_source_dir = include_directories('src')
5-
else
3+
64
pkg = import('pkgconfig')
75

86
cc = meson.get_compiler('c')
97
libm = cc.find_library('m', required : false)
108
libdl = cc.find_library('dl', required : false)
119
luajit_dependencies = [libm, libdl]
1210

11+
1312
luajit_source_dir = include_directories('src')
1413
luajit_abiver = '51'
1514

15+
if not meson.can_run_host_binaries()
16+
warning('Can\'t properly build in cross environment, using system library instead!')
17+
else
18+
1619
dynasm = files('dynasm/dynasm.lua')
1720

1821
subdir('src')
1922

20-
if not get_option('use_prebuilt_libraries') or host_machine.system() in ['darwin', 'linux']
23+
if not get_option('use_prebuilt_libraries') or host_machine.system() in ['linux', 'darwin']
2124
libluajit = library(lj_libname, ljlib_sources + ljcore_sources + buildvm_headers,
2225
include_directories: luajit_source_dir,
2326
c_args: lj_defines,
@@ -43,4 +46,4 @@ luajit_dep = declare_dependency(
4346
)
4447

4548
meson.override_dependency('luajit', luajit_dep)
46-
endif
49+
endif
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
1+
option('portable', type : 'boolean', value : false, description: 'portable install in a single directory')
2+
option('app', type : 'boolean', value : true, description: 'Build the luajit executable')
23
option('use_prebuilt_libraries', type: 'boolean', value: true, yield: true, description: 'On windows use the prebuilt libraries')
3-
option('header_only', type: 'boolean', value: false, description: 'Only expose the header files')

external/sources/LuaJIT-2.1/src/host/meson.build

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# Meson files from github.com/franko/luajit
21
minilua = executable('minilua', 'minilua.c', dependencies: libm, install: false, native: true)
32

43
lj_arch_run = cc.run(lj_arch_test_source)
@@ -28,7 +27,7 @@ buildvm_arch_h = custom_target('buildvm_arch.h',
2827
command : dasm_args,
2928
)
3029

31-
buildvm_sources = files(['buildvm.c', 'buildvm_asm.c', 'buildvm_peobj.c', 'buildvm_lib.c', 'buildvm_fold.c'])
30+
buildvm_sources = files('buildvm.c', 'buildvm_asm.c', 'buildvm_peobj.c', 'buildvm_lib.c', 'buildvm_fold.c')
3231
buildvm_sources += buildvm_arch_h
3332

3433
buildvm = executable('buildvm',
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
# Meson files from github.com/franko/luajit
21
jitlib_files = files('bc.lua', 'v.lua', 'dump.lua', 'dis_x86.lua', 'dis_x64.lua', 'dis_arm.lua', 'dis_ppc.lua', 'dis_mips.lua', 'dis_mipsel.lua', 'bcsave.lua')
2+
3+
if get_option('app')
4+
install_data(jitlib_files, install_dir: jitlib_install_dir)
5+
endif

external/sources/LuaJIT-2.1/src/lj_arch_test.c

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static void add_def(const char *args[], int *args_n, const char *def) {
2626
}
2727

2828
int main() {
29-
const char *lj_arch, *lj_os, *dasm_arch;
29+
const char *lj_arch, *dasm_arch;
3030
const char *arch_defs[16];
3131
int arch_defs_n = 0;
3232
const char *x_arch_option = NULL;
@@ -37,6 +37,8 @@ lj_arch = "x64";
3737
lj_arch = "x86";
3838
#elif LJ_TARGET_ARM
3939
lj_arch = "arm";
40+
#elif LJ_TARGET_ARM64
41+
lj_arch = "arm64";
4042
#elif LJ_TARGET_PPC
4143
lj_arch = "ppc";
4244
#elif LJ_TARGET_PPCSPE
@@ -59,36 +61,20 @@ if (x_arch_option) {
5961
arch_defs[arch_defs_n++] = x_arch_option;
6062
}
6163

62-
#if LUAJIT_OS == LUAJIT_OS_OTHER
63-
lj_os = "OTHER";
64-
#elif LUAJIT_OS == LUAJIT_OS_WINDOWS
65-
lj_os = "WINDOWS";
66-
#elif LUAJIT_OS == LUAJIT_OS_LINUX
67-
lj_os = "LINUX";
68-
#elif LUAJIT_OS == LUAJIT_OS_OSX
69-
lj_os = "OSX";
70-
#elif LUAJIT_OS == LUAJIT_OS_BSD
71-
lj_os = "BSD";
72-
#elif LUAJIT_OS == LUAJIT_OS_POSIX
73-
lj_os = "POSIX";
74-
#else
75-
fprintf(stderr, "Unsupported OS\n");
76-
exit(1);
77-
#endif
78-
79-
char luajit_os_def[128];
80-
sprintf(luajit_os_def, "-DLUAJIT_OS=LUAJIT_OS_%s", lj_os);
81-
arch_defs[arch_defs_n++] = luajit_os_def;
82-
83-
#if defined(LJ_TARGET_X64) && defined(LUAJIT_DISABLE_GC64)
84-
dasm_arch = "x86";
64+
#ifdef LJ_TARGET_X64
65+
dasm_arch = "x64";
8566
#else
8667
dasm_arch = lj_arch;
8768
#endif
8869

8970
const char *dasm[32];
9071
int dasm_n = 0;
9172

73+
#ifdef LJ_LE
74+
add_def(dasm, &dasm_n, "ENDIAN_LE");
75+
#else
76+
add_def(dasm, &dasm_n, "ENDIAN_BE");
77+
#endif
9278
#if LJ_ARCH_BITS == 64
9379
add_def(dasm, &dasm_n, "P64");
9480
#endif

external/sources/LuaJIT-2.1/src/meson.build

Lines changed: 35 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,32 @@
1-
# Meson files from github.com/franko/luajit
2-
3-
41
lj_arch_test_source = files('lj_arch_test.c')
52

6-
jitlib_install_dir = 'share' / ( 'luajit-' + meson.project_version() ) / 'jit'
3+
if get_option('portable')
4+
jitlib_install_dir = get_option('bindir') / 'lua' / 'jit'
5+
else
6+
jitlib_install_dir = 'share' / ( 'luajit-' + meson.project_version() ) / 'jit'
7+
endif
78

89
subdir('host')
910

1011
ljlib_sources = files(
11-
'lib_aux.c',
12-
'lib_base.c',
13-
'lib_bit.c',
14-
'lib_buffer.c',
15-
'lib_debug.c',
16-
'lib_ffi.c',
17-
'lib_init.c',
18-
'lib_io.c',
19-
'lib_jit.c',
20-
'lib_math.c',
21-
'lib_os.c',
22-
'lib_package.c',
23-
'lib_string.c',
24-
'lib_table.c',
25-
)
26-
12+
'lib_base.c', 'lib_math.c', 'lib_bit.c', 'lib_string.c', 'lib_table.c',
13+
'lib_io.c', 'lib_os.c', 'lib_package.c', 'lib_debug.c', 'lib_jit.c', 'lib_ffi.c',
14+
'lib_buffer.c')
2715
ljcore_sources = files(
28-
'lj_alloc.c',
29-
'lj_api.c',
30-
'lj_asm.c',
31-
'lj_assert.c',
32-
'lj_bc.c',
33-
'lj_bcread.c',
34-
'lj_bcwrite.c',
35-
'lj_buf.c',
36-
'lj_carith.c',
37-
'lj_ccall.c',
38-
'lj_ccallback.c',
39-
'lj_cconv.c',
40-
'lj_cdata.c',
41-
'lj_char.c',
42-
'lj_clib.c',
43-
'lj_cparse.c',
44-
'lj_crecord.c',
45-
'lj_ctype.c',
46-
'lj_debug.c',
47-
'lj_dispatch.c',
48-
'lj_err.c',
49-
'lj_ffrecord.c',
50-
'lj_func.c',
51-
'lj_gc.c',
52-
'lj_gdbjit.c',
53-
'lj_ir.c',
54-
'lj_lex.c',
55-
'lj_lib.c',
56-
'lj_load.c',
57-
'lj_mcode.c',
58-
'lj_meta.c',
59-
'lj_obj.c',
60-
'lj_opt_dce.c',
61-
'lj_opt_fold.c',
62-
'lj_opt_loop.c',
63-
'lj_opt_mem.c',
64-
'lj_opt_narrow.c',
65-
'lj_opt_sink.c',
66-
'lj_opt_split.c',
67-
'lj_parse.c',
68-
'lj_prng.c',
69-
'lj_profile.c',
70-
'lj_record.c',
71-
'lj_serialize.c',
72-
'lj_snap.c',
73-
'lj_state.c',
74-
'lj_str.c',
75-
'lj_strfmt.c',
76-
'lj_strfmt_num.c',
77-
'lj_strscan.c',
78-
'lj_tab.c',
79-
'lj_trace.c',
80-
'lj_udata.c',
81-
'lj_vmevent.c',
82-
'lj_vmmath.c',
83-
)
84-
16+
'lj_assert.c', 'lj_gc.c', 'lj_err.c', 'lj_char.c', 'lj_bc.c', 'lj_obj.c', 'lj_buf.c',
17+
'lj_str.c', 'lj_tab.c', 'lj_func.c', 'lj_udata.c', 'lj_meta.c', 'lj_debug.c',
18+
'lj_prng.c', 'lj_state.c', 'lj_dispatch.c', 'lj_vmevent.c', 'lj_vmmath.c',
19+
'lj_strscan.c', 'lj_strfmt.c', 'lj_strfmt_num.c', 'lj_serialize.c',
20+
'lj_api.c', 'lj_profile.c',
21+
'lj_lex.c', 'lj_parse.c', 'lj_bcread.c', 'lj_bcwrite.c', 'lj_load.c',
22+
'lj_ir.c', 'lj_opt_mem.c', 'lj_opt_fold.c', 'lj_opt_narrow.c',
23+
'lj_opt_dce.c', 'lj_opt_loop.c', 'lj_opt_split.c', 'lj_opt_sink.c',
24+
'lj_mcode.c', 'lj_snap.c', 'lj_record.c', 'lj_crecord.c', 'lj_ffrecord.c',
25+
'lj_asm.c', 'lj_trace.c', 'lj_gdbjit.c',
26+
'lj_ctype.c', 'lj_cdata.c', 'lj_cconv.c', 'lj_ccall.c', 'lj_ccallback.c',
27+
'lj_carith.c', 'lj_clib.c', 'lj_cparse.c',
28+
'lj_lib.c', 'lj_alloc.c', 'lib_aux.c',
29+
'lib_init.c')
8530
ljmain_sources = files('luajit.c')
8631

8732
buildvm_commands = [
@@ -101,7 +46,18 @@ lj_defines = [
10146
]
10247

10348
if host_machine.system() == 'darwin'
104-
lj_defines += '-mmacosx-version-min=10.11'
49+
lj_defines += '-DLUAJIT_UNWIND_EXTERNAL'
50+
elif host_machine.system() != 'windows'
51+
if 'NO_UNWIND' not in dasm_args
52+
test_unwind = run_command('test-unwind.sh', ' '.join(cc.cmd_array()), check : false)
53+
if test_unwind.stdout().strip() == 'E'
54+
lj_defines += '-DLUAJIT_UNWIND_EXTERNAL'
55+
endif
56+
endif
57+
endif
58+
59+
if get_option('portable')
60+
lj_defines += '-DLUAJIT_PORTABLE_INSTALL'
10561
endif
10662

10763
lj_linkargs = []
@@ -125,7 +81,6 @@ elif host_machine.system() == 'darwin'
12581
)
12682
lj_libname = 'luajit'
12783
lj_libprefix = 'lib'
128-
lj_linkargs += ['-pagezero_size', '10000', '-image_base', '100000000']
12984
else
13085
ljcore_sources += custom_target('lj_vm.s',
13186
input : [],
@@ -149,7 +104,7 @@ vmdef = custom_target('vmdef.lua',
149104
input : ljlib_sources,
150105
output : 'vmdef.lua',
151106
build_by_default : false,
152-
install: true,
107+
install: false,
153108
install_dir: jitlib_install_dir,
154109
command : [buildvm, '-m', 'vmdef', '-o', '@OUTPUT@', '@INPUT@']
155110
)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
TEST_CC="$1"
4+
5+
cat << EOF > tmpunwind.c
6+
extern void b(void);
7+
8+
int a(void) {
9+
b();
10+
return 0;
11+
}
12+
EOF
13+
14+
$TEST_CC -c -x c tmpunwind.c -o tmpunwind.o && {
15+
grep -qa -e eh_frame -e __unwind_info tmpunwind.o ||
16+
grep -qU -e eh_frame -e __unwind_info tmpunwind.o
17+
} && echo E
18+
19+
rm -f tmpunwind.c tmpunwind.o

meson.build

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ if host_machine.system() in ['linux','darwin']
195195
dependency(['sdl2']),
196196
dependency('flac'),
197197
dependency('minizip'),
198-
dependency('luajit'),
199198
dependency('threads'),
200199
dependency('liblz4'),
201200
dependency('libpng'),
@@ -211,8 +210,6 @@ if host_machine.system() in ['linux','darwin']
211210
elif host_machine.system() == 'windows'
212211
sdl2 = subproject('SDL2-2.26.3')
213212
sdl2_dep = dependency('sdl2')
214-
luajit = subproject('LuaJIT-2.1')
215-
luajit_dep = dependency('luajit')
216213
zlib = subproject('zlib-ng-2.1.3')
217214
zlib_dep = dependency('zlib')
218215
minizip = subproject('minizip-ng-4.0.0')
@@ -221,7 +218,7 @@ elif host_machine.system() == 'windows'
221218
libpng_dep = dependency('libpng')
222219
# Windows Libraries
223220
opengl = compiler.find_library('opengl32')
224-
deps += [sdl2_dep, luajit_dep, zlib_dep, minizip_dep, libpng_dep, opengl]
221+
deps += [sdl2_dep, zlib_dep, minizip_dep, libpng_dep, opengl]
225222
endif
226223

227224

@@ -233,6 +230,9 @@ boost_dep = declare_dependency(include_directories: include_directories('externa
233230
meson.override_dependency('boost-175', boost_dep)
234231
install_rpath = prefix/get_option('fmod_dir')
235232
allegro_proj = subproject('allegro 4.4.3.1-custom')
233+
luajit_proj = subproject('LuaJIT-2.1')
234+
luajit_dep = dependency('luajit')
235+
external_inc_dirs += luajit_proj.get_variable('luajit_source_dir')
236236
allegro_dep = dependency('allegro')
237237
loadpng_dep = dependency('loadpng')
238238
luabind_proj = subproject('luabind-0.7.1')
@@ -241,7 +241,7 @@ raknet_proj = subproject('RakNet')
241241
raknet_dep = dependency('RakNet')
242242
tracy_proj = subproject('tracy')
243243
tracy_dep = dependency('tracy')
244-
deps += [allegro_dep, loadpng_dep, raknet_dep, boost_dep, tracy_dep]
244+
deps += [allegro_dep, luajit_dep, loadpng_dep, raknet_dep, boost_dep, tracy_dep]
245245

246246
#### Sources Setup ####
247247
source_inc_dirs = []

meson_osxcross.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[constants]
2+
arch = 'x86_64-apple-darwin20.2'
3+
[binaries]
4+
c = ['ccache', arch + '-gcc']
5+
cpp = ['ccache', arch + '-g++']
6+
strip = arch + '-strip'
7+
pkg-config = arch + '-pkg-config'
8+
ranlib = arch + '-gcc-ranlib'
9+
ar = arch + '-gcc-ar'
10+
11+
[host_machine]
12+
system = 'darwin'
13+
cpu_family = 'x86_64'
14+
cpu = 'x86_64'
15+
endian = 'little'

0 commit comments

Comments
 (0)