xmake.lua 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package("luau")
  2. set_homepage("https://www.luau.org/")
  3. set_description("A fast, small, safe, gradually typed embeddable scripting language derived from Lua.")
  4. set_license("MIT")
  5. add_urls("https://github.com/luau-lang/luau/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/luau-lang/luau.git")
  7. add_versions("0.683", "a2c7aaf906d625e43ca468792acf8e47a9cbd1d4352623b5e62d2a4011faa15c")
  8. add_versions("0.643", "069702be7646917728ffcddcc72dae0c4191b95dfe455c8611cc5ad943878d3d")
  9. add_versions("0.642", "cc7954979d2b1f6a138a9b0cb0f2d27e3c11d109594379551bc290c0461965ba")
  10. add_versions("0.640", "63ada3e4c8c17e5aff8964b16951bfd1b567329dd81c11ae1144b6e95f354762")
  11. add_versions("0.638", "87ea29188f0d788e3b8649a063cda6b1e1804a648f425f4d0e65ec8449f2d171")
  12. add_versions("0.624", "6d5ce40a7dc0e17da51cc143d2ee1ab32727583c315938f5a69d13ef93ae574d")
  13. add_versions("0.623", "5a72f9e5b996c5ec44ee2c7bd9448d2b2e5061bdf7d057de7490f92fb3003f40")
  14. add_versions("0.538", "8a1240e02a7daacf1e5cff249040a3298c013157fc496c66adce6dcb21cc30be")
  15. add_configs("extern_c", { description = "Use extern C for all APIs.", default = false, type = "boolean" })
  16. add_configs("build_web", { description = "Build web module.", default = false, type = "boolean" })
  17. add_deps("cmake")
  18. on_install(function(package)
  19. io.replace("extern/isocline/src/completers.c", "__finddata64_t", "_finddatai64_t", {plain = true})
  20. local configs = {"-DLUAU_BUILD_TESTS=OFF", "-DCMAKE_POLICY_DEFAULT_CMP0057=NEW"}
  21. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "RelWithDebInfo"))
  22. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  23. table.insert(configs, "-DLUAU_BUILD_WEB=" .. ((package:is_plat("wasm") or package:config("build_web")) and "ON" or "OFF"))
  24. table.insert(configs, "-DLUAU_EXTERN_C=" .. (package:config("extern_c") and "ON" or "OFF"))
  25. if package:is_plat("bsd") then
  26. io.replace("CMakeLists.txt", [[if(CMAKE_SYSTEM_NAME MATCHES "Linux|Darwin|iOS")]], [[if(TRUE)]], {plain = true})
  27. end
  28. if package:is_plat("wasm") then
  29. import("package.tools.cmake").build(package, configs, { target = "Luau.Web", builddir = "build" })
  30. else
  31. import("package.tools.cmake").build(package, configs, { builddir = "build" })
  32. end
  33. local cmake_file = io.readfile("CMakeLists.txt")
  34. local links = {}
  35. for library_name, library_type in cmake_file:gmatch("add_library%(([%a|%.]+) (%w+)") do
  36. library_type = library_type:lower()
  37. if library_name:startswith("Luau.") and (library_type == "static" or library_type == "interface") then
  38. if library_name:endswith(".lib") then
  39. library_name = library_name:sub(1, -5)
  40. end
  41. if library_type == "static" then
  42. table.insert(links, library_name)
  43. end
  44. local include_dir = library_name:sub(6)
  45. include_dir = include_dir:gsub("%..*", "")
  46. os.trycp(include_dir .. "/include/*", package:installdir("include"))
  47. end
  48. end
  49. -- we have to link in reverse order
  50. for i = #links, 1, -1 do
  51. local link = links[i]
  52. package:add("links", link)
  53. end
  54. os.trycp("build/**.a", package:installdir("lib"))
  55. os.trycp("build/**.so", package:installdir("lib"))
  56. os.trycp("build/**.dylib", package:installdir("lib"))
  57. os.trycp("build/**.lib", package:installdir("lib"))
  58. os.trycp("build/**.dll", package:installdir("bin"))
  59. os.trycp("build/luau*", package:installdir("bin"))
  60. package:addenv("PATH", "bin")
  61. end)
  62. on_test(function(package)
  63. if package:config("extern_c") then
  64. assert(package:check_cxxsnippets({ test = [[
  65. extern "C" {
  66. #include <lua.h>
  67. #include <luacode.h>
  68. #include <lualib.h>
  69. }
  70. void test() {
  71. lua_State* L = luaL_newstate();
  72. luaL_openlibs(L);
  73. lua_close(L);
  74. }
  75. ]]}, {configs = {languages = "cxx11"}}))
  76. else
  77. assert(package:check_cxxsnippets({ test = [[
  78. #include <lua.h>
  79. #include <luacode.h>
  80. #include <lualib.h>
  81. void test() {
  82. lua_State* L = luaL_newstate();
  83. luaL_openlibs(L);
  84. lua_close(L);
  85. }
  86. ]]}, {configs = {languages = "cxx11"}}))
  87. end
  88. assert(package:check_cxxsnippets({ test = [[
  89. #include <Luau/Common.h>
  90. void test() {
  91. Luau::FValue<int> v("test", 42, true);
  92. }
  93. ]]}, {configs = {languages = "cxx11"}}))
  94. end)