From 80e04a7fbe6d93bfa69bdaba970bc461398387c1 Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Sat, 26 Aug 2023 07:23:26 +0900 Subject: [PATCH] GH-37394: [C++][S3] Use AWS_SDK_VERSION_* instead of try_compile() --- cpp/src/arrow/CMakeLists.txt | 10 ------ cpp/src/arrow/filesystem/s3fs.cc | 36 ++++++++++++++----- .../filesystem/try_compile/check_s3fs_crt.cc | 28 --------------- 3 files changed, 28 insertions(+), 46 deletions(-) delete mode 100644 cpp/src/arrow/filesystem/try_compile/check_s3fs_crt.cc diff --git a/cpp/src/arrow/CMakeLists.txt b/cpp/src/arrow/CMakeLists.txt index a398e790de14b..ba3f0ef30dd93 100644 --- a/cpp/src/arrow/CMakeLists.txt +++ b/cpp/src/arrow/CMakeLists.txt @@ -497,16 +497,6 @@ if(ARROW_FILESYSTEM) list(APPEND ARROW_SRCS filesystem/hdfs.cc) endif() if(ARROW_S3) - try_compile(S3_HAS_CRT ${CMAKE_CURRENT_BINARY_DIR}/try_compile - SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/filesystem/try_compile/check_s3fs_crt.cc" - CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${CURRENT_INCLUDE_DIRECTORIES}" - LINK_LIBRARIES ${AWSSDK_LINK_LIBRARIES} CXX_STANDARD 17) - - if(S3_HAS_CRT) - message(STATUS "AWS SDK is new enough to have CRT support") - add_definitions(-DARROW_S3_HAS_CRT) - endif() - list(APPEND ARROW_SRCS filesystem/s3fs.cc) set_source_files_properties(filesystem/s3fs.cc PROPERTIES SKIP_PRECOMPILE_HEADERS ON diff --git a/cpp/src/arrow/filesystem/s3fs.cc b/cpp/src/arrow/filesystem/s3fs.cc index c67f7668ffa4d..30ebc01efe52c 100644 --- a/cpp/src/arrow/filesystem/s3fs.cc +++ b/cpp/src/arrow/filesystem/s3fs.cc @@ -44,6 +44,7 @@ #include #include +#include #include #include #include @@ -53,11 +54,6 @@ #include #include #include -#ifdef ARROW_S3_HAS_CRT -#include -#include -#include -#endif #include #include #include @@ -80,6 +76,32 @@ #include #include +// AWS_SDK_VERSION_{MAJOR,MINOR,PATCH} are available since 1.9.7. +#if defined(AWS_SDK_VERSION_MAJOR) && defined(AWS_SDK_VERSION_MINOR) && \ + defined(AWS_SDK_VERSION_PATCH) +#define ARROW_AWS_SDK_VERSION_CHECK(major, minor, patch) \ + (AWS_SDK_VERSION_MAJOR > (major) || \ + (AWS_SDK_VERSION_MAJOR == (major) && AWS_SDK_VERSION_MINOR > (minor)) || \ + (AWS_SDK_VERSION_MAJOR == (major) && AWS_SDK_VERSION_MINOR == (minor) && \ + AWS_SDK_VERSION_PATCH >= (patch))) +#else +#define ARROW_AWS_SDK_VERSION_CHECK(major, minor, patch) 0 +#endif + +// This feature is available since 1.9.0 but +// AWS_SDK_VERSION_{MAJOR,MINOR,PATCH} are available since 1.9.7. So +// we can't use this feature for [1.9.0,1.9.6]. If it's a problem, +// please report it to our issue tracker. +#if ARROW_AWS_SDK_VERSION_CHECK(1, 9, 0) +#define ARROW_S3_HAS_CRT +#endif + +#ifdef ARROW_S3_HAS_CRT +#include +#include +#include +#endif + #include "arrow/util/windows_fixup.h" #include "arrow/buffer.h" @@ -2913,9 +2935,7 @@ struct AwsInstance { return std::make_shared( aws_options_.loggingOptions.logLevel); }; -#if (defined(AWS_SDK_VERSION_MAJOR) && \ - (AWS_SDK_VERSION_MAJOR > 1 || AWS_SDK_VERSION_MINOR > 9 || \ - (AWS_SDK_VERSION_MINOR == 9 && AWS_SDK_VERSION_PATCH >= 272))) +#if ARROW_AWS_SDK_VERSION_CHECK(1, 9, 272) // ARROW-18290: escape all special chars for compatibility with non-AWS S3 backends. // This configuration options is only available with AWS SDK 1.9.272 and later. aws_options_.httpOptions.compliantRfc3986Encoding = true; diff --git a/cpp/src/arrow/filesystem/try_compile/check_s3fs_crt.cc b/cpp/src/arrow/filesystem/try_compile/check_s3fs_crt.cc deleted file mode 100644 index 83240effdbf4b..0000000000000 --- a/cpp/src/arrow/filesystem/try_compile/check_s3fs_crt.cc +++ /dev/null @@ -1,28 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you 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. - -// Dummy file for checking if IOOptions exists in SDKOptions. -// This was introduced when the AWS SDK switched to using the -// CRT for I/O. - -#include - -int main() { - Aws::SDKOptions aws_options; - auto io_options = aws_options.ioOptions; - return 0; -}