diff --git a/.github/.licenserc.yaml b/.github/.licenserc.yaml index a667c903e..dcfcd64f6 100644 --- a/.github/.licenserc.yaml +++ b/.github/.licenserc.yaml @@ -29,6 +29,7 @@ header: - 'LICENSE' - 'NOTICE' - 'requirements.txt' + - 'src/iceberg/expected.h' - 'src/iceberg/util/murmurhash3_internal.*' - 'src/iceberg/test/resources/**' - 'src/iceberg/catalog/hive/gen-cpp/**' diff --git a/LICENSE b/LICENSE index d0429e24b..6d0d88e91 100644 --- a/LICENSE +++ b/LICENSE @@ -230,6 +230,34 @@ License: https://www.apache.org/licenses/LICENSE-2.0 -------------------------------------------------------------------------------- +This product includes code from zeus-cpp/expected. + +* src/iceberg/expected.h is adapted from zeus-cpp/expected. + +Copyright: 2024 zeus-cpp. +Home page: https://github.com/zeus-cpp/expected +License: MIT + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +-------------------------------------------------------------------------------- + This product bundles utf8proc, which is available under the MIT License: utf8proc is a software package originally developed by Jan Behrens and the rest diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index a9bf73cf0..396109e2d 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -20,13 +20,67 @@ cmake_minimum_required(VERSION 3.25) project(example) -set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD 20) find_package(iceberg CONFIG REQUIRED COMPONENTS bundle rest) +if(TARGET iceberg::iceberg_bundle_shared) + set(ICEBERG_BUNDLE_TARGET iceberg::iceberg_bundle_shared) +else() + set(ICEBERG_BUNDLE_TARGET iceberg::iceberg_bundle_static) +endif() + +if(TARGET iceberg::iceberg_rest_shared) + set(ICEBERG_REST_TARGET iceberg::iceberg_rest_shared) +else() + set(ICEBERG_REST_TARGET iceberg::iceberg_rest_static) +endif() + add_executable(demo_example demo_example.cc) -target_link_libraries(demo_example - PRIVATE "$,iceberg::iceberg_bundle_shared,iceberg::iceberg_bundle_static>" - "$,iceberg::iceberg_rest_shared,iceberg::iceberg_rest_static>" -) +target_link_libraries(demo_example PRIVATE ${ICEBERG_BUNDLE_TARGET} + ${ICEBERG_REST_TARGET}) + +# Compile every installed public header as a C++20 consumer. The installed include +# tree is the public API contract: iceberg_install_all_headers excludes internal +# headers before packaging them. +get_target_property(ICEBERG_BUNDLE_INCLUDE_DIRS ${ICEBERG_BUNDLE_TARGET} + INTERFACE_INCLUDE_DIRECTORIES) +foreach(ICEBERG_INCLUDE_DIR IN LISTS ICEBERG_BUNDLE_INCLUDE_DIRS) + if(EXISTS "${ICEBERG_INCLUDE_DIR}/iceberg") + set(ICEBERG_PUBLIC_INCLUDE_DIR "${ICEBERG_INCLUDE_DIR}") + break() + endif() +endforeach() + +if(NOT ICEBERG_PUBLIC_INCLUDE_DIR) + message(FATAL_ERROR "Could not locate iceberg's installed public headers") +endif() + +file(GLOB_RECURSE + ICEBERG_PUBLIC_HEADERS + CONFIGURE_DEPENDS + "${ICEBERG_PUBLIC_INCLUDE_DIR}/iceberg/*.h" + "${ICEBERG_PUBLIC_INCLUDE_DIR}/iceberg/*.hpp") +list(SORT ICEBERG_PUBLIC_HEADERS) + +set(ICEBERG_PUBLIC_HEADER_CHECK_SOURCE + "// Generated from iceberg's installed public headers.\n") +foreach(ICEBERG_PUBLIC_HEADER IN LISTS ICEBERG_PUBLIC_HEADERS) + file(RELATIVE_PATH ICEBERG_PUBLIC_HEADER_RELATIVE_PATH "${ICEBERG_PUBLIC_INCLUDE_DIR}" + "${ICEBERG_PUBLIC_HEADER}") + string(APPEND ICEBERG_PUBLIC_HEADER_CHECK_SOURCE + "#include <${ICEBERG_PUBLIC_HEADER_RELATIVE_PATH}>\n") +endforeach() +string(APPEND ICEBERG_PUBLIC_HEADER_CHECK_SOURCE "\nint main() { return 0; }\n") + +file(GENERATE + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/public_headers_cxx20.cc" + CONTENT "${ICEBERG_PUBLIC_HEADER_CHECK_SOURCE}") + +add_executable(public_headers_cxx20 "${CMAKE_CURRENT_BINARY_DIR}/public_headers_cxx20.cc") +set_target_properties(public_headers_cxx20 + PROPERTIES CXX_STANDARD 20 CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS + OFF) +target_link_libraries(public_headers_cxx20 PRIVATE ${ICEBERG_BUNDLE_TARGET} + ${ICEBERG_REST_TARGET}) diff --git a/src/iceberg/expected.h b/src/iceberg/expected.h new file mode 100644 index 000000000..9754ac0ba --- /dev/null +++ b/src/iceberg/expected.h @@ -0,0 +1,2401 @@ +/* + * MIT License + * + * Copyright (c) 2024 zeus-cpp + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +#include +#include +#include +#include +#include +#if defined(__cpp_lib_expected) && __cpp_lib_expected >= 202202L +# include +#endif + +#include "iceberg/iceberg_export.h" + +// NOLINTBEGIN + +namespace iceberg { + +namespace expected_detail { + +template class Template> +inline constexpr bool is_specialization_v = + false; // true if and only if T is a specialization of Template +template