Skip to content

Commit

Permalink
microsoft-seal: add package (#5706)
Browse files Browse the repository at this point in the history
* microsoft-seal: add package

* fix mingw

* fix iphoneos

* Revert "fix iphoneos"

This reverts commit cf91dce.

* limit plat
  • Loading branch information
star-hengxing authored Nov 9, 2024
1 parent 5f1819a commit 94b75ce
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/m/microsoft-seal/patches/4.1.2/cmake-config-zstd.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
diff --git a/cmake/SEALConfig.cmake.in b/cmake/SEALConfig.cmake.in
index 45f855e..94ea283 100644
--- a/cmake/SEALConfig.cmake.in
+++ b/cmake/SEALConfig.cmake.in
@@ -89,8 +89,10 @@ if(NOT SEAL_CARRY_DEPS)
seal_find_dependency(ZLIB)
endif()
if(SEAL_USE_ZSTD)
- seal_find_dependency(zstd)
- if(NOT TARGET zstd::libzstd_static)
+ include(FindPkgConfig)
+ pkg_search_module("libzstd" REQUIRED IMPORTED_TARGET "libzstd")
+ set(zstd_static "PkgConfig::libzstd")
+ if(0)
if(TARGET libzstd)
get_target_property(libzstd_type libzstd TYPE)
if(libzstd_type STREQUAL "SHARED")
18 changes: 18 additions & 0 deletions packages/m/microsoft-seal/patches/4.1.2/find-zstd.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index de598c7..0035bf7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -190,9 +190,10 @@ if(SEAL_USE_ZSTD)
seal_fetch_thirdparty_content(ExternalZSTD)
set(zstd_static "libzstd_static")
else()
- find_package(zstd CONFIG)
- if(NOT zstd_FOUND)
- message(FATAL_ERROR "Zstandard: not found")
+ include(FindPkgConfig)
+ pkg_search_module("libzstd" REQUIRED IMPORTED_TARGET "libzstd")
+ if(libzstd_FOUND)
+ set(zstd_static "PkgConfig::libzstd")
else()
if(TARGET zstd::libzstd_static)
set(zstd_static "zstd::libzstd_static")
103 changes: 103 additions & 0 deletions packages/m/microsoft-seal/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package("microsoft-seal")
set_homepage("https://www.microsoft.com/en-us/research/group/cryptography-research/")
set_description("Microsoft SEAL is an easy-to-use and powerful homomorphic encryption library.")
set_license("MIT")

add_urls("https://github.com/microsoft/SEAL/archive/refs/tags/$(version).tar.gz",
"https://github.com/microsoft/SEAL.git")

add_versions("v4.1.2", "acc2a1a127a85d1e1ffcca3ffd148f736e665df6d6b072df0e42fff64795a13c")

add_configs("zlib", {description = "Enable zlib", default = false, type = "boolean"})
add_configs("zstd", {description = "Enable zstd", default = false, type = "boolean"})
add_configs("ms_gsl", {description = "Enable microsoft-gsl", default = false, type = "boolean"})
add_configs("hexl", {description = "Enable Intel HEXL", default = false, type = "boolean"})
add_configs("throw_tran", {description = "Throw an exception when Evaluator outputs a transparent ciphertext", default = false, type = "boolean"})
add_configs("gaussian", {description = "Use a rounded Gaussian distribution for noise sampling instead of a Centered Binomial Distribution", default = false, type = "boolean"})
add_configs("intrin", {description = "Use intrinsics", default = false, type = "boolean"})
add_configs("c_api", {description = "Builds C API", default = false, type = "boolean", readonly = true})
if is_plat("windows") then
add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
end

if is_plat("windows", "mingw") then
add_syslinks("bcrypt")
elseif is_plat("linux", "bsd") then
add_syslinks("pthread")
end

add_deps("cmake")

on_load(function (package)
if package:config("zstd") then
package:add("deps", "zstd")
package:add("deps", (is_subhost("windows") and "pkgconf") or "pkg-config")
package:add("patches", "4.1.2", "patches/4.1.2/find-zstd.patch", "d7261a78d6cc873b3563610429dbfa7eb8c67fa410825eb1b180a06f02dd5f1e")
package:add("patches", "4.1.2", "patches/4.1.2/cmake-config-zstd.patch", "a2291f35ee40ef52c021e709dcab2a5414381c0eafeb36efce15ecb4b423114a")
end
if package:config("zlib") then
package:add("deps", "zlib")
end
if package:config("ms_gsl") then
package:add("deps", "microsoft-gsl")
end
if package:config("hexl") then
package:add("deps", "hexl")
end

local version = package:version()
if version then
package:add("includedirs", format("include/SEAL-%s.%s", version:major(), version:minor()))
else
package:add("includedirs", "include/SEAL-4.1")
end
end)

-- TODO: Fix cmake try_run
on_install("!iphoneos", function (package)
io.replace("CMakeLists.txt", "if(WIN32 AND BUILD_SHARED_LIBS)", "if(0)", {plain = true})
if package:config("hexl") then
io.replace("CMakeLists.txt", "1.2.4", "", {plain = true})
end
if package:is_plat("windows", "mingw") then
io.replace("cmake/SEALMacros.cmake", "target_link_libraries(${target} PUBLIC Threads::Threads)",
"target_link_libraries(${target} PUBLIC Threads::Threads bcrypt)", {plain = true})
end

local configs = {"-DSEAL_BUILD_DEPS=OFF"}
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
if package:config("shared") and package:is_plat("windows") then
table.insert(configs, "-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON")
end

table.insert(configs, "-DSEAL_USE_ZLIB=" .. (package:config("zlib") and "ON" or "OFF"))
table.insert(configs, "-DSEAL_USE_ZSTD=" .. (package:config("zstd") and "ON" or "OFF"))
table.insert(configs, "-DSEAL_USE_MSGSL=" .. (package:config("ms_gsl") and "ON" or "OFF"))
table.insert(configs, "-DSEAL_USE_INTEL_HEXL=" .. (package:config("hexl") and "ON" or "OFF"))
table.insert(configs, "-DSEAL_THROW_ON_TRANSPARENT_CIPHERTEXT=" .. (package:config("throw_tran") and "ON" or "OFF"))
table.insert(configs, "-DSEAL_USE_GAUSSIAN_NOISE=" .. (package:config("gaussian") and "ON" or "OFF"))
table.insert(configs, "-DSEAL_BUILD_SEAL_C=" .. (package:config("c_api") and "ON" or "OFF"))
table.insert(configs, "-DSEAL_USE_INTRIN=" .. (package:config("intrin") and "ON" or "OFF"))

if package:is_plat("mingw") then
-- No aligned malloc implementation on MinGW
-- https://github.com/ebassi/graphene/issues/83
table.insert(configs, "-DSEAL_USE_ALIGNED_ALLOC=OFF")
end
import("package.tools.cmake").install(package, configs)

if package:is_plat("windows") and package:is_debug() then
local dir = package:installdir(package:config("shared") and "bin" or "lib")
os.vcp(path.join(package:buildir(), "**.pdb"), dir)
end
end)

on_test(function (package)
assert(package:check_cxxsnippets({test = [[
using namespace seal;
void test() {
EncryptionParameters parms(scheme_type::bfv);
}
]]}, {configs = {languages = "c++17"}, includes = {"seal/seal.h"}}))
end)

0 comments on commit 94b75ce

Please sign in to comment.