From e9b4e2d34af8f0ea4a54d8d093108cdfdc68757c Mon Sep 17 00:00:00 2001 From: mtgmonkey Date: Sat, 13 Dec 2025 19:22:42 +0100 Subject: [PATCH] Cabal; non-Nix support --- .gitignore | 2 + CHANGELOG.md | 21 ++++++++ README.md | 45 +++++++++------- flake.nix | 113 ++++++++++++++++++--------------------- hs-game.cabal | 38 +++++++++++++ package.nix | 39 -------------- src/Game/Internal.hs | 2 +- src/{Game.hs => Main.hs} | 2 +- 8 files changed, 143 insertions(+), 119 deletions(-) create mode 100644 .gitignore create mode 100644 hs-game.cabal delete mode 100644 package.nix rename src/{Game.hs => Main.hs} (99%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bd4112d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +dist-newstyle +result diff --git a/CHANGELOG.md b/CHANGELOG.md index afb9ca7..5db8649 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - use `Double` rather than `FLoat` for internal calculations - `cursorPos`, `dt` natively `Double` already +## [0.3.0] - 2025-12-08 + +### Added + +- Cabal build system +- `.gitignore` against build artifacts + +### Changed + +- versioning using the [PVP standard](https://pvp.haskell.org/), though it will remain SemVer compliant + - SemVer version A.B.C will become PVP version A.B.C.0 +- `README.md` overhauled to reflect new build system + +### Fixed + +- a couple non-impactful typos + +### Removed + +- `Game` module -> moved to `Main` + ## [0.2.1] - 2025-12-08 ### Changed diff --git a/README.md b/README.md index 9c5c051..c3065c4 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,30 @@ -to run: +see CHANGELOG.md -```bash -git clone https://git.mtgmonkey.net/Andromeda/hs-game -cd hs-game -nix run -``` +to run without nix: +- get build tools: + - with apt: `apt install cabal-install ghc git` +- get source code: `git clone https://git.mtgmonkey.net/Andromeda/hs-game --depth 1; cd hs-game` +- get dependencies + - with apt on x86-64: `apt install g++-x86-64_linux-gnu libgl-dev libx11-dev libxi-dev libxrandr-dev libxxf86vm-dev libxcursor-dev libxinerama-dev libglu1-mesa-dev` +- run with `cabal run` or build with `cabal build` + +to run with nix: +`nix run git+https://git.mtgmonkey.net/Andromeda/hs-game` + +to enter nix development shell: +`nix develop git+https://git.mtgmonkey.net/Andromeda/hs-game` + +build tested on +- nix +- Kubuntu 25.10 to release: - -```bash -nix build .#release -``` - -to debug build: - -```bash -nix build .#debug -``` - -todo moved to CHANGELOG.md +- update CHANGELOG.md with new version +- update version in hs-game.cabal +- update version in flake.nix +- check that it builds +- `git add -A` +- `git status` make sure there aren't random files +- `git status -v` make sure all additions are in CHANGELOG.md +- double check that flake, .cabal, and CHANGELOG.md all have the same version +- release diff --git a/flake.nix b/flake.nix index 6468b28..90a80c5 100644 --- a/flake.nix +++ b/flake.nix @@ -2,70 +2,63 @@ inputs = { nixpkgs.url = "nixpkgs/nixpkgs-unstable"; }; - outputs = {nixpkgs, ...}: let + outputs = { + nixpkgs, + self, + ... + }: let + versionString = "0.3.0"; + package = { + mkDerivation, + base, + bytestring, + GLFW-b, + lens, + lib, + linear, + OpenGL, + }: + mkDerivation { + pname = "hs-game"; + version = versionString; + src = ./.; + isLibrary = false; + isExecutable = true; + executableHaskellDepends = [ + base + bytestring + GLFW-b + lens + linear + OpenGL + ]; + homepage = "https://git.mtgmonkey.net/Andromeda/hs-game"; + license = lib.licenses.bsd3; + mainProgram = "hs-game"; + }; system = "x86_64-linux"; pkgs = nixpkgs.legacyPackages.${system}; - debugGhcOptions = pkgs.lib.concatStringsSep " " (debugGhcFlags ++ commonGhcFlags); - debugGhcFlags = [ - "-O0" - "-Wall" - "-Widentities" - "-Wincomplete-record-updates" - "-Wincomplete-uni-patterns" - # "-Wmissing-export-lists" - "-Wmissing-home-modules" - "-Wpartial-fields" - "-Wredundant-constraints" - "-threaded" - "-rtsopts" - "-with-rtsopts=-N" - "-main-is Game" - ]; - haddockOptions = pkgs.lib.concatStringsSep " " haddockFlags; - haddockFlags = [ - "--html" - "--odir docs" - "--optghc=-i./src" - "src/Game.hs" - ]; - releaseGhcOptions = pkgs.lib.concatStringsSep " " (releaseGhcFlags ++ commonGhcFlags); - releaseGhcFlags = [ - "-O2" - "-threaded" - "-rtsopts" - "-with-rtsopts=-N" - "-main-is Game" - ]; - noHaddockOptions = ""; - commonGhcFlags = [ - "-i./src" - ]; - ghcPackages = p: [ - p.GLFW-b - p.linear - p.OpenGL - ]; in { packages.${system} = { - debug = pkgs.callPackage ./package.nix { - ghcOptions = debugGhcOptions; - haddockOptions = noHaddockOptions; - inherit ghcPackages; - }; - release = pkgs.callPackage ./package.nix { - ghcOptions = releaseGhcOptions; - haddockOptions = noHaddockOptions; - inherit ghcPackages; - }; - docs = pkgs.callPackage ./package.nix { - ghcOptions = "--version"; - inherit haddockOptions; - inherit ghcPackages; - }; - default = pkgs.callPackage ./package.nix { - ghcOptions = releaseGhcOptions; - inherit haddockOptions; - inherit ghcPackages; + default = + pkgs.haskellPackages.callPackage package {}; + }; + devShells.${system} = { + default = pkgs.mkShell { + packages = [ + pkgs.cabal-install + pkgs.libGL + pkgs.xorg.libX11 + pkgs.xorg.libXi + pkgs.xorg.libXrandr + pkgs.xorg.libXxf86vm + pkgs.xorg.libXcursor + pkgs.xorg.libXinerama + pkgs.libGLU + ]; + inputsFrom = [ + self.packages.${system}.default + ]; }; }; }; diff --git a/hs-game.cabal b/hs-game.cabal new file mode 100644 index 0000000..c38218a --- /dev/null +++ b/hs-game.cabal @@ -0,0 +1,38 @@ +cabal-version: 3.0 +name: hs-game +version: 0.3.0 +-- synopsis: +-- description: +homepage: https://git.mtgmonkey.net/Andromeda/hs-game +license: BSD-3-Clause +license-file: LICENSE +author: andromeda +maintainer: @andromeda:tchncs.de +-- copyright: +category: Game +build-type: Simple +extra-doc-files: CHANGELOG.md +-- extra-source-files: + +common warnings + ghc-options: -Wall + +common optimizations + ghc-options: -O2 + +executable hs-game + import: optimizations + main-is: Main.hs + other-modules: + Game.Internal, + Game.Internal.LoadShaders, + Game.Internal.Types + -- other-extensions: + build-depends: + base >= 4.18, + bytestring >= 0.12, + GLFW-b >= 3.3, + lens >= 5.3, + linear >= 1.23, + OpenGL >= 3.0, + hs-source-dirs: src diff --git a/package.nix b/package.nix deleted file mode 100644 index 1b6f738..0000000 --- a/package.nix +++ /dev/null @@ -1,39 +0,0 @@ -{ - haskellPackages, - lib, - stdenv, - ghcOptions, - haddockOptions, - ghcPackages, - ... -}: -stdenv.mkDerivation { - pname = "hs-game"; - version = "0.1.0"; - src = ./.; - nativeBuildInputs = [ - (haskellPackages.ghcWithPackages ghcPackages) - ]; - buildInputs = [ - ]; - configurePhase = '' - ''; - buildPhase = '' - touch Main - ghc ${ghcOptions} ./src/Game.hs -o ./Main - mkdir ./docs - haddock ${haddockOptions} - ''; - installPhase = '' - mkdir -p $out/bin - cp ./Main $out/bin/hs-game - cp ./docs $out/docs -r - ''; - - meta = { - homepage = "https://mtgmonkey.net"; - license = lib.licenses.bsd3; - mainProgram = "hs-game"; - platforms = ["x86_64-linux"]; - }; -} diff --git a/src/Game/Internal.hs b/src/Game/Internal.hs index 61832a9..3461d27 100644 --- a/src/Game/Internal.hs +++ b/src/Game/Internal.hs @@ -208,7 +208,7 @@ applyToTuples f (x, y) (a, b) = (f x a, f y b) updateCursorPos :: Double -> Double -> Model -> Model updateCursorPos x y model = let - pyth = (((fst model.cursorPos) - x) ** 2 + ((snd model.cursorPos - y)) ** 2) ** 0.5 + pyth = (((fst model.cursorPos) - x) ** 2 + ((snd model.cursorPos) - y) ** 2) ** 0.5 in if pyth < 16 then model diff --git a/src/Game.hs b/src/Main.hs similarity index 99% rename from src/Game.hs rename to src/Main.hs index f120a6f..2a96e89 100644 --- a/src/Game.hs +++ b/src/Main.hs @@ -7,7 +7,7 @@ - Maintainer : Matrix @Andromeda:tchncs.de - Stability : Experimental -} -module Game (main) where +module Main (main) where import Game.Internal.Types import Game.Internal