From 4bc0872204bfe4b6d412076da069d613e7dbca7f Mon Sep 17 00:00:00 2001 From: Wei Dai Date: Fri, 31 Jan 2020 11:08:36 -0800 Subject: [PATCH] Make SEAL a CMake project and enable auto-download of dependencies --- .gitignore | 14 +- .gitmodules | 3 - native/src/CMakeLists.txt => CMakeLists.txt | 560 +++++++++++------- Changes.md | 4 + ISSUES.md | 12 +- README.md | 22 +- SEAL.sln | 47 +- azure-pipelines.yml | 8 +- {native/src/cmake => cmake}/FindMSGSL.cmake | 0 .../src/cmake => cmake}/SEALConfig.cmake.in | 10 - dotnet/examples/SEALNetExamples.csproj | 10 +- dotnet/nuget/SEALNet.nuspec.in | 12 +- dotnet/nuget/SEALNet.targets.in | 6 +- dotnet/src/SEALNet.csproj | 4 +- dotnet/tests/SEALNetTest.csproj | 10 +- native/examples/CMakeLists.txt | 34 +- native/examples/SEALExamples.vcxproj | 24 +- native/examples/examples.h | 4 +- native/src/CMakeConfig.cmd | 56 +- native/src/SEAL.vcxproj | 49 +- native/src/SEAL.vcxproj.filters | 5 +- native/src/SEAL_C.vcxproj | 38 +- native/src/seal/batchencoder.cpp | 4 +- native/src/seal/batchencoder.h | 6 +- native/src/seal/biguint.cpp | 2 +- native/src/seal/biguint.h | 8 +- native/src/seal/ckks.h | 6 +- native/src/seal/encryptor.h | 4 +- native/src/seal/intarray.h | 4 +- native/src/seal/plaintext.h | 4 +- native/src/seal/util/config.h.in | 1 - native/src/thirdparty/zlib/CMakeLists.txt | 12 - native/tests/CMakeLists.txt | 33 +- native/tests/SEALTest.vcxproj | 24 +- native/tests/seal/CMakeLists.txt | 3 +- native/tests/seal/util/CMakeLists.txt | 2 +- native/tests/thirdparty/googletest | 1 - templates/nix-build.yml | 47 +- templates/pack.yml | 12 +- templates/windows-build.yml | 15 +- thirdparty/googletest/CMakeLists.txt | 19 + thirdparty/msgsl/CMakeLists.txt | 26 + thirdparty/zlib/CMakeLists.txt | 23 + 43 files changed, 658 insertions(+), 530 deletions(-) delete mode 100644 .gitmodules rename native/src/CMakeLists.txt => CMakeLists.txt (60%) rename {native/src/cmake => cmake}/FindMSGSL.cmake (100%) rename {native/src/cmake => cmake}/SEALConfig.cmake.in (93%) delete mode 100644 native/src/thirdparty/zlib/CMakeLists.txt delete mode 160000 native/tests/thirdparty/googletest create mode 100644 thirdparty/googletest/CMakeLists.txt create mode 100644 thirdparty/msgsl/CMakeLists.txt create mode 100644 thirdparty/zlib/CMakeLists.txt diff --git a/.gitignore b/.gitignore index 86763d39..d4acb792 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ # Other stuff -native/src/cmake/SEALConfig.cmake -native/src/cmake/SEALConfigVersion.cmake -native/src/cmake/SEALTargets.cmake +cmake/SEALConfig.cmake +cmake/SEALConfigVersion.cmake +cmake/SEALTargets.cmake native/src/seal/util/config.h **/CMakeCache.txt **/CMakeFiles @@ -21,8 +21,12 @@ native/src/seal/util/config.h **/compile_commands.json **/.DS_Store **/GSL -native/src/thirdparty/zlib/* -!native/src/thirdparty/zlib/CMakeLists.txt +thirdparty/zlib/* +!thirdparty/zlib/CMakeLists.txt +thirdparty/msgsl/* +!thirdparty/msgsl/CMakeLists.txt +thirdparty/googletest/* +!thirdparty/googletest/CMakeLists.txt dotnet/nuget/nuget.exe dotnet/nuget/SEALNet.nuspec dotnet/nuget/SEALNet.targets diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 48f1a394..00000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "native/tests/thirdparty/googletest"] - path = native/tests/thirdparty/googletest - url = https://github.com/google/googletest diff --git a/native/src/CMakeLists.txt b/CMakeLists.txt similarity index 60% rename from native/src/CMakeLists.txt rename to CMakeLists.txt index 1f971348..66b4a464 100644 --- a/native/src/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,8 +3,17 @@ cmake_minimum_required(VERSION 3.12) +################################################### +# Project SEAL includes the following components: # +# 1. SEAL C++ library # +# 2. SEAL C export library # +# 3. SEAL C++ examples # +# 4. SEAL C++ tests # +################################################### + project(SEAL VERSION 3.5.0 LANGUAGES CXX C) +# Check operating system: for Windows, use Visual Studio solution/project files. if(MSVC) if(ALLOW_COMMAND_LINE_BUILD) message(STATUS "Configuring for Visual Studio") @@ -13,78 +22,29 @@ if(MSVC) endif() endif() +######################## +# Global configuration # +######################## + +# [Option] CMAKE_BUILD_TYPE # Build in Release mode by default; otherwise use selected option -set(SEAL_DEFAULT_BUILD_TYPE "Release") if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE ${SEAL_DEFAULT_BUILD_TYPE} CACHE - STRING "Build type" FORCE) + set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Release" "Debug" "MinSizeRel" "RelWithDebInfo") endif() message(STATUS "Build type (CMAKE_BUILD_TYPE): ${CMAKE_BUILD_TYPE}") -# In Debug mode enable also SEAL_DEBUG by default +# [Flag] SEAL_DEBUG +# In Debug mode, enable SEAL_DEBUG if(CMAKE_BUILD_TYPE STREQUAL "Debug") - set(SEAL_DEBUG_DEFAULT ON) + set(SEAL_DEBUG ON) else() - set(SEAL_DEBUG_DEFAULT OFF) + set(SEAL_DEBUG OFF) endif() - -# Required files and directories -include(GNUInstallDirs) -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${SEAL_SOURCE_DIR}/../lib) -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${SEAL_SOURCE_DIR}/../lib) -set(CMAKE_LIBRARY_RUNTIME_DIRECTORY ${SEAL_SOURCE_DIR}/../bin) -set(SEAL_TARGETS_FILENAME ${SEAL_SOURCE_DIR}/cmake/SEALTargets.cmake) -set(SEAL_CONFIG_IN_FILENAME ${SEAL_SOURCE_DIR}/cmake/SEALConfig.cmake.in) -set(SEAL_CONFIG_FILENAME ${SEAL_SOURCE_DIR}/cmake/SEALConfig.cmake) -set(SEAL_CONFIG_VERSION_FILENAME ${SEAL_SOURCE_DIR}/cmake/SEALConfigVersion.cmake) -set(SEAL_CONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/SEAL-${SEAL_VERSION_MAJOR}.${SEAL_VERSION_MINOR}) -set(SEAL_INCLUDES_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}/SEAL-${SEAL_VERSION_MAJOR}.${SEAL_VERSION_MINOR}) -set(MSGSL_FIND_MODULE_PATH ${SEAL_SOURCE_DIR}/cmake/FindMSGSL.cmake) - -# For extra modules we might have -list(APPEND CMAKE_MODULE_PATH ${SEAL_SOURCE_DIR}/cmake) - -include(CMakePushCheckState) -include(CMakeDependentOption) -include(CheckIncludeFiles) -include(CheckCXXSourceRuns) -include(CheckTypeSize) - -# For easier adding of CXX compiler flags -include(CheckCXXCompilerFlag) - -function(enable_cxx_compiler_flag_if_supported flag) - string(FIND "${CMAKE_CXX_FLAGS}" "${flag}" flag_already_set) - if(flag_already_set EQUAL -1) - message(STATUS "Adding CXX compiler flag: ${flag} ...") - check_cxx_compiler_flag("${flag}" flag_supported) - if(flag_supported) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}" PARENT_SCOPE) - endif() - unset(flag_supported CACHE) - endif() -endfunction() - -# enable_cxx_compiler_flag_if_supported("-Wall") -# enable_cxx_compiler_flag_if_supported("-Wextra") -# enable_cxx_compiler_flag_if_supported("-Wconversion") -# enable_cxx_compiler_flag_if_supported("-Wshadow") -# enable_cxx_compiler_flag_if_supported("-pedantic") - -# Are we using SEAL_DEBUG? -set(SEAL_DEBUG ${SEAL_DEBUG_DEFAULT}) message(STATUS "Microsoft SEAL debug mode: ${SEAL_DEBUG}") -# Should we build also the shared library? -set(BUILD_SHARED_LIBS_STR "Build shared library") -option(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_STR} OFF) -if(MSVC AND BUILD_SHARED_LIBS) - message(WARNING "This build system only supports a static build; disabling `BUILD_SHARED_LIBS`") - set(BUILD_SHARED_LIBS OFF CACHE) -endif() - +# [Option] SEAL_USE_CXX17 # Should we use C++14 or C++17? set(SEAL_USE_CXX17_OPTION_STR "Use C++17") option(SEAL_USE_CXX17 ${SEAL_USE_CXX17_OPTION_STR} ON) @@ -105,6 +65,202 @@ if(SEAL_USE_CXX17) set(SEAL_LANG_FLAG "-std=c++17") endif() +# [Option] CXX compiler flags +# For easier adding of CXX compiler flags +include(CheckCXXCompilerFlag) +function(enable_cxx_compiler_flag_if_supported flag) + string(FIND "${CMAKE_CXX_FLAGS}" "${flag}" flag_already_set) + if(flag_already_set EQUAL -1) + message(STATUS "Adding CXX compiler flag: ${flag} ...") + check_cxx_compiler_flag("${flag}" flag_supported) + if(flag_supported) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}" PARENT_SCOPE) + endif() + unset(flag_supported CACHE) + endif() +endfunction() + +# In Debug mode, enable extra compiler flags. +if(SEAL_DEBUG) + enable_cxx_compiler_flag_if_supported("-Wall") + enable_cxx_compiler_flag_if_supported("-Wextra") + enable_cxx_compiler_flag_if_supported("-Wconversion") + enable_cxx_compiler_flag_if_supported("-Wshadow") + enable_cxx_compiler_flag_if_supported("-pedantic") +endif() + +# Required files and directories +include(GNUInstallDirs) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${SEAL_SOURCE_DIR}/lib) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${SEAL_SOURCE_DIR}/lib) +set(CMAKE_LIBRARY_RUNTIME_DIRECTORY ${SEAL_SOURCE_DIR}/bin) +set(SEAL_TARGETS_FILENAME ${SEAL_SOURCE_DIR}/cmake/SEALTargets.cmake) +set(SEAL_CONFIG_IN_FILENAME ${SEAL_SOURCE_DIR}/cmake/SEALConfig.cmake.in) +set(SEAL_CONFIG_FILENAME ${SEAL_SOURCE_DIR}/cmake/SEALConfig.cmake) +set(SEAL_CONFIG_VERSION_FILENAME ${SEAL_SOURCE_DIR}/cmake/SEALConfigVersion.cmake) +set(SEAL_CONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/SEAL-${SEAL_VERSION_MAJOR}.${SEAL_VERSION_MINOR}) +set(SEAL_INCLUDES_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}/SEAL-${SEAL_VERSION_MAJOR}.${SEAL_VERSION_MINOR}) +set(SEAL_INCLUDES_BUILD_DIR ${SEAL_SOURCE_DIR}/native/src) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${SEAL_SOURCE_DIR}/bin) + +# For extra modules we might have +list(APPEND CMAKE_MODULE_PATH ${SEAL_SOURCE_DIR}/cmake) + +include(CMakePushCheckState) +include(CMakeDependentOption) +include(CheckIncludeFiles) +include(CheckCXXSourceRuns) +include(CheckTypeSize) + +################################## +# Macros for configuring targets # +################################## + +# Set the C++ language version +macro(set_language target) + if(SEAL_USE_CXX17) + target_compile_features(${target} PUBLIC cxx_std_17) + else() + target_compile_features(${target} PUBLIC cxx_std_14) + endif() +endmacro() + +# Set the VERSION property +macro(set_version target) + set_target_properties(${target} PROPERTIES VERSION ${SEAL_VERSION}) +endmacro() + +# Set the library filename to reflect version +macro(set_version_filename target) + set_target_properties(${target} PROPERTIES + OUTPUT_NAME ${target}-${SEAL_VERSION_MAJOR}.${SEAL_VERSION_MINOR}) +endmacro() + +# Set the SOVERSION property +macro(set_soversion target) + set_target_properties(${target} PROPERTIES + SOVERSION ${SEAL_VERSION_MAJOR}.${SEAL_VERSION_MINOR}) +endmacro() + +# Set include directories for build and install interfaces +macro(set_include_directories target) + target_include_directories(${target} PUBLIC + $ + $) +endmacro() + +# Link a thread library +macro(link_threads target) + # Require thread library + if(NOT TARGET Threads::Threads) + set(CMAKE_THREAD_PREFER_PTHREAD TRUE) + set(THREADS_PREFER_PTHREAD_FLAG TRUE) + find_package(Threads REQUIRED) + endif() + + # Link Threads + target_link_libraries(${target} PUBLIC Threads::Threads) +endmacro() + +# Include target to given export +macro(install_target target export) + install(TARGETS ${target} EXPORT ${export} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +endmacro() + +######################### +# External dependencies # +######################### + +# Use Microsoft GSL +set(SEAL_USE_MSGSL_OPTION_STR "Use Microsoft GSL") +option(SEAL_USE_MSGSL ${SEAL_USE_MSGSL_OPTION_STR} ON) + +if(SEAL_USE_MSGSL AND NOT MSVC) + add_subdirectory(thirdparty/msgsl) + ExternalProject_Get_Property(msgsl_external SOURCE_DIR) + add_library(msgsl IMPORTED INTERFACE) + + # We need to create the include directory so it exists at the time + # of configuration. Otherwise set_target_properties below will fail. + set(MSGSL_INCLUDE_DIR ${SOURCE_DIR}/include) + file(MAKE_DIRECTORY ${MSGSL_INCLUDE_DIR}) + + set_target_properties(msgsl PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${MSGSL_INCLUDE_DIR}) + add_dependencies(msgsl msgsl_external) +endif() + +# Use ZLIB +set(SEAL_USE_ZLIB_OPTION_STR "Use ZLIB for compressed serialization") +option(SEAL_USE_ZLIB ${SEAL_USE_ZLIB_OPTION_STR} ON) + +if(SEAL_USE_ZLIB AND NOT MSVC) + add_subdirectory(thirdparty/zlib) + ExternalProject_Get_Property(zlib_external SOURCE_DIR BINARY_DIR) + add_library(zlibstatic STATIC IMPORTED) + + set(ZLIB_FILENAME "libz.a") + set(ZLIB_LIBRARY_PATH ${BINARY_DIR}/${ZLIB_FILENAME}) + set_target_properties(zlibstatic PROPERTIES + IMPORTED_LOCATION ${ZLIB_LIBRARY_PATH}) + set_target_properties(zlibstatic PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${SOURCE_DIR}) + add_dependencies(zlibstatic zlib_external) +endif() + +# Use Google Test +if(SEAL_BUILD_TESTS AND NOT MSVC) + # This follows the example in + # https://github.com/google/googletest/blob/release-1.10.0/googletest/README.md. + + # Download + message(STATUS "Setting up Google Test ...") + execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . + OUTPUT_QUIET + RESULT_VARIABLE result + WORKING_DIRECTORY thirdparty/googletest) + if(result) + message(WARNING "Failed to download Google Test (${result}); disabling `SEAL_BUILD_TESTS`") + endif() + + set(BUILD_GMOCK OFF CACHE BOOL "" FORCE) + mark_as_advanced(BUILD_GMOCK) + set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) + mark_as_advanced(INSTALL_GTEST) + + # Build + execute_process(COMMAND ${CMAKE_COMMAND} --build . + OUTPUT_QUIET + RESULT_VARIABLE result + WORKING_DIRECTORY thirdparty/googletest) + if(result) + message(WARNING "Failed to build Google Test (${result}); disabling `SEAL_BUILD_TESTS`") + endif() + + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + + # Set up the targets + add_subdirectory( + thirdparty/googletest/googletest-src + thirdparty/googletest/googletest-build + EXCLUDE_FROM_ALL) +endif() + +#################### +# SEAL C++ library # +#################### + +# Should we build also the shared library? +set(BUILD_SHARED_LIBS_STR "Build shared library") +option(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_STR} OFF) +if(MSVC AND BUILD_SHARED_LIBS) + message(WARNING "This build system only supports a static build; disabling `BUILD_SHARED_LIBS`") + set(BUILD_SHARED_LIBS OFF CACHE BOOL ${BUILD_SHARED_LIBS_STR} FORCE) +endif() + # Always build position-independent-code set(CMAKE_POSITION_INDEPENDENT_CODE ON) @@ -117,14 +273,6 @@ mark_as_advanced(FORCE SEAL_THROW_ON_TRANSPARENT_CIPHERTEXT) set(SEAL_USE_INTRIN_OPTION_STR "Use intrinsics") option(SEAL_USE_INTRIN ${SEAL_USE_INTRIN_OPTION_STR} ON) -# Use Microsoft GSL if available -set(SEAL_USE_MSGSL_OPTION_STR "Use Microsoft GSL") -option(SEAL_USE_MSGSL ${SEAL_USE_MSGSL_OPTION_STR} ON) - -# Use zlib if available -set(SEAL_USE_ZLIB_OPTION_STR "Use zlib for compressed serialization") -option(SEAL_USE_ZLIB ${SEAL_USE_ZLIB_OPTION_STR} ON) - # Check for intrin.h or x64intrin.h if(SEAL_USE_INTRIN) if(MSVC) @@ -260,206 +408,98 @@ if(SEAL_USE_INTRIN) cmake_pop_check_state() endif() -# Helper macro for clearing MSGSL cache -macro(clear_msgsl_cache) - unset(MSGSL_INCLUDE_DIR CACHE) -endmacro() - -# Try to find MSGSL if requested; first clear the cache if SEAL_USE_MSGSL -# is not set, or if SEAL_USE_MSGSL and MSGSL_ROOT are set (force search). -if(NOT SEAL_USE_MSGSL OR MSGSL_ROOT) - clear_msgsl_cache() -endif() -if(SEAL_USE_MSGSL) - find_package(MSGSL MODULE) - if(NOT MSGSL_FOUND) - set(SEAL_USE_MSGSL OFF CACHE BOOL ${SEAL_USE_MSGSL_OPTION_STR} FORCE) - clear_msgsl_cache() - endif() -endif() - -# Specific options depending on SEAL_USE_MSGSL -set(SEAL_USE_MSGSL_SPAN_OPTION_STR "Use gsl::span") -cmake_dependent_option(SEAL_USE_MSGSL_SPAN ${SEAL_USE_MSGSL_SPAN_OPTION_STR} ON "SEAL_USE_MSGSL" OFF) -if(SEAL_USE_MSGSL_SPAN) - # Detect gsl::span - if(NOT HAVE_MSGSL_SPAN) - set(SEAL_USE_MSGSL_SPAN OFF CACHE BOOL ${SEAL_USE_MSGSL_SPAN_OPTION_STR} FORCE) - endif() -endif() - -# Helper macro for clearing zlib cache -macro(clear_zlib_cache) - unset(ZLIB_INCLUDE_DIR CACHE) - unset(ZLIB_LIBRARY CACHE) - unset(ZLIB_LIBRARY_DEBUG CACHE) - unset(ZLIB_LIBRARY_RELEASE CACHE) -endmacro() - -# Try to find zlib if requested; first clear the cache if SEAL_USE_ZLIB -# is not set, or if SEAL_USE_ZLIB and ZLIB_ROOT are set (force search). -if(NOT SEAL_USE_ZLIB OR ZLIB_ROOT) - clear_zlib_cache() -endif() -if(SEAL_USE_ZLIB) - find_package(ZLIB 1.2.11 EXACT) - if(NOT ZLIB_FOUND) - set(SEAL_USE_ZLIB OFF CACHE BOOL ${SEAL_USE_ZLIB_OPTION_STR} FORCE) - clear_zlib_cache() - endif() -endif() - -# Set the sealc dynamic library file names to be included in creating -# the NuGet package. When building a multi-platform package, all three paths -# should be included. -if(SEAL_MULTIPLATFORM_NUGET_BUILD) - set(SEAL_WINDOWS_SEAL_C_PATH ../../native/lib/x64/$Configuration$/sealc.dll) - set(SEAL_LINUX_SEAL_C_PATH ../../native/lib/libsealc.so.${SEAL_VERSION}) - set(SEAL_MACOS_SEAL_C_PATH ../../native/lib/libsealc.${SEAL_VERSION}.dylib) -else() - if(MSVC) - set(SEAL_WINDOWS_SEAL_C_PATH ../../native/lib/x64/$Configuration$/sealc.dll) - elseif(APPLE) - set(SEAL_MACOS_SEAL_C_PATH ../../native/lib/libsealc.${SEAL_VERSION}.dylib) - elseif(UNIX) - set(SEAL_LINUX_SEAL_C_PATH ../../native/lib/libsealc.so.${SEAL_VERSION}) - endif() -endif() - -# Create SEALNet.nuspec from SEALNet.nuspec.in -configure_file( - ${SEAL_SOURCE_DIR}/../../dotnet/nuget/SEALNet.nuspec.in - ${SEAL_SOURCE_DIR}/../../dotnet/nuget/SEALNet.nuspec - @ONLY) - -# Create SEALNet.targets from SEALNet.targets.in -configure_file( - ${SEAL_SOURCE_DIR}/../../dotnet/nuget/SEALNet.targets.in - ${SEAL_SOURCE_DIR}/../../dotnet/nuget/SEALNet.targets - @ONLY) - -# Set the C++ language version -macro(set_language target) - if(SEAL_USE_CXX17) - target_compile_features(${target} PUBLIC cxx_std_17) - else() - target_compile_features(${target} PUBLIC cxx_std_14) - endif() -endmacro() - -# Set the VERSION property -macro(set_version target) - set_target_properties(${target} PROPERTIES VERSION ${SEAL_VERSION}) -endmacro() - -# Set the library filename to reflect version -macro(set_version_filename target) - set_target_properties(seal PROPERTIES - OUTPUT_NAME seal-${SEAL_VERSION_MAJOR}.${SEAL_VERSION_MINOR}) -endmacro() - -# Set the SOVERSION property -macro(set_soversion target) - set_target_properties(${target} PROPERTIES - SOVERSION ${SEAL_VERSION_MAJOR}.${SEAL_VERSION_MINOR}) -endmacro() - -# Set include directories for build and install interfaces -macro(set_include_directories target) - target_include_directories(${target} PUBLIC - $ - $) -endmacro() - -# Link all dependencies -macro(link_dependencies target) - # Require thread library - if(NOT TARGET Threads::Threads) - set(CMAKE_THREAD_PREFER_PTHREAD TRUE) - set(THREADS_PREFER_PTHREAD_FLAG TRUE) - find_package(Threads REQUIRED) - endif() - - # Link Threads - target_link_libraries(${target} PUBLIC Threads::Threads) - - if(SEAL_USE_MSGSL) - # Link MSGSL - target_link_libraries(${target} PUBLIC MSGSL::MSGSL) - endif() - - if(SEAL_USE_ZLIB) - # Link ZLIB - target_link_libraries(${target} PUBLIC ZLIB::ZLIB) - endif() -endmacro() - # Create an object library to compile sources only once add_library(seal_obj OBJECT) # Add source files to library and header files to install -add_subdirectory(seal) +add_subdirectory(native/src/seal) # Set C++ language version and include directories for the object library set_language(seal_obj) set_include_directories(seal_obj) +if(SEAL_USE_MSGSL AND NOT MSVC) + # Make sure Microsoft GSL is downloaded + target_link_libraries(seal_obj PUBLIC msgsl) +endif() + +if(SEAL_USE_ZLIB AND NOT MSVC) + # Make sure ZLIB is downloaded + target_link_libraries(seal_obj PRIVATE zlibstatic) +endif() + # Always build the static library add_library(seal STATIC $) - set_version(seal) set_version_filename(seal) set_language(seal) set_include_directories(seal) -link_dependencies(seal) +link_threads(seal) +install_target(seal SEALTargets) + +if(SEAL_USE_MSGSL AND NOT MSVC) + # In UNIX-like platforms copy Microsoft GSL include files into native/src + add_custom_command(TARGET seal POST_BUILD + COMMAND cp -r ${MSGSL_INCLUDE_DIR}/gsl ${SEAL_INCLUDES_BUILD_DIR}) +endif() + +if(SEAL_USE_ZLIB AND NOT MSVC) + # In UNIX-like platforms combine manually seal and zlibstatic + # into a single archive; not pretty, but works + add_custom_command(TARGET seal POST_BUILD + COMMAND ar x $ + COMMAND ar x ${ZLIB_LIBRARY_PATH} + COMMAND ar rcs $ *.o + COMMAND rm -f *.o + WORKING_DIRECTORY $) +endif() # Conditionally build the shared library if(BUILD_SHARED_LIBS) add_library(seal_shared SHARED $) - + set_target_properties(seal_shared PROPERTIES OUTPUT_NAME seal) set_version(seal_shared) set_soversion(seal_shared) set_language(seal_shared) set_include_directories(seal_shared) - link_dependencies(seal_shared) + link_threads(seal_shared) + + if(SEAL_USE_ZLIB AND NOT MSVC) + # In the shared build we link zlibstatic into the shared library + target_link_libraries(seal_shared PRIVATE zlibstatic) + endif() + + install_target(seal_shared SEALTargets) endif() -# For SEAL_C check that size_t is 8 bytes +######################### +# SEAL C export library # +######################### + +# Check that size_t is 8 bytes include(CheckTypeSize) check_type_size("size_t" SIZET LANGUAGE C) set(SEAL_BUILD_SEAL_C_OPTION_STR "Build C export library for Microsoft SEAL") -cmake_dependent_option(SEAL_BUILD_SEAL_C ${SEAL_BUILD_SEAL_C_OPTION_STR} - OFF "${SIZET} EQUAL 8" OFF) +cmake_dependent_option(SEAL_BUILD_SEAL_C ${SEAL_BUILD_SEAL_C_OPTION_STR} OFF "${SIZET} EQUAL 8" OFF) # Create shared SEAL_C library but add no source files yet if(SEAL_BUILD_SEAL_C) add_library(sealc SHARED) # Add source files to library and header files to install - add_subdirectory(seal/c) - + add_subdirectory(native/src/seal/c) set_version(sealc) set_soversion(sealc) set_language(sealc) set_include_directories(sealc) - link_dependencies(sealc) target_link_libraries(sealc PUBLIC seal) + install_target(sealc SEALTargets) endif() -macro(install_target_if_exists target export) - if(TARGET ${target}) - install(TARGETS ${target} EXPORT ${export} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) - endif() -endmacro() - -# Associate seal and seal_shared to export SEALTargets -install_target_if_exists(seal SEALTargets) -install_target_if_exists(seal_shared SEALTargets) -install_target_if_exists(sealc SEALTargets) +################################# +# Installation and CMake config # +################################# # Create the CMake config file include(CMakePackageConfigHelpers) @@ -493,3 +533,71 @@ export( EXPORT SEALTargets NAMESPACE SEAL:: FILE ${SEAL_TARGETS_FILENAME}) + +##################### +# SEAL C++ examples # +##################### + +set(SEAL_BUILD_EXAMPLES_OPTION_STR "Build C++ examples for Microsoft SEAL") +option(SEAL_BUILD_EXAMPLES ${SEAL_BUILD_EXAMPLES_OPTION_STR} OFF) + +if(SEAL_BUILD_EXAMPLES) + add_executable(sealexamples) + add_subdirectory(native/examples) + target_link_libraries(sealexamples PRIVATE seal) +endif() + +################## +# SEAL C++ tests # +################## + +set(SEAL_BUILD_TESTS_OPTION_STR "Build C++ tests for Microsoft SEAL") +option(SEAL_BUILD_TESTS ${SEAL_BUILD_TESTS_OPTION_STR} OFF) + +if(SEAL_BUILD_TESTS) + add_executable(sealtests) + add_subdirectory(native/tests) + target_link_libraries(sealtests PRIVATE seal gtest) +endif() + +####################################### +# Configure SEALNet and NuGet package # +####################################### + +# Set the sealc dynamic library file names to be included in creating +# the NuGet package. When building a multi-platform package, all three +# paths should be included. + +set(SEAL_WINDOWS_SEAL_C_PATH_ ${SEAL_SOURCE_DIR}/lib/x64/$Configuration$/sealc.dll) +set(SEAL_LINUX_SEAL_C_PATH_ ${SEAL_SOURCE_DIR}/lib/libsealc.so.${SEAL_VERSION}) +set(SEAL_MACOS_SEAL_C_PATH_ ${SEAL_SOURCE_DIR}/lib/libsealc.${SEAL_VERSION}.dylib) + +unset(SEAL_WINDOWS_SEAL_C_PATH) +unset(SEAL_LINUX_SEAL_C_PATH) +unset(SEAL_MACOS_SEAL_C_PATH) + +if(SEAL_MULTIPLATFORM_NUGET_BUILD) + set(SEAL_WINDOWS_SEAL_C_PATH ${SEAL_WINDOWS_SEAL_C_PATH_}) + set(SEAL_LINUX_SEAL_C_PATH ${SEAL_LINUX_SEAL_C_PATH_}) + set(SEAL_MACOS_SEAL_C_PATH ${SEAL_MACOS_SEAL_C_PATH_}) +else() + if(MSVC) + set(SEAL_WINDOWS_SEAL_C_PATH ${SEAL_WINDOWS_SEAL_C_PATH_}) + elseif(UNIX) + set(SEAL_LINUX_SEAL_C_PATH ${SEAL_LINUX_SEAL_C_PATH_}) + elseif(APPLE) + set(SEAL_MACOS_SEAL_C_PATH ${SEAL_MACOS_SEAL_C_PATH_}) + endif() +endif() + +# Create SEALNet.nuspec from SEALNet.nuspec.in +configure_file( + ${SEAL_SOURCE_DIR}/dotnet/nuget/SEALNet.nuspec.in + ${SEAL_SOURCE_DIR}/dotnet/nuget/SEALNet.nuspec + @ONLY) + +# Create SEALNet.targets from SEALNet.targets.in +configure_file( + ${SEAL_SOURCE_DIR}/dotnet/nuget/SEALNet.targets.in + ${SEAL_SOURCE_DIR}/dotnet/nuget/SEALNet.targets + @ONLY) diff --git a/Changes.md b/Changes.md index b422b009..fa55d8c3 100644 --- a/Changes.md +++ b/Changes.md @@ -20,6 +20,10 @@ - Microsoft SEAL now compiles also in FreeBSD ([PR 113](https://github.com/microsoft/SEAL/pull/113)). - In serialization, unsupported compression mode now throws `std::invalid_argument` (native) or `ArgumentException` (.NET). - Examples for serialization have been added. +- ZLIB is now downloaded and compiled by default by CMake, and included into a static/dynamic target object (can be disabled). +- Microsoft GSL is now downloaded automatically (can be disabled). +- Google Test is now downloaded and compiled by CMake and is no longer included as a Git submodule. +- Releases are now listed on GitHub. - Moved `dotnet/native/` to be under `native/src/c/`. The C export library in this directory can be used to build wrappers for other languages also -- not just .NET. - Changed the CMake file structure. Targets available are now: `SEAL::seal` (static library), `SEAL::seal_shared` (shared library), `SEAL::sealc` (C export library). diff --git a/ISSUES.md b/ISSUES.md index 5029992b..b5cc0041 100644 --- a/ISSUES.md +++ b/ISSUES.md @@ -1,16 +1,16 @@ -# Issues +# Issues ## Technical questions -The best way to get help with technical questions is on -[StackOverflow](https://stackoverflow.com/questions/tagged/seal) using the `[seal]` +The best way to get help with technical questions is on +[StackOverflow](https://stackoverflow.com/questions/tagged/seal) using the `[seal]` tag. To contact the Microsoft SEAL team directly, please email [sealcrypto@microsoft.com](mailto:sealcrypto@microsoft.com). ## Bug reports -We appreciate community efforts to find and fix bugs and issues in Microsoft SEAL. -If you believe you have found a bug or want to report some other issue, please +We appreciate community efforts to find and fix bugs and issues in Microsoft SEAL. +If you believe you have found a bug or want to report some other issue, please do so on [GitHub](https://github.com/Microsoft/SEAL/issues). To help others determine what the problem may be, we provide a helpful script that collects relevant system information that you can submit with the bug report (see below). @@ -21,7 +21,7 @@ To collect system information for an improved bug report, please run ``` make -C tools system_info ``` -This will result in a file `system_info.tar.gz` to be generated, which you can +This will result in a file `system_info.tar.gz` to be generated, which you can optionally attach with your bug report. ## Critical security issues diff --git a/README.md b/README.md index 6ca1b8d3..7082aadd 100644 --- a/README.md +++ b/README.md @@ -121,8 +121,8 @@ Studio 2017 version 15.3 or newer is required to build Microsoft SEAL. The Visual Studio solution `SEAL.sln` is configured to build Microsoft SEAL both for `Win32` and `x64` platforms. Please choose the right platform before building -Microsoft SEAL. The `SEALNetNative` project or the .NET wrapper library `SEALNet` -can only be built for `x64`. +Microsoft SEAL. The `SEAL_C` project and the .NET wrapper library `SEALNet` can only +be built for `x64`. #### Debug and Release builds @@ -134,7 +134,7 @@ as the performance will be orders of magnitude worse than in `Release` mode. #### Building Microsoft SEAL Build the SEAL project `native\src\SEAL.vcxproj` from `SEAL.sln`. This results in -the static library `seal.lib` to be created in `native\lib\$(Platform)\$(Configuration)`. +the static library `seal.lib` to be created in `lib\$(Platform)\$(Configuration)`. When linking with applications, you need to add `native\src\` (full path) as an include directory for Microsoft SEAL header files. @@ -142,7 +142,7 @@ include directory for Microsoft SEAL header files. Build the SEALExamples project `native\examples\SEALExamples.vcxproj` from `SEAL.sln`. This results in an executable `sealexamples.exe` to be created in -`native\bin\$(Platform)\$(Configuration)`. +`bin\$(Platform)\$(Configuration)`. #### Building Unit Tests @@ -240,7 +240,7 @@ cd ../.. It is very easy to link your own applications and libraries with Microsoft SEAL if you use CMake. Simply add the following to your `CMakeLists.txt`: ```` -find_package(SEAL 3.4 REQUIRED) +find_package(SEAL 3.5 REQUIRED) target_link_libraries( SEAL::seal) ```` If Microsoft SEAL was installed globally, the above `find_package` command will likely @@ -266,14 +266,10 @@ enabled if it is compiled with support for specific third-party libraries. ## Microsoft GSL Microsoft GSL (Guidelines Support Library) is a header-only library that implements -two convenient (templated) data types: `gsl::span` and `gsl::multi_span`. These -are *view types* that provide safe (bounds-checked) array access to memory. For -example, if Microsoft GSL is available, Microsoft SEAL can allow `BatchEncoder` +`gsl::span`: a *view type* that provide safe (bounds-checked) array access to memory. +For example, if Microsoft GSL is available, Microsoft SEAL can allow `BatchEncoder` and `CKKSEncoder` to encode from and decode to a `gsl::span` instead of `std::vector`, -which can have significant benefit in performance. Additionally, `BatchEncoder` allows -access to the slot data alternatively through a two-dimensional `gsl::multi_span`, -reflecting the batching slot structure. Also the `Ciphertext` class allows the -ciphertext data to be accessed hierarchically through a `gsl::multi_span`. +which can in some cases have a significant performance benefit. #### Microsoft GSL in Windows @@ -546,7 +542,7 @@ It is recommeded to read the comments and the code snippets along with command l from running an example. For easier navigation, command line printout provides the line number in the associated source file where the associated code snippets start. -**WARNING: It is impossible to use Microsoft SEAL correctly without reading all examples +**WARNING: It is impossible to use Microsoft SEAL correctly without reading all examples or by simply re-using the code from examples. Any developer attempting to do so will inevitably produce code that is *vulnerable*, *malfunctioning*, or *extremely slow*.** diff --git a/SEAL.sln b/SEAL.sln index aa06a90f..90037545 100644 --- a/SEAL.sln +++ b/SEAL.sln @@ -42,6 +42,46 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NuGet", "NuGet", "{33C15AAC dotnet\nuget\SEALNet.targets.in = dotnet\nuget\SEALNet.targets.in EndProjectSection EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C73A600E-7F50-467C-9228-58AC2C1A7DDA}" + ProjectSection(SolutionItems) = preProject + .clang-format = .clang-format + .gitignore = .gitignore + azure-pipelines.yml = azure-pipelines.yml + Changes.md = Changes.md + CMakeLists.txt = CMakeLists.txt + CODE_OF_CONDUCT.md = CODE_OF_CONDUCT.md + CONTRIBUTING.md = CONTRIBUTING.md + ISSUES.md = ISSUES.md + LICENSE = LICENSE + NOTICE = NOTICE + README.md = README.md + SECURITY.md = SECURITY.md + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "templates", "templates", "{0518DDC0-82BC-4E7C-A24D-98B8EA9C47B3}" + ProjectSection(SolutionItems) = preProject + templates\nix-build.yml = templates\nix-build.yml + templates\pack.yml = templates\pack.yml + templates\windows-build.yml = templates\windows-build.yml + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "thirdparty", "thirdparty", "{6B00D0DE-8A17-44B8-BF47-F372E9189434}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "zlib", "zlib", "{5E524D23-AD60-45AF-B279-0322941E9F31}" + ProjectSection(SolutionItems) = preProject + thirdparty\zlib\CMakeLists.txt = thirdparty\zlib\CMakeLists.txt + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "msgsl", "msgsl", "{B4EF7358-C76B-4142-9746-B082114B1DDD}" + ProjectSection(SolutionItems) = preProject + thirdparty\msgsl\CMakeLists.txt = thirdparty\msgsl\CMakeLists.txt + EndProjectSection +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "googletest", "googletest", "{0DD76E94-59E1-49D4-9ED7-8C696B89F26E}" + ProjectSection(SolutionItems) = preProject + thirdparty\googletest\CMakeLists.txt = thirdparty\googletest\CMakeLists.txt + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -114,11 +154,16 @@ Global {7EA96C25-FC0D-485A-BB71-32B6DA55652A} = {A5BADDF0-1F03-48FE-AAC0-3355614C9A8D} {0345DC4D-EFE3-460E-AB7E-AA6E05BB8DFF} = {A5BADDF0-1F03-48FE-AAC0-3355614C9A8D} {2B57D847-26DC-45FF-B9AF-EE33910B5093} = {A5BADDF0-1F03-48FE-AAC0-3355614C9A8D} - {70BBB2AA-FA77-40C1-890F-7AA7DBB3AD3D} = {0786F255-C3A7-4912-A669-12273E7AE013} + {70BBB2AA-FA77-40C1-890F-7AA7DBB3AD3D} = {A5BADDF0-1F03-48FE-AAC0-3355614C9A8D} {D7ED94EC-3FAB-4B87-AB5F-0308EA92520E} = {0786F255-C3A7-4912-A669-12273E7AE013} {D0FCCA29-F0F8-49A3-9615-24FF899F1909} = {0786F255-C3A7-4912-A669-12273E7AE013} {18DA9F90-3131-461A-A3E8-40AC0B1D7632} = {0786F255-C3A7-4912-A669-12273E7AE013} {33C15AAC-6E56-477E-A118-3451FD21AC49} = {0786F255-C3A7-4912-A669-12273E7AE013} + {0518DDC0-82BC-4E7C-A24D-98B8EA9C47B3} = {C73A600E-7F50-467C-9228-58AC2C1A7DDA} + {6B00D0DE-8A17-44B8-BF47-F372E9189434} = {C73A600E-7F50-467C-9228-58AC2C1A7DDA} + {5E524D23-AD60-45AF-B279-0322941E9F31} = {6B00D0DE-8A17-44B8-BF47-F372E9189434} + {B4EF7358-C76B-4142-9746-B082114B1DDD} = {6B00D0DE-8A17-44B8-BF47-F372E9189434} + {0DD76E94-59E1-49D4-9ED7-8C696B89F26E} = {6B00D0DE-8A17-44B8-BF47-F372E9189434} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {15A17F22-F747-4B82-BF5F-E0224AF4B3ED} diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 3a8d1c5f..05aed071 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -14,8 +14,6 @@ stages: displayName: Windows pool: vmImage: 'windows-latest' - variables: - ZLIB_ROOT: '$(Build.SourcesDirectory)\native\src\thirdparty\zlib\zlib-src' steps: - template: templates/windows-build.yml parameters: @@ -35,15 +33,14 @@ stages: g++-7 --version which gcc-7 which g++-7 - + sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc-7 50 sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++-7 50 - + displayName: 'Install GCC 7' - template: templates/nix-build.yml parameters: artifactName: linux-drop - ext: a - job: macOs displayName: Mac OS X @@ -54,7 +51,6 @@ stages: - template: templates/nix-build.yml parameters: artifactName: macos-drop - ext: a - job: Nuget displayName: Pack into Nuget diff --git a/native/src/cmake/FindMSGSL.cmake b/cmake/FindMSGSL.cmake similarity index 100% rename from native/src/cmake/FindMSGSL.cmake rename to cmake/FindMSGSL.cmake diff --git a/native/src/cmake/SEALConfig.cmake.in b/cmake/SEALConfig.cmake.in similarity index 93% rename from native/src/cmake/SEALConfig.cmake.in rename to cmake/SEALConfig.cmake.in index b6604e47..ed44fbbd 100644 --- a/native/src/cmake/SEALConfig.cmake.in +++ b/cmake/SEALConfig.cmake.in @@ -52,20 +52,10 @@ set(SEAL_ENFORCE_HE_STD_SECURITY @SEAL_ENFORCE_HE_STD_SECURITY@) # Add the current directory to the module search path list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}) -set(SEAL_USE_MSGSL @SEAL_USE_MSGSL@) -if(SEAL_USE_MSGSL) - find_seal_dependency(MSGSL) -endif() - set(CMAKE_THREAD_PREFER_PTHREAD TRUE) set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_seal_dependency(Threads) -set(SEAL_USE_ZLIB @SEAL_USE_ZLIB@) -if(SEAL_USE_ZLIB) - find_seal_dependency(ZLIB) -endif() - include(${CMAKE_CURRENT_LIST_DIR}/SEALTargets.cmake) if(TARGET SEAL::seal) diff --git a/dotnet/examples/SEALNetExamples.csproj b/dotnet/examples/SEALNetExamples.csproj index c7baddc8..4174daf1 100644 --- a/dotnet/examples/SEALNetExamples.csproj +++ b/dotnet/examples/SEALNetExamples.csproj @@ -11,17 +11,17 @@ x64 - ../bin/$(Configuration) + $(ProjectDir)../../bin/dotnet/$(Configuration) - + - - - + + + diff --git a/dotnet/nuget/SEALNet.nuspec.in b/dotnet/nuget/SEALNet.nuspec.in index e4794e7f..38d0b311 100644 --- a/dotnet/nuget/SEALNet.nuspec.in +++ b/dotnet/nuget/SEALNet.nuspec.in @@ -23,12 +23,12 @@ - - - - - - + + + + + + diff --git a/dotnet/nuget/SEALNet.targets.in b/dotnet/nuget/SEALNet.targets.in index b5791a89..b3be0501 100644 --- a/dotnet/nuget/SEALNet.targets.in +++ b/dotnet/nuget/SEALNet.targets.in @@ -5,9 +5,9 @@ - - - + + + diff --git a/dotnet/src/SEALNet.csproj b/dotnet/src/SEALNet.csproj index 7416f577..3ba8b51e 100644 --- a/dotnet/src/SEALNet.csproj +++ b/dotnet/src/SEALNet.csproj @@ -11,9 +11,9 @@ true - ../lib/$(Configuration)/SEALNet.xml + $(ProjectDir)../../lib/dotnet/$(Configuration)/SEALNet.xml x64 - ../lib/$(Configuration) + $(ProjectDir)../../lib/dotnet/$(Configuration) diff --git a/dotnet/tests/SEALNetTest.csproj b/dotnet/tests/SEALNetTest.csproj index a7a7d249..3dc1b075 100644 --- a/dotnet/tests/SEALNetTest.csproj +++ b/dotnet/tests/SEALNetTest.csproj @@ -11,7 +11,7 @@ x64 - ../lib/$(Configuration) + $(ProjectDir)../../bin/dotnet/$(Configuration) @@ -21,13 +21,13 @@ - + - - - + + + diff --git a/native/examples/CMakeLists.txt b/native/examples/CMakeLists.txt index 60cfe0d0..c3b5d614 100644 --- a/native/examples/CMakeLists.txt +++ b/native/examples/CMakeLists.txt @@ -1,30 +1,14 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT license. -cmake_minimum_required(VERSION 3.12) - -project(SEALExamples VERSION 3.5.0 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 3.5.0 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) + ${CMAKE_CURRENT_LIST_DIR}/examples.cpp + ${CMAKE_CURRENT_LIST_DIR}/1_bfv_basics.cpp + ${CMAKE_CURRENT_LIST_DIR}/2_encoders.cpp + ${CMAKE_CURRENT_LIST_DIR}/3_levels.cpp + ${CMAKE_CURRENT_LIST_DIR}/4_ckks_basics.cpp + ${CMAKE_CURRENT_LIST_DIR}/5_rotation.cpp + ${CMAKE_CURRENT_LIST_DIR}/6_serialization.cpp + ${CMAKE_CURRENT_LIST_DIR}/7_performance.cpp +) \ No newline at end of file diff --git a/native/examples/SEALExamples.vcxproj b/native/examples/SEALExamples.vcxproj index bd25681e..0e101770 100644 --- a/native/examples/SEALExamples.vcxproj +++ b/native/examples/SEALExamples.vcxproj @@ -71,25 +71,25 @@ true - $(ProjectDir)..\bin\$(Platform)\$(Configuration)\ + $(ProjectDir)..\..\bin\$(Platform)\$(Configuration)\ $(ProjectDir)obj\$(Platform)\$(Configuration)\ sealexamples true - $(ProjectDir)..\bin\$(Platform)\$(Configuration)\ + $(ProjectDir)..\..\bin\$(Platform)\$(Configuration)\ $(ProjectDir)obj\$(Platform)\$(Configuration)\ sealexamples false - $(ProjectDir)..\bin\$(Platform)\$(Configuration)\ + $(ProjectDir)..\..\bin\$(Platform)\$(Configuration)\ $(ProjectDir)obj\$(Platform)\$(Configuration)\ sealexamples false - $(ProjectDir)..\bin\$(Platform)\$(Configuration)\ + $(ProjectDir)..\..\bin\$(Platform)\$(Configuration)\ $(ProjectDir)obj\$(Platform)\$(Configuration)\ sealexamples @@ -100,7 +100,7 @@ Disabled _ENABLE_EXTENDED_ALIGNED_STORAGE true - $(MSGSL_ROOT);$(SolutionDir)native\src + $(SolutionDir)native\src stdcpp17 /Zc:__cplusplus %(AdditionalOptions) Guard @@ -110,7 +110,7 @@ Console true - $(ProjectDir)..\lib\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + $(ProjectDir)..\..\lib\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) seal.lib;%(AdditionalDependencies) @@ -121,7 +121,7 @@ Disabled _ENABLE_EXTENDED_ALIGNED_STORAGE true - $(MSGSL_ROOT);$(SolutionDir)native\src + $(SolutionDir)native\src stdcpp17 /Zc:__cplusplus %(AdditionalOptions) Guard @@ -131,7 +131,7 @@ Console true - $(ProjectDir)..\lib\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + $(ProjectDir)..\..\lib\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) seal.lib;%(AdditionalDependencies) @@ -144,7 +144,7 @@ true _ENABLE_EXTENDED_ALIGNED_STORAGE true - $(MSGSL_ROOT);$(SolutionDir)native\src + $(SolutionDir)native\src stdcpp17 /Zc:__cplusplus %(AdditionalOptions) Guard @@ -155,7 +155,7 @@ true true true - $(ProjectDir)..\lib\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + $(ProjectDir)..\..\lib\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) seal.lib;%(AdditionalDependencies) true @@ -169,7 +169,7 @@ true _ENABLE_EXTENDED_ALIGNED_STORAGE true - $(MSGSL_ROOT);$(SolutionDir)native\src + $(SolutionDir)native\src stdcpp17 /Zc:__cplusplus %(AdditionalOptions) Guard @@ -180,7 +180,7 @@ true true true - $(ProjectDir)..\lib\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + $(ProjectDir)..\..\lib\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) seal.lib;%(AdditionalDependencies) true diff --git a/native/examples/examples.h b/native/examples/examples.h index 5d3a7d64..ab557a41 100644 --- a/native/examples/examples.h +++ b/native/examples/examples.h @@ -212,7 +212,7 @@ inline void print_matrix(std::vector matrix, std::size_t row_size) std::cout << std::setw(3) << matrix[i] << ((i != 2 * row_size - 1) ? "," : " ]\n"); } std::cout << std::endl; -}; +} /* Helper function: Print line number. @@ -220,4 +220,4 @@ Helper function: Print line number. inline void print_line(int line_number) { std::cout << "Line " << std::setw(3) << line_number << " --> "; -} \ No newline at end of file +} diff --git a/native/src/CMakeConfig.cmd b/native/src/CMakeConfig.cmd index fcbb374a..21c909ba 100644 --- a/native/src/CMakeConfig.cmd +++ b/native/src/CMakeConfig.cmd @@ -51,7 +51,33 @@ if "%VSVERSION%"=="15.0" ( exit 1 ) -set CONFIGDIR=".config\%VSVERSION%\%PROJECTPLATFORM%" +rem Download Microsoft GSL +set MSGSLCONFIGDIR="..\..\thirdparty\msgsl\.config\%VSVERSION%\%PROJECTPLATFORM%" +cd %~dp0 +if not exist %MSGSLCONFIGDIR% ( + mkdir %MSGSLCONFIGDIR% +) +cd %MSGSLCONFIGDIR% +"%CMAKEPATH%" ..\..\.. -G %CMAKEGEN% -A %PROJECTPLATFORM% +"%CMAKEPATH%" --build . --config "%PROJECTCONFIGURATION%" + +rem Copy Microsoft GSL header files into the local source directory +robocopy ..\..\..\GSL-src\include %~dp0 /s + +rem Download and build ZLIB +set ZLIBCONFIGDIR="..\..\thirdparty\zlib\.config\%VSVERSION%\%PROJECTPLATFORM%" +cd %~dp0 +if not exist %ZLIBCONFIGDIR% ( + mkdir %ZLIBCONFIGDIR% +) +cd %ZLIBCONFIGDIR% +"%CMAKEPATH%" ..\..\.. -G %CMAKEGEN% -A %PROJECTPLATFORM% ^ + -DZLIB_PLATFORM="%PROJECTPLATFORM%" + +"%CMAKEPATH%" --build . --config "%PROJECTCONFIGURATION%" + +rem Configure Microsoft SEAL +set CONFIGDIR="..\..\.config\%VSVERSION%\%PROJECTPLATFORM%" cd %~dp0 if not exist %CONFIGDIR% ( mkdir %CONFIGDIR% @@ -59,27 +85,13 @@ if not exist %CONFIGDIR% ( cd %CONFIGDIR% echo Running CMake configuration in %cd% -rem Determine if ZLIB should be enabled -set USE_ZLIB=0 -if defined ZLIB_ROOT ( - set USE_ZLIB=1 -) - -rem Determine if MSGSL should be enabled -set USE_MSGSL=0 -if defined MSGSL_ROOT ( - set USE_MSGSL=1 -) - -rem Call CMake. -"%CMAKEPATH%" ..\..\.. ^ - -G %CMAKEGEN% ^ - -A %PROJECTPLATFORM% ^ +"%CMAKEPATH%" ..\..\.. -G %CMAKEGEN% -A %PROJECTPLATFORM% ^ -DALLOW_COMMAND_LINE_BUILD=1 ^ -DCMAKE_BUILD_TYPE="%PROJECTCONFIGURATION%" ^ - -DSEAL_USE_MSGSL=%USE_MSGSL% ^ - -DMSGSL_ROOT="%MSGSL_ROOT%" ^ - -DSEAL_USE_ZLIB=%USE_ZLIB% ^ - -DZLIB_ROOT="%ZLIB_ROOT%" ^ - -DCMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX="Release" ^ + -DBUILD_SHARED_LIBS=OFF ^ + -DSEAL_USE_MSGSL=ON ^ + -DSEAL_USE_ZLIB=ON ^ + -DSEAL_BUILD_TESTS=OFF ^ + -DSEAL_BUILD_EXAMPLES=OFF ^ + -DSEAL_BUILD_SEAL_C=OFF ^ --no-warn-unused-cli diff --git a/native/src/SEAL.vcxproj b/native/src/SEAL.vcxproj index 9cc63e98..b4d2cc77 100644 --- a/native/src/SEAL.vcxproj +++ b/native/src/SEAL.vcxproj @@ -118,7 +118,6 @@ - @@ -186,35 +185,43 @@ - $(ProjectDir)..\lib\$(Platform)\$(Configuration)\ - $(ProjectDir)obj\sealc\$(Platform)\$(Configuration)\ + $(ProjectDir)..\..\lib\$(Platform)\$(Configuration)\ + $(ProjectDir)obj\$(Platform)\$(Configuration)\seal\ .lib seal + + - $(ProjectDir)..\lib\$(Platform)\$(Configuration)\ - $(ProjectDir)obj\sealc\$(Platform)\$(Configuration)\ + $(ProjectDir)..\..\lib\$(Platform)\$(Configuration)\ + $(ProjectDir)obj\$(Platform)\$(Configuration)\seal\ .lib seal + + - $(ProjectDir)..\lib\$(Platform)\$(Configuration)\ - $(ProjectDir)obj\sealc\$(Platform)\$(Configuration)\ + $(ProjectDir)..\..\lib\$(Platform)\$(Configuration)\ + $(ProjectDir)obj\$(Platform)\$(Configuration)\seal\ .lib seal + + - $(ProjectDir)..\lib\$(Platform)\$(Configuration)\ - $(ProjectDir)obj\sealc\$(Platform)\$(Configuration)\ + $(ProjectDir)..\..\lib\$(Platform)\$(Configuration)\ + $(ProjectDir)obj\$(Platform)\$(Configuration)\seal\ .lib seal + + Level3 Disabled true - $(ZLIB_ROOT);$(MSGSL_ROOT);$(ProjectDir) + $(SolutionDir)/thirdparty/zlib/zlib-src;$(SolutionDir)/thirdparty/zlib/zlib-build/$(Platform);$(ProjectDir) true Neither stdcpp17 @@ -236,8 +243,8 @@ Configure Microsoft SEAL through CMake - Bcrypt.lib;$(ZlibName) - $(ZLIB_ROOT)\Release + Bcrypt.lib;zlibstaticd.lib + $(SolutionDir)\thirdparty\zlib\zlib-build\$(Platform)\$(Configuration) /IGNORE:4006 %(AdditionalOptions) @@ -246,7 +253,7 @@ Level3 Disabled true - $(ZLIB_ROOT);$(MSGSL_ROOT);$(ProjectDir) + $(SolutionDir)/thirdparty/zlib/zlib-src;$(SolutionDir)/thirdparty/zlib/zlib-build/$(Platform);$(ProjectDir) true Neither stdcpp17 @@ -267,8 +274,8 @@ Configure Microsoft SEAL through CMake - Bcrypt.lib;$(ZlibName) - $(ZLIB_ROOT)\Release + Bcrypt.lib;zlibstaticd.lib + $(SolutionDir)\thirdparty\zlib\zlib-build\$(Platform)\$(Configuration) /IGNORE:4006 %(AdditionalOptions) @@ -279,7 +286,7 @@ true true true - $(ZLIB_ROOT);$(MSGSL_ROOT);$(ProjectDir) + $(SolutionDir)/thirdparty/zlib/zlib-src;$(SolutionDir)/thirdparty/zlib/zlib-build/$(Platform);$(ProjectDir) Speed Default stdcpp17 @@ -302,8 +309,8 @@ Configure Microsoft SEAL through CMake - Bcrypt.lib;$(ZlibName) - $(ZLIB_ROOT)\Release + Bcrypt.lib;zlibstatic.lib + $(SolutionDir)\thirdparty\zlib\zlib-build\$(Platform)\$(Configuration) /IGNORE:4006 %(AdditionalOptions) @@ -314,7 +321,7 @@ true true true - $(ZLIB_ROOT);$(MSGSL_ROOT);$(ProjectDir) + $(SolutionDir)/thirdparty/zlib/zlib-src;$(SolutionDir)/thirdparty/zlib/zlib-build/$(Platform);$(ProjectDir) Speed Default stdcpp17 @@ -336,8 +343,8 @@ Configure Microsoft SEAL through CMake - Bcrypt.lib;$(ZlibName) - $(ZLIB_ROOT)\Release + Bcrypt.lib;zlibstatic.lib + $(SolutionDir)\thirdparty\zlib\zlib-build\$(Platform)\$(Configuration) /IGNORE:4006 %(AdditionalOptions) diff --git a/native/src/SEAL.vcxproj.filters b/native/src/SEAL.vcxproj.filters index a6874c38..e291413c 100644 --- a/native/src/SEAL.vcxproj.filters +++ b/native/src/SEAL.vcxproj.filters @@ -318,9 +318,6 @@ - - Other - Other\seal @@ -342,4 +339,4 @@ Other - + \ No newline at end of file diff --git a/native/src/SEAL_C.vcxproj b/native/src/SEAL_C.vcxproj index e5fab886..7850d6c6 100644 --- a/native/src/SEAL_C.vcxproj +++ b/native/src/SEAL_C.vcxproj @@ -73,27 +73,27 @@ false - $(ProjectDir)..\lib\$(Platform)\$(Configuration)\ + $(ProjectDir)..\..\lib\$(Platform)\$(Configuration)\ sealc - $(ProjectDir)obj\seal\$(Platform)\$(Configuration)\ + $(ProjectDir)obj\$(Platform)\$(Configuration)\seal\c\ false - $(ProjectDir)..\lib\$(Platform)\$(Configuration)\ + $(ProjectDir)..\..\lib\$(Platform)\$(Configuration)\ sealc - $(ProjectDir)obj\seal\$(Platform)\$(Configuration)\ + $(ProjectDir)obj\$(Platform)\$(Configuration)\seal\c\ true - $(ProjectDir)..\lib\$(Platform)\$(Configuration)\ + $(ProjectDir)..\..\lib\$(Platform)\$(Configuration)\ sealc - $(ProjectDir)obj\seal\$(Platform)\$(Configuration)\ + $(ProjectDir)obj\$(Platform)\$(Configuration)\seal\c\ true - $(ProjectDir)..\lib\$(Platform)\$(Configuration)\ + $(ProjectDir)..\..\lib\$(Platform)\$(Configuration)\ sealc - $(ProjectDir)obj\seal\$(Platform)\$(Configuration)\ + $(ProjectDir)obj\$(Platform)\$(Configuration)\seal\c\ @@ -105,11 +105,12 @@ true SEAL_C_EXPORTS;NOMINMAX;_ENABLE_EXTENDED_ALIGNED_STORAGE;_SCL_SECURE_NO_WARNING;NDEBUG;SEALDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) true - $(MSGSL_ROOT);$(ProjectDir) + $(ProjectDir) stdcpp17 seal\c/stdafx.h /Zc:__cplusplus %(AdditionalOptions) true + Guard Windows @@ -117,7 +118,7 @@ true true seal.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - $(ProjectDir)..\lib\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + $(ProjectDir)..\..\lib\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) @@ -130,11 +131,12 @@ true SEAL_C_EXPORTS;NOMINMAX;_ENABLE_EXTENDED_ALIGNED_STORAGE;_SCL_SECURE_NO_WARNING;NDEBUG;SEALDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) true - $(MSGSL_ROOT);$(ProjectDir) + $(ProjectDir) stdcpp17 seal\c\stdafx.h /Zc:__cplusplus %(AdditionalOptions) true + Guard Windows @@ -142,7 +144,7 @@ true true seal.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - $(ProjectDir)..\lib\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + $(ProjectDir)..\..\lib\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) @@ -153,17 +155,19 @@ true SEAL_C_EXPORTS;NOMINMAX;_ENABLE_EXTENDED_ALIGNED_STORAGE;_SCL_SECURE_NO_WARNING;_DEBUG;SEALDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) true - $(MSGSL_ROOT);$(ProjectDir) + $(ProjectDir) stdcpp17 seal\c\stdafx.h /Zc:__cplusplus %(AdditionalOptions) true + Guard + ProgramDatabase Windows true seal.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - $(ProjectDir)..\lib\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + $(ProjectDir)..\..\lib\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) @@ -174,17 +178,19 @@ true SEAL_C_EXPORTS;NOMINMAX;_ENABLE_EXTENDED_ALIGNED_STORAGE;_SCL_SECURE_NO_WARNING;_DEBUG;SEALDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) true - $(MSGSL_ROOT);$(ProjectDir) + $(ProjectDir) stdcpp17 seal\c\stdafx.h /Zc:__cplusplus %(AdditionalOptions) true + Guard + ProgramDatabase Windows true seal.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - $(ProjectDir)..\lib\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + $(ProjectDir)..\..\lib\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) diff --git a/native/src/seal/batchencoder.cpp b/native/src/seal/batchencoder.cpp index 1bf81308..cf71fbe4 100644 --- a/native/src/seal/batchencoder.cpp +++ b/native/src/seal/batchencoder.cpp @@ -196,7 +196,7 @@ namespace seal // Note: We already performed bit-reversal when reading in the matrix inverse_ntt_negacyclic_harvey(destination.data(), *context_data.plain_ntt_tables()); } -#ifdef SEAL_USE_MSGSL_SPAN +#ifdef SEAL_USE_MSGSL void BatchEncoder::encode(gsl::span values_matrix, Plaintext &destination) { auto &context_data = *context_->first_context_data(); @@ -418,7 +418,7 @@ namespace seal : static_cast(curr_value); } } -#ifdef SEAL_USE_MSGSL_SPAN +#ifdef SEAL_USE_MSGSL void BatchEncoder::decode(const Plaintext &plain, gsl::span destination, MemoryPoolHandle pool) { if (!is_valid_for(plain, context_)) diff --git a/native/src/seal/batchencoder.h b/native/src/seal/batchencoder.h index 35c9fab3..6d2e023d 100644 --- a/native/src/seal/batchencoder.h +++ b/native/src/seal/batchencoder.h @@ -11,7 +11,7 @@ #include "seal/util/uintcore.h" #include #include -#ifdef SEAL_USE_MSGSL_SPAN +#ifdef SEAL_USE_MSGSL #include #endif @@ -101,7 +101,7 @@ namespace seal @throws std::invalid_argument if values is too large */ void encode(const std::vector &values, Plaintext &destination); -#ifdef SEAL_USE_MSGSL_SPAN +#ifdef SEAL_USE_MSGSL /** Creates a plaintext from a given matrix. This function "batches" a given matrix of integers modulo the plaintext modulus into a plaintext element, and stores @@ -194,7 +194,7 @@ namespace seal void decode( const Plaintext &plain, std::vector &destination, MemoryPoolHandle pool = MemoryManager::GetPool()); -#ifdef SEAL_USE_MSGSL_SPAN +#ifdef SEAL_USE_MSGSL /** Inverse of encode. This function "unbatches" a given plaintext into a matrix of integers modulo the plaintext modulus, and stores the result in the destination diff --git a/native/src/seal/biguint.cpp b/native/src/seal/biguint.cpp index e1ab0e32..27e8dc5d 100644 --- a/native/src/seal/biguint.cpp +++ b/native/src/seal/biguint.cpp @@ -44,7 +44,7 @@ namespace seal throw invalid_argument("value must be non-null for non-zero bit count"); } } -#ifdef SEAL_USE_MSGSL_SPAN +#ifdef SEAL_USE_MSGSL BigUInt::BigUInt(gsl::span value) { if (unsigned_gt(value.size(), numeric_limits::max() / bits_per_uint64)) diff --git a/native/src/seal/biguint.h b/native/src/seal/biguint.h index 9640a62c..27daf8ae 100644 --- a/native/src/seal/biguint.h +++ b/native/src/seal/biguint.h @@ -15,7 +15,7 @@ #include #include #include -#ifdef SEAL_USE_MSGSL_SPAN +#ifdef SEAL_USE_MSGSL #include #endif @@ -149,7 +149,7 @@ namespace seal and bit_count is positive */ BigUInt(int bit_count, std::uint64_t *value); -#ifdef SEAL_USE_MSGSL_SPAN +#ifdef SEAL_USE_MSGSL /** Creates an aliased BigUInt with given backing array and bit width set to the size of the backing array. An aliased BigUInt does not internally @@ -238,7 +238,7 @@ namespace seal { return value_.get(); } -#ifdef SEAL_USE_MSGSL_SPAN +#ifdef SEAL_USE_MSGSL /** Returns the backing array storing the BigUInt value. @@ -419,7 +419,7 @@ namespace seal value_ = util::Pointer::Aliasing(value); bit_count_ = bit_count; } -#ifdef SEAL_USE_MSGSL_SPAN +#ifdef SEAL_USE_MSGSL /** Makes the BigUInt an aliased BigUInt with the given backing array and bit width set equal to the size of the backing array. An aliased diff --git a/native/src/seal/ckks.h b/native/src/seal/ckks.h index 3d18b4f4..d39ea03c 100644 --- a/native/src/seal/ckks.h +++ b/native/src/seal/ckks.h @@ -15,7 +15,7 @@ #include #include #include -#ifdef SEAL_USE_MSGSL_SPAN +#ifdef SEAL_USE_MSGSL #include #endif @@ -138,7 +138,7 @@ namespace seal { encode(values, context_->first_parms_id(), scale, destination, std::move(pool)); } -#ifdef SEAL_USE_MSGSL_SPAN +#ifdef SEAL_USE_MSGSL /** Encodes a vector of double-precision floating-point real or complex numbers into a plaintext polynomial. Append zeros if vector size is less than N/2. @@ -359,7 +359,7 @@ namespace seal destination.resize(slots_); decode_internal(plain, destination.data(), std::move(pool)); } -#ifdef SEAL_USE_MSGSL_SPAN +#ifdef SEAL_USE_MSGSL /** Decodes a plaintext polynomial into double-precision floating-point real or complex numbers. Dynamic memory allocations in the process are diff --git a/native/src/seal/encryptor.h b/native/src/seal/encryptor.h index 6e2773c4..2c3af90c 100644 --- a/native/src/seal/encryptor.h +++ b/native/src/seal/encryptor.h @@ -282,7 +282,7 @@ namespace seal { Ciphertext destination; encrypt_internal(plain, false, true, destination, pool); - return std::move(destination); + return destination; } /** @@ -310,7 +310,7 @@ namespace seal { Ciphertext destination; encrypt_zero_internal(parms_id, false, true, destination, pool); - return std::move(destination); + return destination; } /** diff --git a/native/src/seal/intarray.h b/native/src/seal/intarray.h index ee8bfb36..985c2991 100644 --- a/native/src/seal/intarray.h +++ b/native/src/seal/intarray.h @@ -13,7 +13,7 @@ #include #include #include -#ifdef SEAL_USE_MSGSL_SPAN +#ifdef SEAL_USE_MSGSL #include #endif @@ -239,7 +239,7 @@ namespace seal { return size_ ? cbegin() + size_ : cbegin(); } -#ifdef SEAL_USE_MSGSL_SPAN +#ifdef SEAL_USE_MSGSL /** Returns a span pointing to the beginning of the IntArray. */ diff --git a/native/src/seal/plaintext.h b/native/src/seal/plaintext.h index 88791871..36db2f28 100644 --- a/native/src/seal/plaintext.h +++ b/native/src/seal/plaintext.h @@ -18,7 +18,7 @@ #include #include #include -#ifdef SEAL_USE_MSGSL_SPAN +#ifdef SEAL_USE_MSGSL #include #endif @@ -346,7 +346,7 @@ namespace seal { return data_.cbegin(); } -#ifdef SEAL_USE_MSGSL_SPAN +#ifdef SEAL_USE_MSGSL /** Returns a span pointing to the beginning of the text polynomial. */ diff --git a/native/src/seal/util/config.h.in b/native/src/seal/util/config.h.in index 70d0f5b2..3cfa2017 100644 --- a/native/src/seal/util/config.h.in +++ b/native/src/seal/util/config.h.in @@ -23,5 +23,4 @@ #cmakedefine SEAL_USE__ADDCARRY_U64 #cmakedefine SEAL_USE__SUBBORROW_U64 #cmakedefine SEAL_USE_MSGSL -#cmakedefine SEAL_USE_MSGSL_SPAN #cmakedefine SEAL_USE_ZLIB diff --git a/native/src/thirdparty/zlib/CMakeLists.txt b/native/src/thirdparty/zlib/CMakeLists.txt deleted file mode 100644 index d3d7b65e..00000000 --- a/native/src/thirdparty/zlib/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -cmake_minimum_required(VERSION 3.12) - -project(ZLIB VERSION 1.2.11 LANGUAGES CXX C) - -include(ExternalProject) -ExternalProject_Add(zlib - GIT_REPOSITORY https://github.com/madler/zlib.git - GIT_TAG v1.2.11 - SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/zlib-src" - BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/zlib-src" - INSTALL_COMMAND "" -) \ No newline at end of file diff --git a/native/tests/CMakeLists.txt b/native/tests/CMakeLists.txt index eb1984e9..2417b1a3 100644 --- a/native/tests/CMakeLists.txt +++ b/native/tests/CMakeLists.txt @@ -1,36 +1,5 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT license. -cmake_minimum_required(VERSION 3.12) - -project(SEALTest LANGUAGES CXX) - -# Executable will be in ../bin -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${SEALTest_SOURCE_DIR}/../bin) - -add_executable(sealtest seal/testrunner.cpp) - -# Import Microsoft SEAL -find_package(SEAL 3.5.0 EXACT REQUIRED - # Providing a path so this can be built without installing Microsoft SEAL - PATHS ${SEALTest_SOURCE_DIR}/../src/cmake -) - # Add source files -add_subdirectory(seal) - -# Only build GTest -option(BUILD_GMOCK OFF) -option(INSTALL_GTEST OFF) -mark_as_advanced(BUILD_GMOCK INSTALL_GTEST) - -# Add GTest -set(GTEST_DIR ${SEALTest_SOURCE_DIR}/thirdparty/googletest) -if(NOT EXISTS ${GTEST_DIR}/CMakeLists.txt) - message(FATAL_ERROR "Could not find `${GTEST_DIR}/CMakeLists.txt`. Run `git submodule update --init` and retry.") -endif() - -add_subdirectory(${GTEST_DIR}) - -# Link Microsoft SEAL and GTest -target_link_libraries(sealtest SEAL::seal gtest) +add_subdirectory(seal) \ No newline at end of file diff --git a/native/tests/SEALTest.vcxproj b/native/tests/SEALTest.vcxproj index 1ec305a6..8b294faa 100644 --- a/native/tests/SEALTest.vcxproj +++ b/native/tests/SEALTest.vcxproj @@ -33,22 +33,22 @@ - $(ProjectDir)..\bin\$(Platform)\$(Configuration)\ + $(ProjectDir)..\..\bin\$(Platform)\$(Configuration)\ $(ProjectDir)obj\$(Platform)\$(Configuration)\ sealtest - $(ProjectDir)..\bin\$(Platform)\$(Configuration)\ + $(ProjectDir)..\..\bin\$(Platform)\$(Configuration)\ $(ProjectDir)obj\$(Platform)\$(Configuration)\ sealtest - $(ProjectDir)..\bin\$(Platform)\$(Configuration)\ + $(ProjectDir)..\..\bin\$(Platform)\$(Configuration)\ $(ProjectDir)obj\$(Platform)\$(Configuration)\ sealtest - $(ProjectDir)..\bin\$(Platform)\$(Configuration)\ + $(ProjectDir)..\..\bin\$(Platform)\$(Configuration)\ $(ProjectDir)obj\$(Platform)\$(Configuration)\ sealtest @@ -117,7 +117,7 @@ EnableFastChecks MultiThreadedDebugDLL Level3 - $(MSGSL_ROOT);$(SolutionDir)/native/src;%(AdditionalIncludeDirectories) + $(SolutionDir)/native/src;%(AdditionalIncludeDirectories) Guard stdcpp17 /Zc:__cplusplus %(AdditionalOptions) @@ -127,7 +127,7 @@ true Console seal.lib;%(AdditionalDependencies) - $(ProjectDir)..\lib\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + $(ProjectDir)..\..\lib\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) @@ -139,7 +139,7 @@ EnableFastChecks MultiThreadedDebugDLL Level3 - $(MSGSL_ROOT);$(SolutionDir)/native/src;%(AdditionalIncludeDirectories) + $(SolutionDir)/native/src;%(AdditionalIncludeDirectories) Guard stdcpp17 /Zc:__cplusplus %(AdditionalOptions) @@ -149,7 +149,7 @@ true Console seal.lib;%(AdditionalDependencies) - $(ProjectDir)..\lib\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + $(ProjectDir)..\..\lib\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) @@ -159,7 +159,7 @@ MultiThreadedDLL Level3 ProgramDatabase - $(MSGSL_ROOT);$(SolutionDir)/native/src;%(AdditionalIncludeDirectories) + $(SolutionDir)/native/src;%(AdditionalIncludeDirectories) Guard stdcpp17 /Zc:__cplusplus %(AdditionalOptions) @@ -171,7 +171,7 @@ true true seal.lib;%(AdditionalDependencies) - $(ProjectDir)..\lib\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + $(ProjectDir)..\..\lib\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) @@ -181,7 +181,7 @@ MultiThreadedDLL Level3 ProgramDatabase - $(MSGSL_ROOT);$(SolutionDir)/native/src;%(AdditionalIncludeDirectories) + $(SolutionDir)/native/src;%(AdditionalIncludeDirectories) Guard stdcpp17 /Zc:__cplusplus %(AdditionalOptions) @@ -193,7 +193,7 @@ true true seal.lib;%(AdditionalDependencies) - $(ProjectDir)..\lib\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) + $(ProjectDir)..\..\lib\$(Platform)\$(Configuration);%(AdditionalLibraryDirectories) diff --git a/native/tests/seal/CMakeLists.txt b/native/tests/seal/CMakeLists.txt index d3ad9168..aebf9023 100644 --- a/native/tests/seal/CMakeLists.txt +++ b/native/tests/seal/CMakeLists.txt @@ -1,7 +1,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT license. -target_sources(sealtest +target_sources(sealtests PRIVATE ${CMAKE_CURRENT_LIST_DIR}/batchencoder.cpp ${CMAKE_CURRENT_LIST_DIR}/biguint.cpp @@ -25,6 +25,7 @@ target_sources(sealtest ${CMAKE_CURRENT_LIST_DIR}/secretkey.cpp ${CMAKE_CURRENT_LIST_DIR}/serialization.cpp ${CMAKE_CURRENT_LIST_DIR}/smallmodulus.cpp + ${CMAKE_CURRENT_LIST_DIR}/testrunner.cpp ) add_subdirectory(util) diff --git a/native/tests/seal/util/CMakeLists.txt b/native/tests/seal/util/CMakeLists.txt index f716df42..3e3dc18b 100644 --- a/native/tests/seal/util/CMakeLists.txt +++ b/native/tests/seal/util/CMakeLists.txt @@ -1,7 +1,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT license. -target_sources(sealtest +target_sources(sealtests PRIVATE ${CMAKE_CURRENT_LIST_DIR}/baseconverter.cpp ${CMAKE_CURRENT_LIST_DIR}/clipnormal.cpp diff --git a/native/tests/thirdparty/googletest b/native/tests/thirdparty/googletest deleted file mode 160000 index 7f1c0f6f..00000000 --- a/native/tests/thirdparty/googletest +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7f1c0f6f8122d7978c9de29d9d468f7fac9ba62c diff --git a/templates/nix-build.yml b/templates/nix-build.yml index 4a75c4b0..0cfde1e8 100644 --- a/templates/nix-build.yml +++ b/templates/nix-build.yml @@ -1,53 +1,24 @@ parameters: artifactName: 'nix-drop' - ext: '' steps: - - task: CMake@1 - displayName: 'CMake ZLIB' - inputs: - workingDirectory: native/src/thirdparty/zlib - cmakeArgs: '-DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=ON' - - - task: CMake@1 - displayName: 'Build ZLIB' - inputs: - workingDirectory: native/src/thirdparty/zlib - cmakeArgs: '--build' - - task: CMake@1 displayName: 'CMake SEAL' inputs: - workingDirectory: native/src - cmakeArgs: '-DCMAKE_BUILD_TYPE=Release -DSEAL_BUILD_SEAL_C=ON -DZLIB_LIBRARY=./thirdparty/zlib/zlib-src/libz.${{parameters.ext}} -DZLIB_INCLUDE_DIR=./thirdparty/zlib/zlib-src/}' + workingDirectory: '$(Build.SourcesDirectory)' + cmakeArgs: '-DCMAKE_BUILD_TYPE=Release -DSEAL_BUILD_TESTS=ON -DSEAL_BUILD_SEAL_C=ON .' - - task: CMake@1 + - script: | + cd $BUILD_SOURCESDIRECTORY + make displayName: 'Build SEAL' inputs: workingDirectory: native/src cmakeArgs: '--build' - - script: | - cd native/tests/thirdparty - git submodule update --init - displayName: 'Install Google Test' - - - task: CMake@1 - displayName: 'CMake SEALTest' - inputs: - workingDirectory: native/tests - cmakeArgs: '-DSEAL_DIR=../src/cmake}' - - - task: CMake@1 - displayName: 'Build SEALTest' - inputs: - workingDirectory: native/tests - cmakeArgs: '--build}' - - script: | cd $BUILD_SOURCESDIRECTORY - cd native/bin - ./sealtest + ./bin/sealtests displayName: 'Run unit tests' - task: UseDotNet@2 @@ -66,12 +37,12 @@ steps: - task: CopyFiles@2 displayName: 'Copy Files to: $(Build.ArtifactStagingDirectory)' inputs: - SourceFolder: '$(Build.SourcesDirectory)/native/lib' + SourceFolder: '$(Build.SourcesDirectory)/lib' Contents: 'libsealc.*' - TargetFolder: '$(Build.ArtifactStagingDirectory)/native/lib' + TargetFolder: '$(Build.ArtifactStagingDirectory)/lib' - task: PublishBuildArtifacts@1 displayName: 'Publish Artifact: drop' inputs: PathtoPublish: '$(Build.ArtifactStagingDirectory)' - artifactName: ${{ parameters.artifactName }} \ No newline at end of file + artifactName: ${{ parameters.artifactName }} diff --git a/templates/pack.yml b/templates/pack.yml index c77a967e..9028db71 100644 --- a/templates/pack.yml +++ b/templates/pack.yml @@ -37,16 +37,16 @@ steps: - task: CopyFiles@2 displayName: 'Copy Linux Files to: $(Build.ArtifactStagingDirectory)' inputs: - SourceFolder: '$(Build.ArtifactStagingDirectory)\linux-drop\dotnet\lib\' + SourceFolder: '$(Build.ArtifactStagingDirectory)\linux-drop\lib\' Contents: '*' - TargetFolder: '$(Build.ArtifactStagingDirectory)\windows-drop\dotnet\lib\' + TargetFolder: '$(Build.ArtifactStagingDirectory)\windows-drop\lib\' - task: CopyFiles@2 displayName: 'Copy Mac OS X Files to: $(Build.ArtifactStagingDirectory)' inputs: - SourceFolder: '$(Build.ArtifactStagingDirectory)\macos-drop\dotnet\lib\' + SourceFolder: '$(Build.ArtifactStagingDirectory)\macos-drop\lib\' Contents: '*' - TargetFolder: '$(Build.ArtifactStagingDirectory)\windows-drop\dotnet\lib\' + TargetFolder: '$(Build.ArtifactStagingDirectory)\windows-drop\lib\' - task: NuGetToolInstaller@1 displayName: 'Use NuGet' @@ -59,9 +59,9 @@ steps: command: 'pack' packagesToPack: '$(Build.ArtifactStagingDirectory)\windows-drop\dotnet\nuget\*.nuspec' packDestination: '$(Build.ArtifactStagingDirectory)\windows-drop\dotnet\nuget\Release' - buildProperties: 'Configuration=Release;LINUX_SEALNETNATIVE=$(Build.ArtifactStagingDirectory)\windows-drop\dotnet\lib\libsealnetnative.so;MACOS_SEALNETNATIVE=$(Build.ArtifactStagingDirectory)\windows-drop\dotnet\lib\libsealnetnative.dylib' + buildProperties: 'Configuration=Release;LINUX_SEAL_C=$(Build.ArtifactStagingDirectory)\windows-drop\lib\libsealc.so*;MACOS_SEAL_C=$(Build.ArtifactStagingDirectory)\windows-drop\lib\libsealc*.dylib' - task: PublishBuildArtifacts@1 displayName: 'Publish Artifact: drop' inputs: - PathtoPublish: '$(Build.ArtifactStagingDirectory)' \ No newline at end of file + PathtoPublish: '$(Build.ArtifactStagingDirectory)' diff --git a/templates/windows-build.yml b/templates/windows-build.yml index e5b286d5..52fbeb58 100644 --- a/templates/windows-build.yml +++ b/templates/windows-build.yml @@ -3,7 +3,6 @@ parameters: configuration: 'release' steps: - - task: NuGetToolInstaller@1 displayName: 'Use NuGet' inputs: @@ -28,18 +27,6 @@ steps: outputFormat: sarif debugMode: false - - task: CMake@1 - displayName: 'CMake ZLIB' - inputs: - workingDirectory: native/src/thirdparty/zlib - cmakeArgs: '-DCMAKE_POSITION_INDEPENDENT_CODE=ON .' - - - task: CMake@1 - displayName: 'Build ZLIB' - inputs: - workingDirectory: native/src/thirdparty/zlib - cmakeArgs: '--build . --config Release' - - task: PowerShell@2 displayName: 'Download Strong Name certificate' inputs: @@ -50,7 +37,7 @@ steps: if (Test-Path env:SEALNetSigningCertificate) { Invoke-WebRequest -Uri "$env:SEALNetSigningCertificate" -OutFile $CertOutFile } - + - task: UseDotNet@2 displayName: 'Get .NET Core 3.1 SDK' inputs: diff --git a/thirdparty/googletest/CMakeLists.txt b/thirdparty/googletest/CMakeLists.txt new file mode 100644 index 00000000..3d7cde56 --- /dev/null +++ b/thirdparty/googletest/CMakeLists.txt @@ -0,0 +1,19 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT license. + +cmake_minimum_required(VERSION 3.12) + +project(GoogleTest NONE) + +include(ExternalProject) +ExternalProject_Add(googletest_external + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG release-1.10.0 + SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/googletest-src + BINARY_DIR ${CMAKE_CURRENT_LIST_DIR}/googletest-build + CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=ON + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" +) diff --git a/thirdparty/msgsl/CMakeLists.txt b/thirdparty/msgsl/CMakeLists.txt new file mode 100644 index 00000000..7b41b7b2 --- /dev/null +++ b/thirdparty/msgsl/CMakeLists.txt @@ -0,0 +1,26 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT license. + +cmake_minimum_required(VERSION 3.12) + +project(GSL VERSION 2.1.0 LANGUAGES CXX C) + +include(ExternalProject) +ExternalProject_Add(msgsl_external + GIT_REPOSITORY https://github.com/microsoft/GSL.git + GIT_TAG v2.1.0 + SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/GSL-src + CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release -DGSL_TEST=OFF + INSTALL_COMMAND "" + TEST_COMMAND "" +) + +# Install the header files +if(SEAL_USE_MSGSL) + install( + DIRECTORY + ${CMAKE_CURRENT_LIST_DIR}/GSL-src/include/gsl + DESTINATION + ${SEAL_INCLUDES_INSTALL_DIR} + ) +endif() diff --git a/thirdparty/zlib/CMakeLists.txt b/thirdparty/zlib/CMakeLists.txt new file mode 100644 index 00000000..127ebdad --- /dev/null +++ b/thirdparty/zlib/CMakeLists.txt @@ -0,0 +1,23 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT license. + +cmake_minimum_required(VERSION 3.12) + +project(ZLIB VERSION 1.2.11 LANGUAGES CXX C) + +if(MSVC) + set(ZLIB_BINARY_DIR ${CMAKE_CURRENT_LIST_DIR}/zlib-build/${ZLIB_PLATFORM}) +else() + set(ZLIB_BINARY_DIR ${CMAKE_CURRENT_LIST_DIR}/zlib-src) +endif() + +include(ExternalProject) +ExternalProject_Add(zlib_external + GIT_REPOSITORY https://github.com/madler/zlib.git + GIT_TAG v1.2.11 + SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/zlib-src + BINARY_DIR ${ZLIB_BINARY_DIR} + CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DSKIP_INSTALL_ALL=ON + INSTALL_COMMAND "" + TEST_COMMAND "" +)