From ad3bc1c92df5c204cd7d32e9d1c80b2bd3176fe5 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Fri, 1 May 2026 20:56:02 +0300 Subject: [PATCH 1/3] lua: support building as C++ --- releases.json | 1 + subprojects/packagefiles/lua/meson.build | 27 ++++++++++++++++--- .../packagefiles/lua/meson_options.txt | 6 +++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/releases.json b/releases.json index 099dd342ed..a77db78313 100644 --- a/releases.json +++ b/releases.json @@ -3001,6 +3001,7 @@ "lua" ], "versions": [ + "5.5.0-2", "5.5.0-1", "5.4.8-1", "5.4.6-5", diff --git a/subprojects/packagefiles/lua/meson.build b/subprojects/packagefiles/lua/meson.build index 2b27d5fa03..c027c08f9a 100644 --- a/subprojects/packagefiles/lua/meson.build +++ b/subprojects/packagefiles/lua/meson.build @@ -10,9 +10,15 @@ project( lua_versions = meson.project_version().split('.') cc = meson.get_compiler('c') -override_options = [ - 'c_std=c99', -] +override_options = [] + +build_as_cpp = get_option('lua_cpp') + +if not build_as_cpp: + override_options += [ + 'c_std=c99', + ] +endif # Skip bogus warning. add_project_arguments( @@ -73,6 +79,14 @@ if dl_dep.found() ) endif + +if build_as_cpp: + add_project_arguments( + '-xc++', + language: 'c' + ) +endif + # Interpreter dependencies. lua_exe_deps = [] lua_exe_args = [] @@ -146,7 +160,12 @@ meson.override_dependency( lua_dep, ) -if get_option('interpreter') +# Note: you can compile C code as C++, but you can't link it. Clang compiler +# has option to treat C source code as C++, but clang linker does not. And +# as there are several possible C++ standard libraries, we can't just pick +# one and pass it to linker explicitly. +# If building Lua as C++ is enabed, then disable interpreter +if get_option('interpreter') and not build_as_cpp lua_exe = executable( 'lua', 'src/lua.c', diff --git a/subprojects/packagefiles/lua/meson_options.txt b/subprojects/packagefiles/lua/meson_options.txt index 23f04bbe14..6efea06cc0 100644 --- a/subprojects/packagefiles/lua/meson_options.txt +++ b/subprojects/packagefiles/lua/meson_options.txt @@ -14,3 +14,9 @@ option( value: true, description: 'Build the Lua interpreter.', ) +option( + 'lua_cpp', + type: 'boolean', + value: false, + description: 'Build Lua as C++. This will disable building interpreter and executable ', +) From 229d9f235cb56a9bf293b80a1f27e1b437d4a8ec Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Fri, 1 May 2026 21:01:23 +0300 Subject: [PATCH 2/3] add msvc support --- subprojects/packagefiles/lua/meson.build | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/subprojects/packagefiles/lua/meson.build b/subprojects/packagefiles/lua/meson.build index c027c08f9a..4e0df1785a 100644 --- a/subprojects/packagefiles/lua/meson.build +++ b/subprojects/packagefiles/lua/meson.build @@ -80,11 +80,16 @@ if dl_dep.found() endif -if build_as_cpp: - add_project_arguments( - '-xc++', - language: 'c' - ) +if build_as_cpp + if cc.get_id() == 'msvc' + add_project_arguments('/TP', '/EHa', language: 'c') + elif cc.get_id() == 'gcc' or cc.get_id() == 'clang' + add_project_arguments( + '-xc++', + language: 'c' + ) + else + warning('Unknown compiler family. We do not know how to enforce C++ on C files') endif # Interpreter dependencies. From f728a77dab2046b6b9f2619bdc8d5a871b6f4bb0 Mon Sep 17 00:00:00 2001 From: Artem Serebriyskiy Date: Fri, 1 May 2026 21:08:15 +0300 Subject: [PATCH 3/3] fix --- subprojects/packagefiles/lua/meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subprojects/packagefiles/lua/meson.build b/subprojects/packagefiles/lua/meson.build index 4e0df1785a..74daa4b86c 100644 --- a/subprojects/packagefiles/lua/meson.build +++ b/subprojects/packagefiles/lua/meson.build @@ -14,7 +14,7 @@ override_options = [] build_as_cpp = get_option('lua_cpp') -if not build_as_cpp: +if not build_as_cpp override_options += [ 'c_std=c99', ]