From bd99baf876d4881a6699e320a040c61e929a68c2 Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Thu, 17 Oct 2024 22:24:58 -0700 Subject: [PATCH] core: project setup --- .clang-format | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ .clang-tidy | 57 ++++++++++++++++++++++++++++++++++++++++++ .editorconfig | 14 +++++++++++ .gitignore | 8 ++++++ CMakeLists.txt | 16 ++++++++++++ LICENSE | 28 +++++++++++++++++++++ Makefile | 24 ++++++++++++++++++ VERSION | 1 + flake.lock | 43 ++++++++++++++++++++++++++++++++ flake.nix | 39 +++++++++++++++++++++++++++++ nix/default.nix | 37 +++++++++++++++++++++++++++ nix/overlays.nix | 23 +++++++++++++++++ nix/shell.nix | 21 ++++++++++++++++ 13 files changed, 376 insertions(+) create mode 100644 .clang-format create mode 100644 .clang-tidy create mode 100644 .editorconfig create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 VERSION create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 nix/default.nix create mode 100644 nix/overlays.nix create mode 100644 nix/shell.nix diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..f521c55 --- /dev/null +++ b/.clang-format @@ -0,0 +1,65 @@ +--- +Language: Cpp +BasedOnStyle: LLVM + +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignConsecutiveMacros: true +AlignConsecutiveAssignments: true +AlignEscapedNewlines: Right +AlignOperands: false +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllConstructorInitializersOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: true +AllowShortCaseLabelsOnASingleLine: true +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: Yes +BreakBeforeBraces: Attach +BreakBeforeTernaryOperators: false +BreakConstructorInitializers: AfterColon +ColumnLimit: 100 +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: false +IncludeBlocks: Preserve +IndentCaseLabels: true +IndentWidth: 4 +PointerAlignment: Left +ReflowComments: false +SortIncludes: false +SortUsingDeclarations: false +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInContainerLiterals: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Auto +TabWidth: 4 +UseTab: Never + +AllowShortEnumsOnASingleLine: false + +BraceWrapping: + AfterEnum: false + +AlignConsecutiveDeclarations: AcrossEmptyLines + +NamespaceIndentation: All diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..c6fe532 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,57 @@ +WarningsAsErrors: '*' +HeaderFilterRegex: '.*\.hpp' +FormatStyle: file +Checks: > + -*, + bugprone-*, + -bugprone-easily-swappable-parameters, + -bugprone-forward-declararion-namespace, + concurrency-*, + cppcoreguidelines-*, + -cppcoreguidelines-owning-memory, + -cppcoreguidelines-avoid-magic-numbers, + -cppcoreguidelines-pro-bounds-constant-array-index, + -cppcoreguidelines-avoid-const-or-ref-data-members, + -cppcoreguidelines-non-private-member-variables-in-classes, + -cppcoreguidelines-pro-bounds-array-to-pointer-decay, + -cppcoreguidelines-avoid-do-while, + google-build-using-namespace. + google-explicit-constructor, + google-global-names-in-headers, + google-readability-casting, + google-runtime-int, + google-runtime-operator, + misc-*, + -misc-no-recursion, + -misc-non-private-member-variables-in-classes, + modernize-*, + -modernize-return-braced-init-list, + -modernize-use-trailing-return-type, + performance-*, + portability-std-allocator-const, + readability-*, + -readability-function-cognitive-complexity, + -readability-function-size, + -readability-identifier-length, + -readability-magic-numbers, + -readability-uppercase-literal-suffix, + -readability-braces-around-statements, + -readability-redundant-access-specifiers, + -readability-else-after-return, + -readability-container-data-pointer, + -readability-implicit-bool-conversion, + tidyfox-*, +CheckOptions: + performance-for-range-copy.WarnOnAllAutoCopies: true + performance-inefficient-string-concatenation.StrictMode: true + readability-identifier-naming.ClassCase: CamelCase + readability-identifier-naming.ConstantCase: UPPER_CASE + readability-identifier-naming.EnumCase: CamelCase + readability-identifier-naming.EnumConstantCase: CamelCase + readability-identifier-naming.FunctionCase: camelBack + readability-identifier-naming.MemberCase: camelBack + readability-identifier-naming.NamespaceCase: lower_case + readability-identifier-naming.LocalConstantCase: camelBack + readability-identifier-naming.MethodCase: camelBack + readability-identifier-naming.ParameterCase: camelBack + readability-identifier-naming.VariableCase: camelBack diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..4d5d744 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,14 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 4 + +[*.qml,*.nix] +indent_size = 2 + +[Makefile] +indent_style = tab diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a836909 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +# build +/build +/result +compile_commands.json + +# direnv +/.direnv +/.envrc diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..d2f0cde --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.20) +include(GNUInstallDirs) + +# Get version +file(READ "${CMAKE_SOURCE_DIR}/VERSION" VER_RAW) +string(STRIP ${VER_RAW} VER) + +project(hyprland-qt-support VERSION ${VER} LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +find_package(Qt6 6.6 REQUIRED COMPONENTS Qml Quick QuickControls2) + +qt_standard_project_setup(REQUIRES 6.6) +set(QT_QML_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/qml) diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d405623 --- /dev/null +++ b/LICENSE @@ -0,0 +1,28 @@ +BSD 3-Clause License + +Copyright (c) 2024, Hypr Development + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..96fd29c --- /dev/null +++ b/Makefile @@ -0,0 +1,24 @@ +.PHONY: all +all: build + cmake --build build + +build: + cmake -GNinja -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo + +.PHONY: dev +dev: + CMAKE_EXPORT_COMPILE_COMMANDS=1 cmake -GNinja -B build -DCMAKE_BUILD_TYPE=Debug + ln -sf build/compile_commands.json . + +.PHONY: fmt +fmt: + find src -type f \( -name "*.cpp" -o -name "*.hpp" \) -print0 | xargs -0 clang-format -i + +.PHONY: lint +lint: + find src -type f -name "*.cpp" -print0 | parallel -q0 --eta clang-tidy + +.PHONY: clean +clean: + rm -rf build + rm -f compile_commands.json diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..8acdd82 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.0.1 diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..76cdf1b --- /dev/null +++ b/flake.lock @@ -0,0 +1,43 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1728888510, + "narHash": "sha256-nsNdSldaAyu6PE3YUA+YQLqUDJh+gRbBooMMekZJwvI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a3c0b3b21515f74fd2665903d4ce6bc4dc81c77c", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "systems": "systems" + } + }, + "systems": { + "locked": { + "lastModified": 1689347949, + "narHash": "sha256-12tWmuL2zgBgZkdoB6qXZsgJEH9LR3oUgpaQq2RbI80=", + "owner": "nix-systems", + "repo": "default-linux", + "rev": "31732fcf5e8fea42e59c2488ad31a0e651500f68", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default-linux", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..7070845 --- /dev/null +++ b/flake.nix @@ -0,0 +1,39 @@ +{ + description = "extra qt support libraries for the hyprland ecosystem"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + systems.url = "github:nix-systems/default-linux"; + }; + + outputs = { + self, + nixpkgs, + systems, + ... + } @ inputs: let + inherit (nixpkgs) lib; + eachSystem = lib.genAttrs (import systems); + pkgsFor = eachSystem ( + system: + import nixpkgs { + localSystem = system; + overlays = [self.overlays.default]; + } + ); + in { + overlays = import ./nix/overlays.nix { inherit inputs self lib; }; + + packages = eachSystem (system: { + default = self.packages.${system}.hyprland-qt-support; + inherit (pkgsFor.${system}) hyprland-qt-support; + }); + + devShells = eachSystem (system: { + default = import ./nix/shell.nix { + pkgs = pkgsFor.${system}; + inherit (pkgsFor.${system}) hyprland-qt-support; + }; + }); + }; +} diff --git a/nix/default.nix b/nix/default.nix new file mode 100644 index 0000000..8ad2f02 --- /dev/null +++ b/nix/default.nix @@ -0,0 +1,37 @@ +{ + lib, + nix-gitignore, + stdenv, + + cmake, + ninja, + qt6, + version ? "0", +}: let + inherit (lib.strings) makeBinPath; +in stdenv.mkDerivation { + pname = "hyprland-qt-support"; + inherit version; + + src = nix-gitignore.gitignoreSource [] ./..; + + nativeBuildInputs = [ + cmake + ninja + qt6.wrapQtAppsHook + ]; + + buildInputs = [ + qt6.qtbase + qt6.qtdeclarative + qt6.qtsvg + qt6.qtwayland + ]; + + meta = { + description = "hyprland-qt-support"; + homepage = "https://github.com/hyprwm/hyprland-qt-support"; + license = lib.licenses.bsd3; + platforms = lib.platforms.linux; + }; +} diff --git a/nix/overlays.nix b/nix/overlays.nix new file mode 100644 index 0000000..aa69d0f --- /dev/null +++ b/nix/overlays.nix @@ -0,0 +1,23 @@ +{ + inputs, + self, + lib, +}: let + mkDate = longDate: (lib.concatStringsSep "-" [ + (builtins.substring 0 4 longDate) + (builtins.substring 4 2 longDate) + (builtins.substring 6 2 longDate) + ]); + date = mkDate (self.lastModifiedDate or "19700101"); + version = lib.removeSuffix "\n" (builtins.readFile ../VERSION); +in { + default = self.overlays.hyprland-qt-support; + + hyprland-qt-support = lib.composeManyExtensions [ + (final: prev: { + hyprland-qt-support = final.callPackage ./. { + version = "${version}+date=${date}_${self.shortRev or "dirty"}"; + }; + }) + ]; +} diff --git a/nix/shell.nix b/nix/shell.nix new file mode 100644 index 0000000..76cc31c --- /dev/null +++ b/nix/shell.nix @@ -0,0 +1,21 @@ +{ + pkgs ? import {}, + hyprland-qt-support ? pkgs.callPackage ./default.nix {}, + ... +}: pkgs.mkShell { + inputsFrom = [ hyprland-qt-support ]; + nativeBuildInputs = [ pkgs.clang-tools pkgs.parallel ]; + + shellHook = let + inherit (pkgs.lib.strings) concatMapStringsSep; + qtLibPath = f: concatMapStringsSep ":" f (with pkgs.qt6; [ + qtbase + qtdeclarative + qtwayland + ]); + in '' + # Add Qt-related environment variables. + export QT_PLUGIN_PATH=${qtLibPath (p: "${p}/lib/qt-6/plugins")} + export QML2_IMPORT_PATH=${qtLibPath (p: "${p}/lib/qt-6/qml")} + ''; +}