From f424cd1fa87c18db53b1330497722ad269f6dca8 Mon Sep 17 00:00:00 2001 From: xinyangli Date: Thu, 4 Apr 2024 01:32:51 +0800 Subject: [PATCH] cpp-cmake: init --- cpp-cmake/.clang-format | 2 + cpp-cmake/.envrc | 1 + cpp-cmake/.gitignore | 97 ++++++++++++++++++++ cpp-cmake/CMakeLists.txt | 8 ++ cpp-cmake/flake.lock | 172 +++++++++++++++++++++++++++++++++++ cpp-cmake/flake.nix | 44 +++++++++ cpp-cmake/src/CMakeLists.txt | 2 + cpp-cmake/src/main.cpp | 3 + flake.nix | 11 +++ 9 files changed, 340 insertions(+) create mode 100644 cpp-cmake/.clang-format create mode 100644 cpp-cmake/.envrc create mode 100644 cpp-cmake/.gitignore create mode 100644 cpp-cmake/CMakeLists.txt create mode 100644 cpp-cmake/flake.lock create mode 100644 cpp-cmake/flake.nix create mode 100644 cpp-cmake/src/CMakeLists.txt create mode 100644 cpp-cmake/src/main.cpp create mode 100644 flake.nix diff --git a/cpp-cmake/.clang-format b/cpp-cmake/.clang-format new file mode 100644 index 0000000..f6b8fdf --- /dev/null +++ b/cpp-cmake/.clang-format @@ -0,0 +1,2 @@ +--- +BasedOnStyle: LLVM diff --git a/cpp-cmake/.envrc b/cpp-cmake/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/cpp-cmake/.envrc @@ -0,0 +1 @@ +use flake diff --git a/cpp-cmake/.gitignore b/cpp-cmake/.gitignore new file mode 100644 index 0000000..9875358 --- /dev/null +++ b/cpp-cmake/.gitignore @@ -0,0 +1,97 @@ +.direnv/ +.pre-commit-config.yaml + +# Created by https://www.toptal.com/developers/gitignore/api/c++,c,cmake +# Edit at https://www.toptal.com/developers/gitignore?templates=c++,c,cmake + +### C ### +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf + +### C++ ### +# Prerequisites + +# Compiled Object files +*.slo + +# Precompiled Headers + +# Compiled Dynamic libraries + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai + +# Executables + +### CMake ### +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps + +### CMake Patch ### +# External projects +*-prefix/ + +# End of https://www.toptal.com/developers/gitignore/api/c++,c,cmake diff --git a/cpp-cmake/CMakeLists.txt b/cpp-cmake/CMakeLists.txt new file mode 100644 index 0000000..e26dd15 --- /dev/null +++ b/cpp-cmake/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.26) + +project() +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_C_STANDARD 17) + +add_subdirectory(src) + diff --git a/cpp-cmake/flake.lock b/cpp-cmake/flake.lock new file mode 100644 index 0000000..513a7e2 --- /dev/null +++ b/cpp-cmake/flake.lock @@ -0,0 +1,172 @@ +{ + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "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" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "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" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1711703276, + "narHash": "sha256-iMUFArF0WCatKK6RzfUJknjem0H9m4KgorO/p3Dopkk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "d8fe5e6c92d0d190646fb9f1056741a229980089", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1710695816, + "narHash": "sha256-3Eh7fhEID17pv9ZxrPwCLfqXnYP006RKzSs0JptsN84=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "614b4613980a522ba49f0d194531beddbb7220d3", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils_2", + "gitignore": "gitignore", + "nixpkgs": [ + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1712055707, + "narHash": "sha256-4XLvuSIDZJGS17xEwSrNuJLL7UjDYKGJSbK1WWX2AK8=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "e35aed5fda3cc79f88ed7f1795021e559582093a", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "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/cpp-cmake/flake.nix b/cpp-cmake/flake.nix new file mode 100644 index 0000000..176f325 --- /dev/null +++ b/cpp-cmake/flake.nix @@ -0,0 +1,44 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + pre-commit-hooks = { + url = "github:cachix/pre-commit-hooks.nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { self, ... }@inputs: with inputs; + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + in + { + checks = { + pre-commit-check = pre-commit-hooks.lib.${system}.run { + src = ./.; + hooks = { + trim-trailing-whitespace.enable = true; + clang-format = { + enable = true; + types_or = pkgs.lib.mkForce [ "c" "c++" ]; + }; + nil.enable = true; + nixpkgs-fmt.enable = true; + }; + }; + }; + devShells.default = with pkgs; mkShell { + inherit (self.checks.${system}.pre-commit-check) shellHook; + buildInputs = self.checks.${system}.pre-commit-check.enabledPackages; + packages = [ + clang-tools + cmake + gdb + nil + ]; + }; + } + ); +} + diff --git a/cpp-cmake/src/CMakeLists.txt b/cpp-cmake/src/CMakeLists.txt new file mode 100644 index 0000000..cf986e3 --- /dev/null +++ b/cpp-cmake/src/CMakeLists.txt @@ -0,0 +1,2 @@ +add_executable(test main.cpp) + diff --git a/cpp-cmake/src/main.cpp b/cpp-cmake/src/main.cpp new file mode 100644 index 0000000..f97e7d8 --- /dev/null +++ b/cpp-cmake/src/main.cpp @@ -0,0 +1,3 @@ +int main(int argc, char **argv){ + return 0; +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..8b94e2c --- /dev/null +++ b/flake.nix @@ -0,0 +1,11 @@ +{ + description = "A collection of flake templates"; + + outputs = { self }: { + templates = { + cpp-cmake = { + path = ./cpp-cmake; + }; + }; + }; +}