diff --git a/templates/c++-meson/.clang-format b/templates/c++-meson/.clang-format new file mode 100644 index 0000000..19c58aa --- /dev/null +++ b/templates/c++-meson/.clang-format @@ -0,0 +1,23 @@ +# vim: ft=yaml +--- +BasedOnStyle: LLVM +IndentWidth: 4 +--- +Language: Cpp +# Force pointers to the type for C++. +DerivePointerAlignment: false +PointerAlignment: Left + +# Short functions should not be on a single line, unless empty +AllowShortFunctionsOnASingleLine: Empty + +# Make them level +AccessModifierOffset: -4 + +# It makes more sense this way +BreakBeforeBinaryOperators: All +BreakBeforeTernaryOperators: true + +# Aesthetic +AlignOperands: AlignAfterOperator +--- diff --git a/templates/c++-meson/.gitignore b/templates/c++-meson/.gitignore new file mode 100644 index 0000000..09ba440 --- /dev/null +++ b/templates/c++-meson/.gitignore @@ -0,0 +1,7 @@ +# CMake build directories +/build +/build-* + +# Nix generated files +/.pre-commit-config.yaml +/result diff --git a/templates/c++-meson/.woodpecker/check.yml b/templates/c++-meson/.woodpecker/check.yml new file mode 100644 index 0000000..c3b00ef --- /dev/null +++ b/templates/c++-meson/.woodpecker/check.yml @@ -0,0 +1,26 @@ +labels: + type: exec + +pipeline: +- name: nix flake check + image: bash + commands: + - nix flake check + +- name: notifiy + image: bash + secrets: + - source: matrix_homeserver + target: address + - source: matrix_roomid + target: room + - source: matrix_username + target: user + - source: matrix_password + target: pass + commands: + - nix run '.#matrix-notifier' + when: + status: + - failure + - success diff --git a/templates/c++-meson/flake.nix b/templates/c++-meson/flake.nix new file mode 100644 index 0000000..d62eda2 --- /dev/null +++ b/templates/c++-meson/flake.nix @@ -0,0 +1,112 @@ +{ + description = "A C++ project"; + + inputs = { + futils = { + type = "github"; + owner = "numtide"; + repo = "flake-utils"; + ref = "main"; + }; + + nixpkgs = { + type = "github"; + owner = "NixOS"; + repo = "nixpkgs"; + ref = "nixos-unstable"; + }; + + pre-commit-hooks = { + type = "github"; + owner = "cachix"; + repo = "pre-commit-hooks.nix"; + ref = "master"; + inputs = { + flake-utils.follows = "futils"; + nixpkgs.follows = "nixpkgs"; + }; + }; + }; + + outputs = { self, futils, nixpkgs, pre-commit-hooks }: + { + overlays = { + default = final: prev: { + project = with final; stdenv.mkDerivation { + pname = "project"; + version = "0.0.0"; + + src = self; + + nativeBuildInputs = with pkgs; [ + meson + ninja + pkg-config + ]; + + checkInputs = with pkgs; [ + gtest + ]; + + doCheck = true; + + meta = with lib; { + description = "A C++ project"; + homepage = "https://gitea.belanyi.fr/ambroisie/project"; + license = licenses.mit; + maintainers = with maintainers; [ ambroisie ]; + platforms = platforms.unix; + }; + }; + }; + }; + } // futils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ + self.overlays.default + ]; + }; + + pre-commit = pre-commit-hooks.lib.${system}.run { + src = self; + + hooks = { + nixpkgs-fmt = { + enable = true; + }; + + clang-format = { + enable = true; + }; + }; + }; + in + { + checks = { + inherit (self.packages.${system}) project; + + inherit pre-commit; + }; + + devShells = { + default = pkgs.mkShell { + inputsFrom = with self.packages.${system}; [ + project + ]; + + packages = with pkgs; [ + clang-tools + ]; + + inherit (pre-commit) shellHook; + }; + }; + + packages = futils.lib.flattenTree { + default = pkgs.project; + inherit (pkgs) project; + }; + }); +} diff --git a/templates/c++-meson/meson.build b/templates/c++-meson/meson.build new file mode 100644 index 0000000..bc228c6 --- /dev/null +++ b/templates/c++-meson/meson.build @@ -0,0 +1,13 @@ +project( + 'project', + 'cpp', + version : '0.0.0', + license: 'MIT', + default_options : [ + 'cpp_std=c++20', + 'warning_level=3', + ], +) + +subdir('src') +subdir('tests') diff --git a/templates/c++-meson/src/main.cc b/templates/c++-meson/src/main.cc new file mode 100644 index 0000000..5eb9e4a --- /dev/null +++ b/templates/c++-meson/src/main.cc @@ -0,0 +1,5 @@ +#include + +int main() { + std::cout << "Hello World!\n"; +} diff --git a/templates/c++-meson/src/meson.build b/templates/c++-meson/src/meson.build new file mode 100644 index 0000000..4b2ff23 --- /dev/null +++ b/templates/c++-meson/src/meson.build @@ -0,0 +1,8 @@ +sources = files( + 'main.cc', +) + +executable( + 'project', + sources : sources, +) diff --git a/templates/c++-meson/tests/meson.build b/templates/c++-meson/tests/meson.build new file mode 100644 index 0000000..082b746 --- /dev/null +++ b/templates/c++-meson/tests/meson.build @@ -0,0 +1 @@ +subdir('unit') diff --git a/templates/c++-meson/tests/unit/dummy_test.cc b/templates/c++-meson/tests/unit/dummy_test.cc new file mode 100644 index 0000000..4573678 --- /dev/null +++ b/templates/c++-meson/tests/unit/dummy_test.cc @@ -0,0 +1,5 @@ +#include + +TEST(misc, passing) { + ASSERT_EQ(1, 1); +} diff --git a/templates/c++-meson/tests/unit/meson.build b/templates/c++-meson/tests/unit/meson.build new file mode 100644 index 0000000..44c8a92 --- /dev/null +++ b/templates/c++-meson/tests/unit/meson.build @@ -0,0 +1,13 @@ +gtest_dep = dependency( + 'gtest', + main : true, + required : false, +) + +dummy_test = executable( + 'dummy_test', + 'dummy_test.cc', + dependencies : gtest_dep, +) + +test('dummy test', dummy_test) diff --git a/templates/default.nix b/templates/default.nix index 60671f9..f58fd72 100644 --- a/templates/default.nix +++ b/templates/default.nix @@ -3,4 +3,8 @@ path = ./c++-cmake; description = "A C++ project using CMake"; }; + "c++-meson" = { + path = ./c++-meson; + description = "A C++ project using CMake"; + }; }