Skip to content

Commit 148dd20

Browse files
committed
fix(c): enable linking to static builds
Fixes #2562.
1 parent a353b96 commit 148dd20

13 files changed

Lines changed: 250 additions & 7 deletions

File tree

c/cmake_modules/GoUtils.cmake

Lines changed: 1 addition & 1 deletion
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}")

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/flightsql/AdbcDriverFlightSQLConfig.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
AdbcDriverFlightSQL::adbc_driver_flightsql_static
3838
adbc_driver_flightsql)
3939
endif()

c/driver/postgresql/AdbcDriverPostgreSQLConfig.cmake.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@
1717

1818
@PACKAGE_INIT@
1919

20+
include(CMakeFindDependencyMacro)
21+
2022
set(ADBC_VERSION "@ADBC_VERSION@")
2123

2224
include("${CMAKE_CURRENT_LIST_DIR}/AdbcDriverPostgreSQLTargets.cmake")
2325

26+
find_dependency(PostgreSQL)
27+
2428
check_required_components(AdbcDriverPostgreSQL)

c/driver/postgresql/copy/writer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,9 @@ class PostgresCopyListFieldWriter : public PostgresCopyFieldWriter {
498498
NANOARROW_RETURN_NOT_OK(WriteChecked<int32_t>(buffer, lb, error));
499499
}
500500

501-
ArrowBufferAppend(buffer, tmp->data, tmp->size_bytes);
501+
NANOARROW_RETURN_NOT_OK(ArrowBufferAppend(buffer, tmp->data, tmp->size_bytes));
502502

503-
return ADBC_STATUS_OK;
503+
return NANOARROW_OK;
504504
}
505505

506506
private:

c/driver/postgresql/postgres_type.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ class PostgresType {
349349
!typname_.empty() ? typname_.c_str() : PostgresTypname(type_id_);
350350
nanoarrow::UniqueBuffer buffer;
351351

352-
ArrowMetadataBuilderInit(buffer.get(), nullptr);
352+
NANOARROW_RETURN_NOT_OK(ArrowMetadataBuilderInit(buffer.get(), nullptr));
353353
// TODO(lidavidm): we have deprecated this in favor of arrow.opaque,
354354
// remove once we feel enough time has passed
355355
NANOARROW_RETURN_NOT_OK(ArrowMetadataBuilderAppend(

c/driver/snowflake/AdbcDriverSnowflakeConfig.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
AdbcDriverSnowflake::adbc_driver_snowflake_static
3838
adbc_driver_snowflake)
3939
endif()

c/driver/sqlite/AdbcDriverSQLiteConfig.cmake.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@
1717

1818
@PACKAGE_INIT@
1919

20+
include(CMakeFindDependencyMacro)
21+
2022
set(ADBC_VERSION "@ADBC_VERSION@")
2123

2224
include("${CMAKE_CURRENT_LIST_DIR}/AdbcDriverSQLiteTargets.cmake")
2325

26+
find_dependency(SQLite3)
27+
2428
check_required_components(AdbcDriverSQLite)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
cmake_minimum_required(VERSION 3.18)
19+
20+
project(adbc-static-test LANGUAGES C CXX)
21+
set(CMAKE_C_STANDARD 11)
22+
set(CMAKE_C_STANDARD_REQUIRED ON)
23+
24+
find_package(AdbcDriverBigQuery REQUIRED)
25+
find_package(AdbcDriverFlightSQL REQUIRED)
26+
find_package(AdbcDriverPostgreSQL REQUIRED)
27+
find_package(AdbcDriverSQLite REQUIRED)
28+
find_package(AdbcDriverSnowflake REQUIRED)
29+
30+
find_package(fmt REQUIRED)
31+
find_package(nanoarrow REQUIRED)
32+
33+
add_executable(static_test main.c)
34+
# We need to link the C++ standard library since some of the drivers are
35+
# written in C++.
36+
set_target_properties(static_test PROPERTIES LINKER_LANGUAGE CXX)
37+
target_link_libraries(static_test
38+
PRIVATE AdbcDriverBigQuery::adbc_driver_bigquery_static
39+
AdbcDriverFlightSQL::adbc_driver_flightsql_static
40+
AdbcDriverPostgreSQL::adbc_driver_postgresql_static
41+
AdbcDriverSQLite::adbc_driver_sqlite_static
42+
AdbcDriverSnowflake::adbc_driver_snowflake_static
43+
PostgreSQL::PostgreSQL
44+
SQLite::SQLite3
45+
fmt::fmt
46+
nanoarrow::nanoarrow)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!---
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
-->
19+
20+
# Static Linking Test
21+
22+
This is only used to test that static linking with multiple drivers behaves as
23+
expected. See the docker-compose job `cpp-static-test`.

0 commit comments

Comments
 (0)