diff --git a/.gitignore b/.gitignore index 27d943d..b8448b8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ build/ *.o *~ +cpp/flake.nix +cpp/flake.lock +cpp/.direnv/* diff --git a/cpp/.envrc b/cpp/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/cpp/.envrc @@ -0,0 +1 @@ +use flake diff --git a/cpp/Makefile b/cpp/Makefile new file mode 100644 index 0000000..eb3e48f --- /dev/null +++ b/cpp/Makefile @@ -0,0 +1,23 @@ +BUILD_DIR := build + +.PHONY: all configure build clean run + +all: build + +configure: + cmake -S . -B $(BUILD_DIR) -G Ninja \ + -DCMAKE_BUILD_TYPE=Debug \ + -DCMAKE_C_COMPILER=clang \ + -DCMAKE_CXX_COMPILER=clang++ + -DBUILD_CLI_VIS=1 + +build: configure + cmake --build $(BUILD_DIR) + @# Symlink compile_commands.json to root so clangd picks it up + @ln -sf $(BUILD_DIR)/compile_commands.json compile_commands.json + +run: build + ./$(BUILD_DIR)/myapp + +clean: + rm -rf $(BUILD_DIR) compile_commands.json diff --git a/cpp/flake.nix b/cpp/flake.nix new file mode 100644 index 0000000..71ce971 --- /dev/null +++ b/cpp/flake.nix @@ -0,0 +1,28 @@ +{ + description = "C++ dev shell with CMake and clangd"; + + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + + outputs = { self, nixpkgs }: + let + systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; + forAll = f: nixpkgs.lib.genAttrs systems (s: f nixpkgs.legacyPackages.${s}); + in { + devShells = forAll (pkgs: { + default = pkgs.mkShell { + packages = with pkgs; [ + cmake + clang-tools # provides clangd, clang-format, clang-tidy + llvmPackages.clang + ninja # optional but pairs well with cmake + catch2 # testing framework + ]; + + shellHook = '' + export CC=clang + export CXX=clang++ + ''; + }; + }); + }; +}