2
0

xmake.lua 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package("luau")
  2. set_homepage("https://luau-lang.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/Roblox/luau/archive/$(version).tar.gz",
  6. "https://github.com/Roblox/luau.git")
  7. add_versions("0.638", "87ea29188f0d788e3b8649a063cda6b1e1804a648f425f4d0e65ec8449f2d171")
  8. add_versions("0.624", "6d5ce40a7dc0e17da51cc143d2ee1ab32727583c315938f5a69d13ef93ae574d")
  9. add_versions("0.623", "5a72f9e5b996c5ec44ee2c7bd9448d2b2e5061bdf7d057de7490f92fb3003f40")
  10. add_versions("0.538", "8a1240e02a7daacf1e5cff249040a3298c013157fc496c66adce6dcb21cc30be")
  11. add_configs("extern_c", { description = "Use extern C for all APIs.", default = false, type = "boolean" })
  12. add_configs("build_web", { description = "Build web module.", default = false, type = "boolean" })
  13. add_deps("cmake")
  14. on_install(function(package)
  15. io.replace("extern/isocline/src/completers.c", "__finddata64_t", "_finddatai64_t", {plain = true})
  16. io.replace("CMakeLists.txt", [[cmake_policy(SET CMP0054 NEW)]], [[
  17. cmake_policy(SET CMP0054 NEW)
  18. cmake_policy(SET CMP0057 NEW)
  19. ]], {plain = true})
  20. local configs = {}
  21. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package: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_TESTS=OFF")
  24. table.insert(configs, "-DLUAU_BUILD_WEB=" .. ((package:is_plat("wasm") or package:config("build_web")) and "ON" or "OFF"))
  25. table.insert(configs, "-DLUAU_EXTERN_C=" .. (package:config("extern_c") and "ON" or "OFF"))
  26. if package:is_plat("bsd") then
  27. io.replace("CMakeLists.txt", [[if(CMAKE_SYSTEM_NAME MATCHES "Linux|Darwin|iOS")]], [[if(TRUE)]], {plain = true})
  28. end
  29. if package:is_plat("wasm") then
  30. import("package.tools.cmake").build(package, configs, { target = "Luau.Web", buildir = "build" })
  31. else
  32. import("package.tools.cmake").install(package, configs, { buildir = "build" })
  33. end
  34. local cmake_file = io.readfile("CMakeLists.txt")
  35. local links = {}
  36. for library_name, library_type in cmake_file:gmatch("add_library%(([%a|%.]+) (%w+)") do
  37. library_type = library_type:lower()
  38. if library_name:startswith("Luau.") and (library_type == "static" or library_type == "interface") then
  39. if library_name:endswith(".lib") then
  40. library_name = library_name:sub(1, -5)
  41. end
  42. if library_type == "static" then
  43. table.insert(links, library_name)
  44. end
  45. local include_dir = library_name:sub(6)
  46. include_dir = include_dir:gsub("%..*", "")
  47. os.trycp(include_dir .. "/include/*", package:installdir("include"))
  48. end
  49. end
  50. -- we have to link in reverse order
  51. for i = #links, 1, -1 do
  52. local link = links[i]
  53. package:add("links", link)
  54. end
  55. os.trycp("build/**.a", package:installdir("lib"))
  56. os.trycp("build/**.so", package:installdir("lib"))
  57. os.trycp("build/**.dylib", package:installdir("lib"))
  58. os.trycp("build/**.lib", package:installdir("lib"))
  59. os.trycp("build/**.dll", package:installdir("bin"))
  60. os.trycp("build/luau*", package:installdir("bin"))
  61. package:addenv("PATH", "bin")
  62. end)
  63. on_test(function(package)
  64. assert(package:check_cxxsnippets({ test = [[
  65. #include <lua.h>
  66. #include <luacode.h>
  67. #include <lualib.h>
  68. void test() {
  69. auto L = luaL_newstate();
  70. luaL_openlibs(L);
  71. lua_close(L);
  72. }
  73. ]]}, {configs = {languages = "cxx11"}}))
  74. assert(package:check_cxxsnippets({ test = [[
  75. #include <Luau/Common.h>
  76. void test() {
  77. Luau::FValue<int> v("test", 42, true);
  78. }
  79. ]]}, {configs = {languages = "cxx11"}}))
  80. end)