-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into Jamie-Cui-patch-1
- Loading branch information
Showing
57 changed files
with
1,971 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,3 +48,5 @@ external | |
|
||
#brpc | ||
rpc_data | ||
|
||
Testing/Temporary/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
# Copyright 2024 Ant Group Co., Ltd. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
# use this file except in compliance with the License. You may obtain a copy of | ||
# the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations under | ||
# the License. | ||
|
||
cmake_minimum_required(VERSION 3.20) | ||
|
||
project( | ||
yacl | ||
VERSION 0.4.5 | ||
DESCRIPTION | ||
"YACL (Yet Another Common crypto library) is a C++ library that contains cryptography, network and io modules which other SecretFlow code depends on." | ||
HOMEPAGE_URL "https://github.com/secretflow/yacl" | ||
LANGUAGES CXX C) | ||
|
||
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/") | ||
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) | ||
|
||
if(NOT CMAKE_BUILD_TYPE) | ||
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}") | ||
|
||
# This policy was introduced in CMake 3.13; OLD by default until CMake 3.21 | ||
cmake_policy(SET CMP0077 NEW) | ||
cmake_policy(SET CMP0135 NEW) | ||
|
||
# CMake modules | ||
include(CMakeDependentOption) | ||
include(CheckCXXCompilerFlag) | ||
include(CheckCXXSourceRuns) | ||
include(CheckLanguage) | ||
include(FetchContent) | ||
include(ExternalProject) | ||
|
||
# Always build position-independent-code | ||
set(CMAKE_POSITION_INDEPENDENT_CODE ON) | ||
|
||
# Enable C++17 | ||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_C_STANDARD_REQUIRED YES) | ||
set(CMAKE_EXE_LINKER_FLAGS | ||
"${CMAKE_EXE_LINKER_FLAGS} -undefined dynamic_lookup") | ||
|
||
include(GNUInstallDirs) | ||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) | ||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) | ||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}) | ||
|
||
include(AddCompilerFlags) | ||
|
||
# make it colorful under ninja-build | ||
if(CMAKE_GENERATOR STREQUAL Ninja) | ||
add_compiler_flags(-fdiagnostics-color=always) | ||
endif() | ||
|
||
# set fetch content base directory | ||
set(FETCHCONTENT_BASE_DIR ${CMAKE_BINARY_DIR}/external_cmake) | ||
|
||
include(ExternalAbseil) | ||
include(ExternalBlake3) | ||
include(ExternalFmt) | ||
include(ExternalSPDLog) | ||
include(ExternalGTest) | ||
include(ExternalGflags) | ||
include(ExternalMsgpack) | ||
include(ExternalOpenSSL) | ||
include(ExternalLibtommath) | ||
include(ExternalSse2neon) | ||
include(ExternalMcl) | ||
include(ExternalFourQ) | ||
include(ExternalLibSodium) | ||
|
||
enable_testing() | ||
|
||
add_library(yacl STATIC) | ||
|
||
target_include_directories( | ||
yacl | ||
PUBLIC | ||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>" # these dirs are only used | ||
# when building inside the | ||
# build tree | ||
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>" # these dirs are only | ||
# used when linking | ||
# against a prebuilt | ||
# version of your package | ||
) | ||
|
||
target_include_directories(yacl PUBLIC ${CMAKE_BINARY_DIR}/include) | ||
|
||
set(YACL_SOURCE_FILES "") | ||
|
||
add_subdirectory(yacl) | ||
add_subdirectory(yacl/base) | ||
add_subdirectory(yacl/crypto) | ||
add_subdirectory(yacl/io) | ||
add_subdirectory(yacl/utils) | ||
add_subdirectory(yacl/math) | ||
|
||
target_sources(yacl PRIVATE ${YACL_SOURCE_FILES}) | ||
|
||
target_link_libraries( | ||
yacl | ||
PUBLIC fmt::fmt | ||
absl::stacktrace | ||
absl::symbolize | ||
absl::int128 | ||
BLAKE3::blake3 | ||
mcl::mcl | ||
ExtLibsodium::libsodium | ||
ExtLibtommath::libtommath | ||
ExtFourQ::fourq) | ||
|
||
if(YACL_WITH_EXT_OPENSSL) | ||
target_link_libraries(yacl PUBLIC ExtOpenSSL::Crypto ExtOpenSSL::SSL) | ||
else() | ||
target_link_libraries(yacl PUBLIC OpenSSL::Crypto OpenSSL::SSL) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Copyright 2024 Ant Group Co., Ltd. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
# use this file except in compliance with the License. You may obtain a copy of | ||
# the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations under | ||
# the License. | ||
|
||
include(CheckCXXCompilerFlag) | ||
|
||
# For easier adding of CXX compiler flags | ||
function(add_compiler_flags 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() | ||
|
||
add_compiler_flags("-Wall") | ||
add_compiler_flags("-Wextra") | ||
add_compiler_flags("-Werror") | ||
|
||
# FIXME remove this flag | ||
add_compiler_flags("-Wno-unused-function") | ||
|
||
# For cryptos | ||
add_compiler_flags("-maes") | ||
add_compiler_flags("-mavx") | ||
add_compiler_flags("-mpclmul") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright 2024 Ant Group Co., Ltd. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
FetchContent_Declare( | ||
abseil | ||
URL https://github.com/abseil/abseil-cpp/archive/refs/tags/20240722.0.tar.gz | ||
URL_HASH SHA256=f50e5ac311a81382da7fa75b97310e4b9006474f9560ac46f54a9967f07d4ae3 | ||
) | ||
|
||
SET(ABSL_PROPAGATE_CXX_STD ON CACHE INTERNAL "") | ||
SET(ABSL_USE_SYSTEM_INCLUDES ON CACHE INTERNAL "") | ||
FetchContent_MakeAvailable(abseil) | ||
|
||
include_directories(${abseil_SOURCE_DIR}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright 2024 Ant Group Co., Ltd. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
# use this file except in compliance with the License. You may obtain a copy of | ||
# the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations under | ||
# the License. | ||
|
||
FetchContent_Declare( | ||
blake3 | ||
URL https://github.com/BLAKE3-team/BLAKE3/archive/refs/tags/1.5.4.tar.gz | ||
URL_HASH | ||
SHA256=ddd24f26a31d23373e63d9be2e723263ac46c8b6d49902ab08024b573fd2a416 | ||
SOURCE_SUBDIR c) | ||
|
||
FetchContent_MakeAvailable(blake3) | ||
|
||
include_directories(${blake3_SOURCE_DIR}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright 2024 Ant Group Co., Ltd. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
FetchContent_Declare(fmt | ||
URL https://github.com/fmtlib/fmt/archive/refs/tags/11.0.2.tar.gz | ||
URL_HASH SHA256=6cb1e6d37bdcb756dbbe59be438790db409cdb4868c66e888d5df9f13f7c027f | ||
) | ||
|
||
SET(FMT_TEST OFF CACHE INTERNAL "") | ||
FetchContent_MakeAvailable(fmt) | ||
|
||
include_directories(${fmt_SOURCE_DIR}/include) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Copyright 2024 Ant Group Co., Ltd. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
# use this file except in compliance with the License. You may obtain a copy of | ||
# the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations under | ||
# the License. | ||
|
||
set(YACL_EXT_FOURQ_URL | ||
https://github.com/microsoft/FourQlib/archive/1031567f23278e1135b35cc04e5d74c2ac88c029.tar.gz | ||
) | ||
|
||
set(YACL_EXT_FOURQ_SHA256 | ||
7417c829d7933facda568c7a08924dfefb0c83dd1dab411e597af4c0cc0417f0) | ||
|
||
set(YACL_EXT_FOURQ_BUILD_COMMAND make ARCH=x64 GENERIC=TRUE EXTENDED_SET=FALSE | ||
-C FourQ_64bit_and_portable libFourQ) | ||
|
||
set(YACL_EXT_FOURQ_INSTALL_COMMAND make PREFIX=${CMAKE_BINARY_DIR} -C | ||
FourQ_64bit_and_portable install) | ||
|
||
ExternalProject_Add( | ||
fourq | ||
PREFIX "external_fourq" | ||
URL ${YACL_EXT_FOURQ_URL} | ||
URL_HASH SHA256=${YACL_EXT_FOURQ_SHA256} | ||
BUILD_IN_SOURCE true | ||
PATCH_COMMAND patch -p1 -l -i | ||
${PROJECT_SOURCE_DIR}/bazel/patches/FourQlib.patch | ||
CONFIGURE_COMMAND "" # no configure | ||
BUILD_COMMAND ${YACL_EXT_FOURQ_BUILD_COMMAND} | ||
INSTALL_COMMAND ${YACL_EXT_FOURQ_INSTALL_COMMAND}) | ||
|
||
add_library(ExtFourQ STATIC IMPORTED) | ||
set_target_properties( | ||
ExtFourQ PROPERTIES IMPORTED_LOCATION | ||
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libFourQ.a) | ||
add_library(ExtFourQ::fourq ALIAS ExtFourQ) | ||
|
||
ExternalProject_Get_Property(fourq SOURCE_DIR) | ||
include_directories(${SOURCE_DIR}/FourQ_64bit_and_portable) | ||
unset(SOURCE_DIR) | ||
|
||
# HACK add yacl global compiler flag | ||
add_compiler_flags("-D __LINUX__") | ||
add_compiler_flags("-D _ARM64_") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright 2024 Ant Group Co., Ltd. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
FetchContent_Declare(googletest | ||
URL https://github.com/google/googletest/archive/refs/tags/v1.15.2.tar.gz | ||
URL_HASH SHA256=7b42b4d6ed48810c5362c265a17faebe90dc2373c885e5216439d37927f02926 | ||
) | ||
|
||
FetchContent_MakeAvailable(googletest) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright 2024 Ant Group Co., Ltd. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
FetchContent_Declare(gflags | ||
URL https://github.com/gflags/gflags/archive/v2.2.2.tar.gz | ||
URL_HASH SHA256=34af2f15cf7367513b352bdcd2493ab14ce43692d2dcd9dfc499492966c64dcf | ||
) | ||
|
||
set(CMAKE_CXX_FLAGS_OLD "${CMAKE_CXX_FLAGS}") | ||
|
||
# Add other flags here. | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter") | ||
set(BUILD_TESTING OFF CACHE INTERNAL "") | ||
|
||
FetchContent_MakeAvailable(gflags) | ||
|
||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_OLD}") | ||
unset(BUILD_TESTING) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Copyright 2024 Ant Group Co., Ltd. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
# use this file except in compliance with the License. You may obtain a copy of | ||
# the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations under | ||
# the License. | ||
|
||
# NOTE download. configure, build, install happens during project make process | ||
ExternalProject_Add( | ||
libsodium | ||
PREFIX "external_libsodium" | ||
URL https://github.com/jedisct1/libsodium/releases/download/1.0.18-RELEASE/libsodium-1.0.18.tar.gz | ||
URL_HASH | ||
SHA256=6f504490b342a4f8a4c4a02fc9b866cbef8622d5df4e5452b46be121e46636c1 | ||
BUILD_IN_SOURCE true | ||
CONFIGURE_COMMAND ./configure --prefix=${CMAKE_BINARY_DIR} | ||
BUILD_COMMAND make | ||
INSTALL_COMMAND make install | ||
EXCLUDE_FROM_ALL) | ||
|
||
add_library(ExtLibsodium STATIC IMPORTED) | ||
set_target_properties( | ||
ExtLibsodium PROPERTIES IMPORTED_LOCATION | ||
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libsodium.a) | ||
add_library(ExtLibsodium::libsodium ALIAS ExtLibsodium) | ||
|
||
ExternalProject_Get_Property(libsodium SOURCE_DIR) | ||
include_directories(${SOURCE_DIR}/src/libsodium/include) | ||
include_directories(${SOURCE_DIR}/src/libsodium/include/sodium) | ||
unset(SOURCE_DIR) |
Oops, something went wrong.