xmake.lua 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package("snmalloc")
  2. set_homepage("https://github.com/microsoft/snmalloc")
  3. set_description("Message passing based allocator")
  4. set_license("MIT")
  5. add_urls("https://github.com/microsoft/snmalloc/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/microsoft/snmalloc.git")
  7. add_versions("0.7.3", "a908b604a77213169b526ab96a64a79c222a03a41a87f13ac00adfeff379f0be")
  8. add_versions("0.7.1", "91824fdf553f03cf6ef8be57f29f1d4f79cd651667455e9fe4af8b7c09e705d3")
  9. add_versions("0.7.0", "9e6bd04e58d981218bd5bd3a853d93bbcb1a82dd914f912670f798e011e86746")
  10. add_versions("0.6.2", "e0486ccf03eac5dd8acbb66ea8ad33bec289572a51614acdf7117397e4f1af8c")
  11. add_versions("0.6.0", "de1bfb86407d5aac9fdad88319efdd5593ca2f6c61fc13371c4f34aee0b6664f")
  12. add_configs("header_only", {description = "Use header only version.", default = false, type = "boolean"})
  13. add_configs("wait_on_address", {description = "Use wait on address backoff strategy if it is available", default = true, type = "boolean"})
  14. if is_plat("windows") then
  15. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  16. end
  17. add_deps("cmake")
  18. if is_plat("windows", "mingw") then
  19. add_syslinks("onecore")
  20. elseif is_plat("linux", "bsd") then
  21. add_syslinks("pthread")
  22. end
  23. if on_check then
  24. on_check("android", function (package)
  25. if package:version() and package:version():ge("0.7.2") then
  26. local ndk = package:toolchain("ndk")
  27. local ndk_sdkver = ndk:config("ndk_sdkver")
  28. assert(ndk_sdkver and tonumber(ndk_sdkver) > 21, "package(snmalloc) require ndk api level > 21")
  29. end
  30. end)
  31. end
  32. on_load(function (package)
  33. if package:config("header_only") then
  34. package:set("kind", "library", {headeronly = true})
  35. end
  36. package:add("defines", "SNMALLOC_USE_WAIT_ON_ADDRESS=" .. (package:config("wait_on_address") and "1" or "0"))
  37. end)
  38. on_install("!wasm and !iphoneos", function (package)
  39. io.replace("CMakeLists.txt", "-Werror", "", {plain = true})
  40. io.replace("CMakeLists.txt", "/WX", "", {plain = true})
  41. if os.isfile("src/snmalloc/pal/pal_windows.h") and package:has_runtime("MT") then
  42. -- duplicate symbol: public: static void * __cdecl snmalloc::PALWindows::reserve(unsigned __int64)
  43. io.replace("src/snmalloc/pal/pal_windows.h",
  44. "static void* reserve(size_t size) noexcept;",
  45. "static inline void* reserve(size_t size) noexcept;", {plain = true})
  46. end
  47. local configs = {"-DSNMALLOC_BUILD_TESTING=OFF"}
  48. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  49. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  50. table.insert(configs, "-DSNMALLOC_STATIC_LIBRARY=" .. (package:config("shared") and "OFF" or "ON"))
  51. table.insert(configs, "-DSNMALLOC_IPO=" .. (package:config("lto") and "ON" or "OFF"))
  52. table.insert(configs, "-DSNMALLOC_HEADER_ONLY_LIBRARY=" .. (package:config("header_only") and "ON" or "OFF"))
  53. table.insert(configs, "-DSNMALLOC_ENABLE_WAIT_ON_ADDRESS=" .. (package:config("wait_on_address") and "ON" or "OFF"))
  54. import("package.tools.cmake").install(package, configs)
  55. os.cp("src/snmalloc", package:installdir("include"))
  56. end)
  57. on_test(function (package)
  58. assert(package:has_cxxfuncs("snmalloc::DefaultPal::message(\"\")",
  59. {includes = "snmalloc/snmalloc.h", configs = {languages = "c++20", cxflags = "-mcx16"}}))
  60. end)