xmake.lua 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package("mimalloc")
  2. set_homepage("https://github.com/microsoft/mimalloc")
  3. set_description("mimalloc (pronounced 'me-malloc') is a general purpose allocator with excellent performance characteristics.")
  4. set_license("MIT")
  5. set_urls("https://github.com/microsoft/mimalloc/archive/refs/tags/$(version).zip",
  6. "https://github.com/microsoft/mimalloc.git")
  7. add_versions("v2.1.7", "fa61cf01e3dd869b35275bfd8be95bfde77f0b65dfa7e34012c09a66e1ea463f")
  8. add_versions("v2.1.2", "86281c918921c1007945a8a31e5ad6ae9af77e510abfec20d000dd05d15123c7")
  9. add_versions("v2.0.7", "ddb32937aabddedd0d3a57bf68158d4e53ecf9e051618df3331a67182b8b0508")
  10. add_versions("v2.0.6", "23e7443d0b4d7aa945779ea8a806e4e109c0ed62d740953d3656cddea7e04cf8")
  11. add_versions("v2.0.5", "e8d4e031123e82081325a5131ac57d954f5123b6a13653a6d984cbc3b8488bd9")
  12. add_versions("v2.0.3", "8e5f0b74fdafab09e8853415700a9ade4d62d5f56cd43f54adf02580ceda86c1")
  13. add_versions("v2.0.2", "6ccba822e251b8d10f8a63d5d7767bc0cbfae689756a4047cdf3d1e4a9fd33d0")
  14. add_versions("v2.0.1", "59c1fe79933e0ac9837a9ca4d954e4887dccd80a84281a6f849681b89a8b8876")
  15. add_versions("v1.8.7", "c37c099244f1096c40fca6ca9d2d456bb22efb99d64d34a26e39e3291a774ed9")
  16. add_versions("v1.7.7", "d51a5b8f3bc6800a0b2fc46830ce67b4d31b12f4e4550ff80cf394d5a88fead8")
  17. add_versions("v1.7.6", "bae56f8ebdcd43da83b52610d7f1c1602ea8d3798d906825defa5c40ad2eb560")
  18. add_versions("v1.7.3", "8319eca4a114dce5f897a4cb7d945bce22d915b4b262adb861cd7ac68fa3e848")
  19. add_versions("v1.7.2", "2c432e44803d9f4f017323be705f194db5d1452f9a60e38896605e7cfe8b332f")
  20. add_versions("v1.7.1", "dc3219066b4fd50c7f23d60c13fa15ae269a2b10b7dd45b046d5c52c9addb477")
  21. add_versions("v1.7.0", "13f3c82bca3a95233c5e29adb5675ab2b772f0ade23184d822079578c9d6c698")
  22. add_versions("v1.6.7", "5a12aac020650876615a2ce3dd8adc8b208cdcee4d9e6bcfc33b3fbe307f0dbf")
  23. add_configs("secure", {description = "Use a secured version of mimalloc", default = false, type = "boolean"})
  24. add_configs("rltgenrandom", {description = "Use a RtlGenRandom instead of BCrypt", default = false, type = "boolean"})
  25. if is_plat("windows") then
  26. add_configs("etw", {description = "Enable Event tracing for Windows", default = false, type = "boolean"})
  27. end
  28. add_deps("cmake")
  29. if is_plat("windows") then
  30. add_syslinks("advapi32", "bcrypt")
  31. elseif is_plat("linux") then
  32. add_syslinks("pthread")
  33. elseif is_plat("android") then
  34. add_syslinks("atomic")
  35. end
  36. on_install(function (package)
  37. if package:is_plat("windows") and package:config("shared") then
  38. package:add("defines", "MI_SHARED_LIB")
  39. end
  40. if package:is_plat("wasm") then
  41. package:add("ldflags", "-sMALLOC=emmalloc")
  42. end
  43. local configs = {
  44. "-DMI_OVERRIDE=OFF",
  45. "-DMI_BUILD_TESTS=OFF",
  46. "-DMI_BUILD_OBJECT=OFF",
  47. }
  48. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  49. table.insert(configs, "-DMI_DEBUG_FULL=" .. (package:is_debug() and "ON" or "OFF"))
  50. table.insert(configs, "-DMI_BUILD_STATIC=" .. (package:config("shared") and "OFF" or "ON"))
  51. table.insert(configs, "-DMI_BUILD_SHARED=" .. (package:config("shared") and "ON" or "OFF"))
  52. table.insert(configs, "-DMI_SECURE=" .. (package:config("secure") and "ON" or "OFF"))
  53. table.insert(configs, "-DMI_TRACK_ETW=" .. (package:config("etw") and "ON" or "OFF"))
  54. --x64:mimalloc-redirect.lib/dll x86:mimalloc-redirect32.lib/dll
  55. if package:version():le("2.0.1") and package:config("shared") and package:is_plat("windows") and package:is_arch("x86") then
  56. io.replace("CMakeLists.txt", "-redirect.", "-redirect32.", {plain = true})
  57. end
  58. local cxflags
  59. if package:config("rltgenrandom") then
  60. if xmake:version():ge("2.5.1") then
  61. cxflags = "-DMI_USE_RTLGENRANDOM"
  62. else
  63. -- it will be deprecated after xmake/v2.5.1
  64. package:configs().cxflags = "-DMI_USE_RTLGENRANDOM"
  65. end
  66. end
  67. if package:gitref() or package:version():ge("2.1.2") then
  68. table.insert(configs, "-DMI_INSTALL_TOPLEVEL=ON")
  69. import("package.tools.cmake").install(package, configs, {cxflags = cxflags})
  70. if package:is_plat("windows") and package:is_debug() then
  71. local dir = package:installdir(package:config("shared") and "bin" or "lib")
  72. os.cp(path.join(package:buildir(), "mimalloc-debug.pdb"), dir)
  73. end
  74. else
  75. import("package.tools.cmake").build(package, configs, {buildir = "build", cxflags = cxflags})
  76. if package:is_plat("windows") then
  77. os.trycp("build/**.dll", package:installdir("bin"))
  78. os.trycp("build/**.lib", package:installdir("lib"))
  79. elseif package:is_plat("mingw") then
  80. os.trycp("build/**.dll", package:installdir("bin"))
  81. os.trycp("build/**.a", package:installdir("lib"))
  82. elseif package:is_plat("macosx") then
  83. os.trycp("build/*.dylib", package:installdir("bin"))
  84. os.trycp("build/*.dylib", package:installdir("lib"))
  85. os.trycp("build/*.a", package:installdir("lib"))
  86. else
  87. os.trycp("build/*.so", package:installdir("bin"))
  88. os.trycp("build/*.so", package:installdir("lib"))
  89. os.trycp("build/*.a", package:installdir("lib"))
  90. end
  91. os.cp("include", package:installdir())
  92. end
  93. end)
  94. on_test(function (package)
  95. assert(package:has_cfuncs("mi_malloc", {includes = "mimalloc.h"}))
  96. end)