forked from lancedb/lancedb-c
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
674 lines (624 loc) · 22.8 KB
/
Copy pathCMakeLists.txt
File metadata and controls
674 lines (624 loc) · 22.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.25)
project(lancedb-c VERSION 0.21.2)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0")
if(CMAKE_CROSSCOMPILING AND NOT RUST_TARGET_TRIPLE)
# Map CMake compiler architecture and platform to the corresponding Rust target triple.
# Note: CMAKE_C_COMPILER_ARCHITECTURE_ID requires CMake 3.10+, with expanded support in 4.1+.
if(WIN32)
if(CMAKE_C_COMPILER_ARCHITECTURE_ID STREQUAL "x64" OR CMAKE_C_COMPILER_ARCHITECTURE_ID STREQUAL "x86_64")
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
set(RUST_TARGET_TRIPLE "x86_64-pc-windows-gnu")
elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
set(RUST_TARGET_TRIPLE "x86_64-pc-windows-gnullvm")
elseif(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
set(RUST_TARGET_TRIPLE "x86_64-pc-windows-msvc")
endif()
endif()
elseif(APPLE)
if(CMAKE_C_COMPILER_ARCHITECTURE_ID STREQUAL "x86_64")
set(RUST_TARGET_TRIPLE "x86_64-apple-darwin")
elseif(CMAKE_C_COMPILER_ARCHITECTURE_ID STREQUAL "arm64")
set(RUST_TARGET_TRIPLE "aarch64-apple-darwin")
endif()
elseif(LINUX)
if(CMAKE_C_COMPILER_ARCHITECTURE_ID STREQUAL "x86_64")
set(RUST_TARGET_TRIPLE "x86_64-unknown-linux-gnu")
elseif(CMAKE_C_COMPILER_ARCHITECTURE_ID STREQUAL "aarch64")
set(RUST_TARGET_TRIPLE "aarch64-unknown-linux-gnu")
endif()
endif()
if(RUST_TARGET_TRIPLE)
message(STATUS "Cross-compiling: Automatically detected Rust target triple.")
else()
message(FATAL_ERROR "Cross-compiling: Failed to detect Rust target triple. Please set RUST_TARGET_TRIPLE manually.")
endif()
endif()
set(RUST_TARGET_DIR target)
if(RUST_TARGET_TRIPLE)
set(RUST_TARGET_DIR "${RUST_TARGET_DIR}/${RUST_TARGET_TRIPLE}")
set(RUST_TARGET_OPT --target ${RUST_TARGET_TRIPLE})
else()
execute_process(
COMMAND rustc --print host-tuple
OUTPUT_VARIABLE RUST_TARGET_TRIPLE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(RUST_TARGET_DIR "${CMAKE_BINARY_DIR}/${RUST_TARGET_DIR}/debug")
set(RUST_BUILD_TYPE "")
else()
set(RUST_TARGET_DIR "${CMAKE_BINARY_DIR}/${RUST_TARGET_DIR}/release")
set(RUST_BUILD_TYPE "--release")
endif()
set(STATIC_LIB_PATH "${RUST_TARGET_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}lancedb${CMAKE_STATIC_LIBRARY_SUFFIX}")
if(WIN32)
set(SHARED_LIB_PATH "${RUST_TARGET_DIR}/lancedb${CMAKE_SHARED_LIBRARY_SUFFIX}")
set(IMPORT_LIB_PATH "${RUST_TARGET_DIR}/${CMAKE_IMPORT_LIBRARY_PREFIX}lancedb${CMAKE_IMPORT_LIBRARY_SUFFIX}")
set(LANCEDB_LIB_PATHS "${STATIC_LIB_PATH}" "${SHARED_LIB_PATH}" "${IMPORT_LIB_PATH}")
else()
set(SHARED_LIB_PATH "${RUST_TARGET_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}lancedb${CMAKE_SHARED_LIBRARY_SUFFIX}")
set(LANCEDB_LIB_PATHS "${STATIC_LIB_PATH}" "${SHARED_LIB_PATH}")
endif()
option(BUILD_EXAMPLES "Build examples" OFF)
option(BUILD_DOCS "Build documentation" OFF)
option(BUILD_TESTS "Build tests" OFF)
option(BUILD_COVERAGE "Enable Rust code coverage reporting (requires llvm-tools-preview)" OFF)
if(BUILD_COVERAGE)
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
message(WARNING "Code coverage results with an optimized build may be misleading. Consider using -DCMAKE_BUILD_TYPE=Debug")
endif()
# Find llvm-profdata and llvm-cov via rustc sysroot or system PATH
execute_process(COMMAND rustc --print sysroot OUTPUT_VARIABLE RUST_SYSROOT OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND rustc -vV OUTPUT_VARIABLE RUSTC_VERSION_INFO OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REGEX MATCH "host: ([a-zA-Z0-9_-]+)" _match "${RUSTC_VERSION_INFO}")
set(RUST_HOST_TRIPLE "${CMAKE_MATCH_1}")
find_program(_profdata llvm-profdata HINTS "${RUST_SYSROOT}/lib/rustlib/${RUST_HOST_TRIPLE}/bin" NO_DEFAULT_PATH)
find_program(_cov llvm-cov HINTS "${RUST_SYSROOT}/lib/rustlib/${RUST_HOST_TRIPLE}/bin" NO_DEFAULT_PATH)
if(_profdata AND _cov)
list(GET _profdata 0 LLVM_PROFDATA)
list(GET _cov 0 LLVM_COV)
else()
find_program(LLVM_PROFDATA llvm-profdata REQUIRED)
find_program(LLVM_COV llvm-cov REQUIRED)
endif()
endif()
find_package(Threads REQUIRED)
if (BUILD_EXAMPLES OR BUILD_TESTS)
find_package(Arrow REQUIRED)
foreach(_TARGET Arrow::arrow_shared arrow_shared Arrow::arrow_static arrow_static)
if(TARGET ${_TARGET})
set(ARROW_LIBRARIES ${_TARGET})
break()
endif()
endforeach()
if(NOT ARROW_LIBRARIES)
message(FATAL_ERROR "Arrow package found but no arrow_shared or arrow_static targets exist")
endif()
endif()
# rust-lib target
set(CARGO_BUILD_COMMAND cargo build ${RUST_BUILD_TYPE} ${RUST_TARGET_OPT} --target-dir "${CMAKE_BINARY_DIR}/target")
if(BUILD_COVERAGE)
set(PROFRAW_DIR "${CMAKE_BINARY_DIR}/profraw")
set(CARGO_BUILD_COMMAND ${CMAKE_COMMAND} -E env "RUSTFLAGS=-C instrument-coverage" "LLVM_PROFILE_FILE=${PROFRAW_DIR}/%p_%m.profraw" ${CARGO_BUILD_COMMAND})
endif()
add_custom_target(rust-lib ALL
COMMAND ${CARGO_BUILD_COMMAND}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Building Rust library..."
BYPRODUCTS ${LANCEDB_LIB_PATHS}
)
# lancedb target
add_library(lancedb SHARED IMPORTED)
set_target_properties(lancedb PROPERTIES
IMPORTED_LOCATION "${SHARED_LIB_PATH}"
IMPORTED_IMPLIB "${IMPORT_LIB_PATH}"
)
add_dependencies(lancedb rust-lib)
if(BUILD_EXAMPLES)
# simple example
add_executable(simple examples/simple.cpp)
target_link_libraries(simple
lancedb
Threads::Threads
${ARROW_LIBRARIES}
)
target_include_directories(simple
PRIVATE ${ARROW_INCLUDE_DIRS}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
)
target_compile_options(simple PRIVATE ${ARROW_CFLAGS_OTHER})
set_target_properties(simple PROPERTIES
BUILD_RPATH ${RUST_TARGET_DIR}
)
# full example
add_executable(full examples/full.cpp)
target_link_libraries(full
lancedb
Threads::Threads
${ARROW_LIBRARIES}
)
target_include_directories(full
PRIVATE ${ARROW_INCLUDE_DIRS}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
)
target_compile_options(full PRIVATE ${ARROW_CFLAGS_OTHER})
set_target_properties(full PROPERTIES
BUILD_RPATH ${RUST_TARGET_DIR}
)
# s3 storage example
add_executable(s3 examples/s3.cpp)
target_link_libraries(s3
lancedb
Threads::Threads
${ARROW_LIBRARIES}
)
target_include_directories(s3
PRIVATE ${ARROW_INCLUDE_DIRS}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
)
target_compile_options(s3 PRIVATE ${ARROW_CFLAGS_OTHER})
set_target_properties(s3 PROPERTIES
BUILD_RPATH ${RUST_TARGET_DIR}
)
add_custom_target(examples DEPENDS simple full s3)
endif()
if(BUILD_DOCS)
# Find Doxygen
find_package(Doxygen REQUIRED)
# Find Sphinx
find_program(SPHINX_EXECUTABLE
NAMES sphinx-build
DOC "Sphinx documentation generator"
)
if(NOT SPHINX_EXECUTABLE)
message(FATAL_ERROR "Sphinx not found. Install with: pip install sphinx sphinx-rtd-theme breathe")
endif()
# Doxygen target - generates XML from header files
set(DOXYGEN_INPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include/lancedb.h)
set(DOXYGEN_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/xml)
set(DOXYFILE_IN ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile)
set(DOXYFILE_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
# Configure Doxyfile to use build directory for output
configure_file(${DOXYFILE_IN} ${DOXYFILE_OUT} @ONLY)
add_custom_target(doxygen
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYFILE_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating Doxygen XML..."
VERBATIM
)
# Sphinx target - builds HTML documentation
set(SPHINX_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/docs)
set(SPHINX_BUILD ${CMAKE_CURRENT_BINARY_DIR}/docs/html)
add_custom_target(docs
COMMAND ${CMAKE_COMMAND} -E env DOXYGEN_XML_DIR=${DOXYGEN_OUTPUT_DIR}
${SPHINX_EXECUTABLE} -b html
-W --keep-going
${SPHINX_SOURCE} ${SPHINX_BUILD}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS doxygen
COMMENT "Building HTML documentation with Sphinx..."
VERBATIM
)
endif()
if(BUILD_TESTS)
# Find or fetch Catch2 v2
find_package(Catch2 2 QUIET)
if(NOT Catch2_FOUND)
message(STATUS "Catch2 not found, fetching from GitHub...")
include(FetchContent)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v2.13.10
)
FetchContent_MakeAvailable(Catch2)
endif()
set(TEST_TARGETS "")
# Add test executable for connection tests (runs with valgrind)
add_executable(lancedb_connection_tests
tests/test_main.cpp
tests/test_common.cpp
tests/test_connection.cpp
)
target_link_libraries(lancedb_connection_tests
PRIVATE
lancedb
Catch2::Catch2
Threads::Threads
${ARROW_LIBRARIES}
)
target_include_directories(lancedb_connection_tests
PRIVATE ${ARROW_INCLUDE_DIRS}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tests
)
target_compile_options(lancedb_connection_tests PRIVATE ${ARROW_CFLAGS_OTHER})
set_target_properties(lancedb_connection_tests PROPERTIES
BUILD_RPATH ${RUST_TARGET_DIR}
)
list(APPEND TEST_TARGETS lancedb_connection_tests)
# Add test executable for table tests (runs with valgrind)
add_executable(lancedb_table_tests
tests/test_main.cpp
tests/test_common.cpp
tests/test_table.cpp
)
target_link_libraries(lancedb_table_tests
PRIVATE
lancedb
Catch2::Catch2
Threads::Threads
${ARROW_LIBRARIES}
)
target_include_directories(lancedb_table_tests
PRIVATE ${ARROW_INCLUDE_DIRS}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tests
)
target_compile_options(lancedb_table_tests PRIVATE ${ARROW_CFLAGS_OTHER})
set_target_properties(lancedb_table_tests PROPERTIES
BUILD_RPATH ${RUST_TARGET_DIR}
)
list(APPEND TEST_TARGETS lancedb_table_tests)
# Add test executable for table metadata/version tests (runs with valgrind)
add_executable(lancedb_table_meta_tests
tests/test_main.cpp
tests/test_common.cpp
tests/test_table_meta.cpp
)
target_link_libraries(lancedb_table_meta_tests
PRIVATE
lancedb
Catch2::Catch2
Threads::Threads
${ARROW_LIBRARIES}
)
target_include_directories(lancedb_table_meta_tests
PRIVATE ${ARROW_INCLUDE_DIRS}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tests
)
target_compile_options(lancedb_table_meta_tests PRIVATE ${ARROW_CFLAGS_OTHER})
set_target_properties(lancedb_table_meta_tests PROPERTIES
BUILD_RPATH ${RUST_TARGET_DIR}
)
# Add test executable for scalar index tests (runs with valgrind)
add_executable(lancedb_index_tests
tests/test_main.cpp
tests/test_common.cpp
tests/test_index.cpp
)
target_link_libraries(lancedb_index_tests
PRIVATE
lancedb
Catch2::Catch2
Threads::Threads
${ARROW_LIBRARIES}
)
target_include_directories(lancedb_index_tests
PRIVATE ${ARROW_INCLUDE_DIRS}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tests
)
target_compile_options(lancedb_index_tests PRIVATE ${ARROW_CFLAGS_OTHER})
set_target_properties(lancedb_index_tests PROPERTIES
BUILD_RPATH ${RUST_TARGET_DIR}
)
list(APPEND TEST_TARGETS lancedb_index_tests)
# Add test executable for vector tests (runs without valgrind)
add_executable(lancedb_vector_index_tests
tests/test_main.cpp
tests/test_common.cpp
tests/test_vector_index.cpp
)
target_link_libraries(lancedb_vector_index_tests
PRIVATE
lancedb
Catch2::Catch2
Threads::Threads
${ARROW_LIBRARIES}
)
target_include_directories(lancedb_vector_index_tests
PRIVATE ${ARROW_INCLUDE_DIRS}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tests
)
target_compile_options(lancedb_vector_index_tests PRIVATE ${ARROW_CFLAGS_OTHER})
set_target_properties(lancedb_vector_index_tests PROPERTIES
BUILD_RPATH ${RUST_TARGET_DIR}
)
list(APPEND TEST_TARGETS lancedb_vector_index_tests)
# Add test executable for query tests (runs with valgrind)
add_executable(lancedb_query_tests
tests/test_main.cpp
tests/test_common.cpp
tests/test_query.cpp
)
target_link_libraries(lancedb_query_tests
PRIVATE
lancedb
Catch2::Catch2
Threads::Threads
${ARROW_LIBRARIES}
)
target_include_directories(lancedb_query_tests
PRIVATE ${ARROW_INCLUDE_DIRS}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tests
)
target_compile_options(lancedb_query_tests PRIVATE ${ARROW_CFLAGS_OTHER})
set_target_properties(lancedb_query_tests PROPERTIES
BUILD_RPATH ${RUST_TARGET_DIR}
)
list(APPEND TEST_TARGETS lancedb_query_tests)
# Add test executable for DataFusion expression query tests
add_executable(lancedb_df_query_tests
tests/test_main.cpp
tests/test_common.cpp
tests/test_df_query.cpp
)
target_link_libraries(lancedb_df_query_tests
PRIVATE
lancedb
Catch2::Catch2
Threads::Threads
${ARROW_LIBRARIES}
)
target_include_directories(lancedb_df_query_tests
PRIVATE ${ARROW_INCLUDE_DIRS}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tests
)
target_compile_options(lancedb_df_query_tests PRIVATE ${ARROW_CFLAGS_OTHER})
set_target_properties(lancedb_df_query_tests PROPERTIES
BUILD_RPATH ${RUST_TARGET_DIR}
)
list(APPEND TEST_TARGETS lancedb_df_query_tests)
# Add test executable for JSON expression tests
add_executable(lancedb_json_tests
tests/test_main.cpp
tests/test_json.cpp
)
target_link_libraries(lancedb_json_tests
PRIVATE
lancedb
Catch2::Catch2
Threads::Threads
${ARROW_LIBRARIES}
)
target_include_directories(lancedb_json_tests
PRIVATE ${ARROW_INCLUDE_DIRS}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tests
)
target_compile_options(lancedb_json_tests PRIVATE ${ARROW_CFLAGS_OTHER})
set_target_properties(lancedb_json_tests PROPERTIES
BUILD_RPATH ${RUST_TARGET_DIR}
)
list(APPEND TEST_TARGETS lancedb_json_tests)
# Add test executable for vector query tests (runs without valgrind)
add_executable(lancedb_vector_query_tests
tests/test_main.cpp
tests/test_common.cpp
tests/test_vector_query.cpp
)
target_link_libraries(lancedb_vector_query_tests
PRIVATE
lancedb
Catch2::Catch2
Threads::Threads
${ARROW_LIBRARIES}
)
target_include_directories(lancedb_vector_query_tests
PRIVATE ${ARROW_INCLUDE_DIRS}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tests
)
target_compile_options(lancedb_vector_query_tests PRIVATE ${ARROW_CFLAGS_OTHER})
set_target_properties(lancedb_vector_query_tests PROPERTIES
BUILD_RPATH ${RUST_TARGET_DIR}
)
list(APPEND TEST_TARGETS lancedb_vector_query_tests)
# Enable CTest
enable_testing()
# Set up coverage profraw output directory
if(BUILD_COVERAGE)
set(TEST_ENV_PREFIX ${CMAKE_COMMAND} -E env "LLVM_PROFILE_FILE=${PROFRAW_DIR}/%p_%m.profraw")
else()
set(TEST_ENV_PREFIX)
endif()
# Check if valgrind is available
find_program(VALGRIND_EXECUTABLE valgrind)
if(VALGRIND_EXECUTABLE)
message(STATUS "Valgrind found: ${VALGRIND_EXECUTABLE}")
# Run connection tests with valgrind
# Only fail on definite leaks, not "possibly lost" from Rust runtime
add_test(NAME lancedb_connection_tests
COMMAND ${TEST_ENV_PREFIX} ${VALGRIND_EXECUTABLE}
--tool=memcheck
--leak-check=full
--show-leak-kinds=definite
--errors-for-leak-kinds=definite
--track-origins=yes
--error-exitcode=1
--log-file=${CMAKE_BINARY_DIR}/valgrind_connection.txt
--suppressions=${CMAKE_CURRENT_SOURCE_DIR}/valgrind.supp
$<TARGET_FILE:lancedb_connection_tests>
)
# Run table tests with valgrind
add_test(NAME lancedb_table_tests
COMMAND ${TEST_ENV_PREFIX} ${VALGRIND_EXECUTABLE}
--tool=memcheck
--leak-check=full
--show-leak-kinds=definite
--errors-for-leak-kinds=definite
--track-origins=yes
--error-exitcode=1
--log-file=${CMAKE_BINARY_DIR}/valgrind_table.txt
--suppressions=${CMAKE_CURRENT_SOURCE_DIR}/valgrind.supp
$<TARGET_FILE:lancedb_table_tests>
)
# Run table metadata/version tests with valgrind
add_test(NAME lancedb_table_meta_tests
COMMAND ${TEST_ENV_PREFIX} ${VALGRIND_EXECUTABLE}
--tool=memcheck
--leak-check=full
--show-leak-kinds=definite
--errors-for-leak-kinds=definite
--track-origins=yes
--error-exitcode=1
--log-file=${CMAKE_BINARY_DIR}/valgrind_table_meta.txt
--suppressions=${CMAKE_CURRENT_SOURCE_DIR}/valgrind.supp
$<TARGET_FILE:lancedb_table_meta_tests>
)
# Run scalar index tests with valgrind
add_test(NAME lancedb_index_tests
COMMAND ${TEST_ENV_PREFIX} ${VALGRIND_EXECUTABLE}
--tool=memcheck
--leak-check=full
--show-leak-kinds=definite
--errors-for-leak-kinds=definite
--track-origins=yes
--error-exitcode=1
--log-file=${CMAKE_BINARY_DIR}/valgrind_index.txt
--suppressions=${CMAKE_CURRENT_SOURCE_DIR}/valgrind.supp
$<TARGET_FILE:lancedb_index_tests>
)
# Run query tests with valgrind
add_test(NAME lancedb_query_tests
COMMAND ${TEST_ENV_PREFIX} ${VALGRIND_EXECUTABLE}
--tool=memcheck
--leak-check=full
--show-leak-kinds=definite
--errors-for-leak-kinds=definite
--track-origins=yes
--error-exitcode=1
--log-file=${CMAKE_BINARY_DIR}/valgrind_query.txt
--suppressions=${CMAKE_CURRENT_SOURCE_DIR}/valgrind.supp
$<TARGET_FILE:lancedb_query_tests>
)
# Run DataFusion expression query tests with valgrind
add_test(NAME lancedb_df_query_tests
COMMAND ${TEST_ENV_PREFIX} ${VALGRIND_EXECUTABLE}
--tool=memcheck
--leak-check=full
--show-leak-kinds=definite
--errors-for-leak-kinds=definite
--track-origins=yes
--error-exitcode=1
--log-file=${CMAKE_BINARY_DIR}/valgrind_df_query.txt
--suppressions=${CMAKE_CURRENT_SOURCE_DIR}/valgrind.supp
$<TARGET_FILE:lancedb_df_query_tests>
)
# Run JSON expression tests with valgrind
add_test(NAME lancedb_json_tests
COMMAND ${TEST_ENV_PREFIX} ${VALGRIND_EXECUTABLE}
--tool=memcheck
--leak-check=full
--show-leak-kinds=definite
--errors-for-leak-kinds=definite
--track-origins=yes
--error-exitcode=1
--log-file=${CMAKE_BINARY_DIR}/valgrind_json.txt
--suppressions=${CMAKE_CURRENT_SOURCE_DIR}/valgrind.supp
$<TARGET_FILE:lancedb_json_tests>
)
else()
message(WARNING "Valgrind not found, running tests without memory checking")
add_test(NAME lancedb_connection_tests COMMAND ${TEST_ENV_PREFIX} $<TARGET_FILE:lancedb_connection_tests>)
add_test(NAME lancedb_table_tests COMMAND ${TEST_ENV_PREFIX} $<TARGET_FILE:lancedb_table_tests>)
add_test(NAME lancedb_table_meta_tests COMMAND ${TEST_ENV_PREFIX} $<TARGET_FILE:lancedb_table_meta_tests>)
add_test(NAME lancedb_index_tests COMMAND ${TEST_ENV_PREFIX} $<TARGET_FILE:lancedb_index_tests>)
add_test(NAME lancedb_query_tests COMMAND ${TEST_ENV_PREFIX} $<TARGET_FILE:lancedb_query_tests>)
add_test(NAME lancedb_df_query_tests COMMAND ${TEST_ENV_PREFIX} $<TARGET_FILE:lancedb_df_query_tests>)
add_test(NAME lancedb_json_tests COMMAND ${TEST_ENV_PREFIX} $<TARGET_FILE:lancedb_json_tests>)
endif()
# Run vector index tests WITHOUT valgrind (too slow under valgrind)
add_test(NAME lancedb_vector_index_tests COMMAND ${TEST_ENV_PREFIX} $<TARGET_FILE:lancedb_vector_index_tests>)
# Run vector query tests WITHOUT valgrind (too slow under valgrind)
add_test(NAME lancedb_vector_query_tests COMMAND ${TEST_ENV_PREFIX} $<TARGET_FILE:lancedb_vector_query_tests>)
if(BUILD_COVERAGE)
set(PROFDATA_FILE "${CMAKE_BINARY_DIR}/coverage.profdata")
set(COVERAGE_REPORT_DIR "${CMAKE_BINARY_DIR}/coverage-report")
add_custom_target(coverage
# Run tests via ctest with profiling output directed to profraw dir
COMMAND ${TEST_ENV_PREFIX}
${CMAKE_CTEST_COMMAND} --test-dir ${CMAKE_BINARY_DIR} -j
# Merge profiling data
COMMAND sh -c "${LLVM_PROFDATA} merge -sparse ${PROFRAW_DIR}/*.profraw -o ${PROFDATA_FILE}"
# Print coverage summary
COMMAND ${LLVM_COV} report ${SHARED_LIB_PATH}
--instr-profile=${PROFDATA_FILE}
${CMAKE_CURRENT_SOURCE_DIR}/src/
# Generate HTML report
COMMAND ${LLVM_COV} show ${SHARED_LIB_PATH}
--instr-profile=${PROFDATA_FILE}
${CMAKE_CURRENT_SOURCE_DIR}/src/
--format=html
--output-dir=${COVERAGE_REPORT_DIR}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
DEPENDS ${TEST_TARGETS}
COMMENT "Running tests and generating Rust code coverage report..."
)
endif()
endif()
add_custom_target(clean-all
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target clean
COMMAND cargo clean --target-dir "${CMAKE_BINARY_DIR}/target"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Cleaning all build artifacts..."
)
# Check target for code quality
add_custom_target(check
COMMAND cargo fmt --check
COMMAND cargo clippy
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Running Rust formatting and linting checks..."
)
# Install
if(WIN32)
install(FILES "${SHARED_LIB_PATH}" DESTINATION bin)
install(FILES "${STATIC_LIB_PATH}" "${IMPORT_LIB_PATH}" DESTINATION lib)
else()
install(FILES ${LANCEDB_LIB_PATHS} DESTINATION lib)
endif()
install(DIRECTORY include/ DESTINATION include)
message(STATUS "=== LanceDB C/C++ Bindings Configuration ===")
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "Rust target triple: ${RUST_TARGET_TRIPLE}")
message(STATUS "lancedb-c library paths: ${LANCEDB_LIB_PATHS}")
if (BUILD_EXAMPLES OR BUILD_TESTS)
message(STATUS "Arrow library: ${ARROW_LIBRARIES}")
endif()
if(BUILD_EXAMPLES)
message(STATUS "Examples: Enabled")
else()
message(STATUS "Examples: Disabled (use -DBUILD_EXAMPLES=ON to enable)")
endif()
if(BUILD_TESTS)
message(STATUS "Tests: Enabled")
else()
message(STATUS "Tests: Disabled (use -DBUILD_TESTS=ON to enable)")
endif()
if(BUILD_COVERAGE)
message(STATUS "Coverage: Enabled")
else()
message(STATUS "Coverage: Disabled (use -DBUILD_COVERAGE=ON to enable)")
endif()
if(BUILD_DOCS)
message(STATUS "Documentation: Enabled")
message(STATUS " - HTML output: ${SPHINX_BUILD}/index.html")
else()
message(STATUS "Documentation: Disabled (use -DBUILD_DOCS=ON to enable)")
endif()
message(STATUS "============================================")