From bdb5010ce19096977c788329a61605d2e9cda98a Mon Sep 17 00:00:00 2001 From: "Alina (Xi) Li" Date: Tue, 10 Feb 2026 16:08:40 -0800 Subject: [PATCH 1/7] Build ODBC statically on macOS * Link ODBC library statically on unix Change unit tests to re-use code. Testing on windows is needed. Now seeing error ``` Library not loaded: /usr/local/opt/grpc/lib/libgrpc++.1.76.dylib ``` on Excel. Attempt to unlink arrow_flight.proto Now I see ODBC.dylib has 100MB, and error from Excel is ``` Library not loaded: /usr/local/opt/libiodbc/lib/libiodbc.2.dylib ``` instead of looking for flightsql. `iodbctest` command outside of Excel works. in-progress link arrow statically for `flightsql-odbc` * both ODBC driver and `arrow_odbc_spi_impl` need to link Arrow statically for tests to work. * getting error `File already exists in database: Flight.proto` since the ODBC layer is linking dynamically while I successfully got `arrow_odbc_spi_impl` to link to Arrow statically Draft for resolving `File already exists in database: FlightSql.proto` error Note: make ODBC available on Excel first, test with `iodbctest`, worry about ODBC test executable later. Add unix build (same as Windows build) * Attempted to link static libraries with `arrow_odbc_spi_impl`, failed as it caused linking errors and rendered the ODBC driver unusable. Undo changes to resolve broken driver Resolves dependency errors Attempt to switch to static build Still getting error ``` [iODBC][Driver Manager]dlopen(/Library/ODBC/arrow-odbc/libarrow_flight_sql_odbc.2300.0.0.dylib, 0x0006): Library not loaded: @rpath/libarrow_flight_sql.2300.dylib ``` In-progress attempt to build ODBC statically on unix systems In-progress changes to enable static odbc_impl library pushing the changes just for saving my code. Currently odbc test still has double registration issue, work on this next. I think it should be solvable by either adding library flags or just using odbc spi shared. Because `odbc_spi_impl_test` works. And the ODBC tests worked just fine before I switched to static odbc spi impl. Fix for gtest missing issue Attempting to fix for issue: IMPORTANT NOTICE - DO NOT IGNORE: This test program did NOT call testing::InitGoogleTest() before calling RUN_ALL_TESTS(). This is INVALID. Soon Google Test will start to enforce the valid usage. Please fix it ASAP, or IT WILL START TO FAIL. Issue fixed with adding `${ARROW_TEST_LINK_LIBS}`. It is needed alongside `arrow_flight_testing_shared`. IN-PROGRESS build static test on macOS * Trying to have 2 builds. One `arrow_odbc_spi_impl_static` for static build and one `arrow_odbc_spi_impl_shared` for a shared lib that links Arrow dynamically --- only committing the approach that worked. Trying to work from `flight_sql_odbc_test` to debug the real issue. Link 3rd party dependencies statically Fix 3rd party headers cannot find issue for: - boost xpressive and beast headers - rapidjson headers Resolve unneeded link for ODBC ---- Moving `set(APPEND CMAKE_FIND_LIBRARY_SUFFIXES ".a")` up didn't seem to have any effect ---- Fix for static gRPC connection issue: export GRPC_DEFAULT_SSL_ROOTS_FILE_PATH=/etc/ssl/cert.pem Fix cares `cannot modify alias target` issue Make arrow_odbc_spi_impl static lib In progress for getting gprc linked statically Add debug msgs in add_arrow_lib BuildUtils.cmake Remove commented out code in odbc lib Fix build issue from odbc impl tests Added draft code for Link Arrow libs statically on Unix for unit tests Add commented out code`ARROW_DEPENDENCY_USE_SHARED` in ODBC cpp yml Uncomment when it is verified to work. In-progress Fix ODBC test build and make it run. Build executable from scratch Revert "Build executable from scratch" This reverts commit a51dc395d69c50b42090f50c22cdc9247d3baf9f. Dummy test dummy test without using ODBC passed without double registration issue Make ODBC test run Issue to resolve: [libprotobuf FATAL /path/to/arrow/cpp/debug-build/_deps/protobuf-src/src/google/protobuf/extension_set.cc:100] Multiple extension registrations for type "google.protobuf.MessageOptions", field number 1000. unknown file: Failure C++ exception with description "Multiple extension registrations for type "google.protobuf.MessageOptions", field number 1000." thrown in SetUp(). Fix: only link test executable directly with ODBC shared dylib. Do not link test executable with odbc spi impl dylib. And change ODBC to link odbc spi impl dylib publicly instead of privately in-progress changes to accomodate macos CI Test ODBC CI - to be reverted Can revert later Only install ODBC dependencies in mac As dependencies are static and built from source Uninstall absl as attempt to resolve build on Intel Add C++ standard 20 Remove absl header from intel Use static linking in dependency install step Use bundled boost for static linking In-progress Fix Windows build Fix macOS (after Windows build) Remove unneeded ODBC link Resolves the issue of ODBC on macOS being dynamically linked to ODBC Fix ODBC double proto issue on macOS Need to check if Windows CI passes Clean up PR - Remove dummy tests - Remove unneeded changes Revert "Test ODBC CI - to be reverted" This reverts commit 711b3e0863ebbf5fe2c5cb1401fbaf72eed58aa4. Remove unneeded code Attempt to revert c-ares change Fix `set_target_properties can not be used on an ALIAS target.` error. Example of failed run in forked repo: https://github.com/Bit-Quill/arrow/actions/runs/21459770235/job/61809740997?pr=153#step:7:540 Fix descriptor pointer tests on static macOS Fix mimalloc issue Fixes issue: ``` mimalloc: assertion failed: at "arrow/cpp/debug-build/mimalloc_ep-prefix/src/mimalloc_ep/include/mimalloc/internal.h":658, _mi_ptr_page assertion: "p==NULL || mi_is_in_heap_region(p)" zsh: abort debug/arrow-flight-sql-odbc-test ``` Enable ODBC tests for static build Add iodbc link to macOS build on ODBC layer Add iodbc link to macOS build on ODBC Test Add iodbc link to macOS build on ODBC layer did not resolve issue of unixodbc being picked in CI * Fix segfault at SQLError * work on Justin's comments --- .github/workflows/cpp_extra.yml | 21 +++++ cpp/cmake_modules/ThirdpartyToolchain.cmake | 20 ++++- cpp/src/arrow/flight/sql/odbc/CMakeLists.txt | 82 +++++++++++++------ .../flight/sql/odbc/odbc_impl/CMakeLists.txt | 29 ++++--- .../config/connection_string_parser.h | 2 +- .../odbc/odbc_impl/ui/add_property_window.cc | 6 +- .../sql/odbc/odbc_impl/ui/custom_window.cc | 2 +- .../sql/odbc/odbc_impl/ui/custom_window.h | 2 +- .../odbc_impl/ui/dsn_configuration_window.h | 4 +- .../flight/sql/odbc/tests/CMakeLists.txt | 77 +++++++++++------ .../flight/sql/odbc/tests/errors_test.cc | 7 +- .../flight/sql/odbc/tests/odbc_test_suite.h | 1 + .../sql/odbc/tests/statement_attr_test.cc | 14 +++- 13 files changed, 189 insertions(+), 78 deletions(-) diff --git a/.github/workflows/cpp_extra.yml b/.github/workflows/cpp_extra.yml index abe2aeb6877d..3f7ba5a7d8b0 100644 --- a/.github/workflows/cpp_extra.yml +++ b/.github/workflows/cpp_extra.yml @@ -357,6 +357,10 @@ jobs: ARROW_BUILD_TESTS: ON ARROW_FLIGHT_SQL_ODBC: ON ARROW_HOME: /tmp/local + ARROW_DEPENDENCY_USE_SHARED: OFF + ARROW_DEPENDENCY_SOURCE: BUNDLED + ARROW_MIMALLOC: OFF + CMAKE_CXX_STANDARD: "20" steps: - name: Checkout Arrow uses: actions/checkout@v6.0.1 @@ -366,6 +370,22 @@ jobs: - name: Install Dependencies run: | brew bundle --file=cpp/Brewfile + + # We want to use bundled RE2 for static linking. If + # Homebrew's RE2 is installed, its header file may be used. + # We uninstall Homebrew's RE2 to ensure using bundled RE2. + brew uninstall grpc || : # gRPC depends on RE2 + brew uninstall grpc@1.54 || : # gRPC 1.54 may be installed too + brew uninstall re2 + + # We want to use bundled Protobuf for static linking. If + # Homebrew's Protobuf is installed, its library file may be + # used on test We uninstall Homebrew's Protobuf to ensure using + # bundled Protobuf. + brew uninstall protobuf + + # We want to use bundled Boost for static linking. + brew uninstall boost - name: Setup ccache run: | ci/scripts/ccache_setup.sh @@ -433,6 +453,7 @@ jobs: CMAKE_INSTALL_PREFIX: /usr VCPKG_BINARY_SOURCES: 'clear;nugettimeout,600;nuget,GitHub,readwrite' VCPKG_DEFAULT_TRIPLET: x64-windows + CMAKE_CXX_STANDARD: "20" steps: - name: Disable Crash Dialogs run: | diff --git a/cpp/cmake_modules/ThirdpartyToolchain.cmake b/cpp/cmake_modules/ThirdpartyToolchain.cmake index 935584c5349c..fb382394bc9d 100644 --- a/cpp/cmake_modules/ThirdpartyToolchain.cmake +++ b/cpp/cmake_modules/ThirdpartyToolchain.cmake @@ -1114,6 +1114,22 @@ function(build_boost) else() list(APPEND BOOST_EXCLUDE_LIBRARIES uuid) endif() + if(ARROW_FLIGHT_SQL_ODBC) + # GH-49244: Replace boost beast with alternatives in ODBC + # GH-49243: Replace boost variant with std::variant in ODBC + # GH-49245: Replace boost xpressive with alternatives in ODBC + list(APPEND + BOOST_INCLUDE_LIBRARIES + beast + variant + xpressive) + else() + list(APPEND + BOOST_EXCLUDE_LIBRARIES + beast + variant + xpressive) + endif() set(BOOST_SKIP_INSTALL_RULES ON) if(NOT ARROW_ENABLE_THREADING) set(BOOST_UUID_LINK_LIBATOMIC OFF) @@ -3025,8 +3041,8 @@ function(build_cares) if(APPLE) # libresolv must be linked from c-ares version 1.16.1 find_library(LIBRESOLV_LIBRARY NAMES resolv libresolv REQUIRED) - set_target_properties(c-ares::cares PROPERTIES INTERFACE_LINK_LIBRARIES - "${LIBRESOLV_LIBRARY}") + set_target_properties(c-ares PROPERTIES INTERFACE_LINK_LIBRARIES + "${LIBRESOLV_LIBRARY}") endif() set(ARROW_BUNDLED_STATIC_LIBS diff --git a/cpp/src/arrow/flight/sql/odbc/CMakeLists.txt b/cpp/src/arrow/flight/sql/odbc/CMakeLists.txt index 39040c45024d..80d3a67c2931 100644 --- a/cpp/src/arrow/flight/sql/odbc/CMakeLists.txt +++ b/cpp/src/arrow/flight/sql/odbc/CMakeLists.txt @@ -19,6 +19,11 @@ # GH-44792: Arrow will switch to C++ 20 set(CMAKE_CXX_STANDARD 20) +if(APPLE) + # CMAKE_FIND_LIBRARY_SUFFIXES. + set(APPEND CMAKE_FIND_LIBRARY_SUFFIXES ".a") +endif() + if(WIN32) if(MSVC_VERSION GREATER_EQUAL 1900) set(ODBCINST legacy_stdio_definitions odbccp32 shlwapi) @@ -61,33 +66,56 @@ if(WIN32) list(APPEND ARROW_FLIGHT_SQL_ODBC_SRCS odbc.def install/versioninfo.rc) endif() -add_arrow_lib(arrow_flight_sql_odbc - CMAKE_PACKAGE_NAME - ArrowFlightSqlOdbc - PKG_CONFIG_NAME - arrow-flight-sql-odbc - OUTPUTS - ARROW_FLIGHT_SQL_ODBC_LIBRARIES - SOURCES - ${ARROW_FLIGHT_SQL_ODBC_SRCS} - DEPENDENCIES - arrow_flight_sql - DEFINITIONS - UNICODE - SHARED_LINK_FLAGS - ${ARROW_VERSION_SCRIPT_FLAGS} # Defined in cpp/arrow/CMakeLists.txt - SHARED_LINK_LIBS - arrow_flight_sql_shared - SHARED_INSTALL_INTERFACE_LIBS - ArrowFlight::arrow_flight_sql_shared - STATIC_LINK_LIBS - arrow_flight_sql_static - STATIC_INSTALL_INTERFACE_LIBS - ArrowFlight::arrow_flight_sql_static - SHARED_PRIVATE_LINK_LIBS - ODBC::ODBC - ${ODBCINST} - arrow_odbc_spi_impl) +# On Windows, dynmaic build for ODBC is supported. +# On unix systems, static build for ODBC is supported, all libraries are linked statically on unix. +if(WIN32) + add_arrow_lib(arrow_flight_sql_odbc + CMAKE_PACKAGE_NAME + ArrowFlightSqlOdbc + PKG_CONFIG_NAME + arrow-flight-sql-odbc + OUTPUTS + ARROW_FLIGHT_SQL_ODBC_LIBRARIES + SOURCES + ${ARROW_FLIGHT_SQL_ODBC_SRCS} + DEFINITIONS + UNICODE + SHARED_LINK_FLAGS + ${ARROW_VERSION_SCRIPT_FLAGS} # Defined in cpp/arrow/CMakeLists.txt + SHARED_LINK_LIBS + arrow_flight_sql_shared + arrow_odbc_spi_impl + SHARED_INSTALL_INTERFACE_LIBS + ArrowFlight::arrow_flight_sql_shared + STATIC_LINK_LIBS + arrow_flight_sql_static + STATIC_INSTALL_INTERFACE_LIBS + ArrowFlight::arrow_flight_sql_static + SHARED_PRIVATE_LINK_LIBS + ODBC::ODBC + ${ODBCINST}) +else() + # Unix + add_arrow_lib(arrow_flight_sql_odbc + CMAKE_PACKAGE_NAME + ArrowFlightSqlOdbc + PKG_CONFIG_NAME + arrow-flight-sql-odbc + OUTPUTS + ARROW_FLIGHT_SQL_ODBC_LIBRARIES + SOURCES + ${ARROW_FLIGHT_SQL_ODBC_SRCS} + DEFINITIONS + UNICODE + SHARED_LINK_FLAGS + ${ARROW_VERSION_SCRIPT_FLAGS} # Defined in cpp/arrow/CMakeLists.txt + STATIC_LINK_LIBS + iodbc + ODBC::ODBC + ${ODBCINST} + SHARED_LINK_LIBS + arrow_odbc_spi_impl) +endif() foreach(LIB_TARGET ${ARROW_FLIGHT_SQL_ODBC_LIBRARIES}) target_compile_definitions(${LIB_TARGET} PRIVATE ARROW_FLIGHT_SQL_ODBC_EXPORTING) diff --git a/cpp/src/arrow/flight/sql/odbc/odbc_impl/CMakeLists.txt b/cpp/src/arrow/flight/sql/odbc/odbc_impl/CMakeLists.txt index e58558258df0..0897248f6cea 100644 --- a/cpp/src/arrow/flight/sql/odbc/odbc_impl/CMakeLists.txt +++ b/cpp/src/arrow/flight/sql/odbc/odbc_impl/CMakeLists.txt @@ -15,7 +15,7 @@ # specific language governing permissions and limitations # under the License. -add_library(arrow_odbc_spi_impl +add_library(arrow_odbc_spi_impl STATIC accessors/binary_array_accessor.cc accessors/binary_array_accessor.h accessors/boolean_array_accessor.cc @@ -133,8 +133,11 @@ endif() if(APPLE) target_include_directories(arrow_odbc_spi_impl SYSTEM BEFORE PUBLIC ${ODBC_INCLUDE_DIR}) target_link_libraries(arrow_odbc_spi_impl - PUBLIC arrow_flight_sql_shared arrow_compute_shared Boost::locale - iodbc) + PUBLIC arrow_flight_sql_static + arrow_compute_static + Boost::locale + Boost::headers + RapidJSON) else() find_package(ODBC REQUIRED) target_include_directories(arrow_odbc_spi_impl PUBLIC ${ODBC_INCLUDE_DIR}) @@ -143,14 +146,6 @@ else() ${ODBCINST}) endif() -set_target_properties(arrow_odbc_spi_impl - PROPERTIES ARCHIVE_OUTPUT_DIRECTORY - ${CMAKE_BINARY_DIR}/$/lib - LIBRARY_OUTPUT_DIRECTORY - ${CMAKE_BINARY_DIR}/$/lib - RUNTIME_OUTPUT_DIRECTORY - ${CMAKE_BINARY_DIR}/$/lib) - # CLI add_executable(arrow_odbc_spi_impl_cli main.cc) set_target_properties(arrow_odbc_spi_impl_cli @@ -159,6 +154,16 @@ set_target_properties(arrow_odbc_spi_impl_cli target_link_libraries(arrow_odbc_spi_impl_cli arrow_odbc_spi_impl) # Unit tests + +# On Windows, dynamic linking ODBC is supported. +# On unix systems, static linking ODBC is supported, thus the library linking is static. +if(WIN32) + set(ODBC_SPI_IMPL_TEST_LINK_LIBS arrow_flight_testing_shared) +else() + # unix + set(ODBC_SPI_IMPL_TEST_LINK_LIBS arrow_flight_testing_static) +endif() + add_arrow_test(odbc_spi_impl_test SOURCES accessors/boolean_array_accessor_test.cc @@ -177,4 +182,4 @@ add_arrow_test(odbc_spi_impl_test util_test.cc EXTRA_LINK_LIBS arrow_odbc_spi_impl - arrow_flight_testing_shared) + ${ODBC_SPI_IMPL_TEST_LINK_LIBS}) diff --git a/cpp/src/arrow/flight/sql/odbc/odbc_impl/config/connection_string_parser.h b/cpp/src/arrow/flight/sql/odbc/odbc_impl/config/connection_string_parser.h index dd937410adc1..2e7196e322fa 100644 --- a/cpp/src/arrow/flight/sql/odbc/odbc_impl/config/connection_string_parser.h +++ b/cpp/src/arrow/flight/sql/odbc/odbc_impl/config/connection_string_parser.h @@ -19,7 +19,7 @@ #include -#include "config/configuration.h" +#include "arrow/flight/sql/odbc/odbc_impl/config/configuration.h" namespace arrow::flight::sql::odbc { namespace config { diff --git a/cpp/src/arrow/flight/sql/odbc/odbc_impl/ui/add_property_window.cc b/cpp/src/arrow/flight/sql/odbc/odbc_impl/ui/add_property_window.cc index 634fd77862e9..6518e48459e7 100644 --- a/cpp/src/arrow/flight/sql/odbc/odbc_impl/ui/add_property_window.cc +++ b/cpp/src/arrow/flight/sql/odbc/odbc_impl/ui/add_property_window.cc @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -#include "ui/add_property_window.h" +#include "arrow/flight/sql/odbc/odbc_impl/ui/add_property_window.h" #include @@ -25,8 +25,8 @@ #include #include "arrow/flight/sql/odbc/odbc_impl/exceptions.h" -#include "ui/custom_window.h" -#include "ui/window.h" +#include "arrow/flight/sql/odbc/odbc_impl/ui/custom_window.h" +#include "arrow/flight/sql/odbc/odbc_impl/ui/window.h" namespace arrow::flight::sql::odbc { namespace config { diff --git a/cpp/src/arrow/flight/sql/odbc/odbc_impl/ui/custom_window.cc b/cpp/src/arrow/flight/sql/odbc/odbc_impl/ui/custom_window.cc index 179303b68e38..47149a33a560 100644 --- a/cpp/src/arrow/flight/sql/odbc/odbc_impl/ui/custom_window.cc +++ b/cpp/src/arrow/flight/sql/odbc/odbc_impl/ui/custom_window.cc @@ -28,7 +28,7 @@ #include #include "arrow/flight/sql/odbc/odbc_impl/exceptions.h" -#include "ui/custom_window.h" +#include "arrow/flight/sql/odbc/odbc_impl/ui/custom_window.h" namespace arrow::flight::sql::odbc { namespace config { diff --git a/cpp/src/arrow/flight/sql/odbc/odbc_impl/ui/custom_window.h b/cpp/src/arrow/flight/sql/odbc/odbc_impl/ui/custom_window.h index a65800114855..9745f58b2e22 100644 --- a/cpp/src/arrow/flight/sql/odbc/odbc_impl/ui/custom_window.h +++ b/cpp/src/arrow/flight/sql/odbc/odbc_impl/ui/custom_window.h @@ -17,7 +17,7 @@ #pragma once -#include "ui/window.h" +#include "arrow/flight/sql/odbc/odbc_impl/ui/window.h" namespace arrow::flight::sql::odbc { namespace config { diff --git a/cpp/src/arrow/flight/sql/odbc/odbc_impl/ui/dsn_configuration_window.h b/cpp/src/arrow/flight/sql/odbc/odbc_impl/ui/dsn_configuration_window.h index bfac68df8b98..74a750537362 100644 --- a/cpp/src/arrow/flight/sql/odbc/odbc_impl/ui/dsn_configuration_window.h +++ b/cpp/src/arrow/flight/sql/odbc/odbc_impl/ui/dsn_configuration_window.h @@ -17,8 +17,8 @@ #pragma once -#include "config/configuration.h" -#include "ui/custom_window.h" +#include "arrow/flight/sql/odbc/odbc_impl/config/configuration.h" +#include "arrow/flight/sql/odbc/odbc_impl/ui/custom_window.h" namespace arrow::flight::sql::odbc { namespace config { diff --git a/cpp/src/arrow/flight/sql/odbc/tests/CMakeLists.txt b/cpp/src/arrow/flight/sql/odbc/tests/CMakeLists.txt index ef0c7271ec23..b44846fb3500 100644 --- a/cpp/src/arrow/flight/sql/odbc/tests/CMakeLists.txt +++ b/cpp/src/arrow/flight/sql/odbc/tests/CMakeLists.txt @@ -25,29 +25,60 @@ set(ARROW_FLIGHT_SQL_MOCK_SERVER_SRCS ../../example/sqlite_server.cc ../../example/sqlite_tables_schema_batch_reader.cc) -add_arrow_test(flight_sql_odbc_test - SOURCES - odbc_test_suite.cc - odbc_test_suite.h - columns_test.cc - connection_attr_test.cc - connection_info_test.cc - connection_test.cc - errors_test.cc - get_functions_test.cc - statement_attr_test.cc - statement_test.cc - tables_test.cc - type_info_test.cc - # Enable Protobuf cleanup after test execution - # GH-46889: move protobuf_test_util to a more common location - ../../../../engine/substrait/protobuf_test_util.cc - ${ARROW_FLIGHT_SQL_MOCK_SERVER_SRCS} - EXTRA_LINK_LIBS - ${ODBC_LIBRARIES} - ${ODBCINST} - ${SQLite3_LIBRARIES} - arrow_odbc_spi_impl) +if(ARROW_TEST_LINKAGE STREQUAL "static") + set(ARROW_FLIGHT_SQL_ODBC_TEST_LINK_LIBS arrow_flight_sql_odbc_static + ${ARROW_TEST_STATIC_LINK_LIBS}) +else() + set(ARROW_FLIGHT_SQL_ODBC_TEST_LINK_LIBS arrow_flight_sql_odbc_shared + ${ARROW_TEST_SHARED_LINK_LIBS}) +endif() + +set(ARROW_FLIGHT_SQL_ODBC_TEST_SRCS + odbc_test_suite.cc + odbc_test_suite.h + columns_test.cc + connection_attr_test.cc + connection_info_test.cc + connection_test.cc + errors_test.cc + get_functions_test.cc + statement_attr_test.cc + statement_test.cc + tables_test.cc + type_info_test.cc + # Enable Protobuf cleanup after test execution + # GH-46889: move protobuf_test_util to a more common location + ../../../../engine/substrait/protobuf_test_util.cc) + +# On Windows, dynamic linking ODBC is supported, tests link libraries dynamically. +# On unix systems, static linking ODBC is supported, thus tests link libraries statically. +if(WIN32) + add_arrow_test(flight_sql_odbc_test + SOURCES + ${ARROW_FLIGHT_SQL_ODBC_TEST_SRCS} + ${ARROW_FLIGHT_SQL_MOCK_SERVER_SRCS} + DEFINITIONS + UNICODE + EXTRA_LINK_LIBS + ${ODBC_LIBRARIES} + ${ODBCINST} + ${SQLite3_LIBRARIES} + ${ARROW_FLIGHT_SQL_ODBC_TEST_LINK_LIBS}) +elseif(APPLE) + # macOS + add_arrow_test(flight_sql_odbc_test + SOURCES + ${ARROW_FLIGHT_SQL_ODBC_TEST_SRCS} + ${ARROW_FLIGHT_SQL_MOCK_SERVER_SRCS} + DEFINITIONS + UNICODE + STATIC_LINK_LIBS + iodbc + ${ODBC_LIBRARIES} + ${ODBCINST} + ${SQLite3_LIBRARIES} + ${ARROW_FLIGHT_SQL_ODBC_TEST_LINK_LIBS}) +endif() find_package(ODBC REQUIRED) target_link_libraries(arrow-flight-sql-odbc-test PRIVATE ODBC::ODBC) diff --git a/cpp/src/arrow/flight/sql/odbc/tests/errors_test.cc b/cpp/src/arrow/flight/sql/odbc/tests/errors_test.cc index 34a32738455a..e8e62d54fc78 100644 --- a/cpp/src/arrow/flight/sql/odbc/tests/errors_test.cc +++ b/cpp/src/arrow/flight/sql/odbc/tests/errors_test.cc @@ -507,7 +507,7 @@ TYPED_TEST(ErrorsOdbcV2Test, TestSQLErrorStmtErrorODBCVer2) { // When application passes buffer length greater than SQL_MAX_MESSAGE_LENGTH (512), // DM passes 512 as buffer length to SQLError. - std::wstring wsql = L"1"; + std::wstring wsql = L"SELECT * from non_existent_table;"; std::vector sql0(wsql.begin(), wsql.end()); ASSERT_EQ(SQL_ERROR, @@ -515,11 +515,10 @@ TYPED_TEST(ErrorsOdbcV2Test, TestSQLErrorStmtErrorODBCVer2) { SQLWCHAR sql_state[6] = {0}; SQLINTEGER native_error = 0; - SQLWCHAR message[SQL_MAX_MESSAGE_LENGTH] = {0}; SQLSMALLINT message_length = 0; - ASSERT_EQ(SQL_SUCCESS, SQLError(nullptr, nullptr, this->stmt, sql_state, &native_error, + SQLWCHAR message[SQL_MAX_MESSAGE_LENGTH] = {0}; + ASSERT_EQ(SQL_SUCCESS, SQLError(SQL_NULL_HENV, this->conn, this->stmt, sql_state, &native_error, message, SQL_MAX_MESSAGE_LENGTH, &message_length)); - EXPECT_GT(message_length, 70); EXPECT_EQ(100, native_error); diff --git a/cpp/src/arrow/flight/sql/odbc/tests/odbc_test_suite.h b/cpp/src/arrow/flight/sql/odbc/tests/odbc_test_suite.h index 3115cd627547..419f698c5d96 100644 --- a/cpp/src/arrow/flight/sql/odbc/tests/odbc_test_suite.h +++ b/cpp/src/arrow/flight/sql/odbc/tests/odbc_test_suite.h @@ -236,6 +236,7 @@ static constexpr std::string_view kErrorStateHY106 = "HY106"; static constexpr std::string_view kErrorStateHY114 = "HY114"; static constexpr std::string_view kErrorStateHY118 = "HY118"; static constexpr std::string_view kErrorStateHYC00 = "HYC00"; +static constexpr std::string_view kErrorStateIM001 = "IM001"; static constexpr std::string_view kErrorStateS1002 = "S1002"; static constexpr std::string_view kErrorStateS1004 = "S1004"; static constexpr std::string_view kErrorStateS1010 = "S1010"; diff --git a/cpp/src/arrow/flight/sql/odbc/tests/statement_attr_test.cc b/cpp/src/arrow/flight/sql/odbc/tests/statement_attr_test.cc index 0a4e99d33a6f..c1b021bca659 100644 --- a/cpp/src/arrow/flight/sql/odbc/tests/statement_attr_test.cc +++ b/cpp/src/arrow/flight/sql/odbc/tests/statement_attr_test.cc @@ -477,15 +477,25 @@ TYPED_TEST(StatementAttributeTest, TestSQLSetStmtAttrFetchBookmarkPointer) { TYPED_TEST(StatementAttributeTest, TestSQLSetStmtAttrIMPParamDesc) { // Invalid use of an automatically allocated descriptor handle ValidateSetStmtAttrErrorCode(this->stmt, SQL_ATTR_IMP_PARAM_DESC, - static_cast(0), kErrorStateHY017); + static_cast(0), +#ifdef __APPLE__ + // static iODBC on MacOS returns IM001 for this case + kErrorStateIM001); +#else + kErrorStateHY017); +#endif // __APPLE__ } TYPED_TEST(StatementAttributeTest, TestSQLSetStmtAttrIMPRowDesc) { // Invalid use of an automatically allocated descriptor handle ValidateSetStmtAttrErrorCode(this->stmt, SQL_ATTR_IMP_ROW_DESC, static_cast(0), +#ifdef __APPLE__ + // static iODBC on MacOS returns IM001 for this case + kErrorStateIM001); +#else kErrorStateHY017); +#endif // __APPLE__ } - TYPED_TEST(StatementAttributeTest, TestSQLSetStmtAttrKeysetSizeUnsupported) { ValidateSetStmtAttr(this->stmt, SQL_ATTR_KEYSET_SIZE, static_cast(0)); } From 3ca6af2a311dc0514da533da02de1c0664644c36 Mon Sep 17 00:00:00 2001 From: "Alina (Xi) Li" Date: Wed, 11 Feb 2026 12:47:29 -0800 Subject: [PATCH 2/7] Fix Lint issue --- cpp/src/arrow/flight/sql/odbc/tests/errors_test.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cpp/src/arrow/flight/sql/odbc/tests/errors_test.cc b/cpp/src/arrow/flight/sql/odbc/tests/errors_test.cc index e8e62d54fc78..36f91f827e4d 100644 --- a/cpp/src/arrow/flight/sql/odbc/tests/errors_test.cc +++ b/cpp/src/arrow/flight/sql/odbc/tests/errors_test.cc @@ -517,8 +517,9 @@ TYPED_TEST(ErrorsOdbcV2Test, TestSQLErrorStmtErrorODBCVer2) { SQLINTEGER native_error = 0; SQLSMALLINT message_length = 0; SQLWCHAR message[SQL_MAX_MESSAGE_LENGTH] = {0}; - ASSERT_EQ(SQL_SUCCESS, SQLError(SQL_NULL_HENV, this->conn, this->stmt, sql_state, &native_error, - message, SQL_MAX_MESSAGE_LENGTH, &message_length)); + ASSERT_EQ(SQL_SUCCESS, + SQLError(SQL_NULL_HENV, this->conn, this->stmt, sql_state, &native_error, + message, SQL_MAX_MESSAGE_LENGTH, &message_length)); EXPECT_GT(message_length, 70); EXPECT_EQ(100, native_error); From e66c43f2356afa29b415e78864076075c81a99a1 Mon Sep 17 00:00:00 2001 From: "Alina (Xi) Li" Date: Mon, 23 Feb 2026 17:54:58 -0800 Subject: [PATCH 3/7] Add check for static ODBC dependency --- .github/workflows/cpp_extra.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/cpp_extra.yml b/.github/workflows/cpp_extra.yml index 3f7ba5a7d8b0..2e9bf2eda543 100644 --- a/.github/workflows/cpp_extra.yml +++ b/.github/workflows/cpp_extra.yml @@ -415,6 +415,10 @@ jobs: export ARROW_CMAKE_ARGS="-DODBC_INCLUDE_DIR=$ODBC_INCLUDE_DIR" export CXXFLAGS="$CXXFLAGS -I$ODBC_INCLUDE_DIR" ci/scripts/cpp_build.sh $(pwd) $(pwd)/build + - name: Check ODBC Dependency + run: | + # ODBC dependency should not include Arrow or third party libraries + ! otool -L $(pwd)/build/cpp/debug/libarrow_flight_sql_odbc.dylib | grep -Ei 'arrow_flight_sql\.|arrow_flight\.|arrow_compute|boost|iodbc|grpc' - name: Register Flight SQL ODBC Driver run: | sudo cpp/src/arrow/flight/sql/odbc/install/mac/install_odbc.sh $(pwd)/build/cpp/debug/libarrow_flight_sql_odbc.dylib From 3fbc3d36eacb41f7fe0d7ac301d6584229dbb939 Mon Sep 17 00:00:00 2001 From: "Alina (Xi) Li" Date: Mon, 23 Feb 2026 17:54:42 -0800 Subject: [PATCH 4/7] In-progress Work on kou's comments - remove `CMAKE_CXX_STANDARD: "20"` as `20` is used by default. - Keep environment variables in alphabetical order. - Revert `set(APPEND CMAKE_FIND_LIBRARY_SUFFIXES ".a")`. --- .github/workflows/cpp_extra.yml | 6 ++---- cpp/src/arrow/flight/sql/odbc/CMakeLists.txt | 12 +----------- cpp/src/arrow/flight/sql/odbc/tests/CMakeLists.txt | 2 -- 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/.github/workflows/cpp_extra.yml b/.github/workflows/cpp_extra.yml index 2e9bf2eda543..66d1c4b52ebd 100644 --- a/.github/workflows/cpp_extra.yml +++ b/.github/workflows/cpp_extra.yml @@ -355,12 +355,11 @@ jobs: macos-version: "14" env: ARROW_BUILD_TESTS: ON + ARROW_DEPENDENCY_SOURCE: BUNDLED + ARROW_DEPENDENCY_USE_SHARED: OFF ARROW_FLIGHT_SQL_ODBC: ON ARROW_HOME: /tmp/local - ARROW_DEPENDENCY_USE_SHARED: OFF - ARROW_DEPENDENCY_SOURCE: BUNDLED ARROW_MIMALLOC: OFF - CMAKE_CXX_STANDARD: "20" steps: - name: Checkout Arrow uses: actions/checkout@v6.0.1 @@ -457,7 +456,6 @@ jobs: CMAKE_INSTALL_PREFIX: /usr VCPKG_BINARY_SOURCES: 'clear;nugettimeout,600;nuget,GitHub,readwrite' VCPKG_DEFAULT_TRIPLET: x64-windows - CMAKE_CXX_STANDARD: "20" steps: - name: Disable Crash Dialogs run: | diff --git a/cpp/src/arrow/flight/sql/odbc/CMakeLists.txt b/cpp/src/arrow/flight/sql/odbc/CMakeLists.txt index 80d3a67c2931..ddf7f9aef2eb 100644 --- a/cpp/src/arrow/flight/sql/odbc/CMakeLists.txt +++ b/cpp/src/arrow/flight/sql/odbc/CMakeLists.txt @@ -15,15 +15,6 @@ # specific language governing permissions and limitations # under the License. -# Use C++ 20 for ODBC and its subdirectory -# GH-44792: Arrow will switch to C++ 20 -set(CMAKE_CXX_STANDARD 20) - -if(APPLE) - # CMAKE_FIND_LIBRARY_SUFFIXES. - set(APPEND CMAKE_FIND_LIBRARY_SUFFIXES ".a") -endif() - if(WIN32) if(MSVC_VERSION GREATER_EQUAL 1900) set(ODBCINST legacy_stdio_definitions odbccp32 shlwapi) @@ -31,7 +22,7 @@ if(WIN32) set(ODBCINST odbccp32 shlwapi) endif() elseif(APPLE) - set(ODBCINST iodbcinst) + set(ODBCINST iodbc iodbcinst) else() set(ODBCINST odbcinst) endif() @@ -110,7 +101,6 @@ else() SHARED_LINK_FLAGS ${ARROW_VERSION_SCRIPT_FLAGS} # Defined in cpp/arrow/CMakeLists.txt STATIC_LINK_LIBS - iodbc ODBC::ODBC ${ODBCINST} SHARED_LINK_LIBS diff --git a/cpp/src/arrow/flight/sql/odbc/tests/CMakeLists.txt b/cpp/src/arrow/flight/sql/odbc/tests/CMakeLists.txt index b44846fb3500..24b747e21e05 100644 --- a/cpp/src/arrow/flight/sql/odbc/tests/CMakeLists.txt +++ b/cpp/src/arrow/flight/sql/odbc/tests/CMakeLists.txt @@ -65,7 +65,6 @@ if(WIN32) ${SQLite3_LIBRARIES} ${ARROW_FLIGHT_SQL_ODBC_TEST_LINK_LIBS}) elseif(APPLE) - # macOS add_arrow_test(flight_sql_odbc_test SOURCES ${ARROW_FLIGHT_SQL_ODBC_TEST_SRCS} @@ -73,7 +72,6 @@ elseif(APPLE) DEFINITIONS UNICODE STATIC_LINK_LIBS - iodbc ${ODBC_LIBRARIES} ${ODBCINST} ${SQLite3_LIBRARIES} From 8eb68a83e044e4903e601d98080b998d0a7b5dfb Mon Sep 17 00:00:00 2001 From: "Alina (Xi) Li" Date: Tue, 24 Feb 2026 11:09:54 -0800 Subject: [PATCH 5/7] Continue work on kou's comments - Use `target_link_libraries` for `c-ares`. - Use one `add_arrow_lib` --- cpp/cmake_modules/ThirdpartyToolchain.cmake | 3 +- cpp/src/arrow/flight/sql/odbc/CMakeLists.txt | 79 +++++++++---------- .../flight/sql/odbc/tests/CMakeLists.txt | 39 ++++----- 3 files changed, 53 insertions(+), 68 deletions(-) diff --git a/cpp/cmake_modules/ThirdpartyToolchain.cmake b/cpp/cmake_modules/ThirdpartyToolchain.cmake index fb382394bc9d..2da5c830d1e4 100644 --- a/cpp/cmake_modules/ThirdpartyToolchain.cmake +++ b/cpp/cmake_modules/ThirdpartyToolchain.cmake @@ -3041,8 +3041,7 @@ function(build_cares) if(APPLE) # libresolv must be linked from c-ares version 1.16.1 find_library(LIBRESOLV_LIBRARY NAMES resolv libresolv REQUIRED) - set_target_properties(c-ares PROPERTIES INTERFACE_LINK_LIBRARIES - "${LIBRESOLV_LIBRARY}") + target_link_libraries(c-ares INTERFACE ${LIBRESOLV_LIBRARY}) endif() set(ARROW_BUNDLED_STATIC_LIBS diff --git a/cpp/src/arrow/flight/sql/odbc/CMakeLists.txt b/cpp/src/arrow/flight/sql/odbc/CMakeLists.txt index ddf7f9aef2eb..f11d0eac71e2 100644 --- a/cpp/src/arrow/flight/sql/odbc/CMakeLists.txt +++ b/cpp/src/arrow/flight/sql/odbc/CMakeLists.txt @@ -59,54 +59,47 @@ endif() # On Windows, dynmaic build for ODBC is supported. # On unix systems, static build for ODBC is supported, all libraries are linked statically on unix. +set(ARROW_FLIGHT_SQL_ODBC_SHARED_INSTALL_INTERFACE_LIBS "") +set(ARROW_FLIGHT_SQL_ODBC_STATIC_INSTALL_INTERFACE_LIBS "") +set(ARROW_FLIGHT_SQL_ODBC_SHARED_PRIVATE_LINK_LIBS "") if(WIN32) - add_arrow_lib(arrow_flight_sql_odbc - CMAKE_PACKAGE_NAME - ArrowFlightSqlOdbc - PKG_CONFIG_NAME - arrow-flight-sql-odbc - OUTPUTS - ARROW_FLIGHT_SQL_ODBC_LIBRARIES - SOURCES - ${ARROW_FLIGHT_SQL_ODBC_SRCS} - DEFINITIONS - UNICODE - SHARED_LINK_FLAGS - ${ARROW_VERSION_SCRIPT_FLAGS} # Defined in cpp/arrow/CMakeLists.txt - SHARED_LINK_LIBS - arrow_flight_sql_shared - arrow_odbc_spi_impl - SHARED_INSTALL_INTERFACE_LIBS - ArrowFlight::arrow_flight_sql_shared - STATIC_LINK_LIBS - arrow_flight_sql_static - STATIC_INSTALL_INTERFACE_LIBS - ArrowFlight::arrow_flight_sql_static - SHARED_PRIVATE_LINK_LIBS - ODBC::ODBC - ${ODBCINST}) + set(ARROW_FLIGHT_SQL_ODBC_SHARED_LINK_LIBS arrow_flight_sql_shared arrow_odbc_spi_impl) + set(ARROW_FLIGHT_SQL_ODBC_STATIC_LINK_LIBS arrow_flight_sql_static) + list(APPEND ARROW_FLIGHT_SQL_ODBC_SHARED_INSTALL_INTERFACE_LIBS + ArrowFlight::arrow_flight_sql_shared) + list(APPEND ARROW_FLIGHT_SQL_ODBC_STATIC_INSTALL_INTERFACE_LIBS + ArrowFlight::arrow_flight_sql_static) + list(APPEND ARROW_FLIGHT_SQL_ODBC_SHARED_PRIVATE_LINK_LIBS ODBC::ODBC ${ODBCINST}) else() # Unix - add_arrow_lib(arrow_flight_sql_odbc - CMAKE_PACKAGE_NAME - ArrowFlightSqlOdbc - PKG_CONFIG_NAME - arrow-flight-sql-odbc - OUTPUTS - ARROW_FLIGHT_SQL_ODBC_LIBRARIES - SOURCES - ${ARROW_FLIGHT_SQL_ODBC_SRCS} - DEFINITIONS - UNICODE - SHARED_LINK_FLAGS - ${ARROW_VERSION_SCRIPT_FLAGS} # Defined in cpp/arrow/CMakeLists.txt - STATIC_LINK_LIBS - ODBC::ODBC - ${ODBCINST} - SHARED_LINK_LIBS - arrow_odbc_spi_impl) + set(ARROW_FLIGHT_SQL_ODBC_SHARED_LINK_LIBS arrow_odbc_spi_impl) + set(ARROW_FLIGHT_SQL_ODBC_STATIC_LINK_LIBS ODBC::ODBC ${ODBCINST}) endif() +add_arrow_lib(arrow_flight_sql_odbc + CMAKE_PACKAGE_NAME + ArrowFlightSqlOdbc + PKG_CONFIG_NAME + arrow-flight-sql-odbc + OUTPUTS + ARROW_FLIGHT_SQL_ODBC_LIBRARIES + SOURCES + ${ARROW_FLIGHT_SQL_ODBC_SRCS} + DEFINITIONS + UNICODE + SHARED_LINK_FLAGS + ${ARROW_VERSION_SCRIPT_FLAGS} # Defined in cpp/arrow/CMakeLists.txt + SHARED_LINK_LIBS + ${ARROW_FLIGHT_SQL_ODBC_SHARED_LINK_LIBS} + SHARED_INSTALL_INTERFACE_LIBS + ${ARROW_FLIGHT_SQL_ODBC_SHARED_INSTALL_INTERFACE_LIBS} + STATIC_LINK_LIBS + ${ARROW_FLIGHT_SQL_ODBC_STATIC_LINK_LIBS} + STATIC_INSTALL_INTERFACE_LIBS + ${ARROW_FLIGHT_SQL_ODBC_STATIC_INSTALL_INTERFACE_LIBS} + SHARED_PRIVATE_LINK_LIBS + ${ARROW_FLIGHT_SQL_ODBC_SHARED_PRIVATE_LINK_LIBS}) + foreach(LIB_TARGET ${ARROW_FLIGHT_SQL_ODBC_LIBRARIES}) target_compile_definitions(${LIB_TARGET} PRIVATE ARROW_FLIGHT_SQL_ODBC_EXPORTING) endforeach() diff --git a/cpp/src/arrow/flight/sql/odbc/tests/CMakeLists.txt b/cpp/src/arrow/flight/sql/odbc/tests/CMakeLists.txt index 24b747e21e05..ceeaf064e2f2 100644 --- a/cpp/src/arrow/flight/sql/odbc/tests/CMakeLists.txt +++ b/cpp/src/arrow/flight/sql/odbc/tests/CMakeLists.txt @@ -53,31 +53,24 @@ set(ARROW_FLIGHT_SQL_ODBC_TEST_SRCS # On Windows, dynamic linking ODBC is supported, tests link libraries dynamically. # On unix systems, static linking ODBC is supported, thus tests link libraries statically. if(WIN32) - add_arrow_test(flight_sql_odbc_test - SOURCES - ${ARROW_FLIGHT_SQL_ODBC_TEST_SRCS} - ${ARROW_FLIGHT_SQL_MOCK_SERVER_SRCS} - DEFINITIONS - UNICODE - EXTRA_LINK_LIBS - ${ODBC_LIBRARIES} - ${ODBCINST} - ${SQLite3_LIBRARIES} - ${ARROW_FLIGHT_SQL_ODBC_TEST_LINK_LIBS}) -elseif(APPLE) - add_arrow_test(flight_sql_odbc_test - SOURCES - ${ARROW_FLIGHT_SQL_ODBC_TEST_SRCS} - ${ARROW_FLIGHT_SQL_MOCK_SERVER_SRCS} - DEFINITIONS - UNICODE - STATIC_LINK_LIBS - ${ODBC_LIBRARIES} - ${ODBCINST} - ${SQLite3_LIBRARIES} - ${ARROW_FLIGHT_SQL_ODBC_TEST_LINK_LIBS}) + set(ARROW_FLIGHT_SQL_ODBC_TEST_LINK_LIBS_TYPE EXTRA_LINK_LIBS) +else() + # Unix + set(ARROW_FLIGHT_SQL_ODBC_TEST_LINK_LIBS_TYPE STATIC_LINK_LIBS) endif() +add_arrow_test(flight_sql_odbc_test + SOURCES + ${ARROW_FLIGHT_SQL_ODBC_TEST_SRCS} + ${ARROW_FLIGHT_SQL_MOCK_SERVER_SRCS} + DEFINITIONS + UNICODE + ${ARROW_FLIGHT_SQL_ODBC_TEST_LINK_LIBS_TYPE} + ${ODBC_LIBRARIES} + ${ODBCINST} + ${SQLite3_LIBRARIES} + ${ARROW_FLIGHT_SQL_ODBC_TEST_LINK_LIBS}) + find_package(ODBC REQUIRED) target_link_libraries(arrow-flight-sql-odbc-test PRIVATE ODBC::ODBC) From 7f2cd00f0b12c62ad485a9cc890213e05ad9ab40 Mon Sep 17 00:00:00 2001 From: "Alina (Xi) Li" Date: Wed, 25 Feb 2026 14:33:59 -0800 Subject: [PATCH 6/7] Address kou's comments - Add archery check - Use `EXTRA_LINK_LIBS` and `STATIC_LINK_LIBS` separately in code --- .github/workflows/cpp_extra.yml | 18 ++++++++- .../flight/sql/odbc/tests/CMakeLists.txt | 39 ++++++++++++------- 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/.github/workflows/cpp_extra.yml b/.github/workflows/cpp_extra.yml index 66d1c4b52ebd..98ca4b317888 100644 --- a/.github/workflows/cpp_extra.yml +++ b/.github/workflows/cpp_extra.yml @@ -414,10 +414,24 @@ jobs: export ARROW_CMAKE_ARGS="-DODBC_INCLUDE_DIR=$ODBC_INCLUDE_DIR" export CXXFLAGS="$CXXFLAGS -I$ODBC_INCLUDE_DIR" ci/scripts/cpp_build.sh $(pwd) $(pwd)/build + - name: Setup Python + uses: actions/setup-python@v6 + with: + python-version: 3 + - name: Setup Archery + run: python3 -m pip install -e dev/archery - name: Check ODBC Dependency run: | - # ODBC dependency should not include Arrow or third party libraries - ! otool -L $(pwd)/build/cpp/debug/libarrow_flight_sql_odbc.dylib | grep -Ei 'arrow_flight_sql\.|arrow_flight\.|arrow_compute|boost|iodbc|grpc' + # ODBC dependency should not include other Arrow or third party libraries + archery linking check-dependencies \ + --allow CoreFoundation \ + --allow libSystem \ + --allow libarrow_flight_sql_odbc \ + --allow libc++ \ + --allow libiconv \ + --allow libresolv \ + --allow libz \ + "$(pwd)/build/cpp/debug/libarrow_flight_sql_odbc.dylib" - name: Register Flight SQL ODBC Driver run: | sudo cpp/src/arrow/flight/sql/odbc/install/mac/install_odbc.sh $(pwd)/build/cpp/debug/libarrow_flight_sql_odbc.dylib diff --git a/cpp/src/arrow/flight/sql/odbc/tests/CMakeLists.txt b/cpp/src/arrow/flight/sql/odbc/tests/CMakeLists.txt index ceeaf064e2f2..f9a90727e6b9 100644 --- a/cpp/src/arrow/flight/sql/odbc/tests/CMakeLists.txt +++ b/cpp/src/arrow/flight/sql/odbc/tests/CMakeLists.txt @@ -25,14 +25,6 @@ set(ARROW_FLIGHT_SQL_MOCK_SERVER_SRCS ../../example/sqlite_server.cc ../../example/sqlite_tables_schema_batch_reader.cc) -if(ARROW_TEST_LINKAGE STREQUAL "static") - set(ARROW_FLIGHT_SQL_ODBC_TEST_LINK_LIBS arrow_flight_sql_odbc_static - ${ARROW_TEST_STATIC_LINK_LIBS}) -else() - set(ARROW_FLIGHT_SQL_ODBC_TEST_LINK_LIBS arrow_flight_sql_odbc_shared - ${ARROW_TEST_SHARED_LINK_LIBS}) -endif() - set(ARROW_FLIGHT_SQL_ODBC_TEST_SRCS odbc_test_suite.cc odbc_test_suite.h @@ -50,13 +42,31 @@ set(ARROW_FLIGHT_SQL_ODBC_TEST_SRCS # GH-46889: move protobuf_test_util to a more common location ../../../../engine/substrait/protobuf_test_util.cc) +if(ARROW_TEST_LINKAGE STREQUAL "static") + set(ARROW_FLIGHT_SQL_ODBC_TEST_LINK_LIBS arrow_flight_sql_odbc_static + ${ARROW_TEST_LINK_LIBS}) +else() + set(ARROW_FLIGHT_SQL_ODBC_TEST_LINK_LIBS arrow_flight_sql_odbc_shared + ${ARROW_TEST_LINK_LIBS}) +endif() + +list(APPEND + ARROW_FLIGHT_SQL_ODBC_TEST_LINK_LIBS + ${ODBC_LIBRARIES} + ${ODBCINST} + ${SQLite3_LIBRARIES}) + # On Windows, dynamic linking ODBC is supported, tests link libraries dynamically. # On unix systems, static linking ODBC is supported, thus tests link libraries statically. +set(ARROW_FLIGHT_SQL_ODBC_TEST_EXTRA_LINK_LIBS "") +set(ARROW_FLIGHT_SQL_ODBC_TEST_STATIC_LINK_LIBS "") if(WIN32) - set(ARROW_FLIGHT_SQL_ODBC_TEST_LINK_LIBS_TYPE EXTRA_LINK_LIBS) + list(APPEND ARROW_FLIGHT_SQL_ODBC_TEST_EXTRA_LINK_LIBS + ${ARROW_FLIGHT_SQL_ODBC_TEST_LINK_LIBS}) else() # Unix - set(ARROW_FLIGHT_SQL_ODBC_TEST_LINK_LIBS_TYPE STATIC_LINK_LIBS) + list(APPEND ARROW_FLIGHT_SQL_ODBC_TEST_STATIC_LINK_LIBS + ${ARROW_FLIGHT_SQL_ODBC_TEST_LINK_LIBS}) endif() add_arrow_test(flight_sql_odbc_test @@ -65,11 +75,10 @@ add_arrow_test(flight_sql_odbc_test ${ARROW_FLIGHT_SQL_MOCK_SERVER_SRCS} DEFINITIONS UNICODE - ${ARROW_FLIGHT_SQL_ODBC_TEST_LINK_LIBS_TYPE} - ${ODBC_LIBRARIES} - ${ODBCINST} - ${SQLite3_LIBRARIES} - ${ARROW_FLIGHT_SQL_ODBC_TEST_LINK_LIBS}) + EXTRA_LINK_LIBS + ${ARROW_FLIGHT_SQL_ODBC_TEST_EXTRA_LINK_LIBS} + STATIC_LINK_LIBS + ${ARROW_FLIGHT_SQL_ODBC_TEST_STATIC_LINK_LIBS}) find_package(ODBC REQUIRED) target_link_libraries(arrow-flight-sql-odbc-test PRIVATE ODBC::ODBC) From ef4686d0365a17bc8bb22a4e1f431f1f3906ba82 Mon Sep 17 00:00:00 2001 From: "Alina (Xi) Li" Date: Tue, 3 Mar 2026 10:55:41 -0800 Subject: [PATCH 7/7] Resolve `Windows ODBC` test error - Add `arrow_odbc_spi_impl` linking back to odbc test to resolve test issues. - `ARROW_TEST_LINK_LIBS` contains more libraries than `ARROW_TEST_STATIC_LINK_LIBS`/`ARROW_TEST_SHARED_LINK_LIBS`, might have been causing linking issues. - Add `DEPENDENCIES ` variable back on Windows --- cpp/src/arrow/flight/sql/odbc/CMakeLists.txt | 4 ++++ .../arrow/flight/sql/odbc/tests/CMakeLists.txt | 17 +++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/cpp/src/arrow/flight/sql/odbc/CMakeLists.txt b/cpp/src/arrow/flight/sql/odbc/CMakeLists.txt index f11d0eac71e2..2560cdccd09e 100644 --- a/cpp/src/arrow/flight/sql/odbc/CMakeLists.txt +++ b/cpp/src/arrow/flight/sql/odbc/CMakeLists.txt @@ -59,10 +59,12 @@ endif() # On Windows, dynmaic build for ODBC is supported. # On unix systems, static build for ODBC is supported, all libraries are linked statically on unix. +set(ARROW_FLIGHT_SQL_ODBC_DEPENDENCIES "") set(ARROW_FLIGHT_SQL_ODBC_SHARED_INSTALL_INTERFACE_LIBS "") set(ARROW_FLIGHT_SQL_ODBC_STATIC_INSTALL_INTERFACE_LIBS "") set(ARROW_FLIGHT_SQL_ODBC_SHARED_PRIVATE_LINK_LIBS "") if(WIN32) + set(ARROW_FLIGHT_SQL_ODBC_DEPENDENCIES arrow_flight_sql) set(ARROW_FLIGHT_SQL_ODBC_SHARED_LINK_LIBS arrow_flight_sql_shared arrow_odbc_spi_impl) set(ARROW_FLIGHT_SQL_ODBC_STATIC_LINK_LIBS arrow_flight_sql_static) list(APPEND ARROW_FLIGHT_SQL_ODBC_SHARED_INSTALL_INTERFACE_LIBS @@ -87,6 +89,8 @@ add_arrow_lib(arrow_flight_sql_odbc ${ARROW_FLIGHT_SQL_ODBC_SRCS} DEFINITIONS UNICODE + DEPENDENCIES + ${ARROW_FLIGHT_SQL_ODBC_DEPENDENCIES} SHARED_LINK_FLAGS ${ARROW_VERSION_SCRIPT_FLAGS} # Defined in cpp/arrow/CMakeLists.txt SHARED_LINK_LIBS diff --git a/cpp/src/arrow/flight/sql/odbc/tests/CMakeLists.txt b/cpp/src/arrow/flight/sql/odbc/tests/CMakeLists.txt index f9a90727e6b9..7f9ab668a792 100644 --- a/cpp/src/arrow/flight/sql/odbc/tests/CMakeLists.txt +++ b/cpp/src/arrow/flight/sql/odbc/tests/CMakeLists.txt @@ -44,29 +44,26 @@ set(ARROW_FLIGHT_SQL_ODBC_TEST_SRCS if(ARROW_TEST_LINKAGE STREQUAL "static") set(ARROW_FLIGHT_SQL_ODBC_TEST_LINK_LIBS arrow_flight_sql_odbc_static - ${ARROW_TEST_LINK_LIBS}) + ${ARROW_TEST_STATIC_LINK_LIBS}) else() set(ARROW_FLIGHT_SQL_ODBC_TEST_LINK_LIBS arrow_flight_sql_odbc_shared - ${ARROW_TEST_LINK_LIBS}) + ${ARROW_TEST_SHARED_LINK_LIBS}) endif() -list(APPEND - ARROW_FLIGHT_SQL_ODBC_TEST_LINK_LIBS - ${ODBC_LIBRARIES} - ${ODBCINST} - ${SQLite3_LIBRARIES}) +set(ARROW_FLIGHT_SQL_ODBC_TEST_LIBS ${ODBC_LIBRARIES} ${ODBCINST} ${SQLite3_LIBRARIES}) # On Windows, dynamic linking ODBC is supported, tests link libraries dynamically. # On unix systems, static linking ODBC is supported, thus tests link libraries statically. set(ARROW_FLIGHT_SQL_ODBC_TEST_EXTRA_LINK_LIBS "") set(ARROW_FLIGHT_SQL_ODBC_TEST_STATIC_LINK_LIBS "") if(WIN32) - list(APPEND ARROW_FLIGHT_SQL_ODBC_TEST_EXTRA_LINK_LIBS - ${ARROW_FLIGHT_SQL_ODBC_TEST_LINK_LIBS}) + # arrow_odbc_spi_impl is required on Windows due to dynamic linking + list(APPEND ARROW_FLIGHT_SQL_ODBC_TEST_EXTRA_LINK_LIBS arrow_odbc_spi_impl + ${ARROW_FLIGHT_SQL_ODBC_TEST_LIBS}) else() # Unix list(APPEND ARROW_FLIGHT_SQL_ODBC_TEST_STATIC_LINK_LIBS - ${ARROW_FLIGHT_SQL_ODBC_TEST_LINK_LIBS}) + ${ARROW_FLIGHT_SQL_ODBC_TEST_LIBS} ${ARROW_FLIGHT_SQL_ODBC_TEST_LINK_LIBS}) endif() add_arrow_test(flight_sql_odbc_test