Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Separate implementation from interface for nanoarrow_testing component #561

Merged
merged 17 commits into from
Aug 2, 2024
Merged
41 changes: 35 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ option(NANOARROW_FLATCC_INCLUDE_DIR "Include directory for flatcc includes" OFF)
option(NANOARROW_FLATCC_LIB_DIR "Library directory that contains libflatccrt.a" OFF)

option(NANOARROW_DEVICE "Build device extension" OFF)
option(NANOARROW_TESTING "Build testng extension" OFF)

# Development options
option(NANOARROW_BUILD_APPS "Build utility applications" OFF)
Expand Down Expand Up @@ -86,7 +87,7 @@ if(NANOARROW_BUNDLE)
REQUIRED)

# Set up arguments to the bundler
set(NANOARROW_BUNDLE_ARGS "--with-ipc" "--with-device" "--with-flatcc")
set(NANOARROW_BUNDLE_ARGS "--with-ipc" "--with-device" "--with-testing" "--with-flatcc")

if(NANOARROW_BUNDLE_AS_CPP)
list(APPEND NANOARROW_BUNDLE_ARGS "--cpp")
Expand All @@ -108,6 +109,8 @@ if(NANOARROW_BUNDLE)
set(NANOARROW_BUILD_INCLUDE_DIR "${CMAKE_BINARY_DIR}/bundled/include")
set(NANOARROW_IPC_BUILD_SOURCES "${CMAKE_BINARY_DIR}/bundled/src/nanoarrow_ipc.c")
set(NANOARROW_DEVICE_BUILD_SOURCES "${CMAKE_BINARY_DIR}/bundled/src/nanoarrow_device.c")
set(NANOARROW_TESTING_BUILD_SOURCES
"${CMAKE_BINARY_DIR}/bundled/src/nanoarrow_testing.cc")
set(NANOARROW_FLATCC_BUILD_SOURCES "${CMAKE_BINARY_DIR}/bundled/src/flatcc.c")
else()
# Generate the version information
Expand Down Expand Up @@ -308,10 +311,32 @@ if(NANOARROW_DEVICE)
install(FILES src/nanoarrow/nanoarrow_device.h DESTINATION include/nanoarrow)
endif()

# Always build integration test if building tests
if(NANOARROW_BUILD_TESTS OR NANOARROW_BUILD_INTEGRATION_TESTS)
if(NANOARROW_TESTING
OR NANOARROW_BUILD_TESTS
OR NANOARROW_BUILD_INTEGRATION_TESTS)
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()

if(NOT NANOARROW_BUNDLE)
set(NANOARROW_TESTING_BUILD_SOURCES src/nanoarrow/testing/testing.cc)
endif()

add_subdirectory("thirdparty/nlohmann_json")

add_library(nanoarrow_testing src/nanoarrow/testing/testing.cc)
target_include_directories(nanoarrow_testing
PUBLIC $<BUILD_INTERFACE:${NANOARROW_BUILD_INCLUDE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src>
$<INSTALL_INTERFACE:include>)
target_link_libraries(nanoarrow_testing PRIVATE nlohmann_json::nlohmann_json)
target_link_libraries(nanoarrow_testing PUBLIC nanoarrow)
set_target_properties(nanoarrow_testing PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()

# Always build integration test if building tests
if(NANOARROW_BUILD_TESTS OR NANOARROW_BUILD_INTEGRATION_TESTS)
set_target_properties(nanoarrow PROPERTIES POSITION_INDEPENDENT_CODE ON)
add_library(nanoarrow_c_data_integration SHARED
src/nanoarrow/integration/c_data_integration.cc)
Expand All @@ -321,7 +346,7 @@ if(NANOARROW_BUILD_TESTS OR NANOARROW_BUILD_INTEGRATION_TESTS)
PUBLIC $<BUILD_INTERFACE:${NANOARROW_BUILD_INCLUDE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src>
$<INSTALL_INTERFACE:include>)
target_link_libraries(nanoarrow_c_data_integration PRIVATE nanoarrow nlohmann_json)
target_link_libraries(nanoarrow_c_data_integration PRIVATE nanoarrow nanoarrow_testing)
endif()

if(NANOARROW_BUILD_TESTS)
Expand Down Expand Up @@ -371,6 +396,7 @@ if(NANOARROW_BUILD_TESTS)

target_link_libraries(utils_test
nanoarrow
nanoarrow_testing
gtest_main
gmock_main
${NANOARROW_ARROW_TARGET}
Expand All @@ -388,7 +414,10 @@ if(NANOARROW_BUILD_TESTS)
gtest_main
gmock_main
nlohmann_json::nlohmann_json)
target_link_libraries(nanoarrow_testing_test nanoarrow gtest_main
target_link_libraries(nanoarrow_testing_test
nanoarrow
nanoarrow_testing
gtest_main
nlohmann_json::nlohmann_json)
target_link_libraries(c_data_integration_test nanoarrow nanoarrow_c_data_integration
gtest_main)
Expand Down Expand Up @@ -449,7 +478,7 @@ if(NANOARROW_BUILD_TESTS)
gtest_discover_tests(nanoarrow_ipc_${name}_test)
endforeach()

target_link_libraries(nanoarrow_ipc_files_test nlohmann_json ZLIB::ZLIB)
target_link_libraries(nanoarrow_ipc_files_test nanoarrow_testing ZLIB::ZLIB)
endif()

if(NANOARROW_DEVICE)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ python ci/scripts/bundle.py \
--header-namespace= \
--with-device \
--with-ipc \
--with-testing \
--with-flatcc
```

Expand Down
50 changes: 48 additions & 2 deletions ci/scripts/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ def bundle_nanoarrow(
# Generate files that don't need special handling
for filename in [
"nanoarrow.hpp",
"nanoarrow_testing.hpp",
"nanoarrow_gtest_util.hpp",
]:
content = read_content(src_dir / filename)
content = namespace_nanoarrow_includes(content, header_namespace)
Expand Down Expand Up @@ -214,6 +212,38 @@ def bundle_nanoarrow_ipc(
yield f"{output_source_dir}/nanoarrow_ipc.c", nanoarrow_ipc_c


def bundle_nanoarrow_testing(
root_dir,
header_namespace="nanoarrow/",
output_source_dir="src",
output_include_dir="include",
):
root_dir = pathlib.Path(root_dir)
src_dir = root_dir / "src" / "nanoarrow"

output_source_dir = pathlib.Path(output_source_dir)
output_include_dir = pathlib.Path(output_include_dir) / header_namespace

# Generate headers
for filename in [
"nanoarrow_testing.hpp",
"nanoarrow_gtest_util.hpp",
]:
content = read_content(src_dir / filename)
content = namespace_nanoarrow_includes(content, header_namespace)
yield f"{output_include_dir}/{filename}", content

nanoarrow_testing_cc = concatenate_content(
[
src_dir / "testing" / "testing.cc",
]
)
nanoarrow_testing_cc = namespace_nanoarrow_includes(
nanoarrow_testing_cc, header_namespace
)
yield f"{output_source_dir}/nanoarrow_testing.cc", nanoarrow_testing_cc


def bundle_flatcc(
root_dir,
output_source_dir="src",
Expand Down Expand Up @@ -310,6 +340,11 @@ def do_bundle(bundler):
help="Include nanoarrow_ipc sources/headers",
action="store_true",
)
parser.add_argument(
"--with-testing",
help="Include nanoarrow_testing sources/headers",
action="store_true",
)
parser.add_argument(
"--with-flatcc",
help="Include flatcc sources/headers",
Expand Down Expand Up @@ -358,6 +393,17 @@ def do_bundle(bundler):
)
)

# Bundle nanoarrow_testing
if args.with_testing:
do_bundle(
bundle_nanoarrow_testing(
root_dir,
header_namespace=args.header_namespace,
output_source_dir=args.source_output_dir,
output_include_dir=args.include_output_dir,
)
)

# Bundle flatcc
if args.with_flatcc:
do_bundle(
Expand Down
Loading
Loading