Skip to content

Commit

Permalink
Make an example of including UnoDB as a CMake subdirectory
Browse files Browse the repository at this point in the history
- Update UnoDB CMakeLists.txt to use GSL, Google Test, & Google Benchmark CMake
  targets if they are already set up by parent CMake.
- Convert examples/CMakeLists.txt to be a top-level CMake script, showing an
  example of using UnoDB as a dependency.
- Update CI to build examples from the top-level script.
  • Loading branch information
laurynas-biveinis committed Jan 13, 2025
1 parent f896f77 commit 34e417a
Show file tree
Hide file tree
Showing 9 changed files with 326 additions and 95 deletions.
94 changes: 80 additions & 14 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ jobs:
resource_class: arm.medium
steps:
- checkout
- run:
name: Checkout submodules
command: git submodule update --init
- run:
name: Installing dependencies (common)
command: |
Expand Down Expand Up @@ -70,6 +67,57 @@ jobs:
- run:
name: Create build environment
command: mkdir build
- when:
condition:
not:
or:
- << parameters.asan >>
- << parameters.tsan >>
- << parameters.ubsan >>
steps:
- run:
name: Create build environment (examples)
command: mkdir build/build-examples
- run:
name: Installing dependencies (examples)
command: |
sudo apt-get install -y libmsgsl-dev libgtest-dev \
libbenchmark-dev
- run:
name: Configure CMake (examples)
working_directory: build/build-examples
command: |
readonly BUILD_TYPE=<< parameters.build_type >>
readonly COMPILER=<< parameters.compiler >>
if [[ $COMPILER == "gcc" ]]; then
V=13
export CC=gcc-$V
export CXX=g++-$V
EXTRA_CMAKE_ARGS=()
elif [[ $COMPILER == "clang" ]]; then
V=19
export CC=clang-$V
export CXX=clang++-$V
if [[ $BUILD_TYPE == "Release" ]]; then
EXTRA_CMAKE_ARGS=(\
"-DLLVMAR_EXECUTABLE=/usr/bin/llvm-ar-$V" \
"-DLLVMNM_EXECUTABLE=/usr/bin/llvm-nm-$V" \
"-DLLVMRANLIB_EXECUTABLE=/usr/bin/llvm-ranlib-$V")
else
EXTRA_CMAKE_ARGS=()
fi
EXTRA_CMAKE_ARGS=("${EXTRA_CMAKE_ARGS[@]}" \
"-DCLANG_TIDY_EXE=/usr/bin/clang-tidy-$V")
fi
cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE \
"${EXTRA_CMAKE_ARGS[@]}"
- run:
name: Examples
working_directory: build/build-examples
command: make -j2 examples
- run:
name: Checkout submodules
command: git submodule update --init
- run:
name: Configure CMake
working_directory: build
Expand Down Expand Up @@ -107,10 +155,6 @@ jobs:
name: Build
working_directory: build
command: make -j2
- run:
name: Examples
working_directory: build
command: make examples
- run:
name: Correctness test
working_directory: build
Expand Down Expand Up @@ -160,9 +204,6 @@ jobs:
resource_class: macos.m1.medium.gen1
steps:
- checkout
- run:
name: Checkout submodules
command: git submodule update --init --recursive
- run:
name: Install dependencies
command: |
Expand All @@ -171,6 +212,35 @@ jobs:
- run:
name: Create build environment
command: mkdir build
- when:
condition:
not:
or:
- << parameters.asan >>
- << parameters.tsan >>
- << parameters.ubsan >>
steps:
- run:
name: Create build environment (examples)
command: mkdir build/build-examples
- run:
name: Installing dependencies (examples)
command: brew install cpp-gsl googletest google-benchmark
- run:
name: Configure CMake (examples)
working_directory: build/build-examples
command: |
readonly BUILD_TYPE=<< parameters.build_type >>
export CC=clang
export CXX=clang++
cmake .. -DCMAKE_BUILD_TYPE=$BUILD_TYPE
- run:
name: Examples
working_directory: build/build-examples
command: make -j3 examples
- run:
name: Checkout submodules
command: git submodule update --init --recursive
- run:
name: Configure CMake
working_directory: build
Expand All @@ -188,10 +258,6 @@ jobs:
name: Build
working_directory: build
command: make -j3
- run:
name: Examples
working_directory: build
command: make examples
- run:
name: Correctness test
working_directory: build
Expand Down
79 changes: 72 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
submodules: true
submodules: false

- name: Setup common dependencies for Linux
run: |
Expand Down Expand Up @@ -340,6 +340,13 @@ jobs:
sudo cpanm install JSON
if: runner.os == 'Linux' && env.COVERAGE == 'ON'

- name: Set up dependencies for Linux (examples)
run: sudo apt-get install -y libmsgsl-dev libgtest-dev libbenchmark-dev
if: >
env.SANITIZE_ADDRESS != 'ON' && env.SANITIZE_THREAD != 'ON'
&& env.SANITIZE_UB != 'ON' && env.STATIC_ANALYSIS != 'ON'
&& runner.os == 'Linux' && env.COVERAGE != 'ON'
- name: Set up dependencies for macOS (common)
run: |
brew install boost include-what-you-use python-setuptools
Expand All @@ -349,8 +356,71 @@ jobs:
run: brew install cppcheck
if: runner.os == 'macOS' && env.CPPCHECK == 'ON'

- name: Set up dependencies for macOS (examples)
run: brew install cpp-gsl googletest google-benchmark
if: >
env.SANITIZE_ADDRESS != 'ON' && env.SANITIZE_THREAD != 'ON'
&& env.SANITIZE_UB != 'ON' && env.STATIC_ANALYSIS != 'ON'
&& runner.os == 'macOS' && env.COVERAGE != 'ON'
- name: Create build environment
run: mkdir ${{github.workspace}}/build
run: |
mkdir ${{github.workspace}}/build \
${{github.workspace}}/build/build-examples
- name: Configure CMake (examples)
# Use a bash shell so we can use the same syntax for environment
# variable access regardless of the host operating system
shell: bash
working-directory: ${{github.workspace}}/build/build-examples
run: |
COMPILER="${COMPILER:-$DEFAULT_COMPILER}"
AVX2="${AVX2:-$DEFAULT_AVX2}"
export PATH="$HOME/.local/bin:$PATH"
if [[ -n "$BUILD_TYPE" ]]; then
CBT="-DCMAKE_BUILD_TYPE=$BUILD_TYPE"
else
CBT=""
fi
if [[ $COMPILER == "gcc" ]]; then
V=13
EXTRA_CMAKE_ARGS=()
export CC=gcc-$V
export CXX=g++-$V
elif [[ $COMPILER == "clang" ]]; then
V=19
export CC=clang-$V
export CXX=clang++-$V
if [[ $BUILD_TYPE == "Release" ]]; then
EXTRA_CMAKE_ARGS=(\
"-DLLVMAR_EXECUTABLE=/usr/bin/llvm-ar-$V" \
"-DLLVMNM_EXECUTABLE=/usr/bin/llvm-nm-$V" \
"-DLLVMRANLIB_EXECUTABLE=/usr/bin/llvm-ranlib-$V")
else
EXTRA_CMAKE_ARGS=()
fi
elif [[ $COMPILER == "macos-clang" ]]; then
export CC=clang
export CXX=clang++
fi
cmake "$GITHUB_WORKSPACE" "$CBT" "-DAVX2=${AVX2}" \
"${EXTRA_CMAKE_ARGS[@]}"
if: >
env.SANITIZE_ADDRESS != 'ON' && env.SANITIZE_THREAD != 'ON'
&& env.SANITIZE_UB != 'ON' && env.STATIC_ANALYSIS != 'ON'
&& env.COVERAGE != 'ON'
- name: Examples
working-directory: ${{github.workspace}}/build/build-examples
run: make -j3 examples
if: >
env.SANITIZE_ADDRESS != 'ON' && env.SANITIZE_THREAD != 'ON'
&& env.SANITIZE_UB != 'ON' && env.STATIC_ANALYSIS != 'ON'
&& env.COVERAGE != 'ON'
- uses: actions/checkout@v4
with:
submodules: true

- name: Configure CMake
# Use a bash shell so we can use the same syntax for environment
Expand Down Expand Up @@ -426,11 +496,6 @@ jobs:
--force-analyze-debug-code make -j3;
if: env.STATIC_ANALYSIS == 'ON' && env.COMPILER == 'clang'

- name: Examples
working-directory: ${{github.workspace}}/build
run: make examples
if: env.STATIC_ANALYSIS != 'ON' && env.COVERAGE != 'ON'

- name: Correctness test
working-directory: ${{github.workspace}}/build
run: ctest -j3 -V
Expand Down
53 changes: 47 additions & 6 deletions .github/workflows/old-compilers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
submodules: true
submodules: false

- name: Setup common dependencies
run: |
Expand Down Expand Up @@ -485,8 +485,53 @@ jobs:
sudo apt-get install -y gcc
if: env.COMPILER == 'gcc' && env.VERSION == '11'

- name: Set up dependencies for examples
run: sudo apt-get install -y libmsgsl-dev libgtest-dev libbenchmark-dev
if: >
env.SANITIZE_ADDRESS != 'ON' && env.SANITIZE_THREAD != 'ON'
&& env.SANITIZE_UB != 'ON'
- name: Create build environment
run: mkdir ${{github.workspace}}/build
run: |
mkdir ${{github.workspace}}/build \
${{github.workspace}}/build/build-examples
- name: Configure CMake (examples)
# Use a bash shell so we can use the same syntax for environment
# variable access regardless of the host operating system
shell: bash
working-directory: ${{github.workspace}}/build-examples
run: |
export PATH=$HOME/.local/bin:$PATH
if [[ $COMPILER == "gcc" ]]; then
export CC="gcc-${VERSION}"
export CXX="g++-${VERSION}"
else
export CC="clang-${VERSION}"
export CXX="clang++-${VERSION}"
if [[ $BUILD_TYPE == "Release" ]]; then
EXTRA_CMAKE_ARGS=("${EXTRA_CMAKE_ARGS[@]}" \
"-DLLVMAR_EXECUTABLE=/usr/bin/llvm-ar-${VERSION}" \
"-DLLVMNM_EXECUTABLE=/usr/bin/llvm-nm-${VERSION}" \
"-DLLVMRANLIB_EXECUTABLE=/usr/bin/llvm-ranlib-${VERSION}")
fi
fi
cmake "$GITHUB_WORKSPACE" "-DCMAKE_BUILD_TYPE=$BUILD_TYPE" \
"${EXTRA_CMAKE_ARGS[@]}"
if: >
env.SANITIZE_ADDRESS != 'ON' && env.SANITIZE_THREAD != 'ON'
&& env.SANITIZE_UB != 'ON'
- name: Examples
working-directory: ${{github.workspace}}/build/build-examples
run: make -j3 examples
if: >
env.SANITIZE_ADDRESS != 'ON' && env.SANITIZE_THREAD != 'ON'
&& env.SANITIZE_UB != 'ON'
- uses: actions/checkout@v4
with:
submodules: true

- name: Configure CMake
# Use a bash shell so we can use the same syntax for environment
Expand Down Expand Up @@ -530,10 +575,6 @@ jobs:
working-directory: ${{github.workspace}}/build
run: make -j3

- name: Examples
working-directory: ${{github.workspace}}/build
run: make examples

- name: Correctness test
working-directory: ${{github.workspace}}/build
run: ctest -j3 -V
Expand Down
53 changes: 47 additions & 6 deletions .github/workflows/ubuntu-20.04.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
submodules: true
submodules: false

- name: Setup common dependencies
run: |
Expand All @@ -195,8 +195,53 @@ jobs:
"lld-${VERSION}"
if: env.COMPILER == 'clang' && env.BUILD_TYPE == 'Release'

- name: Set up dependencies for examples
run: sudo apt-get install -y libmsgsl-dev libgtest-dev libbenchmark-dev
if: >
env.SANITIZE_ADDRESS != 'ON' && env.SANITIZE_THREAD != 'ON'
&& env.SANITIZE_UB != 'ON'
- name: Create build environment
run: mkdir ${{github.workspace}}/build
run: |
mkdir ${{github.workspace}}/build \
${{github.workspace}}/build/build-examples
- name: Configure CMake (examples)
# Use a bash shell so we can use the same syntax for environment
# variable access regardless of the host operating system
shell: bash
working-directory: ${{github.workspace}}/build-examples
run: |
export PATH=$HOME/.local/bin:$PATH
if [[ $COMPILER == "gcc" ]]; then
export CC="gcc-${VERSION}"
export CXX="g++-${VERSION}"
else
export CC="clang-${VERSION}"
export CXX="clang++-${VERSION}"
if [[ $BUILD_TYPE == "Release" ]]; then
EXTRA_CMAKE_ARGS=("${EXTRA_CMAKE_ARGS[@]}" \
"-DLLVMAR_EXECUTABLE=/usr/bin/llvm-ar-${VERSION}" \
"-DLLVMNM_EXECUTABLE=/usr/bin/llvm-nm-${VERSION}" \
"-DLLVMRANLIB_EXECUTABLE=/usr/bin/llvm-ranlib-${VERSION}")
fi
fi
cmake "$GITHUB_WORKSPACE" "-DCMAKE_BUILD_TYPE=$BUILD_TYPE" \
"${EXTRA_CMAKE_ARGS[@]}"
if: >
env.SANITIZE_ADDRESS != 'ON' && env.SANITIZE_THREAD != 'ON'
&& env.SANITIZE_UB != 'ON'
- name: Examples
working-directory: ${{github.workspace}}/build/build-examples
run: make -j3 examples
if: >
env.SANITIZE_ADDRESS != 'ON' && env.SANITIZE_THREAD != 'ON'
&& env.SANITIZE_UB != 'ON'
- uses: actions/checkout@v4
with:
submodules: true

- name: Configure CMake
# Use a bash shell so we can use the same syntax for environment
Expand Down Expand Up @@ -232,10 +277,6 @@ jobs:
working-directory: ${{github.workspace}}/build
run: make -j3

- name: Examples
working-directory: ${{github.workspace}}/build
run: make examples

- name: Correctness test
working-directory: ${{github.workspace}}/build
run: ctest -j3 -V
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@
# MSVC
/.vs
/out
/examples/compile_commands.json
Loading

0 comments on commit 34e417a

Please sign in to comment.