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
7 changes: 7 additions & 0 deletions .clang-format-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# apart from all the .gitignores, what else files should be
# ignored by the clang formatter
.git/
.github/
third_party/*
*/generated/*
build/*
69 changes: 69 additions & 0 deletions .github/actions/cmake-setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: "Setup CMake"
description: "Download/cache specific CMake version"

inputs:
cmake-version:
description: 'CMake version'
required: true
cmake-cache-path:
description: 'Path to cache CMake'
required: false
default: ~/.cache
outputs:
cmake-path:
description: 'Path to the CMake executable'
value: ${{ steps.add-cmake-to-path.outputs.cmake-path }}

runs:
using: "composite"
steps:
- name: Setup Variables
id: variables
run: |
CMAKE_VERSION="${{ inputs.cmake-version }}"
CMAKE_COMPRESSED="cmake-${CMAKE_VERSION}-linux-x86_64.tar.gz"
CMAKE_URL="https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/${CMAKE_COMPRESSED}"
CMAKE_SHA256_URL="https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-SHA-256.txt"
CMAKE_CACHE_PATH="${{ inputs.cmake-cache-path }}/cmake-${CMAKE_VERSION}"

echo "cmake-version=${CMAKE_VERSION}" >> "${GITHUB_OUTPUT}"
echo "cmake-compressed=${CMAKE_COMPRESSED}" >> "${GITHUB_OUTPUT}"
echo "cmake-url=${CMAKE_URL}" >> "${GITHUB_OUTPUT}"
echo "cmake-sha256-url=${CMAKE_SHA256_URL}" >> "${GITHUB_OUTPUT}"
echo "cmake-cache-path=${CMAKE_CACHE_PATH}" >> "${GITHUB_OUTPUT}"
shell: bash

- name: Cache CMake
id: cache-cmake
uses: actions/cache@v3
with:
path: ${{ steps.variables.outputs.cmake-cache-path }}
key: ${{ runner.os }}-cmake-${{ inputs.cmake-version }}

- name: Download & Extract CMake
if: steps.cache-cmake.outputs.cache-hit != 'true'
run: |
# Download CMake and its SHA256 file
curl -L "${{ steps.variables.outputs.cmake-url }}" -o "${{ steps.variables.outputs.cmake-compressed }}"
curl -L "${{ steps.variables.outputs.cmake-sha256-url }}" -o cmake.sha256

# Extract the expected SHA256 from the file
EXPECTED_SHA=$(
grep "${{ steps.variables.outputs.cmake-compressed }}" "cmake.sha256" |
awk '{ print $1 }'
)

# Verify the SHA256 checksum
echo "${EXPECTED_SHA} ${{ steps.variables.outputs.cmake-compressed }}" | sha256sum -c -

# Create the cache directory and extract CMake
mkdir -p ${{ steps.variables.outputs.cmake-cache-path }}
tar -xzf "${{ steps.variables.outputs.cmake-compressed }}" --strip-components=1 -C ${{ steps.variables.outputs.cmake-cache-path }}
shell: bash

- name: Add CMake to PATH & Export CMake Executable Path
id: add-cmake-to-path
run: |
echo "${{ steps.variables.outputs.cmake-cache-path }}/bin" >> "${GITHUB_PATH}"
echo "cmake-path=${{ steps.variables.outputs.cmake-cache-path }}/bin/cmake" >> "${GITHUB_OUTPUT}"
shell: bash
80 changes: 80 additions & 0 deletions .github/workflows/black-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Python Format Check

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
cmake-version: "3.22.6"
python-version: "3.10"

jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

# === Get CMake ===
- name: Setup CMake
id: setup-cmake
uses: ./.github/actions/cmake-setup
with:
cmake-version: ${{ env.cmake-version }}

# === Get Python3 ===
- name: Set up Python3
uses: actions/setup-python@v5
with:
python-version: ${{ env.python-version }}

# === CMake configuration ===
- name: Initialize Build System
env:
cmake-exe: ${{ steps.setup-cmake.outputs.cmake-path }}
run: |
${{ env.cmake-exe }} -B ${{github.workspace}}/build -DFORMATTING_ONLY=ON
${{ env.cmake-exe }} --build ${{github.workspace}}/build --target help

# === Check for CMake format check target ===
- name: Check CMake Format Target
id: check-cmake-format-target
env:
cmake-exe: ${{ steps.setup-cmake.outputs.cmake-path }}
run: |
# skip download if target is found
if ${{ env.cmake-exe }} --build ${{github.workspace}}/build --target help | grep -q "python-check-format"; then
echo "black-found=true" >> "${GITHUB_OUTPUT}"
else
echo "black-found=false" >> "${GITHUB_OUTPUT}"
fi

# === Get Python3 black formatter ===
- name: Get Python3 Black Formatter
if: steps.check-cmake-format-target.outputs.black-found != 'true'
env:
cmake-exe: ${{ steps.setup-cmake.outputs.cmake-path }}
run: |
# install_black_py3pkg_requirements target will only be available if the black package is not found
${{ env.cmake-exe }} --build ${{github.workspace}}/build --target install_black_py3pkg_requirements

# === Redo the CMake configuration ===
- name: Initialize Build System Again
if: steps.check-cmake-format-target.outputs.black-found != 'true'
env:
cmake-exe: ${{ steps.setup-cmake.outputs.cmake-path }}
run: |
${{ env.cmake-exe }} -B ${{github.workspace}}/build -DFORMATTING_ONLY=ON
${{ env.cmake-exe }} --build ${{github.workspace}}/build --target help

# === Format check ===
- name: Python Format Check
env:
cmake-exe: ${{ steps.setup-cmake.outputs.cmake-path }}
run: |
${{ env.cmake-exe }} --build ${{github.workspace}}/build --target python-check-format
68 changes: 68 additions & 0 deletions .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: C/C++ Format Check

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
cmake-version: "3.22.6"
clang-format-version: "14"

jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

# === Get CMake ===
- name: Setup CMake
id: setup-cmake
uses: ./.github/actions/cmake-setup
with:
cmake-version: ${{ env.cmake-version }}

# === Get clang-format ===
- name: Cache clang-format
uses: actions/cache@v3
id: cache-clang-format
with:
path: ~/.cache/clang-format-${{ env.clang-format-version }}
key: ${{ runner.os }}-clang-format-${{ env.clang-format-version }}

- name: Download clang-format
if: steps.cache-clang-format.outputs.cache-hit != 'true'
env:
clang-format-url: https://github.com/muttleyxd/clang-tools-static-binaries/releases/download/master-2da3e7b/clang-format-${{ env.clang-format-version }}_linux-amd64
clang-format-cache-path: ~/.cache/clang-format-${{ env.clang-format-version }}
clang-format-sha256: 5daf48b8331afb85575e11dfd73ffc6bf47af10ccde260b40751df246f1bf1ff
run: |
curl -L ${{ env.clang-format-url }} -o clang-format
echo "${{ env.clang-format-sha256 }} clang-format" | sha256sum -c -
chmod +x clang-format
mkdir -p ${{ env.clang-format-cache-path }}
mv clang-format ${{ env.clang-format-cache-path }}/clang-format-${{ env.clang-format-version }}

- name: Add clang-format to PATH
run: echo ~/.cache/clang-format-${{ env.clang-format-version }} >> "$GITHUB_PATH"

# === CMake configuration and build ===
- name: CMake Setup
env:
cmake-exe: ${{ steps.setup-cmake.outputs.cmake-path }}
run: |
${{ env.cmake-exe }} -B ${{github.workspace}}/build -DFORMATTING_ONLY=ON
${{ env.cmake-exe }} --build ${{github.workspace}}/build --target help

- name: Format Check
env:
cmake-exe: ${{ steps.setup-cmake.outputs.cmake-path }}
run: |
which clang-format
${{ env.cmake-exe }} --build ${{github.workspace}}/build --target cpp-check-format

22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# editor specific
.vscode/

# build directory
build/

# any database
*.db

# python
.python_history
.ptpython_history
**/__pycache__/
requirements.txt

# build artifacts
build/

# dataset data
*.csv
*.arrow
*.json
13 changes: 13 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[submodule "third_party/pybind11"]
path = third_party/pybind11
url = https://github.com/pybind/pybind11.git
[submodule "third_party/protobuf"]
path = third_party/protobuf
url = https://github.com/protocolbuffers/protobuf.git
[submodule "third_party/date"]
path = third_party/date
url = https://github.com/HowardHinnant/date.git
[submodule "third_party/pybind11_mkdoc"]
path = third_party/pybind11_mkdoc
url = https://github.com/0-EricZhou-0/pybind11_mkdoc.git
branch = arg_support
96 changes: 96 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
cmake_minimum_required(VERSION 3.22)

project(rag_sys LANGUAGES C CXX)

# === CMake Options ===
option(FORMATTING_ONLY
"Only generate format related targets" OFF)
option(GENERATE_GLOBAL_PY3_DEPENDENCY
"Generate global Python3 package requirements, only asserted when excluding env-specific packages" OFF)
option(GENERATE_ESSENTIAL_PY3_DEPENDENCY
"Generate essential Python3 package requirements (i.e., excluding formatting, QoL, etc.)" OFF)

# === CMake policy ===
# make CMAKE_INTERPROCEDURAL_OPTIMIZATION applies globally
set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)

# === C/C++ standard ===
set(CMAKE_C_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)

# === Cmake configurations ===
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_VERBOSE_MAKEFILE OFF)
# build type & optimization
set(CMAKE_BUILD_TYPE Release)
if(CMAKE_BUILD_TYPE STREQUAL "Release")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()

# === Custom configurations ===
# Print all target building information formulated using cmake/build_helper.cmake:function(cxx_setup_target)
set(EXPORT_TARGET_CONFIG OFF)

# === Prioritize executables and libraries in conda environment ===
# if(DEFINED ENV{CONDA_PREFIX})
# execute_process(
# COMMAND [=[echo $SHELL; echo "${CONDA_PREFIX:-'$(dirname $(which conda))/../'}"]=]
# OUTPUT_VARIABLE CONDA_CMAKE_PREFIX_PATH
# COMMAND_ECHO STDOUT
# ECHO_OUTPUT_VARIABLE
# )
# list(APPEND CMAKE_PREFIX_PATH "${CONDA_CMAKE_PREFIX_PATH}")
# endif()

# === Custom repository-wide variables ===
set(PYTHON_SRC_DIR ${CMAKE_SOURCE_DIR}/src)
set(RESOURCE_DIR ${CMAKE_SOURCE_DIR}/resource)

# === Create necessary directories ===
file(MAKE_DIRECTORY ${RESOURCE_DIR}/generated)

# === Include custom module subdirectories ===
set(CMAKE_MODULE_PATH
${CMAKE_SOURCE_DIR}/cmake/module
${CMAKE_MODULE_PATH})

# === Include utilities ===
# cmake utilities
include(cmake/utils.cmake)

# python utilities
set(PY3_PKG_EXISTENCE_DIR ${CMAKE_BINARY_DIR}/py3_pkg_info)
set(PY3_PKGDEP_CHK_SCRIPT ${RESOURCE_DIR}/build_helper/py3_require_package.py)
set(PY3_EXEMOD_CHK_SCRIPT ${RESOURCE_DIR}/build_helper/py3_require_executable_module.py)
include(cmake/python_env.cmake)

# === Code Formatting configuration ===
set(CLANG_FORMAT_DIR ${RESOURCE_DIR}/clang_format)
set(BLACK_FORMAT_DIR ${RESOURCE_DIR}/black_format)
include(cmake/clang_format.cmake)
include(cmake/black_format.cmake)
if(FORMATTING_ONLY)
message(STATUS "Only running clang-format, skipping other configurations.")
return()
endif()

# === Include other predefined cmake files ===
# c++ build helper
include(cmake/build_helper.cmake)

# misc
set(LIBCLANG_FIND_VERSION_SCRIPT ${RESOURCE_DIR}/build_helper/libclang_get_lib_version.py)
include(cmake/misc.cmake)

# third-party library import
set(THIRD_PARTY_DIR ${CMAKE_SOURCE_DIR}/third_party)
include(cmake/third_party.cmake)

# === Custom project-wide variables ===

# === Include subdirectories ===
add_subdirectory(monitoring_sys)
add_subdirectory(example)

# === Status report ===
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
Loading