Skip to content

Commit 04433e7

Browse files
authored
Add example (#31)
Add example
1 parent e36e33e commit 04433e7

File tree

13 files changed

+606
-49
lines changed

13 files changed

+606
-49
lines changed

.github/workflows/linux.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ jobs:
3636
-DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX \
3737
-DCMAKE_PREFIX_PATH=$CONDA_PREFIX \
3838
-DSPARROW_IPC_BUILD_SHARED=${{ matrix.build_shared }} \
39-
-DSPARROW_IPC_BUILD_TESTS=ON
39+
-DSPARROW_IPC_BUILD_TESTS=ON \
40+
-DSPARROW_IPC_BUILD_EXAMPLES=ON
4041
4142
- name: Build sparrow-ipc
4243
working-directory: build
@@ -50,6 +51,14 @@ jobs:
5051
working-directory: build
5152
run: cmake --build . --target run_tests_with_junit_report
5253

54+
- name: Build example
55+
working-directory: build
56+
run: cmake --build . --target write_and_read_streams
57+
58+
- name: Run example
59+
working-directory: build
60+
run: cmake --build . --target run_example
61+
5362
- name: Install
5463
working-directory: build
5564
run: cmake --install .
@@ -71,6 +80,7 @@ jobs:
7180
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
7281
-DSPARROW_IPC_BUILD_SHARED=${{ matrix.build_shared }} \
7382
-DSPARROW_IPC_BUILD_TESTS=ON \
83+
-DSPARROW_IPC_BUILD_EXAMPLES=ON \
7484
-DFETCH_DEPENDENCIES_WITH_CMAKE=MISSING
7585
7686
- name: Build sparrow-ipc
@@ -85,6 +95,14 @@ jobs:
8595
working-directory: build
8696
run: cmake --build . --target run_tests_with_junit_report
8797

98+
- name: Build example
99+
working-directory: build
100+
run: cmake --build . --target write_and_read_streams
101+
102+
- name: Run example
103+
working-directory: build
104+
run: cmake --build . --target run_example
105+
88106
- name: Install
89107
working-directory: build
90108
run: sudo cmake --install .

.github/workflows/osx.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ jobs:
4141
-DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX \
4242
-DCMAKE_PREFIX_PATH=$CONDA_PREFIX \
4343
-DSPARROW_IPC_BUILD_SHARED=${{ matrix.build_shared }} \
44-
-DSPARROW_IPC_BUILD_TESTS=ON
44+
-DSPARROW_IPC_BUILD_TESTS=ON \
45+
-DSPARROW_IPC_BUILD_EXAMPLES=ON
4546
4647
- name: Build sparrow-ipc
4748
working-directory: build
@@ -55,6 +56,14 @@ jobs:
5556
working-directory: build
5657
run: cmake --build . --target run_tests_with_junit_report
5758

59+
- name: Build example
60+
working-directory: build
61+
run: cmake --build . --target write_and_read_streams
62+
63+
- name: Run example
64+
working-directory: build
65+
run: cmake --build . --target run_example
66+
5867
- name: Install
5968
working-directory: build
6069
run: cmake --install .
@@ -81,6 +90,7 @@ jobs:
8190
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
8291
-DSPARROW_IPC_BUILD_SHARED=${{ matrix.build_shared }} \
8392
-DSPARROW_IPC_BUILD_TESTS=ON \
93+
-DSPARROW_IPC_BUILD_EXAMPLES=ON \
8494
-DFETCH_DEPENDENCIES_WITH_CMAKE=MISSING
8595
8696
- name: Build sparrow-ipc
@@ -95,6 +105,14 @@ jobs:
95105
working-directory: build
96106
run: cmake --build . --target run_tests_with_junit_report
97107

108+
- name: Build example
109+
working-directory: build
110+
run: cmake --build . --target write_and_read_streams
111+
112+
- name: Run example
113+
working-directory: build
114+
run: cmake --build . --target run_example
115+
98116
- name: Install
99117
working-directory: build
100118
run: sudo cmake --install .

.github/workflows/windows.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ jobs:
4040
-DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX \
4141
-DCMAKE_PREFIX_PATH=$GLOB_PREFIX_PATH \
4242
-DSPARROW_IPC_BUILD_SHARED=${{ matrix.build_shared }} \
43-
-DSPARROW_IPC_BUILD_TESTS=ON
43+
-DSPARROW_IPC_BUILD_TESTS=ON \
44+
-DSPARROW_IPC_BUILD_EXAMPLES=ON
4445
4546
- name: Build sparrow-ipc
4647
working-directory: build
@@ -55,6 +56,14 @@ jobs:
5556
run: |
5657
cmake --build . --config ${{ matrix.build_type }} --target run_tests_with_junit_report
5758
59+
- name: Build example
60+
working-directory: build
61+
run: cmake --build . --config ${{ matrix.build_type }} --target write_and_read_streams
62+
63+
- name: Run example
64+
working-directory: build
65+
run: cmake --build . --config ${{ matrix.build_type }} --target run_example
66+
5867
- name: Install
5968
working-directory: build
6069
run: cmake --install . --config ${{ matrix.build_type }}
@@ -80,6 +89,7 @@ jobs:
8089
cmake -S ./ -B ./build \
8190
-DSPARROW_IPC_BUILD_SHARED=${{ matrix.build_shared }} \
8291
-DSPARROW_IPC_BUILD_TESTS=ON \
92+
-DSPARROW_IPC_BUILD_EXAMPLES=ON \
8393
-DFETCH_DEPENDENCIES_WITH_CMAKE=MISSING \
8494
$TEST_COVERAGE_ACTIVATION
8595
@@ -95,6 +105,14 @@ jobs:
95105
working-directory: build
96106
run: cmake --build . --config ${{ matrix.build_type }} --target run_tests_with_junit_report
97107

108+
- name: Build example
109+
working-directory: build
110+
run: cmake --build . --config ${{ matrix.build_type }} --target write_and_read_streams
111+
112+
- name: Run example
113+
working-directory: build
114+
run: cmake --build . --config ${{ matrix.build_type }} --target run_example
115+
98116
- name: Install
99117
working-directory: build
100118
run: cmake --install . --config ${{ matrix.build_type }}

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ MESSAGE(STATUS "🔧 Build tests: ${SPARROW_IPC_BUILD_TESTS}")
8282
OPTION(SPARROW_IPC_BUILD_DOCS "Build sparrow-ipc documentation" OFF)
8383
MESSAGE(STATUS "🔧 Build docs: ${SPARROW_IPC_BUILD_DOCS}")
8484

85+
OPTION(SPARROW_IPC_BUILD_EXAMPLES "Build sparrow-ipc examples" OFF)
86+
MESSAGE(STATUS "🔧 Build examples: ${SPARROW_IPC_BUILD_EXAMPLES}")
87+
8588
# Code coverage
8689
# =============
8790
OPTION(SPARROW_IPC_ENABLE_COVERAGE "Enable sparrow-ipc test coverage" OFF)
@@ -270,6 +273,13 @@ if(SPARROW_IPC_BUILD_DOCS)
270273
add_subdirectory(docs)
271274
endif()
272275

276+
# Examples
277+
# ========
278+
if(SPARROW_IPC_BUILD_EXAMPLES)
279+
message(STATUS "🔨 Create examples targets")
280+
add_subdirectory(examples)
281+
endif()
282+
273283
# Installation
274284
# ============
275285
include(GNUInstallDirs)

cmake/external_dependencies.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ endif()
5252
find_package_or_fetch(
5353
PACKAGE_NAME sparrow
5454
GIT_REPOSITORY https://github.com/man-group/sparrow.git
55-
TAG 1.1.2
55+
TAG 1.2.0
5656
)
5757
unset(CREATE_JSON_READER_TARGET)
5858

@@ -111,7 +111,7 @@ if(SPARROW_IPC_BUILD_TESTS)
111111

112112
# Iterate over all the files in the arrow-testing-data source directiory. When it's a gz, extract in place.
113113
file(GLOB_RECURSE arrow_testing_data_targz_files CONFIGURE_DEPENDS
114-
"${arrow-testing_SOURCE_DIR}/data/arrow-ipc-stream/integration/1.0.0-littleendian/*.json.gz"
114+
"${arrow-testing_SOURCE_DIR}/data/arrow-ipc-stream/integration/cpp-21.0.0/*.json.gz"
115115
)
116116
foreach(file_path IN LISTS arrow_testing_data_targz_files)
117117
cmake_path(GET file_path PARENT_PATH parent_dir)

examples/CMakeLists.txt

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
cmake_minimum_required(VERSION 3.28)
2+
3+
# Create executable for the write_and_read_streams example
4+
add_executable(write_and_read_streams write_and_read_streams.cpp)
5+
6+
# Link against sparrow-ipc and its dependencies
7+
target_link_libraries(write_and_read_streams
8+
PRIVATE
9+
sparrow-ipc
10+
sparrow::sparrow
11+
arrow-testing-data
12+
)
13+
14+
# Set C++ standard to match the main project
15+
set_target_properties(write_and_read_streams
16+
PROPERTIES
17+
CXX_STANDARD 20
18+
CXX_STANDARD_REQUIRED ON
19+
CXX_EXTENSIONS OFF
20+
)
21+
22+
# Include directories for headers
23+
target_include_directories(write_and_read_streams
24+
PRIVATE
25+
${CMAKE_SOURCE_DIR}/include
26+
${CMAKE_BINARY_DIR}/generated
27+
)
28+
29+
# Ensure generated flatbuffer headers are available
30+
add_dependencies(write_and_read_streams generate_flatbuffers_headers)
31+
32+
# Optional: Copy to build directory for easy execution
33+
if(WIN32)
34+
# On Windows, copy required DLLs
35+
add_custom_command(
36+
TARGET write_and_read_streams POST_BUILD
37+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
38+
"$<TARGET_FILE:sparrow::sparrow>"
39+
"$<TARGET_FILE_DIR:write_and_read_streams>"
40+
COMMAND ${CMAKE_COMMAND} -E copy_if_different
41+
"$<TARGET_FILE:sparrow-ipc>"
42+
"$<TARGET_FILE_DIR:write_and_read_streams>"
43+
COMMENT "Copying sparrow and sparrow-ipc DLLs to example executable directory"
44+
)
45+
endif()
46+
47+
# Create a custom target to easily run the example
48+
add_custom_target(run_example
49+
COMMAND write_and_read_streams
50+
DEPENDS write_and_read_streams
51+
COMMENT "Running write_and_read_streams example"
52+
USES_TERMINAL
53+
)
54+
55+
set_target_properties(run_example PROPERTIES FOLDER "Examples")

0 commit comments

Comments
 (0)