Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 37 additions & 9 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ on:

jobs:
check:
runs-on: ubuntu-latest
# Pinned: clang-format-15 (used by setup-ubuntu.sh) is not available on
# ubuntu-latest (26.04).
runs-on: ubuntu-24.04

steps:
- uses: actions/checkout@v3
Expand All @@ -27,7 +29,7 @@ jobs:
run: git diff --exit-code

ubuntu-build-and-test:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -55,18 +57,44 @@ jobs:
- name: Configure CMake
run: |
cmake --version
cmake -B build -G Ninja \
-DCMAKE_BUILD_TYPE=Debug \
-DBUILD_TZ_LIB=ON \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
cmake --preset ci

- name: Build
run: cmake --build --preset ci

- name: Test
run: ctest --preset ci

fedora-build-and-test:
runs-on: ubuntu-latest
container: fedora:latest

steps:
- name: Install git (needed for submodule checkout)
run: dnf install -y git

- uses: actions/checkout@v4
with:
submodules: recursive

- name: Setup Fedora
run: ./scripts/setup-fedora.sh

- name: Set up ccache
uses: hendrikmuhs/ccache-action@1bbbcda0748b3e340dee71a314fa68ffcbd6df79 # v1.2.21
with:
key: fedora

- name: Configure CMake
run: |
cmake --build build
cmake --version
cmake --preset ci

- name: Build
run: cmake --build --preset ci

- name: Test
run: ctest --test-dir build --output-on-failure --timeout 30
run: ctest --preset ci

windows-build-and-test:
runs-on: windows-latest
Expand Down
57 changes: 53 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
cmake_minimum_required(VERSION 3.24)

# set the project name
project(substrait-cpp)
project(
substrait-cpp
VERSION 0.1.0
LANGUAGES C CXX)

include(GNUInstallDirs)

message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")

Expand Down Expand Up @@ -48,8 +53,12 @@ set(ANTLR4_TAG df4d68c09cdef73e023b8838a8bc7ca4dff1d1de)
include(ExternalAntlr4Cpp)
include_directories(${ANTLR4_INCLUDE_DIRS})
set(ANTLR_EXECUTABLE_DIR ${CMAKE_CURRENT_BINARY_DIR})
file(DOWNLOAD https://www.antlr.org/download/antlr-4.13.2-complete.jar
"${ANTLR_EXECUTABLE_DIR}/antlr.jar")
file(
DOWNLOAD https://www.antlr.org/download/antlr-4.13.2-complete.jar
"${ANTLR_EXECUTABLE_DIR}/antlr.jar"
EXPECTED_HASH
SHA256=eae2dfa119a64327444672aff63e9ec35a20180dc5b8090b7a6ab85125df4d76
TLS_VERIFY ON)
set(ANTLR_EXECUTABLE "${ANTLR_EXECUTABLE_DIR}/antlr.jar")

# Local files come first.
Expand All @@ -68,7 +77,47 @@ if(${SUBSTRAIT_CPP_BUILD_TESTING})
enable_testing()
endif()

install(EXPORT SubstraitTargets DESTINATION lib/cmake/Substrait)
# Install the exported targets together with a package configuration file, so
# that consumers can use `find_package(Substrait CONFIG REQUIRED)` and link
# against `Substrait::<target>`.
include(CMakePackageConfigHelpers)
set(SUBSTRAIT_CPP_CMAKE_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/Substrait)

install(
EXPORT SubstraitTargets
NAMESPACE Substrait::
DESTINATION ${SUBSTRAIT_CPP_CMAKE_INSTALL_DIR})

# The ANTLR4 runtime is built by ExternalProject and is not part of any export
# set; install it so that the exported static libraries can be linked.
get_filename_component(SUBSTRAIT_CPP_ANTLR4_LIBRARY_FILE
"${ANTLR4_STATIC_LIBRARIES}" NAME)
string(REPLACE "$(Configuration)" "$<CONFIG>" _SUBSTRAIT_ANTLR4_INSTALL_FILE
"${ANTLR4_STATIC_LIBRARIES}")
string(REPLACE "$(CONFIGURATION)" "$<CONFIG>" _SUBSTRAIT_ANTLR4_INSTALL_FILE
"${_SUBSTRAIT_ANTLR4_INSTALL_FILE}")
install(FILES ${_SUBSTRAIT_ANTLR4_INSTALL_FILE}
DESTINATION ${CMAKE_INSTALL_LIBDIR})

if(NOT SUBSTRAIT_CPP_PROTOBUF_BUILD_VERSION)
message(
FATAL_ERROR
"SUBSTRAIT_CPP_PROTOBUF_BUILD_VERSION is not defined after third_party setup."
)
endif()

configure_package_config_file(
cmake/SubstraitConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/SubstraitConfig.cmake"
INSTALL_DESTINATION ${SUBSTRAIT_CPP_CMAKE_INSTALL_DIR}
PATH_VARS CMAKE_INSTALL_LIBDIR)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/SubstraitConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/SubstraitConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/SubstraitConfigVersion.cmake"
DESTINATION ${SUBSTRAIT_CPP_CMAKE_INSTALL_DIR})

add_subdirectory(src/substrait)
add_subdirectory(export)
62 changes: 62 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"version": 5,
"cmakeMinimumRequired": { "major": 3, "minor": 24, "patch": 0 },
"configurePresets": [
{
"name": "base",
"hidden": true,
"generator": "Ninja",
"binaryDir": "${sourceDir}/build-${presetName}",
"cacheVariables": {
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
}
},
{
"name": "debug",
"displayName": "Debug",
"inherits": "base",
"cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" }
},
{
"name": "release",
"displayName": "Release",
"inherits": "base",
"cacheVariables": { "CMAKE_BUILD_TYPE": "Release" }
},
{
"name": "asan",
"displayName": "Debug with ASan/UBSan",
"inherits": "debug",
"cacheVariables": { "SUBSTRAIT_CPP_SANITIZE_DEBUG_BUILD": "ON" }
},
{
"name": "ci",
"displayName": "CI (Debug, ccache)",
"inherits": "debug",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"BUILD_TZ_LIB": "ON",
"CMAKE_C_COMPILER_LAUNCHER": "ccache",
"CMAKE_CXX_COMPILER_LAUNCHER": "ccache"
}
}
],
"buildPresets": [
{ "name": "debug", "configurePreset": "debug" },
{ "name": "release", "configurePreset": "release" },
{ "name": "asan", "configurePreset": "asan" },
{ "name": "ci", "configurePreset": "ci" }
],
"testPresets": [
{
"name": "default",
"hidden": true,
"output": { "outputOnFailure": true },
"execution": { "timeout": 30 }
},
{ "name": "debug", "inherits": "default", "configurePreset": "debug" },
{ "name": "release", "inherits": "default", "configurePreset": "release" },
{ "name": "asan", "inherits": "default", "configurePreset": "asan" },
{ "name": "ci", "inherits": "default", "configurePreset": "ci" }
]
}
27 changes: 5 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,36 +1,19 @@
# SPDX-License-Identifier: Apache-2.0

.PHONY: all clean build debug release
# Build configurations live in CMakePresets.json.

BUILD_TYPE := Release
.PHONY: all clean debug release asan format

all: debug

clean:
@rm -rf build-*

build-common:
@mkdir -p build-${BUILD_TYPE}
@cd build-${BUILD_TYPE} && \
cmake -Wno-dev \
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
-DPREFER_STATIC_LIBS=OFF \
$(FORCE_COLOR) \
..

build:
VERBOSE=1 cmake --build build-${BUILD_TYPE} -j $${CPU_COUNT:-`nproc`} || \
cmake --build build-${BUILD_TYPE}
debug release asan:
cmake --preset $@ -Wno-dev $(FORCE_COLOR)
cmake --build --preset $@ -j $${CPU_COUNT:-`nproc`}

format:
set -f
bash scripts/run-cmake-format.sh && bash scripts/run-clang-format.sh
set +f

debug:
@$(MAKE) build-common BUILD_TYPE=Debug
@$(MAKE) build BUILD_TYPE=Debug

release:
@$(MAKE) build-common BUILD_TYPE=Release
@$(MAKE) build BUILD_TYPE=Release
74 changes: 71 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,83 @@ git submodule sync --recursive
git submodule update --init --recursive
```

### Setting up on Linux (Ubuntu 20.04 or later)
### Setting up on Linux

Once you have checked out substrait-cpp, you can set up and build like so:
Once you have checked out substrait-cpp, install the build tools and build.
Run the setup script from the repository root. It installs system packages, so
it needs `sudo` (you will be prompted for your password unless you are root).
Comment thread
mbwhite marked this conversation as resolved.
Resolved

| Distribution | Setup script | Package manager |
|---|---|---|
| Ubuntu (24.04 or later) | `./scripts/setup-ubuntu.sh` | `apt` |
| Fedora | `./scripts/setup-fedora.sh` | `dnf` |

> **Note**: Building substrait-cpp requires CMake 3.24 or newer. Ubuntu 24.04 supplies CMake 3.28; if using older Ubuntu releases (e.g. 22.04), install CMake >= 3.24 (e.g. via the Kitware APT repository or `pip`).

What the scripts install: a C++ compiler, CMake, Ninja, ccache, git, `tzdata`,
libuuid and libcurl development headers, a Java runtime (needed at build time by
ANTLR), `clang-format`/`clang-tidy` and `cmake-format`. The Fedora script also
installs GoogleTest from the distribution.

`make format` uses `clang-format-15` to match CI. Fedora does not package that
version under this name, so install it yourself and point the script at it,
e.g. `CLANG_FORMAT=/path/to/clang-format make format`.

Ubuntu:

```shell
$ ./scripts/setup-ubuntu.sh
$ ./scripts/setup-ubuntu.sh
$ make
```

Fedora:

```shell
$ ./scripts/setup-fedora.sh
$ make
```

`make` builds the `debug` configuration. `make release` and `make asan` build
the other configurations. Builds use [CMake presets](CMakePresets.json)
(`debug`, `release`, `asan`, and `ci`, which also uses ccache):

```shell
$ cmake --preset debug
$ cmake --build --preset debug
$ ctest --preset debug
```

The first build takes several minutes because Protobuf and Abseil are
downloaded and compiled. If the system Protobuf is older than
`SUBSTRAIT_CPP_PROTOBUF_MIN_VERSION` (5.28), a suitable version is fetched
automatically. The Fedora script does not install Protobuf; the Ubuntu script
only installs a `protoc` binary into `~/.local`.

Other dnf-based distributions can usually use the Fedora script. Without root
access, run the script inside a container (for example `fedora:latest` or
`ubuntu:24.04`) with the repository copied in.

### Using substrait-cpp from another CMake project

Install it, then find it with `find_package`:

```shell
$ cmake --install build-debug --prefix /path/to/prefix
```

```cmake
find_package(Substrait 0.1 CONFIG REQUIRED)
target_link_libraries(my_app PRIVATE Substrait::substrait_io)
```

Configure your project with `-DCMAKE_PREFIX_PATH=/path/to/prefix`. The install
includes Protobuf, Abseil, fmt, yaml-cpp, date and the ANTLR4 runtime, which the
package config locates for you. The library directory is `lib64` on Fedora and
`lib` on Ubuntu.

The ANTLR parser jar is downloaded at configure time and verified against a
pinned SHA-256 hash, so a changed or corrupted download fails the configure step.

### Coding style
Basically the coding style is based on Google C++ Style, but there are some naming style changed:
- Function case style change to 'camelBack'
Expand Down
39 changes: 39 additions & 0 deletions cmake/SubstraitConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# SPDX-License-Identifier: Apache-2.0

@PACKAGE_INIT@

# Preserve the package prefix and libdir before dependency discovery,
# since find_dependency() calls in nested packages can overwrite PACKAGE_PREFIX_DIR.
set(_SUBSTRAIT_INSTALL_LIBDIR "@PACKAGE_CMAKE_INSTALL_LIBDIR@")

include(CMakeFindDependencyMacro)

# Dependencies that appear in the interface of the exported targets. They are
# either installed alongside this package or provided by the system.
if(@SUBSTRAIT_CPP_FIND_PROTOBUF_CONFIG@)
find_dependency(Protobuf @SUBSTRAIT_CPP_PROTOBUF_BUILD_VERSION@ CONFIG)
else()
find_dependency(Protobuf @SUBSTRAIT_CPP_PROTOBUF_BUILD_VERSION@)
endif()
find_dependency(absl CONFIG)
find_dependency(fmt CONFIG)
find_dependency(yaml-cpp CONFIG)
find_dependency(date CONFIG)

# The ANTLR4 runtime is built with ExternalProject and installed by this
# package as a plain static library, so it has to be re-declared here.
if(NOT TARGET antlr4_static)
add_library(antlr4_static STATIC IMPORTED)
set_target_properties(
antlr4_static
PROPERTIES
IMPORTED_LOCATION
"${_SUBSTRAIT_INSTALL_LIBDIR}/@SUBSTRAIT_CPP_ANTLR4_LIBRARY_FILE@"
)
endif()

unset(_SUBSTRAIT_INSTALL_LIBDIR)

include("${CMAKE_CURRENT_LIST_DIR}/SubstraitTargets.cmake")

check_required_components(Substrait)
4 changes: 2 additions & 2 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ docker run -it substrait-cpp

## Evaluate

Run function tests
Run tests

```bash
./build-Debug/substrait/function/tests/substrait_function_test
cd substrait-cpp && ctest --preset debug
```
Loading
Loading