feat(cpp): add nix build stuff

backup
flop 3 weeks ago
parent 82458df080
commit 3e34bd8404
  1. 3
      .gitignore
  2. 1
      cpp/.envrc
  3. 23
      cpp/Makefile
  4. 28
      cpp/flake.nix

3
.gitignore vendored

@ -1,3 +1,6 @@
build/
*.o
*~
cpp/flake.nix
cpp/flake.lock
cpp/.direnv/*

@ -0,0 +1 @@
use flake

@ -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

@ -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++
'';
};
});
};
}
Loading…
Cancel
Save