Skip to content

Commit 19ff899

Browse files
lidavidmkou
andauthored
fix(c): enable linking to static builds (#2738)
- Correct a typo that was causing CMake to look for the shared library instead of the static library. - Fix CMake looking for the static library in the wrong place. - Test that linking against the static library works. - Test that linking with system-provided fmt/nanoarrow works. - Test that linking against multiple static drivers works. - Add headers to provide the entrypoint for static drivers. - Add build option to disable generation of shared Adbc* functions. - Respect this option from Go drivers too. - Namespace the functions inside adbc_driver_common (things like SetError appear to be leaking out) - Namespace the SQLite driver functions (e.g. StatementReaderUpcastInt64ToDouble) - Add static linking documentation. Fixes #2562. --------- Co-authored-by: Sutou Kouhei <kou@cozmixng.org>
1 parent 27c68c0 commit 19ff899

File tree

76 files changed

+1470
-535
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+1470
-535
lines changed

.github/workflows/nightly-verify.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,23 @@ jobs:
201201
pushd arrow-adbc
202202
docker compose run --rm cpp-gcc-latest
203203
204+
- name: cpp-shared-no-common-entrypoints-test
205+
run: |
206+
pushd arrow-adbc
207+
docker compose run --rm cpp-shared-no-common-entrypoints-test
208+
209+
- name: cpp-static-test
210+
run: |
211+
pushd arrow-adbc
212+
docker compose run --rm cpp-static-test
213+
204214
- name: python-debug
205215
run: |
216+
# Need to set this or ASAN inside the container gets stuck
217+
# printing a loop of DEADLYSIGNAL
218+
sudo sysctl vm.mmap_rnd_bits=28
206219
pushd arrow-adbc
207-
docker compose run -e PYTHON=3.12 --rm python-debug
220+
docker compose run -e PYTHON=3.13 --rm python-debug
208221
209222
source-verify-docker:
210223
name: "Verify Source (OS)/${{ matrix.os }} ${{ matrix.version }}"

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ repos:
114114
name: Ensure CGO adbc.h is syncd
115115
language: script
116116
pass_filenames: true
117-
files: '^c/include/arrow-adbc/.*\.h$'
117+
files: '^c/include/arrow-adbc/[^/]*\.h$'
118118
entry: "./ci/scripts/run_cgo_drivermgr_check.sh"
119119
# https://infra.apache.org/github-actions-policy.html
120120
- id: check-pin

c/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
2929

3030
include(CTest)
3131

32+
set(ADBC_TARGET_COMPILE_DEFINITIONS)
33+
if(NOT ADBC_DEFINE_COMMON_ENTRYPOINTS)
34+
message(STATUS "Defining ADBC_NO_COMMON_ENTRYPOINTS")
35+
set(ADBC_TARGET_COMPILE_DEFINITIONS "ADBC_NO_COMMON_ENTRYPOINTS")
36+
endif()
37+
3238
if(ADBC_WITH_VENDORED_FMT)
3339
add_subdirectory(vendor/fmt EXCLUDE_FROM_ALL)
3440
set_target_properties(fmt PROPERTIES POSITION_INDEPENDENT_CODE ON)
@@ -58,6 +64,8 @@ if(ADBC_INTEGRATION_DUCKDB)
5864
endif()
5965

6066
if(ADBC_DRIVER_FLIGHTSQL)
67+
install(FILES "${REPOSITORY_ROOT}/c/include/arrow-adbc/driver/flightsql.h"
68+
DESTINATION include/arrow-adbc/driver)
6169
add_subdirectory(driver/flightsql)
6270
endif()
6371

@@ -69,18 +77,26 @@ if(ADBC_DRIVER_MANAGER)
6977
endif()
7078

7179
if(ADBC_DRIVER_POSTGRESQL)
80+
install(FILES "${REPOSITORY_ROOT}/c/include/arrow-adbc/driver/postgresql.h"
81+
DESTINATION include/arrow-adbc/driver)
7282
add_subdirectory(driver/postgresql)
7383
endif()
7484

7585
if(ADBC_DRIVER_SQLITE)
86+
install(FILES "${REPOSITORY_ROOT}/c/include/arrow-adbc/driver/sqlite.h"
87+
DESTINATION include/arrow-adbc/driver)
7688
add_subdirectory(driver/sqlite)
7789
endif()
7890

7991
if(ADBC_DRIVER_SNOWFLAKE)
92+
install(FILES "${REPOSITORY_ROOT}/c/include/arrow-adbc/driver/snowflake.h"
93+
DESTINATION include/arrow-adbc/driver)
8094
add_subdirectory(driver/snowflake)
8195
endif()
8296

8397
if(ADBC_DRIVER_BIGQUERY)
98+
install(FILES "${REPOSITORY_ROOT}/c/include/arrow-adbc/driver/bigquery.h"
99+
DESTINATION include/arrow-adbc/driver)
84100
add_subdirectory(driver/bigquery)
85101
endif()
86102

c/cmake_modules/BuildUtils.cmake

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,6 @@ function(add_thirdparty_lib LIB_NAME LIB_TYPE LIB)
6767
endif()
6868
endfunction()
6969

70-
function(REUSE_PRECOMPILED_HEADER_LIB TARGET_NAME LIB_NAME)
71-
if(ADBC_USE_PRECOMPILED_HEADERS)
72-
target_precompile_headers(${TARGET_NAME} REUSE_FROM ${LIB_NAME})
73-
endif()
74-
endfunction()
75-
7670
function(arrow_install_cmake_package PACKAGE_NAME EXPORT_NAME)
7771
set(CONFIG_CMAKE "${PACKAGE_NAME}Config.cmake")
7872
set(BUILT_CONFIG_CMAKE "${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_CMAKE}")
@@ -102,11 +96,9 @@ function(ADD_ARROW_LIB LIB_NAME)
10296
BUILD_STATIC
10397
CMAKE_PACKAGE_NAME
10498
PKG_CONFIG_NAME
105-
SHARED_LINK_FLAGS
106-
PRECOMPILED_HEADER_LIB)
99+
SHARED_LINK_FLAGS)
107100
set(multi_value_args
108101
SOURCES
109-
PRECOMPILED_HEADERS
110102
OUTPUTS
111103
STATIC_LINK_LIBS
112104
SHARED_LINK_LIBS
@@ -172,12 +164,6 @@ function(ADD_ARROW_LIB LIB_NAME)
172164
if(ARG_DEPENDENCIES)
173165
add_dependencies(${LIB_NAME}_objlib ${ARG_DEPENDENCIES})
174166
endif()
175-
if(ARG_PRECOMPILED_HEADER_LIB)
176-
reuse_precompiled_header_lib(${LIB_NAME}_objlib ${ARG_PRECOMPILED_HEADER_LIB})
177-
endif()
178-
if(ARG_PRECOMPILED_HEADERS AND ADBC_USE_PRECOMPILED_HEADERS)
179-
target_precompile_headers(${LIB_NAME}_objlib PRIVATE ${ARG_PRECOMPILED_HEADERS})
180-
endif()
181167
set(LIB_DEPS $<TARGET_OBJECTS:${LIB_NAME}_objlib>)
182168
set(LIB_INCLUDES)
183169
set(EXTRA_DEPS)
@@ -220,10 +206,6 @@ function(ADD_ARROW_LIB LIB_NAME)
220206
add_dependencies(${LIB_NAME}_shared ${EXTRA_DEPS})
221207
endif()
222208

223-
if(ARG_PRECOMPILED_HEADER_LIB)
224-
reuse_precompiled_header_lib(${LIB_NAME}_shared ${ARG_PRECOMPILED_HEADER_LIB})
225-
endif()
226-
227209
if(ARG_OUTPUTS)
228210
list(APPEND ${ARG_OUTPUTS} ${LIB_NAME}_shared)
229211
endif()
@@ -318,10 +300,6 @@ function(ADD_ARROW_LIB LIB_NAME)
318300
add_dependencies(${LIB_NAME}_static ${EXTRA_DEPS})
319301
endif()
320302

321-
if(ARG_PRECOMPILED_HEADER_LIB)
322-
reuse_precompiled_header_lib(${LIB_NAME}_static ${ARG_PRECOMPILED_HEADER_LIB})
323-
endif()
324-
325303
if(ARG_OUTPUTS)
326304
list(APPEND ${ARG_OUTPUTS} ${LIB_NAME}_static)
327305
endif()
@@ -550,10 +528,8 @@ endfunction()
550528
# names must exist
551529
function(ADD_TEST_CASE REL_TEST_NAME)
552530
set(options NO_VALGRIND ENABLED)
553-
set(one_value_args PRECOMPILED_HEADER_LIB)
554531
set(multi_value_args
555532
SOURCES
556-
PRECOMPILED_HEADERS
557533
STATIC_LINK_LIBS
558534
EXTRA_LINK_LIBS
559535
EXTRA_INCLUDES
@@ -613,14 +589,6 @@ function(ADD_TEST_CASE REL_TEST_NAME)
613589
target_link_libraries(${TEST_NAME} PRIVATE ${ADBC_TEST_LINK_LIBS})
614590
endif()
615591

616-
if(ARG_PRECOMPILED_HEADER_LIB)
617-
reuse_precompiled_header_lib(${TEST_NAME} ${ARG_PRECOMPILED_HEADER_LIB})
618-
endif()
619-
620-
if(ARG_PRECOMPILED_HEADERS AND ADBC_USE_PRECOMPILED_HEADERS)
621-
target_precompile_headers(${TEST_NAME} PRIVATE ${ARG_PRECOMPILED_HEADERS})
622-
endif()
623-
624592
if(ARG_EXTRA_LINK_LIBS)
625593
target_link_libraries(${TEST_NAME} PRIVATE ${ARG_EXTRA_LINK_LIBS})
626594
endif()

c/cmake_modules/DefineOptions.cmake

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -98,34 +98,13 @@ if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
9898

9999
define_option(ADBC_BUILD_SHARED "Build shared libraries" ON)
100100

101-
define_option_string(ADBC_PACKAGE_KIND
102-
"Arbitrary string that identifies the kind of package;\
103-
(for informational purposes)" "")
104-
105101
define_option_string(ADBC_GIT_ID "The Arrow git commit id (if any)" "")
106102

107103
define_option_string(ADBC_GIT_DESCRIPTION "The Arrow git commit description (if any)"
108104
"")
109105

110-
define_option(ADBC_NO_DEPRECATED_API "Exclude deprecated APIs from build" OFF)
111-
112106
define_option(ADBC_USE_CCACHE "Use ccache when compiling (if available)" ON)
113107

114-
define_option(ADBC_USE_PRECOMPILED_HEADERS "Use precompiled headers when compiling" OFF)
115-
116-
# Arm64 architectures and extensions can lead to exploding combinations.
117-
# So set it directly through cmake command line.
118-
#
119-
# If you change this, you need to change the definition in
120-
# python/CMakeLists.txt too.
121-
define_option_string(ADBC_ARMV8_ARCH
122-
"Arm64 arch and extensions"
123-
"armv8-a" # Default
124-
"armv8-a"
125-
"armv8-a+crc+crypto")
126-
127-
define_option(ADBC_ALTIVEC "Build with Altivec if compiler has support" ON)
128-
129108
define_option(ADBC_RPATH_ORIGIN "Build Arrow libraries with RATH set to \$ORIGIN" OFF)
130109

131110
define_option(ADBC_INSTALL_NAME_RPATH
@@ -230,7 +209,11 @@ if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
230209
#----------------------------------------------------------------------
231210
set_option_category("Advanced developer")
232211

233-
option(ADBC_BUILD_CONFIG_SUMMARY_JSON "Summarize build configuration in a JSON file" ON)
212+
define_option(ADBC_BUILD_CONFIG_SUMMARY_JSON
213+
"Summarize build configuration in a JSON file" ON)
214+
215+
define_option(ADBC_DEFINE_COMMON_ENTRYPOINTS
216+
"Define the Adbc functions in static/shared driver libraries" ON)
234217

235218
#----------------------------------------------------------------------
236219
set_option_category("Project components")

c/cmake_modules/GoUtils.cmake

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function(adbc_add_static_library target_name base_name)
5757
PROPERTIES
5858
IMPORTED_LOCATION "${_IMPORT_PREFIX}/bin/${static_base_name}")
5959
else()
60-
set(prefix "${_IMPORT_PREFIX}/${ADBC_IMPORT_LIB_DIR}")
60+
set(prefix "${_IMPORT_PREFIX}/${ADBC_INSTALL_LIBDIR}")
6161
set_target_properties(${target_name}
6262
PROPERTIES
6363
IMPORTED_LOCATION "${prefix}/${static_base_name}")
@@ -74,7 +74,7 @@ function(add_go_lib GO_MOD_DIR GO_LIBNAME)
7474
PKG_CONFIG_NAME
7575
BUILD_STATIC
7676
BUILD_SHARED)
77-
set(multi_value_args SOURCES OUTPUTS)
77+
set(multi_value_args SOURCES DEFINES OUTPUTS)
7878

7979
cmake_parse_arguments(ARG
8080
"${options}"
@@ -135,10 +135,15 @@ function(add_go_lib GO_MOD_DIR GO_LIBNAME)
135135
"${GO_BUILD_FLAGS} $<$<CONFIG:DEBUG>:-gcflags=\"-N -l\">")
136136

137137
# if we're building debug mode then change the default CGO_CFLAGS and CGO_CXXFLAGS from "-g O2" to "-g3"
138-
set(GO_ENV_VARS
139-
"CGO_ENABLED=1 $<$<CONFIG:DEBUG>:CGO_CFLAGS=-g3> $<$<CONFIG:DEBUG>:CGO_CXXFLAGS=-g3>"
140-
)
141-
separate_arguments(GO_ENV_VARS NATIVE_COMMAND "${GO_ENV_VARS}")
138+
set(GO_FLAGS "$<$<CONFIG:Debug>:-g3>")
139+
foreach(DEFINE ${ARG_DEFINES})
140+
string(APPEND GO_FLAGS " -D${DEFINE}")
141+
endforeach()
142+
143+
set(GO_ENV_VARS)
144+
list(APPEND GO_ENV_VARS "CGO_ENABLED=1")
145+
list(APPEND GO_ENV_VARS "CGO_CFLAGS=${GO_FLAGS}")
146+
list(APPEND GO_ENV_VARS "CGO_CXXFLAGS=${GO_FLAGS}")
142147

143148
if(BUILD_SHARED)
144149
set(LIB_NAME_SHARED

c/driver/bigquery/AdbcDriverBigQueryConfig.cmake.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ if(ADBC_BUILD_SHARED)
3333
endif()
3434

3535
if(ADBC_BUILD_STATIC)
36-
adbc_add_shared_library(
36+
adbc_add_static_library(
3737
AdbcDriverBigQuery::adbc_driver_bigquery_static
3838
adbc_driver_bigquery)
3939
endif()

c/driver/bigquery/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ add_go_lib("${REPOSITORY_ROOT}/go/adbc/pkg/bigquery/"
3232
adbc-driver-bigquery
3333
SHARED_LINK_FLAGS
3434
${LDFLAGS}
35+
DEFINES
36+
${ADBC_TARGET_COMPILE_DEFINITIONS}
3537
OUTPUTS
3638
ADBC_LIBRARIES)
3739

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
@PACKAGE_INIT@
19+
20+
set(ADBC_VERSION "@ADBC_VERSION@")
21+
22+
include("${CMAKE_CURRENT_LIST_DIR}/AdbcDriverCommonTargets.cmake")
23+
24+
check_required_components(AdbcDriverCommon)

c/driver/common/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ set_target_properties(adbc_driver_common PROPERTIES POSITION_INDEPENDENT_CODE ON
2121
target_include_directories(adbc_driver_common PRIVATE "${REPOSITORY_ROOT}/c/include")
2222
target_link_libraries(adbc_driver_common PUBLIC nanoarrow::nanoarrow)
2323

24+
# For static builds, we need to install the static library here so downstream
25+
# applications can link to it
26+
if(ADBC_BUILD_STATIC)
27+
if(ADBC_WITH_VENDORED_NANOARROW)
28+
message(WARNING "adbc_driver_common is not installed when ADBC_WITH_VENDORED_NANOARROW is ON. To use the static libraries, for now you must provide nanoarrow instead of using the vendored copy"
29+
)
30+
else()
31+
install(TARGETS adbc_driver_common ${INSTALL_IS_OPTIONAL}
32+
EXPORT adbc_driver_common_targets
33+
RUNTIME DESTINATION ${RUNTIME_INSTALL_DIR}
34+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
35+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
36+
arrow_install_cmake_package(AdbcDriverCommon adbc_driver_common_targets)
37+
endif()
38+
endif()
39+
2440
if(ADBC_BUILD_TESTS)
2541
add_test_case(driver_common_test
2642
PREFIX

0 commit comments

Comments
 (0)