xmake.lua 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package("luasocket")
  2. set_homepage("http://lunarmodules.github.io/luasocket/")
  3. set_description("Network support for the Lua language")
  4. set_license("MIT")
  5. add_urls("https://github.com/lunarmodules/luasocket/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/lunarmodules/luasocket.git")
  7. add_versions("v3.1.0", "bf033aeb9e62bcaa8d007df68c119c966418e8c9ef7e4f2d7e96bddeca9cca6e")
  8. add_deps("lua")
  9. if is_plat("windows") then
  10. add_syslinks("ws2_32")
  11. end
  12. on_install("windows", function (package)
  13. import("package.tools.msbuild")
  14. local lua_dep = package:dep("lua")
  15. -- Fetch include/lib dir
  16. local lua_fetchinfo = lua_dep:fetch()
  17. local include_paths = {}
  18. local libfiles = {}
  19. local linkdir_paths = {}
  20. for _, includedir in ipairs(lua_fetchinfo.includedirs or lua_fetchinfo.sysincludedirs) do
  21. table.insert(include_paths, includedir)
  22. end
  23. for _, libfile in ipairs(lua_fetchinfo.libfiles) do
  24. table.insert(libfiles, path.filename(libfile))
  25. end
  26. for _, linkdir in ipairs(lua_fetchinfo.linkdirs) do
  27. table.insert(linkdir_paths, linkdir)
  28. end
  29. -- Specify config
  30. local arch = package:is_arch("x64") and "x64" or "Win32"
  31. if package:is_arch("arm64") then
  32. arch = "ARM64"
  33. io.replace("luasocket.sln", "|x64", "|ARM64", {plain = true})
  34. end
  35. local mode = package:is_debug() and "Debug" or "Release"
  36. local configs = { "luasocket.sln", "/t:mime;socket" }
  37. table.insert(configs, "/p:Configuration=" .. mode)
  38. table.insert(configs, "/p:Platform=" .. arch)
  39. for _, vcxproj in ipairs(os.files("**.vcxproj")) do
  40. io.replace(vcxproj, "$(LUAINC)", table.concat(include_paths, ";"), {plain = true})
  41. io.replace(vcxproj, "$(LUALIBNAME)", table.concat(libfiles, ";"), {plain = true})
  42. io.replace(vcxproj, "$(LUALIB)", table.concat(linkdir_paths, ";"), {plain = true})
  43. -- Support arm64 builds
  44. if package:is_arch("arm64") then
  45. io.replace(vcxproj, "|x64", "|ARM64", {plain = true})
  46. io.replace(vcxproj, "<Platform>x64", "<Platform>ARM64", {plain = true})
  47. io.replace(vcxproj, "<RandomizedBaseAddress>false</RandomizedBaseAddress>", "", {plain = true})
  48. end
  49. -- Switch vs_runtime MD / MDd -> MT / MTd
  50. if package:has_runtime("MT", "MTd") then
  51. io.replace(vcxproj, "MultiThreadedDebugDLL", "MultiThreadedDebug", {plain = true})
  52. io.replace(vcxproj, "MultiThreadedDLL", "MultiThreaded", {plain = true})
  53. end
  54. -- Support static lib builds
  55. if not package:config("shared") then
  56. io.replace(vcxproj, "DynamicLibrary", "StaticLibrary", {plain = true})
  57. io.replace(vcxproj, "LUASOCKET_API=__declspec(dllexport)", "", {plain = true})
  58. io.replace(vcxproj, "MIME_API=__declspec(dllexport)", "", {plain = true})
  59. end
  60. end
  61. msbuild.build(package, configs)
  62. os.cp("**.h", package:installdir("include"))
  63. local folders_skip = package:is_arch("x64", "arm64") and "*/*/" or "*/"
  64. os.cp(folders_skip .. "socket/core.lib", path.join(package:installdir("lib"), "socket", "core.lib"))
  65. os.cp(folders_skip .. "mime/core.lib", path.join(package:installdir("lib"), "mime", "core.lib"))
  66. if package:config("shared") then
  67. os.cp(folders_skip .. "socket/core.dll", path.join(package:installdir("lib"), "socket", "core.dll"))
  68. os.cp(folders_skip .. "mime/core.dll", path.join(package:installdir("lib"), "mime", "core.dll"))
  69. end
  70. os.trycp(folders_skip .. "socket/**.pdb", path.join(package:installdir("lib"), "socket"))
  71. os.trycp(folders_skip .. "mime/**.pdb", path.join(package:installdir("lib"), "mime"))
  72. package:add("linkdirs", "lib/socket")
  73. end)
  74. on_test(function (package)
  75. assert(package:check_csnippets({test = [[
  76. #include <lua.h>
  77. #include <luasocket.h>
  78. void test() {
  79. lua_State* L = luaL_newstate();
  80. luaopen_socket_core(L);
  81. }
  82. ]]}))
  83. end)