Skip to content

Commit

Permalink
apacheGH-43164: [C++] Fix CMake link order for AWS SDK (apache#43230)
Browse files Browse the repository at this point in the history
### Rationale for this change

To resolve conflicts with AWS SDK for C++ static variables when linked with libarrow by ensuring correct link order.

### What changes are included in this PR?

- Adjusted `CMakeLists.txt` to set `ARROW_S3_TEST_EXTRA_LINK_LIBS`.
- Ensured `libarrow` is linked before `libaws*` libraries.
- Updated `s3fs_test` configuration to use the new link order.

### Are these changes tested?

I ran the test locally and observed the same result as mentioned. Additionally, I confirmed that if `ARROW_S3` is set to OFF or if the configuration includes `exclude_tests=arrow-s3fs-test`, the test is excluded.

### Are there any user-facing changes?

No.

* GitHub Issue: apache#43164

Authored-by: Hyunseok Seo <hsseo0501@gmail.com>
Signed-off-by: Sutou Kouhei <kou@clear-code.com>
  • Loading branch information
llama90 committed Jul 15, 2024
1 parent 4e939f5 commit 57ac40c
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions cpp/src/arrow/filesystem/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,41 @@ if(ARROW_AZURE)
endif()

if(ARROW_S3)
set(ARROW_S3_TEST_EXTRA_LINK_LIBS)
# arrow_shared/arrow_static is specified implicitly via
# arrow_testing_shared/arrow_testing_static but we specify
# arrow_shared/arrow_static explicitly here to ensure using libarrow
# before libaws* on link. If we use libaws*.a before libarrow,
# static variables storage of AWS SDK for C++ in libaws*.a may be
# mixed with one in libarrow.
if(ARROW_TEST_LINKAGE STREQUAL "shared")
list(APPEND ARROW_S3_TEST_EXTRA_LINK_LIBS arrow_shared)
else()
list(APPEND ARROW_S3_TEST_EXTRA_LINK_LIBS arrow_static)
endif()
list(APPEND
ARROW_S3_TEST_EXTRA_LINK_LIBS
${AWSSDK_LINK_LIBRARIES}
Boost::filesystem
Boost::system)
add_arrow_test(s3fs_test
SOURCES
s3fs_test.cc
s3_test_util.cc
EXTRA_LABELS
filesystem
EXTRA_LINK_LIBS
${AWSSDK_LINK_LIBRARIES}
Boost::filesystem
Boost::system)
${ARROW_S3_TEST_EXTRA_LINK_LIBS})
if(TARGET arrow-s3fs-test)
set(ARROW_S3FS_TEST_COMPILE_DEFINITIONS)
get_target_property(AWS_CPP_SDK_S3_TYPE aws-cpp-sdk-s3 TYPE)
# We need to initialize AWS C++ SDK for direct use (not via
# We need to initialize AWS SDK for C++ for direct use (not via
# arrow::fs::S3FileSystem) in arrow-s3fs-test if we use static AWS
# C++ SDK and hide symbols of them. Because AWS C++ SDK has
# internal static variables that aren't shared in libarrow and
# SDK for C++ and hide symbols of them. Because AWS SDK for C++
# has internal static variables that aren't shared in libarrow and
# arrow-s3fs-test. It means that arrow::fs::InitializeS3() doesn't
# initialize AWS C++ SDK that is directly used in arrow-s3fs-test.
# initialize AWS SDK for C++ that is directly used in
# arrow-s3fs-test.
if(AWS_CPP_SDK_S3_TYPE STREQUAL "STATIC_LIBRARY"
AND CXX_LINKER_SUPPORTS_VERSION_SCRIPT)
list(APPEND ARROW_S3FS_TEST_COMPILE_DEFINITIONS "AWS_CPP_SDK_S3_PRIVATE_STATIC")
Expand Down

0 comments on commit 57ac40c

Please sign in to comment.