Skip to content

Commit 7b7f6ed

Browse files
committed
feat: add initial CI
1 parent 717bb01 commit 7b7f6ed

File tree

12 files changed

+122
-82
lines changed

12 files changed

+122
-82
lines changed

.github/workflows/build_test.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Ubuntu Build & Test
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
with:
16+
submodules: recursive
17+
- name: Setup Ubuntu
18+
run: ./scripts/setup-ubuntu.sh
19+
- run: mkdir build
20+
- name: Run cmake
21+
run: cmake -Bbuild -GNinja -DCMAKE_BUILD_TYPE=Debug
22+
- name: Build
23+
run: ninja -C build
24+
- name: Test
25+
run: ctest --test-dir build

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,12 @@
3131
*.out
3232
*.app
3333

34+
# IDE files
35+
*~
36+
.vscode/
37+
38+
# Common CMake Build directory
39+
build/
40+
41+
# Generated code
3442
src/proto/substrait

CMakeLists.txt

+11-3
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,21 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
1212
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
1313

1414
option(
15-
BUILD_TESTING
16-
"Enable substrait-cpp tests. This will enable all other build options automatically."
17-
ON)
15+
SUBSTRAIT_CPP_BUILD_TESTING
16+
"Enable substrait-cpp tests. This will enable all other build options automatically."
17+
ON)
1818

1919
find_package(Protobuf REQUIRED)
2020
include_directories(${PROTOBUF_INCLUDE_DIRS})
2121

2222
add_subdirectory(third_party)
2323
include_directories(include)
24+
25+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules")
26+
include(BuildUtils)
27+
28+
if(${SUBSTRAIT_CPP_BUILD_TESTING})
29+
enable_testing()
30+
endif()
31+
2432
add_subdirectory(substrait)

cmake_modules/BuildUtils.cmake

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
# This file contains various cmake helper functions that are used throughout the
4+
# project.
5+
6+
# Add a new test case, with or without an executable that should be built.
7+
#
8+
# TEST_NAME is the name of the test.
9+
#
10+
# SOURCES is the list of C++ source files to compile into the test executable.
11+
function(ADD_TEST_CASE TEST_NAME)
12+
set(multi_value_args SOURCES EXTRA_LINK_LIBS EXTRA_INCLUDES
13+
EXTRA_DEPENDENCIES)
14+
cmake_parse_arguments(ARG "${options}" "${one_value_args}"
15+
"${multi_value_args}" ${ARGN})
16+
if(ARG_UNPARSED_ARGUMENTS)
17+
message(
18+
SEND_ERROR "Error: unrecognized arguments: ${ARG_UNPARSED_ARGUMENTS}")
19+
endif()
20+
21+
if(ARG_SOURCES)
22+
set(SOURCES ${ARG_SOURCES})
23+
else()
24+
message(SEND_ERROR "Error: SOURCES is a required argument to add_test_case")
25+
endif()
26+
27+
add_executable(${TEST_NAME} ${SOURCES})
28+
set_target_properties(
29+
${TEST_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY
30+
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tests)
31+
32+
if(ARG_EXTRA_LINK_LIBS)
33+
target_link_libraries(${TEST_NAME} PRIVATE ${ARG_EXTRA_LINK_LIBS})
34+
endif()
35+
36+
if(ARG_EXTRA_INCLUDES)
37+
target_include_directories(${TEST_NAME} SYSTEM PUBLIC ${ARG_EXTRA_INCLUDES})
38+
endif()
39+
40+
if(ARG_EXTRA_DEPENDENCIES)
41+
add_dependencies(${TEST_NAME} ${ARG_EXTRA_DEPENDENCIES})
42+
endif()
43+
44+
add_test(NAME ${TEST_NAME} COMMAND $<TARGET_FILE:${TEST_NAME}>)
45+
endfunction()

include/substrait/function/Function.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
#pragma once
44

5-
#include "substrait/type/Type.h"
5+
#include <optional>
6+
67
#include "substrait/function/FunctionSignature.h"
8+
#include "substrait/type/Type.h"
79

810
namespace io::substrait {
911

scripts/setup-helper-functions.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ function cmake_install {
122122
"${INSTALL_PREFIX+-DCMAKE_PREFIX_PATH=}${INSTALL_PREFIX-}" \
123123
"${INSTALL_PREFIX+-DCMAKE_INSTALL_PREFIX=}${INSTALL_PREFIX-}" \
124124
-DCMAKE_CXX_FLAGS="$COMPILER_FLAGS" \
125-
-DBUILD_TESTING=OFF \
125+
-DSUBSTRAIT_CPP_BUILD_TESTING=OFF \
126126
"$@"
127127
ninja -C "${BINARY_DIR}" install
128128
}

scripts/setup-ubuntu.sh

+3-49
Original file line numberDiff line numberDiff line change
@@ -20,52 +20,6 @@ sudo --preserve-env apt install -y \
2020
ninja-build \
2121
checkinstall \
2222
git \
23-
wget
24-
25-
function run_and_time {
26-
time "$@"
27-
{ echo "+ Finished running $*"; } 2> /dev/null
28-
}
29-
30-
function prompt {
31-
(
32-
while true; do
33-
local input="${PROMPT_ALWAYS_RESPOND:-}"
34-
echo -n "$(tput bold)$* [Y, n]$(tput sgr0) "
35-
[[ -z "${input}" ]] && read input
36-
if [[ "${input}" == "Y" || "${input}" == "y" || "${input}" == "" ]]; then
37-
return 0
38-
elif [[ "${input}" == "N" || "${input}" == "n" ]]; then
39-
return 1
40-
fi
41-
done
42-
) 2> /dev/null
43-
}
44-
45-
function install_protobuf {
46-
wget https://github.com/protocolbuffers/protobuf/releases/download/v21.4/protobuf-all-21.4.tar.gz
47-
tar -xzf protobuf-all-21.4.tar.gz
48-
cd protobuf-21.4
49-
./configure --prefix=/usr
50-
make "-j$(nproc)"
51-
make install
52-
ldconfig
53-
}
54-
55-
function install_deps {
56-
run_and_time install_protobuf
57-
}
58-
59-
(return 2> /dev/null) && return # If script was sourced, don't run commands.
60-
61-
(
62-
if [[ $# -ne 0 ]]; then
63-
for cmd in "$@"; do
64-
run_and_time "${cmd}"
65-
done
66-
else
67-
install_deps
68-
fi
69-
)
70-
71-
echo "All deps installed! Now try \"make\""
23+
wget \
24+
libprotobuf-dev \
25+
libprotobuf23

substrait/CMakeLists.txt

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# SPDX-License-Identifier: Apache-2.0
22

3+
string(TOLOWER ${CMAKE_BUILD_TYPE} BUILD_SUBDIR_NAME)
4+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY
5+
"${CMAKE_CURRENT_BINARY_DIR}/../${BUILD_SUBDIR_NAME}/lib")
6+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
7+
"${CMAKE_CURRENT_BINARY_DIR}/../${BUILD_SUBDIR_NAME}/")
8+
set(ADDITIONAL_CLEAN_FILES
9+
"${CMAKE_ARCHIVE_OUTPUT_DIRECTORY};${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
10+
311
add_subdirectory(common)
412
add_subdirectory(type)
513
add_subdirectory(function)

substrait/function/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ target_link_libraries(
1212
substrait_type
1313
yaml-cpp)
1414

15-
if (${BUILD_TESTING})
15+
if (${SUBSTRAIT_CPP_BUILD_TESTING})
1616
add_subdirectory(tests)
1717
endif ()
+8-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
# SPDX-License-Identifier: Apache-2.0
22

3-
add_executable(
4-
substrait_function_test
5-
FunctionLookupTest.cpp)
6-
7-
add_test(
8-
substrait_function_test
9-
substrait_function_test)
10-
11-
target_link_libraries(
12-
substrait_function_test
13-
substrait_function
14-
gtest
15-
gtest_main)
3+
add_test_case(
4+
substrait_function_test
5+
SOURCES
6+
FunctionLookupTest.cpp
7+
EXTRA_LINK_LIBS
8+
substrait_function
9+
gtest
10+
gtest_main)

substrait/type/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ target_link_libraries(
99
substrait_type
1010
substrait_common)
1111

12-
if (${BUILD_TESTING})
12+
if (${SUBSTRAIT_CPP_BUILD_TESTING})
1313
add_subdirectory(tests)
1414
endif ()

substrait/type/tests/CMakeLists.txt

+8-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
# SPDX-License-Identifier: Apache-2.0
22

3-
add_executable(
4-
substrait_type_test
5-
TypeTest.cpp)
6-
7-
add_test(
8-
substrait_type_test
9-
substrait_type_test)
10-
11-
target_link_libraries(
12-
substrait_type_test
13-
substrait_type
14-
gtest
15-
gtest_main)
3+
add_test_case(
4+
substrait_type_test
5+
EXTRA_LINK_LIBS
6+
substrait_type
7+
gtest
8+
gtest_main
9+
SOURCES
10+
TypeTest.cpp)

0 commit comments

Comments
 (0)