Skip to content

Commit

Permalink
[#77] Refactor project to not use C++20 coroutines.
Browse files Browse the repository at this point in the history
This commit lays the foundation for moving away from C++20 coroutines.
This commit removes all S3-specific logic. That means the features which
shipped in v0.1.0 of this project will need to be ported to the new
design.

The changes in this commit were ported from HTTP API v0.2.0. All iRODS
4.3.1 features used by the HTTP API are included.

Notable features are:

    - 4.2 compatibility
    - configuration validation
    - connection pooling
    - secure communication with iRODS
  • Loading branch information
korydraughn committed Feb 29, 2024
1 parent 924d867 commit 7e0026c
Show file tree
Hide file tree
Showing 24 changed files with 3,155 additions and 104 deletions.
5 changes: 2 additions & 3 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ Standard: c++20
ColumnLimit: 120
UseCRLF: false

#UseTab: AlignWithSpaces
UseTab: Never
UseTab: AlignWithSpaces
TabWidth: 4
IndentWidth: 4
ConstructorInitializerIndentWidth: 4
Expand All @@ -28,7 +27,7 @@ AlignConsecutiveDeclarations: None
AlignConsecutiveMacros: AcrossEmptyLinesAndComments
AlignEscapedNewlines: Left
AlignOperands: Align
AlignTrailingComments: true
AlignTrailingComments: false

AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: false
Expand Down
185 changes: 84 additions & 101 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,125 +1,109 @@
cmake_minimum_required(VERSION 3.15 FATAL_ERROR)

set(IRODS_CLIENT_VERSION "0.1.0")
set(IRODS_PACKAGE_REVISION "0")
cmake_minimum_required(VERSION 3.18.0 FATAL_ERROR)

#
# Build Configuration
#

find_package(IRODS 4.3.1 REQUIRED)
find_package(IRODS REQUIRED)

include(RequireOutOfSourceBuild)
include(IrodsCXXCompiler)

set(IRODS_S3_API_BINARY_NAME "irods_s3_api")

set(IRODS_CLIENT_VERSION "0.2.0")
set(IRODS_S3_API_VERSION "${IRODS_CLIENT_VERSION}")

set(IRODS_PACKAGE_REVISION "1")

include(IrodsExternals)

include(IrodsCXXCompiler)
set(CMAKE_CXX_STANDARD ${IRODS_CXX_STANDARD})
set(CMAKE_CXX_EXTENSIONS OFF)
# export-dynamic so stacktrace entries from executables have function names.
set(CMAKE_EXE_LINKER_FLAGS_INIT "-rdynamic -Wl,--export-dynamic -Wl,--enable-new-dtags -Wl,--as-needed -Wl,-z,defs")
# we have intentionally(?) undefined symbols in the plugins, so no -Wl,-z,defs
set(CMAKE_MODULE_LINKER_FLAGS_INIT "-Wl,--enable-new-dtags -Wl,--as-needed")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT "-Wl,--gc-sections -Wl,-z,combreloc")
set(CMAKE_MODULE_LINKER_FLAGS_RELEASE_INIT "-Wl,--gc-sections -Wl,-z,combreloc")
set(CMAKE_EXE_LINKER_FLAGS_INIT "-Wl,--export-dynamic -Wl,--enable-new-dtags -Wl,--as-needed")
include(IrodsRunpathDefaults)

project(irods_client_s3_api VERSION "${IRODS_CLIENT_VERSION}" LANGUAGES CXX C)
project(${IRODS_S3_API_BINARY_NAME} VERSION "${IRODS_S3_API_VERSION}" LANGUAGES CXX)

find_package(Threads REQUIRED)

include(${IRODS_TARGETS_PATH})
include("${IRODS_TARGETS_PATH}")
include(GNUInstallDirs)
include(UseLibCXX)

if (NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build {Debug, Release}." FORCE)
message(STATUS "Setting unspecified CMAKE_BUILD_TYPE to '${CMAKE_BUILD_TYPE}'. This is the correct setting for normal builds.")
endif()

if (CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
set(IRODS_BUILD_WITH_WERROR_DEFAULT ON)
else()
set(IRODS_BUILD_WITH_WERROR_DEFAULT OFF)
endif()
set(IRODS_BUILD_WITH_WERROR ${IRODS_BUILD_WITH_WERROR_DEFAULT} CACHE BOOL "Choose whether to compile with -Werror.")

if (IRODS_BUILD_WITH_WERROR)
add_compile_options(-Werror)
endif()

if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fpermissive>)
endif()

add_subdirectory(third-party/hmac_sha256)
add_compile_options(-Wall -Wextra -Wpedantic)

option(IRODS_ENABLE_ADDRESS_SANITIZER "Enables detection of memory leaks and other features provided by Address Sanitizer." OFF)
if (IRODS_ENABLE_ADDRESS_SANITIZER)
# Make sure the correct llvm-symbolizer binary is available to Address Sanitizer. This binary
# allows debug symbols to be reported appropriately. There are two ways to do this:
#
# export PATH=/opt/irods-externals/clang13.0.0-0/bin:$PATH
#
# - or -
#
# export ASAN_SYMBOLIZER_PATH=/opt/irods-externals/clang13.0.0-0/bin/llvm-symbolizer
#
# detect_container_overflow is disabled to guard against false positives which occur when
# parts of the binary are compiled with ASAN and other parts are not.
add_compile_definitions(IRODS_ADDRESS_SANITIZER_DEFAULT_OPTIONS="log_path=/tmp/irods_client_s3_api_asan_output:detect_container_overflow=0")
add_compile_options(
-fsanitize=address
-fno-omit-frame-pointer
-fno-optimize-sibling-calls
-O1)
add_link_options(
-fsanitize=address
-fno-omit-frame-pointer
-fno-optimize-sibling-calls
-O1)
else()
set(CMAKE_EXE_LINKER_FLAGS_INIT "${CMAKE_EXE_LINKER_FLAGS_INIT} -Wl,-z,defs")
endif()

include_directories(
${IRODS_EXTERNALS_FULLPATH_BOOST}/include
${IRODS_EXTERNALS_FULLPATH_FMT}/include)
set(IRODS_S3_API_PROJECT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(IRODS_S3_API_PROJECT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")

find_package(CURL REQUIRED)
find_package(nlohmann_json "3.6.1" REQUIRED)
find_package(OpenSSL REQUIRED COMPONENTS Crypto SSL)

set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
include(ObjectTargetHelpers)

find_package(Threads REQUIRED)
add_subdirectory(core)
add_subdirectory(endpoints)

set(IRODS_S3_API_BINARY_NAME irods_s3_api)
add_executable(${IRODS_S3_API_BINARY_NAME})

set(IRODS_S3_API_BUCKET_RESOLVER_PLUGIN_NAME static_bucket_resolver)
add_library(${IRODS_S3_API_BUCKET_RESOLVER_PLUGIN_NAME} MODULE)

set(IRODS_S3_API_AUTH_RESOLVER_NAME static_authentication_resolver)
add_library(${IRODS_S3_API_AUTH_RESOLVER_NAME} MODULE)

set(IRODS_S3_API_PERSISTENCE_PLUGIN sqlite_persistence_plugin)
add_library(${IRODS_S3_API_PERSISTENCE_PLUGIN} MODULE)

target_link_libraries(
${IRODS_S3_API_BINARY_NAME}
PRIVATE
${IRODS_EXTERNALS_FULLPATH_BOOST}/lib/libboost_system.so
${IRODS_EXTERNALS_FULLPATH_FMT}/lib/libfmt.so
irods_client
hmac_sha256
${CMAKE_DL_LIBS}
CURL::libcurl
nlohmann_json::nlohmann_json
Threads::Threads)

target_include_directories(${IRODS_S3_API_BUCKET_RESOLVER_PLUGIN_NAME} PRIVATE src)
target_include_directories(${IRODS_S3_API_AUTH_RESOLVER_NAME} PRIVATE src)
target_include_directories(${IRODS_S3_API_PERSISTENCE_PLUGIN} PRIVATE src)

target_link_libraries(
${IRODS_S3_API_BUCKET_RESOLVER_PLUGIN_NAME}
PRIVATE
irods_client
${CMAKE_DL_LIBS}
CURL::libcurl
nlohmann_json::nlohmann_json
${IRODS_EXTERNALS_FULLPATH_FMT}/lib/libfmt.so)

target_link_libraries(
${IRODS_S3_API_AUTH_RESOLVER_NAME}
PRIVATE
irods_client
${CMAKE_DL_LIBS}
CURL::libcurl
nlohmann_json::nlohmann_json
${IRODS_EXTERNALS_FULLPATH_FMT}/lib/libfmt.so)

target_link_libraries(
${IRODS_S3_API_PERSISTENCE_PLUGIN}
PRIVATE
irods_client
${CMAKE_DL_LIBS}
CURL::libcurl
nlohmann_json::nlohmann_json
${IRODS_EXTERNALS_FULLPATH_FMT}/lib/libfmt.so)

target_include_directories(
target_link_objects(
${IRODS_S3_API_BINARY_NAME}
PRIVATE
third-party/hmac_sha256
${IRODS_EXTERNALS_FULLPATH_BOOST}/include)

target_include_directories(${IRODS_S3_API_AUTH_RESOLVER_NAME} PRIVATE ${IRODS_EXTERNALS_FULLPATH_BOOST}/include)
target_include_directories(${IRODS_S3_API_BUCKET_RESOLVER_PLUGIN_NAME} PRIVATE ${IRODS_EXTERNALS_FULLPATH_BOOST}/include)
target_include_directories(${IRODS_S3_API_PERSISTENCE_PLUGIN} PRIVATE ${IRODS_EXTERNALS_FULLPATH_BOOST}/include)

add_subdirectory(src)
irods_s3_api_core
irods_s3_api_endpoint_authentication
irods_s3_api_endpoint_put_object
)

install(
TARGETS
${IRODS_S3_API_BINARY_NAME}
${IRODS_S3_API_AUTH_RESOLVER_NAME}
${IRODS_S3_API_BUCKET_RESOLVER_PLUGIN_NAME}
DESTINATION "${CMAKE_INSTALL_LIBDIR}/irods/clients/s3_api")
install(TARGETS ${IRODS_S3_API_BINARY_NAME} DESTINATION "${CMAKE_INSTALL_BINDIR}")

#
# Packaging Configuration
Expand All @@ -130,6 +114,11 @@ include(IrodsCPackPlatform)

set(IRODS_PACKAGE_NAME irods-experimental-client-s3-api)

#list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "${CPACK_PACKAGING_INSTALL_PREFIX}${IRODS_HOME_DIRECTORY}")
#list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "${CPACK_PACKAGING_INSTALL_PREFIX}${IRODS_HOME_DIRECTORY}/scripts")
#list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "${CPACK_PACKAGING_INSTALL_PREFIX}${IRODS_HOME_DIRECTORY}/scripts/irods")
#list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "${CPACK_PACKAGING_INSTALL_PREFIX}${IRODS_HOME_DIRECTORY}/scripts/irods/test")

set(CPACK_PACKAGE_VERSION ${IRODS_CLIENT_VERSION})
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF)
set(CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY OFF)
Expand All @@ -138,28 +127,22 @@ set(CPACK_COMPONENTS_GROUPING IGNORE)
set(CPACK_DEB_COMPONENT_INSTALL OFF)
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS OFF)
set(CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION ON)
set(CPACK_DEBIAN_PACKAGE_RELEASE "${IRODS_PACKAGE_REVISION}")
if (IRODS_LINUX_DISTRIBUTION_VERSION_CODENAME)
set(CPACK_DEBIAN_PACKAGE_RELEASE "${CPACK_DEBIAN_PACKAGE_RELEASE}~${IRODS_LINUX_DISTRIBUTION_VERSION_CODENAME}")
endif()
#set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_SOURCE_DIR}/packaging/postinst;")
#set(CPACK_DEBIAN_PACKAGE_BREAKS ${IRODS_S3_API_BINARY_NAME})
#set(CPACK_DEBIAN_PACKAGE_REPLACES ${IRODS_S3_API_BINARY_NAME})
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)

set(CPACK_RPM_COMPONENT_INSTALL OFF)
set(CPACK_RPM_PACKAGE_LICENSE "BSD-3-Clause")
set(CPACK_RPM_PACKAGE_AUTOREQ 0)
set(CPACK_RPM_PACKAGE_AUTOPROV 0)
#set(CPACK_RPM_PACKAGE_OBSOLETES ${IRODS_PACKAGE_NAME})
#set(CPACK_RPM_PACKAGE_OBSOLETES ${IRODS_S3_API_BINARY_NAME})
#set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_SOURCE_DIR}/packaging/postinst")
set(CPACK_RPM_PACKAGE_RELEASE "${IRODS_PACKAGE_REVISION}")
set(CPACK_RPM_FILE_NAME RPM-DEFAULT)

list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "${CPACK_PACKAGING_INSTALL_PREFIX}${CMAKE_INSTALL_LIBEXECDIR}")
list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "${CPACK_PACKAGING_INSTALL_PREFIX}${CMAKE_INSTALL_LIBEXECDIR}/irods")
list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "${CPACK_PACKAGING_INSTALL_PREFIX}${CMAKE_INSTALL_LIBEXECDIR}/irods/clients")

set(CPACK_ARCHIVE_COMPONENT_INSTALL OFF)

set(CPACK_DEBIAN_PACKAGE_NAME "${IRODS_PACKAGE_NAME}")
set(CPACK_DEBIAN_PACKAGE_NAME ${IRODS_PACKAGE_NAME})
set(CPACK_DEBIAN_PACKAGE_DEPENDS "irods-runtime (= ${IRODS_VERSION})")

get_filename_component(CURL_LIBRARY_REALPATH ${CURL_LIBRARY} REALPATH)
Expand All @@ -184,7 +167,7 @@ elseif (CURL_LIBRARY_REALNAME STREQUAL "libcurl")
endif ()
endif ()

set(CPACK_RPM_PACKAGE_NAME "${IRODS_PACKAGE_NAME}")
set(CPACK_RPM_PACKAGE_NAME ${IRODS_PACKAGE_NAME})
set(CPACK_RPM_PACKAGE_REQUIRES "irods-runtime = ${IRODS_VERSION}, libcurl")

if (NOT CPACK_GENERATOR)
Expand Down
57 changes: 57 additions & 0 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
include(GetGitRevisionDescription)
get_git_head_revision(IRODS_S3_API_GIT_REFSPEC IRODS_S3_API_GIT_SHA1)

configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/include/irods/private/s3_api/version.hpp.in"
"${CMAKE_CURRENT_BINARY_DIR}/include/irods/private/s3_api/version.hpp"
@ONLY
)

add_library(
irods_s3_api_core
OBJECT
"${CMAKE_CURRENT_SOURCE_DIR}/src/common.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/crlf_parser.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/globals.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/process_stash.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/session.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/transport.cpp"
)

target_link_libraries(
irods_s3_api_core
PRIVATE
irods_client
"${IRODS_EXTERNALS_FULLPATH_BOOST}/lib/libboost_filesystem.so"
"${IRODS_EXTERNALS_FULLPATH_BOOST}/lib/libboost_program_options.so"
"${IRODS_EXTERNALS_FULLPATH_BOOST}/lib/libboost_url.so"
"${IRODS_EXTERNALS_FULLPATH_FMT}/lib/libfmt.so"
CURL::libcurl
)

target_compile_definitions(
irods_s3_api_core
PRIVATE
${IRODS_COMPILE_DEFINITIONS}
${IRODS_COMPILE_DEFINITIONS_PRIVATE}
# The following macro requires that the application never attempt to
# change log levels concurrently across threads.
SPDLOG_NO_ATOMIC_LEVELS
# Defines a macro which is used to construct the URL paths to individual
# endpoint handlers (e.g. /irods-s3-api/0.2.0/collections).
IRODS_S3_API_BASE_URL="/irods-s3-api/${IRODS_S3_API_VERSION}"
)

target_include_directories(
irods_s3_api_core
PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/include"
"${CMAKE_CURRENT_BINARY_DIR}/include"
"${IRODS_S3_API_PROJECT_SOURCE_DIR}/endpoints/shared/include"
"${IRODS_EXTERNALS_FULLPATH_BOOST}/include"
"${IRODS_EXTERNALS_FULLPATH_FMT}/include"
"${IRODS_EXTERNALS_FULLPATH_SPDLOG}/include"
)

set_target_properties(irods_s3_api_core PROPERTIES EXCLUDE_FROM_ALL TRUE)
Loading

0 comments on commit 7e0026c

Please sign in to comment.