xmake.lua 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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.624", "6d5ce40a7dc0e17da51cc143d2ee1ab32727583c315938f5a69d13ef93ae574d")
  8. add_versions("0.623", "5a72f9e5b996c5ec44ee2c7bd9448d2b2e5061bdf7d057de7490f92fb3003f40")
  9. add_versions("0.538", "8a1240e02a7daacf1e5cff249040a3298c013157fc496c66adce6dcb21cc30be")
  10. add_configs("extern_c", { description = "Use extern C for all APIs.", default = false, type = "boolean" })
  11. add_configs("build_web", { description = "Build web module.", default = false, type = "boolean" })
  12. add_deps("cmake")
  13. on_install("!bsd and !wasm", function(package)
  14. local configs = {}
  15. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "RelWithDebInfo"))
  16. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  17. table.insert(configs, "-DLUAU_BUILD_TESTS=OFF")
  18. table.insert(configs, "-DLUAU_BUILD_WEB=" .. (package:config("build_web") and "ON" or "OFF"))
  19. table.insert(configs, "-DLUAU_EXTERN_C=" .. (package:config("extern_c") and "ON" or "OFF"))
  20. import("package.tools.cmake").install(package, configs, { buildir = "build" })
  21. io.replace("CMakeLists.txt", ".lib", "", {plain = true})
  22. io.replace("Sources.cmake", ".lib", "", {plain = true})
  23. local cmake_file = io.readfile("CMakeLists.txt")
  24. local links = {}
  25. for library_name, library_type in string.gmatch(cmake_file, "add_library%(([%a|%.]+) ([STATIC|INTERFACE]+)") do
  26. if string.startswith(library_name, "Luau.") then
  27. if library_type == "STATIC" then
  28. table.insert(links, library_name)
  29. end
  30. local include_dir = library_name:gsub("Luau%.", "")
  31. include_dir = include_dir:gsub("%..*", "")
  32. os.trycp(include_dir .. "/include/*", package:installdir("include"))
  33. end
  34. end
  35. -- we have to link in reverse order
  36. for i = #links, 1, -1 do
  37. local link = links[i]
  38. package:add("links", link)
  39. end
  40. os.trycp("build/**.a", package:installdir("lib"))
  41. os.trycp("build/**.so", package:installdir("lib"))
  42. os.trycp("build/**.dylib", package:installdir("lib"))
  43. os.trycp("build/**.lib", package:installdir("lib"))
  44. os.trycp("build/**.dll", package:installdir("bin"))
  45. os.trycp("build/luau*", package:installdir("bin"))
  46. package:addenv("PATH", "bin")
  47. end)
  48. on_test(function(package)
  49. assert(package:check_cxxsnippets({ test = [[
  50. #include <lua.h>
  51. #include <luacode.h>
  52. #include <lualib.h>
  53. void test() {
  54. auto L = luaL_newstate();
  55. luaL_openlibs(L);
  56. lua_close(L);
  57. }
  58. ]]}, {configs = {languages = "cxx11"}}))
  59. assert(package:check_cxxsnippets({ test = [[
  60. #include <Luau/Common.h>
  61. void test() {
  62. Luau::FValue<int> v("test", 42, true);
  63. }
  64. ]]}, {configs = {languages = "cxx11"}}))
  65. end)