From 5ad83773cc208e20b20fb5c1d4570d4d7b18e68f Mon Sep 17 00:00:00 2001 From: Michael Schlottke-Lakemper Date: Sat, 30 Dec 2023 11:34:28 +0100 Subject: [PATCH] Add OpenFHE library (#7869) * Add OpenFHE * Add CSL to provide libgomp; disable unittests/benchmarks for hopefully wider platform support * Disable MUSL builds since it is not supported * Use suitable dependencies for OpenMP support * Exclude unsupported architectures (PowerPC & 32-bit x86) * Add patch for macOS * Add missing " --- O/OpenFHE/build_tarballs.jl | 71 +++++++++++++++++++ .../bundled/patches/macos-include-cmath.patch | 10 +++ 2 files changed, 81 insertions(+) create mode 100644 O/OpenFHE/build_tarballs.jl create mode 100644 O/OpenFHE/bundled/patches/macos-include-cmath.patch diff --git a/O/OpenFHE/build_tarballs.jl b/O/OpenFHE/build_tarballs.jl new file mode 100644 index 00000000000..2c3db6afe93 --- /dev/null +++ b/O/OpenFHE/build_tarballs.jl @@ -0,0 +1,71 @@ +# Note that this script can accept some limited command-line arguments, run +# `julia build_tarballs.jl --help` to see a usage message. +using BinaryBuilder, Pkg + +name = "OpenFHE" +version = v"1.1.2" + +# Collection of sources required to complete build +sources = [ + GitSource("https://github.com/openfheorg/openfhe-development.git", + "b2869aef5cf61afd364b3eaea748dcc8a7020b9c"), + DirectorySource("./bundled") +] + +# Bash recipe for building across all platforms +script = raw""" +cd $WORKSPACE/srcdir/openfhe-development/ + +if [[ "${target}" == *-apple* ]]; then + atomic_patch -p1 "${WORKSPACE}/srcdir/patches/macos-include-cmath.patch" +fi + +mkdir build && cd build + +cmake .. \ + -DCMAKE_INSTALL_PREFIX=$prefix \ + -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TARGET_TOOLCHAIN} \ + -DCMAKE_BUILD_TYPE=Release \ + -DWITH_BE2=ON \ + -DWITH_BE4=ON \ + -DBUILD_UNITTESTS=OFF \ + -DBUILD_BENCHMARKS=OFF + +make -j${nproc} +make install +""" + +# These are the platforms we will build for by default, unless further +# platforms are passed in on the command line +platforms = supported_platforms() + +# We cannot build with musl since OpenFHE requires the `execinfo.h` header for `backtrace` +platforms = filter(p -> libc(p) != "musl", platforms) + +# PowerPC and 32-bit x86 platforms are not supported by OpenFHE +platforms = filter(p -> arch(p) != "i686", platforms) +platforms = filter(p -> arch(p) != "powerpc64le", platforms) + +# Expand C++ string ABIs since we use std::string +platforms = expand_cxxstring_abis(platforms) + + +# The products that we will ensure are always built +products = [ + LibraryProduct("libOPENFHEbinfhe", :libOPENFHEbinfhe), + LibraryProduct("libOPENFHEpke", :libOPENFHEpke), + LibraryProduct("libOPENFHEcore", :libOPENFHEcore), +] + +# Dependencies that must be installed before this package can be built +dependencies = Dependency[ + # For OpenMP we use libomp from `LLVMOpenMP_jll` where we use LLVM as compiler (BSD + # systems), and libgomp from `CompilerSupportLibraries_jll` everywhere else. + Dependency(PackageSpec(name="CompilerSupportLibraries_jll", uuid="e66e0078-7015-5450-92f7-15fbd957f2ae"); + platforms=filter(!Sys.isbsd, platforms)), + Dependency(PackageSpec(name="LLVMOpenMP_jll", uuid="1d63c593-3942-5779-bab2-d838dc0a180e"); + platforms=filter(Sys.isbsd, platforms)), +] + +# Build the tarballs, and possibly a `build.jl` as well. +build_tarballs(ARGS, name, version, sources, script, platforms, products, dependencies; julia_compat="1.6", preferred_gcc_version = v"10.2.0") diff --git a/O/OpenFHE/bundled/patches/macos-include-cmath.patch b/O/OpenFHE/bundled/patches/macos-include-cmath.patch new file mode 100644 index 00000000000..a8836c3338b --- /dev/null +++ b/O/OpenFHE/bundled/patches/macos-include-cmath.patch @@ -0,0 +1,10 @@ +--- a/src/core/include/utils/utilities.h ++++ b/src/core/include/utils/utilities.h +@@ -36,6 +36,7 @@ + #include "utils/inttypes.h" + + #include // CHAR_BIT ++#include + #include // std::numeric_limits + #include + #include // std::is_integral