Skip to content

Commit fa1a83b

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

8 files changed

Lines changed: 144 additions & 3 deletions

File tree

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/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()
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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)
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+
add_executable(static_test main.c)
31+
target_link_libraries(static_test
32+
PRIVATE
33+
AdbcDriverBigQuery::adbc_driver_bigquery_static
34+
AdbcDriverFlightSQL::adbc_driver_flightsql_static
35+
AdbcDriverPostgreSQL::adbc_driver_postgresql_static
36+
AdbcDriverSQLite::adbc_driver_sqlite_static
37+
AdbcDriverSnowflake::adbc_driver_snowflake_static
38+
)
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`.

c/integration/static_test/main.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
#include <stdlib.h>
19+
20+
int main(int argc, char** argv) {
21+
return EXIT_SUCCESS;
22+
}

ci/scripts/cpp_static_test.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env bash
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+
# Test building a simple application using the static drivers, ensuring that
20+
# symbols do not clash and all dependencies are present.
21+
# https://github.com/apache/arrow-adbc/issues/2562
22+
23+
set -euo pipefail
24+
25+
main() {
26+
local -r source_dir="${1}"
27+
local -r build_dir="${2}"
28+
local -r install_dir="${3}"
29+
30+
# No shared libraries should exist
31+
if find "${install_dir}" | grep -E "libadbc.*\.so"; then
32+
echo "Found ADBC shared libraries, which should not exist for this test"
33+
return 1
34+
fi
35+
36+
mkdir -p "${build_dir}"
37+
pushd "${build_dir}"
38+
cmake "${source_dir}/c/integration/static_test" \
39+
-DCMAKE_PREFIX_PATH="${install_dir}" \
40+
-DCMAKE_VERBOSE_MAKEFILE=ON
41+
cmake --build "${build_dir}" --target static_test
42+
43+
"${build_dir}/static_test"
44+
popd
45+
}
46+
47+
main "$@"

compose.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ services:
3434

3535
# Build/test with latest Clang
3636
cpp-clang-latest:
37+
image: ${REPO}:${ARCH}-cpp-clang-latest-adbc
3738
build:
3839
context: .
3940
dockerfile: ci/docker/cpp-clang-latest.dockerfile
@@ -44,6 +45,7 @@ services:
4445
command: "bash -c 'git config --global --add safe.directory /adbc && /adbc/ci/scripts/cpp_build.sh /adbc /adbc/build/clang-latest && env BUILD_ALL=0 BUILD_DRIVER_MANAGER=1 BUILD_DRIVER_SQLITE=1 /adbc/ci/scripts/cpp_test.sh /adbc/build/clang-latest'"
4546

4647
cpp-gcc-latest:
48+
image: ${REPO}:${ARCH}-cpp-gcc-latest-adbc
4749
build:
4850
context: .
4951
dockerfile: ci/docker/cpp-gcc-latest.dockerfile
@@ -54,6 +56,15 @@ services:
5456
- .:/adbc:delegated
5557
command: "bash -c 'git config --global --add safe.directory /adbc && /adbc/ci/scripts/cpp_build.sh /adbc /adbc/build/gcc-latest && env BUILD_ALL=0 BUILD_DRIVER_MANAGER=1 BUILD_DRIVER_SQLITE=1 /adbc/ci/scripts/cpp_test.sh /adbc/build/gcc-latest'"
5658

59+
# Test building and installing the static libraries, then try linking to them.
60+
cpp-static-test:
61+
image: ${REPO}:${ARCH}-cpp-clang-latest-adbc
62+
volumes:
63+
- .:/adbc:delegated
64+
# TODO: this should use system fmt, nanoarrow
65+
command: "bash -c 'git config --global --add safe.directory /adbc && env ADBC_BUILD_SHARED=OFF ADBC_BUILD_STATIC=ON ADBC_BUILD_TESTS=OFF ADBC_USE_ASAN=OFF ADBC_USE_UBSAN=OFF /adbc/ci/scripts/cpp_build.sh /adbc /adbc/build/static-deps /adbc/build/local && /adbc/ci/scripts/cpp_static_test.sh /adbc /adbc/build/static-test /adbc/build/local'"
66+
67+
5768
############################ Documentation ###################################
5869

5970
docs:

0 commit comments

Comments
 (0)