From c1c1daa9e508a985cb171ba06c2c63c4e70b8b1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Wed, 21 Feb 2024 10:07:13 +0100 Subject: [PATCH] Allow exporting Lua symbols Which optionally enables loading Lua shared modules from within even static TPT. Not that anyone actually needs this. This currently can't work on Windows because DLLs there import symbols by [module name, symbol name] rather than just symbol name. One could in theory export Lua symbols from TPT (I don't know the exact MSVC hack this would require, .def files?) and place a lua51.dll next to the executable that just re-exports them, see https://learn.microsoft.com/en-us/cpp/build/reference/exports?view=msvc-170 , but I've yet to try this. --- meson.build | 16 ++++++++++++++++ meson_options.txt | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/meson.build b/meson.build index 33d3abcd1..f439df2d6 100644 --- a/meson.build +++ b/meson.build @@ -376,6 +376,22 @@ if host_platform == 'emscripten' '-o', app_exe + '.js', # so we get a .wasm, and a .js ] endif +if get_option('export_lua_symbols') + if is_static and lua_variant != 'none' and not project_export_dynamic + if host_platform == 'windows' + error('Lua symbols are currently impossible to export correctly on Windows') + elif c_compiler.has_link_argument('-Wl,--export-dynamic-symbol') + project_link_args += [ + '-Wl,--export-dynamic-symbol=lua_*', + '-Wl,--export-dynamic-symbol=luaL_*', + '-Wl,--export-dynamic-symbol=luaopen_*', + ] + else + warning('your linker does not support -Wl,--export-dynamic-symbol so Meson will be instructed to export all symbols in order to enable loading Lua shared modules, which may blow up the size of the resulting binary') + project_export_dynamic = true + endif + endif +endif if get_option('build_powder') powder_deps += project_deps + [ diff --git a/meson_options.txt b/meson_options.txt index 427dcf105..f0c81bbbf 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -305,3 +305,9 @@ option( value: true, description: 'Ask Windows nicely for UTF-8 as the codepage' ) +option( + 'export_lua_symbols', + type: 'boolean', + value: false, + description: 'Export Lua symbols to enable loading of Lua shared modules' +)