|
| 1 | +set shell := ["bash", "-eu", "-o", "pipefail", "-c"] |
| 2 | + |
| 3 | +# Defaults (edit as needed) |
| 4 | +build_type := "Debug" # choices: "Debug" "Release" "RelWithDebInfo" "MinSizeRel" |
| 5 | +preset := "conan-debug" # choices: "conan-debug" "conan-release" |
| 6 | +profile := "conan/clang21" # choices: "conan/gcc15" "conan/clang21" "conan/default" |
| 7 | +generator := "Ninja" # choices: "Ninja" "Unix Makefiles" |
| 8 | +CC := "clang" # choices: "gcc" "clang" |
| 9 | +CXX := "clang++" # choices: "g++" "clang++" |
| 10 | +skip_test := "False" # choices: "True" "False" |
| 11 | +cache_option := "ccache" # choices: "ccache" "sccache" "none" |
| 12 | +enable_cppcheck := "False" # choices: "True" "False" |
| 13 | +enable_clang_tidy := "False" # choices: "True" "False" |
| 14 | +enable_coverage := "False" # choices: "True" "False" |
| 15 | +run_binary := "leetcode_cpp" # executable name produced by the build |
| 16 | + |
| 17 | +# Show available recipes |
| 18 | +help: |
| 19 | + @just --list |
| 20 | + |
| 21 | +# Setup virtual environment using uv (from README) |
| 22 | +venv: |
| 23 | + uv venv |
| 24 | + |
| 25 | +sync: |
| 26 | + uv sync |
| 27 | + |
| 28 | +pre-commit-install: |
| 29 | + uv run pre-commit install |
| 30 | + |
| 31 | +conan-profile-detect: |
| 32 | + # idempotent: only run detect if the default profile file does not already exist |
| 33 | + if [ -f "$HOME/.conan2/profiles/default" ]; then echo "Conan profile 'default' exists -- skipping"; else uv run conan profile detect; fi |
| 34 | + |
| 35 | +# One-shot setup: run venv, sync, pre-commit install and conan profile detect |
| 36 | +setup: venv sync pre-commit-install conan-profile-detect |
| 37 | + @echo "Setup finished. To activate the virtualenv run: source .venv/bin/activate" |
| 38 | + |
| 39 | +# Install dependencies via Conan (edit variables above before running) |
| 40 | +conan-install: |
| 41 | + uv run conan install -pr:a default \ |
| 42 | + -pr:h {{profile}} \ |
| 43 | + -c:a tools.cmake.cmaketoolchain:generator={{generator}} \ |
| 44 | + -c:h tools.build:compiler_executables='{"c": "{{CC}}", "cpp": "{{CXX}}"}' \ |
| 45 | + -c:h tools.build:skip_test={{skip_test}} \ |
| 46 | + -s:h build_type={{build_type}} -b missing . |
| 47 | + |
| 48 | +# Activate virtualenv (prints instruction because sourcing won't persist) |
| 49 | +activate: |
| 50 | + @echo "Run: source .venv/bin/activate" |
| 51 | + |
| 52 | +# Configure project using CMake presets (adjust -D flags as needed) |
| 53 | +configure: |
| 54 | + uv run cmake --preset {{preset}} \ |
| 55 | + -D ENABLE_CPPCHECK={{enable_cppcheck}} \ |
| 56 | + -D ENABLE_CLANG_TIDY={{enable_clang_tidy}} \ |
| 57 | + -D ENABLE_IPO=OFF \ |
| 58 | + -D ENABLE_CACHE=OFF \ |
| 59 | + -D CACHE_OPTION={{cache_option}} \ |
| 60 | + -D ENABLE_COVERAGE={{enable_coverage}} \ |
| 61 | + -D ENABLE_HARDENINGS=OFF \ |
| 62 | + -D ENABLE_FORTIFY_SOURCE=OFF \ |
| 63 | + -D ENABLE_ASAN=OFF \ |
| 64 | + -D ENABLE_LSAN=OFF \ |
| 65 | + -D ENABLE_UBSAN=OFF \ |
| 66 | + -D ENABLE_TSAN=OFF |
| 67 | + |
| 68 | +# Build and test |
| 69 | +build: |
| 70 | + uv run cmake --build --preset {{preset}} |
| 71 | + |
| 72 | +test: |
| 73 | + uv run ctest --preset {{preset}} |
| 74 | + |
| 75 | +# Run the compiled leetcode_cpp executable. Depends on `build` so the binary |
| 76 | +# is up-to-date. Override `run_binary` or `build_type` locally if needed. |
| 77 | +run: build |
| 78 | + uv run ./build/{{build_type}}/{{run_binary}} ${RUN_ARGS:-} |
| 79 | + |
| 80 | +# Cleaning targets |
| 81 | +# - `clean-setup`: remove setup artifacts (virtualenv, pre-commit hooks) |
| 82 | +# - `clean-build`: remove build artifacts |
| 83 | +# - `clean-all`: remove both setup and build artifacts |
| 84 | +# Keep `clean` as an alias to `clean-build` for backwards compatibility. |
| 85 | +clean-setup: |
| 86 | + # If a virtualenv exists, attempt to uninstall pre-commit (without creating a venv), then remove it |
| 87 | + if [ -d .venv ]; then if [ -x .venv/bin/pre-commit ]; then .venv/bin/pre-commit uninstall || true; elif command -v uv >/dev/null 2>&1; then uv run pre-commit uninstall || true; fi; fi; rm -rf .venv/ || true |
| 88 | + |
| 89 | +clean-build: |
| 90 | + # Remove common build directories and artifacts |
| 91 | + for d in build "{{build_type}}" Debug Release "build/{{build_type}}" build/Debug build/Release build/bin; do if [ -d "$d" ]; then rm -rf "$d" || true; fi; done |
| 92 | + # remove CMake-generated files in project root if present |
| 93 | + rm -f CMakeCache.txt cmake_install.cmake compile_commands.json CMakeUserPresets.json CMakeSettings.json || true |
| 94 | + |
| 95 | +clean-all: clean-setup clean-build |
| 96 | + |
| 97 | +clean: clean-build |
| 98 | + |
| 99 | +# Collect coverage (use appropriate gcov value for your toolchain) |
| 100 | +coverage: |
| 101 | + GCOV="gcov" uv run gcovr |
| 102 | + |
| 103 | +# Format C/C++ sources under src/ using clang-format |
| 104 | +fmt: |
| 105 | + if ! command -v clang-format >/dev/null 2>&1; then echo "clang-format not found; install clang-format to use just fmt"; exit 2; fi |
| 106 | + find src -type f \( -name '*.cpp' -o -name '*.cc' -o -name '*.cxx' -o -name '*.h' -o -name '*.hpp' \) -print0 | xargs -0 clang-format -i |
| 107 | + @echo "Formatted C/C++ sources under src/" |
| 108 | + |
| 109 | +# Default task |
| 110 | +default: help |
0 commit comments