homebrew-core/Formula/seal.rb

106 lines
3.5 KiB
Ruby

class Seal < Formula
desc "Easy-to-use homomorphic encryption library"
homepage "https://github.com/microsoft/SEAL"
url "https://github.com/microsoft/SEAL/archive/v3.7.2.tar.gz"
sha256 "12676de5766b8e2d641d6e45e92114ccdf8debd6f6d44b42a2ecc39a59b0bf13"
license "MIT"
bottle do
sha256 cellar: :any, arm64_monterey: "c0261e67c231e553089da32847512f48f323e65b6b3ea93971ce6c4b425582e0"
sha256 cellar: :any, arm64_big_sur: "82b22467391cc77167beaf017991f3998f8898986d7585e59a2431ad7dd4935f"
sha256 cellar: :any, monterey: "09c85d9093cb00526fac994d4171f075cc355027bea5880d1b3e89443f8abfeb"
sha256 cellar: :any, big_sur: "69838eeb9e678c35c0263cb6f39597384e9d98ffbbd9d23cdf3a21f8b949f62f"
sha256 cellar: :any, catalina: "f38ba78c2dfd2f8475519ff1bd5d930d4f8990a72e9b1e3de87bab2b4db0c623"
sha256 cellar: :any_skip_relocation, x86_64_linux: "d0f6c8d6a438d90b23f42e06c765d088b4ec4b3b02afb58783ff8dd855a97918"
end
depends_on "cmake" => [:build, :test]
depends_on "cpp-gsl"
depends_on "zstd"
uses_from_macos "zlib"
on_linux do
depends_on "gcc"
end
fails_with gcc: "5"
resource "hexl" do
url "https://github.com/intel/hexl/archive/v1.2.3.tar.gz"
sha256 "f2cf33ee2035d12996d10b69d2f41a586b9954a29b99c70a852495cf5758878c"
end
def install
if Hardware::CPU.intel?
resource("hexl").stage do
hexl_args = std_cmake_args + %w[
-DHEXL_BENCHMARK=OFF
-DHEXL_TESTING=OFF
-DHEXL_EXPORT=ON
]
system "cmake", "-S", ".", "-B", "build", *hexl_args
system "cmake", "--build", "build"
system "cmake", "--install", "build"
end
ENV.append "LDFLAGS", "-L#{lib}"
end
args = std_cmake_args + %W[
-DBUILD_SHARED_LIBS=ON
-DSEAL_BUILD_DEPS=OFF
-DSEAL_USE_ALIGNED_ALLOC=#{(MacOS.version > :mojave) ? "ON" : "OFF"}
-DSEAL_USE_INTEL_HEXL=#{Hardware::CPU.intel? ? "ON" : "OFF"}
-DHEXL_DIR=#{lib}/cmake
-DCMAKE_CXX_FLAGS=-I#{include}
]
system "cmake", ".", *args
system "make"
system "make", "install"
pkgshare.install "native/examples"
end
test do
cp_r (pkgshare/"examples"), testpath
# remove the partial CMakeLists
File.delete testpath/"examples/CMakeLists.txt"
# Chip in a new "CMakeLists.txt" for example code tests
(testpath/"examples/CMakeLists.txt").write <<~EOS
cmake_minimum_required(VERSION 3.12)
project(SEALExamples VERSION #{version} LANGUAGES CXX)
# Executable will be in ../bin
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${SEALExamples_SOURCE_DIR}/../bin)
add_executable(sealexamples examples.cpp)
target_sources(sealexamples
PRIVATE
1_bfv_basics.cpp
2_encoders.cpp
3_levels.cpp
4_ckks_basics.cpp
5_rotation.cpp
6_serialization.cpp
7_performance.cpp
)
# Import Microsoft SEAL
find_package(SEAL #{version} EXACT REQUIRED
# Providing a path so this can be built without installing Microsoft SEAL
PATHS ${SEALExamples_SOURCE_DIR}/../src/cmake
)
# Link Microsoft SEAL
target_link_libraries(sealexamples SEAL::seal_shared)
EOS
system "cmake", "examples", "-DHEXL_DIR=#{lib}/cmake"
system "make"
# test examples 1-5 and exit
input = "1\n2\n3\n4\n5\n0\n"
assert_match "Correct", pipe_output("bin/sealexamples", input)
end
end