From ebf50df679ac26f68aa187cbe5f4823b456d786c Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Mon, 18 Mar 2024 12:12:08 +0100 Subject: [PATCH] chore: init project --- .envrc | 9 +++++ .gitignore | 4 ++ .nix/flake.lock | 61 +++++++++++++++++++++++++++++++ .nix/flake.nix | 32 ++++++++++++++++ .pre-commit-config.yaml | 29 +++++++++++++++ CMakeLists.txt | 21 +++++++++++ cmake/ExportCompileCommands.cmake | 8 ++++ cmake/sccache.cmake | 6 +++ main.cpp | 7 ++++ scripts/bootstrap.sh | 4 ++ scripts/build.sh | 3 ++ 11 files changed, 184 insertions(+) create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 .nix/flake.lock create mode 100644 .nix/flake.nix create mode 100644 .pre-commit-config.yaml create mode 100644 CMakeLists.txt create mode 100644 cmake/ExportCompileCommands.cmake create mode 100644 cmake/sccache.cmake create mode 100644 main.cpp create mode 100755 scripts/bootstrap.sh create mode 100755 scripts/build.sh diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..db72d2a --- /dev/null +++ b/.envrc @@ -0,0 +1,9 @@ +use flake .nix +dotenv_if_exists + +if on_git_branch; then + echo + git status --short --branch + echo + git fetch +fi diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c871890 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.build/ +.cache/ +bin/ +compile_commands.json diff --git a/.nix/flake.lock b/.nix/flake.lock new file mode 100644 index 0000000..b8a078d --- /dev/null +++ b/.nix/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1710734606, + "narHash": "sha256-rFJl+WXfksu2NkWJWKGd5Km17ZGEjFg9hOQNwstsoU8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "79bb4155141a5e68f2bdee2bf6af35b1d27d3a1d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/.nix/flake.nix b/.nix/flake.nix new file mode 100644 index 0000000..ee64884 --- /dev/null +++ b/.nix/flake.nix @@ -0,0 +1,32 @@ +{ + description = "A basic flake with a shell"; + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + inputs.flake-utils.url = "github:numtide/flake-utils"; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + in + { + devShell = pkgs.mkShell { + nativeBuildInputs = [ pkgs.bashInteractive ]; + buildInputs = with pkgs; [ + # building + gcc + cmake + ninja + sccache + + # pre-commit + pre-commit + commitizen + ]; + + shellHook = '' + pre-commit install --allow-missing-config --hook-type pre-commit --hook-type commit-msg + ''; + }; + } + ); +} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..3e76f32 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,29 @@ +repos: + - repo: https://github.com/commitizen-tools/commitizen + rev: v3.15.0 + hooks: + - id: commitizen + stages: [commit-msg] + + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v4.0.0-alpha.8 + hooks: + - id: prettier + name: check markdown/yaml formatting + types_or: + - markdown + - yaml + args: [--no-config] + exclude: CHANGELOG.md + + - repo: https://github.com/pocc/pre-commit-hooks + rev: v1.3.5 + hooks: + - id: clang-format + - id: clang-tidy + + - repo: https://github.com/cheshirekow/cmake-format-precommit + rev: v0.6.13 + hooks: + - id: cmake-format + - id: cmake-lint diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..a96ffad --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,21 @@ +cmake_minimum_required(VERSION 3.20) + +project( + VectorSearch + VERSION 0.1.0 + LANGUAGES CXX) + +list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") + +include(ExportCompileCommands) +include(sccache) + +add_executable(VectorSearch main.cpp) + +target_compile_features(VectorSearch PUBLIC cxx_std_20) + +set_target_properties( + VectorSearch + PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/bin" + RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/bin" + RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/bin") diff --git a/cmake/ExportCompileCommands.cmake b/cmake/ExportCompileCommands.cmake new file mode 100644 index 0000000..5db8897 --- /dev/null +++ b/cmake/ExportCompileCommands.cmake @@ -0,0 +1,8 @@ +set(CMAKE_EXPORT_COMPILE_COMMANDS + ON + CACHE BOOL "Export compile commands database") + +if(CMAKE_EXPORT_COMPILE_COMMANDS) + set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES + ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}) +endif() diff --git a/cmake/sccache.cmake b/cmake/sccache.cmake new file mode 100644 index 0000000..52adea6 --- /dev/null +++ b/cmake/sccache.cmake @@ -0,0 +1,6 @@ +find_program(SCCACHE_FOUND sccache) + +if(SCCACHE_FOUND) + set(CMAKE_C_COMPILER_LAUNCHER sccache) + set(CMAKE_CXX_COMPILER_LAUNCHER sccache) +endif() diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..33025f4 --- /dev/null +++ b/main.cpp @@ -0,0 +1,7 @@ +#include + +int main(int argc, char *argv[]) { + std::cout << "VectorSearch" << std::endl; + + return 0; +} diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh new file mode 100755 index 0000000..dd791a8 --- /dev/null +++ b/scripts/bootstrap.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env sh + +cmake -S . -B .build -G Ninja -D CMAKE_EXPORT_COMPILE_COMMANDS=ON +ln --symbolic --force .build/compile_commands.json diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100755 index 0000000..d26a5a3 --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +cmake --build .build