@@ -91,6 +91,13 @@ class InstallOptions:
9191 duktape_build_dir : str = "<duktape-src-dir>/build/<duktape-build-type:lower><\" -\" :if(cc)><cc:basename><\" -\" :if(sanitizer)><sanitizer:lower>"
9292 duktape_install_dir : str = "<duktape-src-dir>/install/<duktape-build-type:lower><\" -\" :if(cc)><cc:basename><\" -\" :if(sanitizer)><sanitizer:lower>"
9393
94+ # Lua
95+ lua_src_dir : str = "<third-party-src-dir>/lua"
96+ lua_url : str = "https://github.com/lua/lua/archive/refs/tags/v5.4.8.tar.gz"
97+ lua_build_type : str = "<mrdocs-build-type>"
98+ lua_build_dir : str = "<lua-src-dir>/build/<lua-build-type:lower><\" -\" :if(cc)><cc:basename><\" -\" :if(sanitizer)><sanitizer:lower>"
99+ lua_install_dir : str = "<lua-src-dir>/install/<lua-build-type:lower><\" -\" :if(cc)><cc:basename><\" -\" :if(sanitizer)><sanitizer:lower>"
100+
94101 # LLVM
95102 llvm_src_dir : str = "<third-party-src-dir>/llvm-project"
96103 llvm_build_type : str = "<mrdocs-build-type>"
@@ -152,6 +159,11 @@ class InstallOptions:
152159 "duktape_build_type" : "CMake build type for Duktape. (Release, Debug, RelWithDebInfo, MilRelSize)" ,
153160 "duktape_build_dir" : "Directory where Duktape will be built." ,
154161 "duktape_install_dir" : "Directory where Duktape will be installed." ,
162+ "lua_src_dir" : "Directory for the Lua source code." ,
163+ "lua_url" : "Download URL for the Lua source archive." ,
164+ "lua_build_type" : "Build type for Lua. (Release, Debug)" ,
165+ "lua_build_dir" : "Directory where Lua will be built." ,
166+ "lua_install_dir" : "Directory where Lua will be installed." ,
155167 "libxml2_src_dir" : "Directory for the libxml2 source code." ,
156168 "libxml2_build_type" : "CMake build type for libxml2: Release always recommended. (Release, Debug, RelWithDebInfo, MilRelSize)" ,
157169 "libxml2_build_dir" : "Directory where libxml2 will be built." ,
@@ -1162,6 +1174,63 @@ def install_duktape(self):
11621174 self .options .duktape_install_dir ,
11631175 extra_args )
11641176
1177+ def install_lua (self ):
1178+ # Resolve paths/values
1179+ self .prompt_dependency_path_option ("lua_src_dir" )
1180+ if not os .path .exists (self .options .lua_src_dir ):
1181+ self .prompt_option ("lua_url" )
1182+ os .makedirs (self .options .lua_src_dir , exist_ok = True )
1183+ archive_filename = os .path .basename (self .options .lua_url )
1184+ archive_path = os .path .join (self .options .third_party_src_dir , archive_filename )
1185+ self .download_file (self .options .lua_url , archive_path )
1186+
1187+ # Extract lua-5.4.8.tar.gz, flatten top-level dir into lua_src_dir
1188+ mode = "r:gz" if archive_filename .endswith (".gz" ) else "r:*"
1189+ with tarfile .open (archive_path , mode ) as tar :
1190+ top_level = tar .getmembers ()[0 ].name .split ('/' )[0 ]
1191+ for member in tar .getmembers ():
1192+ rel = os .path .relpath (member .name , top_level )
1193+ if rel == '.' or rel .startswith ('..' ):
1194+ continue
1195+ member .name = rel
1196+ tar .extract (member , path = self .options .lua_src_dir )
1197+ os .remove (archive_path )
1198+
1199+ # Copy our tiny CMake patch files (like we do for Duktape)
1200+ lua_patches = os .path .join (self .options .mrdocs_src_dir , 'third-party' , 'lua' )
1201+ if os .path .exists (lua_patches ):
1202+ for fname in os .listdir (lua_patches ):
1203+ src = os .path .join (lua_patches , fname )
1204+ dst = os .path .join (self .options .lua_src_dir , fname )
1205+ shutil .copy (src , dst )
1206+
1207+ # Lua’s own tree puts sources under src/; our CMakeLists handles that.
1208+ self .prompt_build_type_option ("lua_build_type" )
1209+ # align ABI expectations like we do for Duktape:
1210+ if not self .is_abi_compatible (self .options .mrdocs_build_type , self .options .lua_build_type ):
1211+ if self .options .mrdocs_build_type .lower () == "debug" :
1212+ self .options .lua_build_type = "OptimizedDebug"
1213+ else :
1214+ self .options .lua_build_type = self .options .mrdocs_build_type
1215+
1216+ self .prompt_dependency_path_option ("lua_build_dir" )
1217+ self .prompt_dependency_path_option ("lua_install_dir" )
1218+
1219+ extra_args = []
1220+ if self .options .sanitizer :
1221+ flag = self .sanitizer_flag_name (self .options .sanitizer )
1222+ for arg in ("CMAKE_C_FLAGS" , "CMAKE_CXX_FLAGS" ):
1223+ extra_args .append (f"-D{ arg } =-fsanitize={ flag } -fno-sanitize-recover={ flag } -fno-omit-frame-pointer" )
1224+
1225+ # Standard cmake_workflow like Duktape
1226+ self .cmake_workflow (
1227+ self .options .lua_src_dir ,
1228+ self .options .lua_build_type ,
1229+ self .options .lua_build_dir ,
1230+ self .options .lua_install_dir ,
1231+ extra_args
1232+ )
1233+
11651234 def install_libxml2 (self ):
11661235 self .prompt_dependency_path_option ("libxml2_src_dir" )
11671236 if not os .path .exists (self .options .libxml2_src_dir ):
@@ -1338,7 +1407,9 @@ def create_cmake_presets(self):
13381407 "Duktape_ROOT" : self .options .duktape_install_dir ,
13391408 "libxml2_ROOT" : self .options .libxml2_install_dir ,
13401409 "LibXml2_ROOT" : self .options .libxml2_install_dir ,
1341- "MRDOCS_BUILD_TESTS" : self .options .mrdocs_build_tests ,
1410+ "LUA_ROOT" : self .options .lua_install_dir ,
1411+ "Lua_ROOT" : self .options .lua_install_dir ,
1412+ "lua_ROOT" : self .options .lua_install_dir ,
13421413 "MRDOCS_BUILD_DOCS" : False ,
13431414 "MRDOCS_GENERATE_REFERENCE" : False ,
13441415 "MRDOCS_GENERATE_ANTORA_REFERENCE" : False
@@ -2580,6 +2651,7 @@ def install_all(self):
25802651 self .probe_compilers ()
25812652 self .install_ninja ()
25822653 self .install_duktape ()
2654+ self .install_lua ()
25832655 self .install_llvm ()
25842656 if self .prompt_option ("mrdocs_build_tests" ):
25852657 self .install_libxml2 ()
0 commit comments