Skip to content

Commit 9ebd46d

Browse files
authored
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 a51dc39. 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 711b3e0. 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
1 parent a099ca6 commit 9ebd46d

16 files changed

Lines changed: 177 additions & 91 deletions

.github/workflows/cpp_extra.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,10 @@ jobs:
357357
ARROW_BUILD_TESTS: ON
358358
ARROW_FLIGHT_SQL_ODBC: ON
359359
ARROW_HOME: /tmp/local
360+
ARROW_DEPENDENCY_USE_SHARED: OFF
361+
ARROW_DEPENDENCY_SOURCE: BUNDLED
362+
ARROW_MIMALLOC: OFF
363+
CMAKE_CXX_STANDARD: "20"
360364
steps:
361365
- name: Checkout Arrow
362366
uses: actions/checkout@v6.0.1
@@ -366,6 +370,22 @@ jobs:
366370
- name: Install Dependencies
367371
run: |
368372
brew bundle --file=cpp/Brewfile
373+
374+
# We want to use bundled RE2 for static linking. If
375+
# Homebrew's RE2 is installed, its header file may be used.
376+
# We uninstall Homebrew's RE2 to ensure using bundled RE2.
377+
brew uninstall grpc || : # gRPC depends on RE2
378+
brew uninstall grpc@1.54 || : # gRPC 1.54 may be installed too
379+
brew uninstall re2
380+
381+
# We want to use bundled Protobuf for static linking. If
382+
# Homebrew's Protobuf is installed, its library file may be
383+
# used on test We uninstall Homebrew's Protobuf to ensure using
384+
# bundled Protobuf.
385+
brew uninstall protobuf
386+
387+
# We want to use bundled Boost for static linking.
388+
brew uninstall boost
369389
- name: Setup ccache
370390
run: |
371391
ci/scripts/ccache_setup.sh
@@ -395,6 +415,10 @@ jobs:
395415
export ARROW_CMAKE_ARGS="-DODBC_INCLUDE_DIR=$ODBC_INCLUDE_DIR"
396416
export CXXFLAGS="$CXXFLAGS -I$ODBC_INCLUDE_DIR"
397417
ci/scripts/cpp_build.sh $(pwd) $(pwd)/build
418+
- name: Register Flight SQL ODBC Driver
419+
run: |
420+
chmod +x cpp/src/arrow/flight/sql/odbc/install/mac/install_odbc.sh
421+
sudo cpp/src/arrow/flight/sql/odbc/install/mac/install_odbc.sh $(pwd)/build/cpp/debug/libarrow_flight_sql_odbc.dylib
398422
- name: Test
399423
shell: bash
400424
run: |
@@ -431,6 +455,7 @@ jobs:
431455
CMAKE_INSTALL_PREFIX: /usr
432456
VCPKG_BINARY_SOURCES: 'clear;nugettimeout,600;nuget,GitHub,readwrite'
433457
VCPKG_DEFAULT_TRIPLET: x64-windows
458+
CMAKE_CXX_STANDARD: "20"
434459
steps:
435460
- name: Disable Crash Dialogs
436461
run: |

ci/scripts/cpp_test.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ case "$(uname)" in
5959
;;
6060
Darwin)
6161
n_jobs=$(sysctl -n hw.ncpu)
62-
exclude_tests+=("arrow-flight-sql-odbc-test")
6362
# TODO: https://github.com/apache/arrow/issues/40410
6463
exclude_tests+=("arrow-s3fs-test")
6564
;;

cpp/cmake_modules/ThirdpartyToolchain.cmake

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,11 @@ function(build_boost)
11141114
else()
11151115
list(APPEND BOOST_EXCLUDE_LIBRARIES uuid)
11161116
endif()
1117+
if(ARROW_FLIGHT_SQL_ODBC)
1118+
list(APPEND BOOST_INCLUDE_LIBRARIES beast xpressive)
1119+
else()
1120+
list(APPEND BOOST_EXCLUDE_LIBRARIES beast xpressive)
1121+
endif()
11171122
set(BOOST_SKIP_INSTALL_RULES ON)
11181123
if(NOT ARROW_ENABLE_THREADING)
11191124
set(BOOST_UUID_LINK_LIBATOMIC OFF)
@@ -3023,8 +3028,8 @@ function(build_cares)
30233028
if(APPLE)
30243029
# libresolv must be linked from c-ares version 1.16.1
30253030
find_library(LIBRESOLV_LIBRARY NAMES resolv libresolv REQUIRED)
3026-
set_target_properties(c-ares::cares PROPERTIES INTERFACE_LINK_LIBRARIES
3027-
"${LIBRESOLV_LIBRARY}")
3031+
set_target_properties(c-ares PROPERTIES INTERFACE_LINK_LIBRARIES
3032+
"${LIBRESOLV_LIBRARY}")
30283033
endif()
30293034

30303035
set(ARROW_BUNDLED_STATIC_LIBS

cpp/src/arrow/flight/sql/odbc/CMakeLists.txt

Lines changed: 55 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
# GH-44792: Arrow will switch to C++ 20
2020
set(CMAKE_CXX_STANDARD 20)
2121

22+
if(APPLE)
23+
# CMAKE_FIND_LIBRARY_SUFFIXES.
24+
set(APPEND CMAKE_FIND_LIBRARY_SUFFIXES ".a")
25+
endif()
26+
2227
if(WIN32)
2328
if(MSVC_VERSION GREATER_EQUAL 1900)
2429
set(ODBCINST legacy_stdio_definitions odbccp32 shlwapi)
@@ -61,33 +66,56 @@ if(WIN32)
6166
list(APPEND ARROW_FLIGHT_SQL_ODBC_SRCS odbc.def install/versioninfo.rc)
6267
endif()
6368

64-
add_arrow_lib(arrow_flight_sql_odbc
65-
CMAKE_PACKAGE_NAME
66-
ArrowFlightSqlOdbc
67-
PKG_CONFIG_NAME
68-
arrow-flight-sql-odbc
69-
OUTPUTS
70-
ARROW_FLIGHT_SQL_ODBC_LIBRARIES
71-
SOURCES
72-
${ARROW_FLIGHT_SQL_ODBC_SRCS}
73-
DEPENDENCIES
74-
arrow_flight_sql
75-
DEFINITIONS
76-
UNICODE
77-
SHARED_LINK_FLAGS
78-
${ARROW_VERSION_SCRIPT_FLAGS} # Defined in cpp/arrow/CMakeLists.txt
79-
SHARED_LINK_LIBS
80-
arrow_flight_sql_shared
81-
SHARED_INSTALL_INTERFACE_LIBS
82-
ArrowFlight::arrow_flight_sql_shared
83-
STATIC_LINK_LIBS
84-
arrow_flight_sql_static
85-
STATIC_INSTALL_INTERFACE_LIBS
86-
ArrowFlight::arrow_flight_sql_static
87-
SHARED_PRIVATE_LINK_LIBS
88-
ODBC::ODBC
89-
${ODBCINST}
90-
arrow_odbc_spi_impl)
69+
# On Windows, dynmaic build for ODBC is supported.
70+
# On unix systems, static build for ODBC is supported, all libraries are linked statically on unix.
71+
if(WIN32)
72+
add_arrow_lib(arrow_flight_sql_odbc
73+
CMAKE_PACKAGE_NAME
74+
ArrowFlightSqlOdbc
75+
PKG_CONFIG_NAME
76+
arrow-flight-sql-odbc
77+
OUTPUTS
78+
ARROW_FLIGHT_SQL_ODBC_LIBRARIES
79+
SOURCES
80+
${ARROW_FLIGHT_SQL_ODBC_SRCS}
81+
DEFINITIONS
82+
UNICODE
83+
SHARED_LINK_FLAGS
84+
${ARROW_VERSION_SCRIPT_FLAGS} # Defined in cpp/arrow/CMakeLists.txt
85+
SHARED_LINK_LIBS
86+
arrow_flight_sql_shared
87+
arrow_odbc_spi_impl
88+
SHARED_INSTALL_INTERFACE_LIBS
89+
ArrowFlight::arrow_flight_sql_shared
90+
STATIC_LINK_LIBS
91+
arrow_flight_sql_static
92+
STATIC_INSTALL_INTERFACE_LIBS
93+
ArrowFlight::arrow_flight_sql_static
94+
SHARED_PRIVATE_LINK_LIBS
95+
ODBC::ODBC
96+
${ODBCINST})
97+
else()
98+
# Unix
99+
add_arrow_lib(arrow_flight_sql_odbc
100+
CMAKE_PACKAGE_NAME
101+
ArrowFlightSqlOdbc
102+
PKG_CONFIG_NAME
103+
arrow-flight-sql-odbc
104+
OUTPUTS
105+
ARROW_FLIGHT_SQL_ODBC_LIBRARIES
106+
SOURCES
107+
${ARROW_FLIGHT_SQL_ODBC_SRCS}
108+
DEFINITIONS
109+
UNICODE
110+
SHARED_LINK_FLAGS
111+
${ARROW_VERSION_SCRIPT_FLAGS} # Defined in cpp/arrow/CMakeLists.txt
112+
STATIC_LINK_LIBS
113+
iodbc
114+
ODBC::ODBC
115+
${ODBCINST}
116+
SHARED_LINK_LIBS
117+
arrow_odbc_spi_impl)
118+
endif()
91119

92120
foreach(LIB_TARGET ${ARROW_FLIGHT_SQL_ODBC_LIBRARIES})
93121
target_compile_definitions(${LIB_TARGET} PRIVATE ARROW_FLIGHT_SQL_ODBC_EXPORTING)

cpp/src/arrow/flight/sql/odbc/odbc_impl/CMakeLists.txt

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
add_library(arrow_odbc_spi_impl
18+
add_library(arrow_odbc_spi_impl STATIC
1919
accessors/binary_array_accessor.cc
2020
accessors/binary_array_accessor.h
2121
accessors/boolean_array_accessor.cc
@@ -133,8 +133,11 @@ endif()
133133
if(APPLE)
134134
target_include_directories(arrow_odbc_spi_impl SYSTEM BEFORE PUBLIC ${ODBC_INCLUDE_DIR})
135135
target_link_libraries(arrow_odbc_spi_impl
136-
PUBLIC arrow_flight_sql_shared arrow_compute_shared Boost::locale
137-
iodbc)
136+
PUBLIC arrow_flight_sql_static
137+
arrow_compute_static
138+
Boost::locale
139+
Boost::headers
140+
RapidJSON)
138141
else()
139142
find_package(ODBC REQUIRED)
140143
target_include_directories(arrow_odbc_spi_impl PUBLIC ${ODBC_INCLUDE_DIR})
@@ -143,14 +146,6 @@ else()
143146
${ODBCINST})
144147
endif()
145148

146-
set_target_properties(arrow_odbc_spi_impl
147-
PROPERTIES ARCHIVE_OUTPUT_DIRECTORY
148-
${CMAKE_BINARY_DIR}/$<CONFIG>/lib
149-
LIBRARY_OUTPUT_DIRECTORY
150-
${CMAKE_BINARY_DIR}/$<CONFIG>/lib
151-
RUNTIME_OUTPUT_DIRECTORY
152-
${CMAKE_BINARY_DIR}/$<CONFIG>/lib)
153-
154149
# CLI
155150
add_executable(arrow_odbc_spi_impl_cli main.cc)
156151
set_target_properties(arrow_odbc_spi_impl_cli
@@ -159,6 +154,16 @@ set_target_properties(arrow_odbc_spi_impl_cli
159154
target_link_libraries(arrow_odbc_spi_impl_cli arrow_odbc_spi_impl)
160155

161156
# Unit tests
157+
158+
# On Windows, dynamic linking ODBC is supported.
159+
# On unix systems, static linking ODBC is supported, thus the library linking is static.
160+
if(WIN32)
161+
set(ODBC_SPI_IMPL_TEST_LINK_LIBS arrow_flight_testing_shared)
162+
else()
163+
# unix
164+
set(ODBC_SPI_IMPL_TEST_LINK_LIBS arrow_flight_testing_static)
165+
endif()
166+
162167
add_arrow_test(odbc_spi_impl_test
163168
SOURCES
164169
accessors/boolean_array_accessor_test.cc
@@ -177,4 +182,4 @@ add_arrow_test(odbc_spi_impl_test
177182
util_test.cc
178183
EXTRA_LINK_LIBS
179184
arrow_odbc_spi_impl
180-
arrow_flight_testing_shared)
185+
${ODBC_SPI_IMPL_TEST_LINK_LIBS})

cpp/src/arrow/flight/sql/odbc/odbc_impl/config/connection_string_parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#include <string>
2121

22-
#include "config/configuration.h"
22+
#include "arrow/flight/sql/odbc/odbc_impl/config/configuration.h"
2323

2424
namespace arrow::flight::sql::odbc {
2525
namespace config {

cpp/src/arrow/flight/sql/odbc/odbc_impl/odbc_statement.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include <sql.h>
3131
#include <sqlext.h>
3232
#include <sqltypes.h>
33-
#include <boost/variant.hpp>
3433
#include <optional>
3534
#include <utility>
3635

cpp/src/arrow/flight/sql/odbc/odbc_impl/spi/connection.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#pragma once
1919

2020
#include <boost/algorithm/string.hpp>
21-
#include <boost/variant.hpp>
2221
#include <functional>
2322
#include <map>
2423
#include <optional>

cpp/src/arrow/flight/sql/odbc/odbc_impl/ui/add_property_window.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
#include "ui/add_property_window.h"
18+
#include "arrow/flight/sql/odbc/odbc_impl/ui/add_property_window.h"
1919

2020
#include <Windowsx.h>
2121

@@ -25,8 +25,8 @@
2525
#include <commctrl.h>
2626

2727
#include "arrow/flight/sql/odbc/odbc_impl/exceptions.h"
28-
#include "ui/custom_window.h"
29-
#include "ui/window.h"
28+
#include "arrow/flight/sql/odbc/odbc_impl/ui/custom_window.h"
29+
#include "arrow/flight/sql/odbc/odbc_impl/ui/window.h"
3030

3131
namespace arrow::flight::sql::odbc {
3232
namespace config {

cpp/src/arrow/flight/sql/odbc/odbc_impl/ui/custom_window.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include <sstream>
3030

3131
#include "arrow/flight/sql/odbc/odbc_impl/exceptions.h"
32-
#include "ui/custom_window.h"
32+
#include "arrow/flight/sql/odbc/odbc_impl/ui/custom_window.h"
3333

3434
namespace arrow::flight::sql::odbc {
3535
namespace config {

0 commit comments

Comments
 (0)