Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow creation of shared library for libTink #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
cmake_minimum_required(VERSION 3.13)
project(Tink VERSION 2.1.1 LANGUAGES CXX)
project(tink VERSION 2.1.1 LANGUAGES CXX)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

option(TINK_BUILD_TESTS "Build Tink tests" OFF)
option(TINK_USE_SYSTEM_OPENSSL "Build Tink linking to OpenSSL installed in the system" OFF)
option(TINK_USE_INSTALLED_ABSEIL "Build Tink linking to Abseil installed in the system" OFF)
option(TINK_USE_INSTALLED_GOOGLETEST "Build Tink linking to GTest installed in the system" OFF)
option(TINK_USE_INSTALLED_PROTOBUF "Build Tink linking to Protobuf installed in the system" OFF)
option(TINK_USE_INSTALLED_RAPIDJSON "Build Tink linking to Rapidjson installed in the system" OFF)
option(USE_ONLY_FIPS "Enables the FIPS only mode in Tink" OFF)
option(TINK_BUILD_SHARED_LIB "Build libtink bundle it with the headers" OFF)

if (TINK_BUILD_SHARED_LIB)
set(CMAKE_POSITION_INDEPENDENT_CODE ON CACHE BOOL "libtink override" FORCE)
endif()

set(CPACK_GENERATOR TGZ)
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
Expand All @@ -34,3 +41,25 @@ list(APPEND TINK_INCLUDE_DIRS "${TINK_INCLUDE_ALIAS_DIR}")

add_subdirectory(tink)
add_subdirectory(proto)

if (TINK_BUILD_SHARED_LIB)
install(
DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}/tink/"
"${TINK_GENFILE_DIR}/tink/"
DESTINATION "include/tink"
FILES_MATCHING PATTERN "*.h"
)

install(
DIRECTORY
"${TINK_GENFILE_DIR}/proto"
DESTINATION "include"
FILES_MATCHING PATTERN "*.h"
)

export(EXPORT Tink FILE tinkConfig.cmake)
install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)
endif()
28 changes: 17 additions & 11 deletions cmake/TinkWorkspace.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ if (NOT TARGET crypto)
"$<BUILD_INTERFACE:${boringssl_SOURCE_DIR}/src/include>")
else()
# Support for ED25519 was added from 1.1.1.
find_package(OpenSSL 1.1.1 REQUIRED)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving 1.1.1 here provides a lower bound for OpenSSL which is what we want. I my understanding correct?

find_package(OpenSSL REQUIRED)
_create_interface_target(crypto OpenSSL::Crypto)
endif()
else()
Expand All @@ -123,11 +123,13 @@ set(RAPIDJSON_BUILD_DOC OFF CACHE BOOL "Tink dependency override" FORCE)
set(RAPIDJSON_BUILD_EXAMPLES OFF CACHE BOOL "Tink dependency override" FORCE)
set(RAPIDJSON_BUILD_TESTS OFF CACHE BOOL "Tink dependency override" FORCE)

http_archive(
NAME rapidjson
URL https://github.com/Tencent/rapidjson/archive/v1.1.0.tar.gz
SHA256 bf7ced29704a1e696fbccf2a2b4ea068e7774fa37f6d7dd4039d0787f8bed98e
)
if(NOT TINK_USE_INSTALLED_RAPIDJSON)
http_archive(
NAME rapidjson
URL https://github.com/Tencent/rapidjson/archive/v1.1.0.tar.gz
SHA256 bf7ced29704a1e696fbccf2a2b4ea068e7774fa37f6d7dd4039d0787f8bed98e
)
endif()
# Rapidjson is a header-only library with no explicit target. Here we create one.
add_library(rapidjson INTERFACE)
target_include_directories(rapidjson INTERFACE "${rapidjson_SOURCE_DIR}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this variable populated when TINK_USE_INSTALLED_RAPIDJSON=ON?

Expand All @@ -136,8 +138,12 @@ set(protobuf_BUILD_TESTS OFF CACHE BOOL "Tink dependency override" FORCE)
set(protobuf_BUILD_EXAMPLES OFF CACHE BOOL "Tink dependency override" FORCE)
set(protobuf_INSTALL OFF CACHE BOOL "Tink dependency override" FORCE)

http_archive(
NAME com_google_protobuf
URL https://github.com/protocolbuffers/protobuf/releases/download/v25.1/protobuf-25.1.zip
SHA256 5c86c077b0794c3e9bb30cac872cf883043febfb0f992137f0a8b1c3d534617c
)
if(NOT TINK_USE_INSTALLED_PROTOBUF)
http_archive(
NAME com_google_protobuf
URL https://github.com/protocolbuffers/protobuf/releases/download/v25.1/protobuf-25.1.zip
SHA256 5c86c077b0794c3e9bb30cac872cf883043febfb0f992137f0a8b1c3d534617c
)
else()
find_package(Protobuf REQUIRED)
endif()
45 changes: 40 additions & 5 deletions tink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ endif()

set(TINK_VERSION_H "${TINK_GENFILE_DIR}/tink/version.h")

tink_cc_library(
NAME cc
SRCS
set(TINK_PUBLIC_APIS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TINK_PUBLIC_API_HDRS?

aead.h
aead_config.h
aead_factory.h
Expand Down Expand Up @@ -74,7 +72,9 @@ tink_cc_library(
streaming_mac.h
tink_config.h
"${TINK_VERSION_H}"
DEPS
)

set(TINK_PUBLIC_API_DEPS
tink::core::aead
tink::core::binary_keyset_reader
tink::core::binary_keyset_writer
Expand Down Expand Up @@ -139,7 +139,15 @@ tink_cc_library(
tink::util::validation
tink::proto::config_cc_proto
tink::proto::tink_cc_proto
PUBLIC
)

tink_cc_library(
NAME cc
SRCS
${TINK_PUBLIC_APIS}
DEPS
${TINK_PUBLIC_API_DEPS}
PUBLIC
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: PUBLIC should be aligned with DEPS

)

add_library(tink::static ALIAS tink_core_cc)
Expand Down Expand Up @@ -1123,6 +1131,33 @@ tink_cc_test(
tink::util::test_matchers
)


if (TINK_BUILD_SHARED_LIB)
add_library(tink SHARED
${TINK_PUBLIC_APIS}
version_script.lds
exported_symbols.lds
)
target_link_libraries(tink
PRIVATE
-fuse-ld=gold # GNU ld does not support ICF.
-Wl,--version-script="${CMAKE_CURRENT_SOURCE_DIR}/version_script.lds"
-Wl,--gc-sections
-Wl,--icf=all
-Wl,--strip-all
)
target_include_directories(tink PUBLIC ${TINK_INCLUDE_DIRS})
target_link_libraries(tink
PRIVATE
-Wl,--whole-archive
${TINK_PUBLIC_API_DEPS}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do this, would the tink target include (and export) absl?

-Wl,--no-whole-archive
)
set_target_properties(tink PROPERTIES SOVERSION ${TINK_CC_VERSION_LABEL})

install(TARGETS tink EXPORT Tink LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()

tink_cc_test(
NAME big_integer_test
SRCS
Expand Down