xmake.lua 4.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package("microsoft-seal")
  2. set_homepage("https://www.microsoft.com/en-us/research/group/cryptography-research/")
  3. set_description("Microsoft SEAL is an easy-to-use and powerful homomorphic encryption library.")
  4. set_license("MIT")
  5. add_urls("https://github.com/microsoft/SEAL/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/microsoft/SEAL.git")
  7. add_versions("v4.1.2", "acc2a1a127a85d1e1ffcca3ffd148f736e665df6d6b072df0e42fff64795a13c")
  8. add_configs("zlib", {description = "Enable zlib", default = false, type = "boolean"})
  9. add_configs("zstd", {description = "Enable zstd", default = false, type = "boolean"})
  10. add_configs("ms_gsl", {description = "Enable microsoft-gsl", default = false, type = "boolean"})
  11. add_configs("hexl", {description = "Enable Intel HEXL", default = false, type = "boolean"})
  12. add_configs("throw_tran", {description = "Throw an exception when Evaluator outputs a transparent ciphertext", default = false, type = "boolean"})
  13. add_configs("gaussian", {description = "Use a rounded Gaussian distribution for noise sampling instead of a Centered Binomial Distribution", default = false, type = "boolean"})
  14. add_configs("intrin", {description = "Use intrinsics", default = false, type = "boolean"})
  15. add_configs("c_api", {description = "Builds C API", default = false, type = "boolean", readonly = true})
  16. if is_plat("windows") then
  17. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  18. end
  19. if is_plat("windows", "mingw") then
  20. add_syslinks("bcrypt")
  21. elseif is_plat("linux", "bsd") then
  22. add_syslinks("pthread")
  23. end
  24. add_deps("cmake")
  25. on_load(function (package)
  26. if package:config("zstd") then
  27. package:add("deps", "zstd")
  28. end
  29. if package:config("zlib") then
  30. package:add("deps", "zlib")
  31. end
  32. if package:config("ms_gsl") then
  33. package:add("deps", "microsoft-gsl")
  34. end
  35. if package:config("hexl") then
  36. package:add("deps", "hexl")
  37. end
  38. local version = package:version()
  39. if version then
  40. package:add("includedirs", format("include/SEAL-%s.%s", version:major(), version:minor()))
  41. else
  42. package:add("includedirs", "include/SEAL-4.1")
  43. end
  44. end)
  45. -- TODO: Fix cmake try_run
  46. on_install("!iphoneos", function (package)
  47. io.replace("CMakeLists.txt", "if(WIN32 AND BUILD_SHARED_LIBS)", "if(0)", {plain = true})
  48. if package:config("hexl") then
  49. io.replace("CMakeLists.txt", "1.2.4", "", {plain = true})
  50. end
  51. if package:is_plat("windows", "mingw") then
  52. io.replace("cmake/SEALMacros.cmake", "target_link_libraries(${target} PUBLIC Threads::Threads)",
  53. "target_link_libraries(${target} PUBLIC Threads::Threads bcrypt)", {plain = true})
  54. end
  55. local configs = {"-DSEAL_BUILD_DEPS=OFF"}
  56. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  57. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  58. if package:config("shared") and package:is_plat("windows") then
  59. table.insert(configs, "-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON")
  60. end
  61. table.insert(configs, "-DSEAL_USE_ZLIB=" .. (package:config("zlib") and "ON" or "OFF"))
  62. table.insert(configs, "-DSEAL_USE_ZSTD=" .. (package:config("zstd") and "ON" or "OFF"))
  63. table.insert(configs, "-DSEAL_USE_MSGSL=" .. (package:config("ms_gsl") and "ON" or "OFF"))
  64. table.insert(configs, "-DSEAL_USE_INTEL_HEXL=" .. (package:config("hexl") and "ON" or "OFF"))
  65. table.insert(configs, "-DSEAL_THROW_ON_TRANSPARENT_CIPHERTEXT=" .. (package:config("throw_tran") and "ON" or "OFF"))
  66. table.insert(configs, "-DSEAL_USE_GAUSSIAN_NOISE=" .. (package:config("gaussian") and "ON" or "OFF"))
  67. table.insert(configs, "-DSEAL_BUILD_SEAL_C=" .. (package:config("c_api") and "ON" or "OFF"))
  68. table.insert(configs, "-DSEAL_USE_INTRIN=" .. (package:config("intrin") and "ON" or "OFF"))
  69. if package:is_plat("mingw") then
  70. -- No aligned malloc implementation on MinGW
  71. -- https://github.com/ebassi/graphene/issues/83
  72. table.insert(configs, "-DSEAL_USE_ALIGNED_ALLOC=OFF")
  73. end
  74. import("package.tools.cmake").install(package, configs)
  75. end)
  76. on_test(function (package)
  77. assert(package:check_cxxsnippets({test = [[
  78. using namespace seal;
  79. void test() {
  80. EncryptionParameters parms(scheme_type::bfv);
  81. }
  82. ]]}, {configs = {languages = "c++17"}, includes = {"seal/seal.h"}}))
  83. end)