Skip to content

Commit

Permalink
feat(c/driver): add support for CMake packages of Go based drivers (#…
Browse files Browse the repository at this point in the history
…2561)

Fixes #2506.
  • Loading branch information
kou authored Feb 26, 2025
1 parent 89c52bf commit add7d28
Show file tree
Hide file tree
Showing 12 changed files with 192 additions and 6 deletions.
12 changes: 7 additions & 5 deletions c/cmake_modules/BuildUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,13 @@ function(arrow_install_cmake_package PACKAGE_NAME EXPORT_NAME)
set(INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PACKAGE_NAME}")
install(FILES "${BUILT_CONFIG_CMAKE}" "${BUILT_CONFIG_VERSION_CMAKE}"
DESTINATION "${INSTALL_CMAKEDIR}")
set(TARGETS_CMAKE "${PACKAGE_NAME}Targets.cmake")
install(EXPORT ${EXPORT_NAME}
DESTINATION "${INSTALL_CMAKEDIR}"
NAMESPACE "${PACKAGE_NAME}::"
FILE "${TARGETS_CMAKE}")
if(EXPORT_NAME)
set(TARGETS_CMAKE "${PACKAGE_NAME}Targets.cmake")
install(EXPORT ${EXPORT_NAME}
DESTINATION "${INSTALL_CMAKEDIR}"
NAMESPACE "${PACKAGE_NAME}::"
FILE "${TARGETS_CMAKE}")
endif()
endfunction()

# \arg OUTPUTS list to append built targets to
Expand Down
51 changes: 51 additions & 0 deletions c/cmake_modules/GoUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,53 @@
find_program(GO_BIN "go" REQUIRED)
message(STATUS "Detecting Go executable: Found ${GO_BIN}")

set(ADBC_GO_PACKAGE_INIT
[=[
get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
if(_IMPORT_PREFIX STREQUAL "/")
set(_IMPORT_PREFIX "")
endif()

function(adbc_add_shared_library target_name base_name)
set(shared_base_name
"${CMAKE_SHARED_LIBRARY_PREFIX}${base_name}${CMAKE_SHARED_LIBRARY_SUFFIX}")
set(prefix "${_IMPORT_PREFIX}/${ADBC_INSTALL_LIBDIR}")
add_library(${target_name} SHARED IMPORTED)
if(WINDOWS)
set(import_base_name
"${CMAKE_IMPORT_LIBRARY_PREFIX}${base_name}${CMAKE_IMPORT_LIBRARY_SUFFIX}")
set_target_properties(${target_name}
PROPERTIES
IMPORTED_IMPLIB "${prefix}/${import_base_name}"
IMPORTED_LOCATION "${_IMPORT_PREFIX}/bin/${shared_base_name}")
else()
set_target_properties(${target_name}
PROPERTIES
IMPORTED_LOCATION "${prefix}/${shared_base_name}.${ADBC_FULL_SO_VERSION}"
IMPORTED_SONAME "${prefix}/${shared_base_name}.${ADBC_SO_VERSION}")
endif()
endfunction()

function(adbc_add_static_library target_name base_name)
set(static_base_name
"${CMAKE_STATIC_LIBRARY_PREFIX}${base_name}${CMAKE_STATIC_LIBRARY_SUFFIX}")
add_library(${target_name} STATIC IMPORTED)
if(WINDOWS)
set_target_properties(${target_name}
PROPERTIES
IMPORTED_LOCATION "${_IMPORT_PREFIX}/bin/${static_base_name}")
else()
set(prefix "${_IMPORT_PREFIX}/${ADBC_IMPORT_LIB_DIR}")
set_target_properties(${target_name}
PROPERTIES
IMPORTED_LOCATION "${prefix}/${static_base_name}")
endif()
endfunction()
]=])

function(add_go_lib GO_MOD_DIR GO_LIBNAME)
set(options)
set(one_value_args
Expand Down Expand Up @@ -245,6 +292,10 @@ function(add_go_lib GO_MOD_DIR GO_LIBNAME)
install(FILES "${LIBOUT_STATIC}" TYPE LIB)
endif()

if(ARG_CMAKE_PACKAGE_NAME)
arrow_install_cmake_package(${ARG_CMAKE_PACKAGE_NAME} "")
endif()

if(ARG_PKG_CONFIG_NAME)
arrow_add_pkg_config("${ARG_PKG_CONFIG_NAME}")
endif()
Expand Down
41 changes: 41 additions & 0 deletions c/driver/bigquery/AdbcDriverBigQueryConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# 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.

@PACKAGE_INIT@

set(ADBC_BUILD_SHARED @ADBC_BUILD_SHARED@)
set(ADBC_BUILD_STATIC @ADBC_BUILD_STATIC@)
set(ADBC_FULL_SO_VERSION "@ADBC_FULL_SO_VERSION@")
set(ADBC_INSTALL_LIBDIR "@CMAKE_INSTALL_LIBDIR@")
set(ADBC_SO_VERSION "@ADBC_SO_VERSION@")
set(ADBC_VERSION "@ADBC_VERSION@")

@ADBC_GO_PACKAGE_INIT@

if(ADBC_BUILD_SHARED)
adbc_add_shared_library(
AdbcDriverBigQuery::adbc_driver_bigquery_shared
adbc_driver_bigquery)
endif()

if(ADBC_BUILD_STATIC)
adbc_add_shared_library(
AdbcDriverBigQuery::adbc_driver_bigquery_static
adbc_driver_bigquery)
endif()

check_required_components(AdbcDriverBigQuery)
2 changes: 2 additions & 0 deletions c/driver/bigquery/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ add_go_lib("${REPOSITORY_ROOT}/go/adbc/pkg/bigquery/"
utils.c
BUILD_TAGS
driverlib
CMAKE_PACKAGE_NAME
AdbcDriverBigQuery
PKG_CONFIG_NAME
adbc-driver-bigquery
SHARED_LINK_FLAGS
Expand Down
2 changes: 1 addition & 1 deletion c/driver/bigquery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
under the License.
-->

# ADBC Snowflake Driver
# ADBC BigQuery Driver

This driver provides an interface to
[BigQuery](https://cloud.google.com/bigquery) using ADBC.
Expand Down
41 changes: 41 additions & 0 deletions c/driver/flightsql/AdbcDriverFlightSQLConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# 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.

@PACKAGE_INIT@

set(ADBC_BUILD_SHARED @ADBC_BUILD_SHARED@)
set(ADBC_BUILD_STATIC @ADBC_BUILD_STATIC@)
set(ADBC_FULL_SO_VERSION "@ADBC_FULL_SO_VERSION@")
set(ADBC_INSTALL_LIBDIR "@CMAKE_INSTALL_LIBDIR@")
set(ADBC_SO_VERSION "@ADBC_SO_VERSION@")
set(ADBC_VERSION "@ADBC_VERSION@")

@ADBC_GO_PACKAGE_INIT@

if(ADBC_BUILD_SHARED)
adbc_add_shared_library(
AdbcDriverFlightSQL::adbc_driver_flightsql_shared
adbc_driver_flightsql)
endif()

if(ADBC_BUILD_STATIC)
adbc_add_shared_library(
AdbcDriverFlightSQL::adbc_driver_flightsql_static
adbc_driver_flightsql)
endif()

check_required_components(AdbcDriverFlightSQL)
2 changes: 2 additions & 0 deletions c/driver/flightsql/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ add_go_lib("${REPOSITORY_ROOT}/go/adbc/pkg/flightsql/"
utils.c
BUILD_TAGS
driverlib
CMAKE_PACKAGE_NAME
AdbcDriverFlightSQL
PKG_CONFIG_NAME
adbc-driver-flightsql
SHARED_LINK_FLAGS
Expand Down
41 changes: 41 additions & 0 deletions c/driver/snowflake/AdbcDriverSnowflakeConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# 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.

@PACKAGE_INIT@

set(ADBC_BUILD_SHARED @ADBC_BUILD_SHARED@)
set(ADBC_BUILD_STATIC @ADBC_BUILD_STATIC@)
set(ADBC_FULL_SO_VERSION "@ADBC_FULL_SO_VERSION@")
set(ADBC_INSTALL_LIBDIR "@CMAKE_INSTALL_LIBDIR@")
set(ADBC_SO_VERSION "@ADBC_SO_VERSION@")
set(ADBC_VERSION "@ADBC_VERSION@")

@ADBC_GO_PACKAGE_INIT@

if(ADBC_BUILD_SHARED)
adbc_add_shared_library(
AdbcDriverSnowflake::adbc_driver_snowflake_shared
adbc_driver_snowflake)
endif()

if(ADBC_BUILD_STATIC)
adbc_add_shared_library(
AdbcDriverSnowflake::adbc_driver_snowflake_static
adbc_driver_snowflake)
endif()

check_required_components(AdbcDriverSnowflake)
2 changes: 2 additions & 0 deletions c/driver/snowflake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ add_go_lib("${REPOSITORY_ROOT}/go/adbc/pkg/snowflake/"
utils.c
BUILD_TAGS
driverlib
CMAKE_PACKAGE_NAME
AdbcDriverSnowflake
PKG_CONFIG_NAME
adbc-driver-snowflake
SHARED_LINK_FLAGS
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
usr/lib/*/cmake/AdbcDriverFlightSQL/
usr/lib/*/libadbc_driver_flightsql.a
usr/lib/*/libadbc_driver_flightsql.so
usr/lib/*/pkgconfig/adbc-driver-flightsql.pc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
usr/lib/*/cmake/AdbcDriverSnowflake/
usr/lib/*/libadbc_driver_snowflake.a
usr/lib/*/libadbc_driver_snowflake.so
usr/lib/*/pkgconfig/adbc-driver-snowflake.pc
2 changes: 2 additions & 0 deletions ci/linux-packages/yum/apache-arrow-adbc.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ Libraries and header files for ADBC Flight SQL driver.
%defattr(-,root,root,-)
%doc README.md
%license LICENSE.txt NOTICE.txt
%{_libdir}/cmake/AdbcDriverFlightSQL/
%{_libdir}/libadbc_driver_flightsql.a
%{_libdir}/libadbc_driver_flightsql.so
%{_libdir}/pkgconfig/adbc-driver-flightsql.pc
Expand Down Expand Up @@ -244,6 +245,7 @@ Libraries and header files for ADBC Snowflake driver
%defattr(-,root,root,-)
%doc README.md
%license LICENSE.txt NOTICE.txt
%{_libdir}/cmake/AdbcDriverSnowflake/
%{_libdir}/libadbc_driver_snowflake.a
%{_libdir}/libadbc_driver_snowflake.so
%{_libdir}/pkgconfig/adbc-driver-snowflake.pc
Expand Down

0 comments on commit add7d28

Please sign in to comment.