Skip to content

Commit 2930787

Browse files
authored
test: Make Arrow C++ dependency optional (#677)
1 parent 9945d33 commit 2930787

15 files changed

+331
-44
lines changed

.github/workflows/build-and-test-device.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ jobs:
9898
cd build
9999
export VERBOSE=1
100100
cmake .. -DCMAKE_BUILD_TYPE=Debug -DNANOARROW_DEVICE=ON \
101-
-DNANOARROW_BUILD_TESTS=ON -DCMAKE_PREFIX_PATH="${ARROW_PATH}" \
102-
${{ matrix.config.cmake_args }}
101+
-DNANOARROW_BUILD_TESTS=ON -DNANOARROW_BUILD_TESTS_WITH_ARROW=ON \
102+
-DCMAKE_PREFIX_PATH="${ARROW_PATH}" ${{ matrix.config.cmake_args }}
103103
104104
cmake --build .
105105

.github/workflows/build-and-test-ipc.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ jobs:
9191
cd build
9292
9393
cmake .. -DCMAKE_BUILD_TYPE=Debug -DNANOARROW_BUILD_TESTS=ON \
94-
-DNANOARROW_IPC=ON -DCMAKE_PREFIX_PATH="${ARROW_PATH}" \
95-
${{ matrix.config.cmake_args }}
94+
-DNANOARROW_BUILD_TESTS_WITH_ARROW=ON -DNANOARROW_IPC=ON \
95+
-DCMAKE_PREFIX_PATH="${ARROW_PATH}" ${{ matrix.config.cmake_args }}
9696
9797
cmake --build .
9898

.github/workflows/build-and-test.yaml

+20-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ jobs:
8282
cd build
8383
8484
cmake .. -DNANOARROW_BUILD_TESTS=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
85-
-DCMAKE_PREFIX_PATH="${ARROW_PATH}" ${{ matrix.config.cmake_args }}
85+
-DNANOARROW_BUILD_TESTS_WITH_ARROW=ON -DCMAKE_PREFIX_PATH="${ARROW_PATH}" \
86+
${{ matrix.config.cmake_args }}
8687
8788
cmake --build .
8889
@@ -158,3 +159,21 @@ jobs:
158159
- name: Run meson testing script
159160
run: |
160161
PKG_CONFIG_PATH="$(pwd)/arrow/lib/pkgconfig" ci/scripts/build-with-meson.sh
162+
163+
test-no-arrow:
164+
name: test-no-arrow
165+
runs-on: ubuntu-latest
166+
steps:
167+
- uses: actions/checkout@v4
168+
169+
- name: Build nanoarrow
170+
run: |
171+
cmake -S . -B build -DNANOARROW_BUILD_TESTS=ON -DNANOARROW_BUILD_TESTS_WITH_ARROW=OFF \
172+
-DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_PREFIX_PATH="${ARROW_PATH}"
173+
174+
cmake --build build
175+
176+
- name: Run tests
177+
run: |
178+
cd build
179+
ctest -T test --output-on-failure .

.github/workflows/clang-tidy.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ jobs:
6666
cd build
6767
6868
cmake .. -DNANOARROW_DEVICE=ON -DNANOARROW_IPC=ON \
69-
-DNANOARROW_BUILD_TESTS=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
70-
-DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
71-
-DCMAKE_PREFIX_PATH="${ARROW_PATH}"
69+
-DNANOARROW_BUILD_TESTS=ON -DNANOARROW_BUILD_TESTS_WITH_ARROW=ON \
70+
-DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_BUILD_TYPE=Debug \
71+
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_PREFIX_PATH="${ARROW_PATH}"
7272
7373
cmake --build .
7474

.github/workflows/verify.yaml

+10-2
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,21 @@ jobs:
101101
if: matrix.config.label == 'windows'
102102
shell: bash
103103
run: |
104-
echo "NANOARROW_CMAKE_OPTIONS=${NANOARROW_CMAKE_OPTIONS} -DNANOARROW_ARROW_STATIC=ON -DArrow_DIR=$(pwd -W)/arrow/lib/cmake/Arrow -Dgtest_force_shared_crt=ON" >> $GITHUB_ENV
104+
cat << EOF | tr '\n' ' ' >> $GITHUB_ENV
105+
NANOARROW_CMAKE_OPTIONS=${NANOARROW_CMAKE_OPTIONS}
106+
-DNANOARROW_ARROW_STATIC=ON
107+
-DNANOARROW_BUILD_TESTS_WITH_ARROW=ON
108+
-DArrow_DIR=$(pwd -W)/arrow/lib/cmake/Arrow
109+
-Dgtest_force_shared_crt=ON
105110
106111
- name: Set CMake options (POSIX)
107112
if: matrix.config.label != 'windows'
108113
shell: bash
109114
run: |
110-
echo "NANOARROW_CMAKE_OPTIONS=${NANOARROW_CMAKE_OPTIONS} -DArrow_DIR=$(pwd)/arrow/lib/cmake/Arrow" >> $GITHUB_ENV
115+
cat << EOF | tr '\n' ' ' >> $GITHUB_ENV
116+
NANOARROW_CMAKE_OPTIONS=${NANOARROW_CMAKE_OPTIONS}
117+
-DNANOARROW_BUILD_TESTS_WITH_ARROW=ON
118+
-DArrow_DIR=$(pwd)/arrow/lib/cmake/Arrow
111119
112120
- name: Run dev/release/verify-release-candidate.sh
113121
shell: bash

CMakeLists.txt

+61-17
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ option(NANOARROW_DEVICE_WITH_CUDA "Build CUDA libraries" OFF)
4545
# Development options
4646
option(NANOARROW_BUILD_APPS "Build utility applications" OFF)
4747
option(NANOARROW_BUILD_TESTS "Build tests" OFF)
48+
option(NANOARROW_BUILD_TESTS_WITH_ARROW "Build tests that require Arrow" OFF)
4849
option(NANOARROW_BUILD_BENCHMARKS "Build benchmarks" OFF)
4950
option(NANOARROW_BUILD_INTEGRATION_TESTS
5051
"Build cross-implementation Arrow integration tests" OFF)
@@ -422,26 +423,28 @@ if(NANOARROW_BUILD_TESTS)
422423
)
423424
include(CTest)
424425

425-
find_package(Arrow REQUIRED)
426-
message(STATUS "Arrow version: ${ARROW_VERSION}")
427-
message(STATUS "Arrow SO version: ${ARROW_FULL_SO_VERSION}")
426+
if(NANOARROW_BUILD_TESTS_WITH_ARROW)
427+
find_package(Arrow REQUIRED)
428+
message(STATUS "Arrow version: ${ARROW_VERSION}")
429+
message(STATUS "Arrow SO version: ${ARROW_FULL_SO_VERSION}")
428430

429-
# Give caller the option to link a static version of Arrow C++
430-
if(NANOARROW_ARROW_STATIC)
431-
set(NANOARROW_ARROW_TARGET arrow_static)
432-
else()
433-
set(NANOARROW_ARROW_TARGET arrow_shared)
434-
endif()
431+
# Give caller the option to link a static version of Arrow C++
432+
if(NANOARROW_ARROW_STATIC)
433+
set(NANOARROW_ARROW_TARGET arrow_static)
434+
else()
435+
set(NANOARROW_ARROW_TARGET arrow_shared)
436+
endif()
435437

436-
# Arrow >= 10.0.0 requires C++17; GTest requires C++11.
437-
# Leave the option open to use an older version of Arrow
438-
# to make it easier to test on old Linux (e.g., Centos7)
439-
if(${ARROW_VERSION} VERSION_GREATER_EQUAL "10.0.0")
440-
set(CMAKE_CXX_STANDARD 17)
441-
else()
442-
set(CMAKE_CXX_STANDARD 11)
438+
# Arrow >= 10.0.0 requires C++17; GTest requires C++11.
439+
# Leave the option open to use an older version of Arrow
440+
# to make it easier to test on old Linux (e.g., Centos7)
441+
if(${ARROW_VERSION} VERSION_GREATER_EQUAL "10.0.0")
442+
set(CMAKE_CXX_STANDARD 17)
443+
else()
444+
set(CMAKE_CXX_STANDARD 11)
445+
endif()
446+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
443447
endif()
444-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
445448

446449
add_subdirectory("thirdparty/googletest")
447450

@@ -517,6 +520,27 @@ if(NANOARROW_BUILD_TESTS)
517520
gmock_main
518521
nanoarrow_coverage_config)
519522

523+
list(APPEND
524+
NanoarrowTests
525+
utils_test
526+
buffer_test
527+
array_test
528+
schema_test
529+
array_stream_test
530+
nanoarrow_testing_test
531+
c_data_integration_test
532+
hpp_array_stream
533+
hpp_buffer
534+
hpp_exception
535+
hpp_unique
536+
hpp_view)
537+
if(Arrow_FOUND)
538+
foreach(test_target ${NanoarrowTests})
539+
target_compile_definitions(${test_target}
540+
PRIVATE -DNANOARROW_BUILD_TESTS_WITH_ARROW)
541+
endforeach()
542+
endif()
543+
520544
include(GoogleTest)
521545
# Some users have reported a timeout with the default value of 5
522546
# Building with -DBUILD_SHARED_LIBS=ON may also help reduce the size of test
@@ -569,6 +593,11 @@ if(NANOARROW_BUILD_TESTS)
569593
target_link_libraries(nanoarrow_ipc_${name}_test flatccrt)
570594
endif()
571595

596+
if(Arrow_FOUND)
597+
target_compile_definitions(nanoarrow_ipc_${name}_test
598+
PRIVATE -DNANOARROW_BUILD_TESTS_WITH_ARROW)
599+
endif()
600+
572601
gtest_discover_tests(nanoarrow_ipc_${name}_test)
573602
endforeach()
574603

@@ -593,6 +622,13 @@ if(NANOARROW_BUILD_TESTS)
593622
gtest_main
594623
nanoarrow_coverage_config)
595624

625+
if(Arrow_FOUND)
626+
target_compile_definitions(nanoarrow_device_test
627+
PRIVATE -DNANOARROW_BUILD_TESTS_WITH_ARROW)
628+
target_compile_definitions(nanoarrow_device_hpp_test
629+
PRIVATE -DNANOARROW_BUILD_TESTS_WITH_ARROW)
630+
endif()
631+
596632
include(GoogleTest)
597633
gtest_discover_tests(nanoarrow_device_test)
598634
gtest_discover_tests(nanoarrow_device_hpp_test)
@@ -604,6 +640,10 @@ if(NANOARROW_BUILD_TESTS)
604640
nanoarrow
605641
gtest_main
606642
nanoarrow_coverage_config)
643+
if(Arrow_FOUND)
644+
target_compile_definitions(nanoarrow_device_metal_test
645+
PRIVATE -DNANOARROW_BUILD_TESTS_WITH_ARROW)
646+
endif()
607647
gtest_discover_tests(nanoarrow_device_metal_test)
608648
endif()
609649

@@ -615,6 +655,10 @@ if(NANOARROW_BUILD_TESTS)
615655
CUDA::cuda_driver
616656
gtest_main
617657
nanoarrow_coverage_config)
658+
if(Arrow_FOUND)
659+
target_compile_definitions(nanoarrow_device_cuda_test
660+
PRIVATE -DNANOARROW_BUILD_TESTS_WITH_ARROW)
661+
endif()
618662
gtest_discover_tests(nanoarrow_device_cuda_test)
619663
endif()
620664
endif()

README.md

+13-6
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,23 @@ cmake ..
127127
cmake --build .
128128
```
129129

130-
Building nanoarrow with tests currently requires [Arrow C++](https://arrow.apache.org/install/).
131-
If installed via a system package manager like `apt`, `dnf`, or `brew`, the tests can be
132-
built with:
130+
To build nanoarrow along with tests run:
133131

134132
```sh
135133
mkdir build && cd build
136134
cmake .. -DNANOARROW_BUILD_TESTS=ON
137135
cmake --build .
138136
```
139137

138+
If you are able to install [Arrow C++](https://arrow.apache.org/install/) you can enable
139+
more testing:
140+
141+
```sh
142+
mkdir build && cd build
143+
cmake .. -DNANOARROW_BUILD_TESTS=ON -DNANOARROW_BUILD_TESTS_WITH_ARROW=ON
144+
cmake --build .
145+
```
146+
140147
Tests can be run with `ctest`.
141148

142149
### Building with Meson
@@ -155,9 +162,9 @@ After setting up your project, be sure to enable the options you want:
155162
meson configure -Dtests=true -Dbenchmarks=true
156163
```
157164

158-
If Arrow is installed in a non-standard location on your system, you may need to
159-
pass the `--pkg-config-path <path to directory with arrow.pc>` argument to either
160-
the setup or configure steps above.
165+
You can enable better test coverage if Apache Arrow is installed on your system
166+
with `-Dtest_with_arrow=true`. Depending on how you have installed Apache Arrow,
167+
you may also need to pass `--pkg-config-path <path to directory with arrow.pc>`.
161168

162169
With the above out of the way, the `compile` command should take care of the rest:
163170

ci/scripts/coverage.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ function main() {
7474

7575
cmake "${TARGET_NANOARROW_DIR}" \
7676
-DNANOARROW_DEVICE=ON -DNANOARROW_IPC=ON \
77-
-DNANOARROW_BUILD_TESTS=ON -DNANOARROW_CODE_COVERAGE=ON
77+
-DNANOARROW_BUILD_TESTS=ON -DNANOARROW_BUILD_TESTS_WITH_ARROW=ON \
78+
-DNANOARROW_CODE_COVERAGE=ON
7879
cmake --build .
7980
CTEST_OUTPUT_ON_FAILURE=1 ctest .
8081

meson.build

+10-2
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,16 @@ if get_option('tests')
208208
# Similarly code coverage has a built in option users should use instead
209209
# https://mesonbuild.com/Unit-tests.html#coverage
210210

211-
# The system include suppresses compilation warnings from Arrow
212-
arrow_dep = dependency('arrow', include_type: 'system')
211+
arrow_dep = dependency('arrow', include_type: 'system', required: false)
212+
if get_option('tests_with_arrow') and not arrow_dep.found()
213+
error('tests_with_arrow=true but could not find Arrow')
214+
endif
215+
216+
test_cpp_args = []
217+
if get_option('tests_with_arrow')
218+
test_cpp_args += ['-DNANOARROW_BUILD_TESTS_WITH_ARROW']
219+
endif
220+
213221
gtest_dep = dependency('gtest_main')
214222
gmock_dep = dependency('gmock')
215223

meson.options

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# under the License.
1717

1818
option('tests', type: 'boolean', description: 'Build tests', value: false)
19+
option('tests_with_arrow', type: 'boolean', description: 'Build tests with Arrow', value: false)
1920
option('benchmarks', type: 'boolean', description: 'Build benchmarks', value: false)
2021
option('apps', type: 'boolean', description: 'Build utility applications', value: false)
2122
option('ipc', type: 'boolean', description: 'Build IPC libraries', value: false)

0 commit comments

Comments
 (0)