Skip to content

Commit 5b79b48

Browse files
committed
Address #1524 - fix meson cross compilation linking.
In the cross compilation case, we need to resolve our dependencies on libc twice, once for the build machine and once for the target machine. This includes pthreads, -libc, and android-spawn.
1 parent 7c44127 commit 5b79b48

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
All notable changes to this project will be documented in this file.
33

44
## ??? - Unreleased
5+
- Fix meson cross compilation
56
- Update timeout documentation for networking APIs: timeouts raise errors and do not return nil.
67
- Add `janet_addtimeout_nil(double sec);` to the C API.
78
- Change string hashing.

meson.build

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,17 @@ project('janet', 'c',
2626
janet_path = join_paths(get_option('prefix'), get_option('libdir'), 'janet')
2727
header_path = join_paths(get_option('prefix'), get_option('includedir'), 'janet')
2828

29-
# Link math library on all systems
29+
# Compilers
3030
cc = meson.get_compiler('c')
31+
native_cc = meson.get_compiler('c', native : true)
32+
33+
# Native deps
34+
native_m_dep = native_cc.find_library('m', required : false)
35+
native_dl_dep = native_cc.find_library('dl', required : false)
36+
native_android_spawn_dep = native_cc.find_library('android-spawn', required : false)
37+
native_thread_dep = dependency('threads', native : true)
38+
39+
# Deps
3140
m_dep = cc.find_library('m', required : false)
3241
dl_dep = cc.find_library('dl', required : false)
3342
android_spawn_dep = cc.find_library('android-spawn', required : false)
@@ -164,11 +173,18 @@ mainclient_src = [
164173
'src/mainclient/shell.c'
165174
]
166175

176+
janet_dependencies = [m_dep, dl_dep, android_spawn_dep]
177+
janet_native_dependencies = [native_m_dep, native_dl_dep, native_android_spawn_dep]
178+
if not get_option('single_threaded')
179+
janet_dependencies += thread_dep
180+
janet_native_dependencies += native_thread_dep
181+
endif
182+
167183
# Build boot binary
168184
janet_boot = executable('janet-boot', core_src, boot_src,
169185
include_directories : incdir,
170186
c_args : '-DJANET_BOOTSTRAP',
171-
dependencies : [m_dep, dl_dep, thread_dep, android_spawn_dep],
187+
dependencies : janet_native_dependencies,
172188
native : true)
173189

174190
# Build janet.c
@@ -181,11 +197,6 @@ janetc = custom_target('janetc',
181197
'JANET_PATH', janet_path
182198
])
183199

184-
janet_dependencies = [m_dep, dl_dep, android_spawn_dep]
185-
if not get_option('single_threaded')
186-
janet_dependencies += thread_dep
187-
endif
188-
189200
# Allow building with no shared library
190201
if cc.has_argument('-fvisibility=hidden')
191202
lib_cflags = ['-fvisibility=hidden']
@@ -231,7 +242,7 @@ if meson.is_cross_build()
231242
endif
232243
janet_nativeclient = executable('janet-native', janetc, mainclient_src,
233244
include_directories : incdir,
234-
dependencies : janet_dependencies,
245+
dependencies : janet_native_dependencies,
235246
c_args : extra_native_cflags,
236247
native : true)
237248
else

0 commit comments

Comments
 (0)