Cabal; non-Nix support

This commit is contained in:
mtgmonkey
2025-12-13 19:22:42 +01:00
parent 73985e298a
commit e9b4e2d34a
8 changed files with 143 additions and 119 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
dist-newstyle
result

View File

@@ -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 - use `Double` rather than `FLoat` for internal calculations
- `cursorPos`, `dt` natively `Double` already - `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 ## [0.2.1] - 2025-12-08
### Changed ### Changed

View File

@@ -1,21 +1,30 @@
to run: see CHANGELOG.md
```bash to run without nix:
git clone https://git.mtgmonkey.net/Andromeda/hs-game - get build tools:
cd hs-game - with apt: `apt install cabal-install ghc git`
nix run - 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: to release:
- update CHANGELOG.md with new version
```bash - update version in hs-game.cabal
nix build .#release - update version in flake.nix
``` - check that it builds
- `git add -A`
to debug build: - `git status` make sure there aren't random files
- `git status -v` make sure all additions are in CHANGELOG.md
```bash - double check that flake, .cabal, and CHANGELOG.md all have the same version
nix build .#debug - release
```
todo moved to CHANGELOG.md

113
flake.nix
View File

@@ -2,70 +2,63 @@
inputs = { inputs = {
nixpkgs.url = "nixpkgs/nixpkgs-unstable"; 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"; system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system}; 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 { in {
packages.${system} = { packages.${system} = {
debug = pkgs.callPackage ./package.nix { default =
ghcOptions = debugGhcOptions; pkgs.haskellPackages.callPackage package {};
haddockOptions = noHaddockOptions; };
inherit ghcPackages; devShells.${system} = {
}; default = pkgs.mkShell {
release = pkgs.callPackage ./package.nix { packages = [
ghcOptions = releaseGhcOptions; pkgs.cabal-install
haddockOptions = noHaddockOptions; pkgs.libGL
inherit ghcPackages; pkgs.xorg.libX11
}; pkgs.xorg.libXi
docs = pkgs.callPackage ./package.nix { pkgs.xorg.libXrandr
ghcOptions = "--version"; pkgs.xorg.libXxf86vm
inherit haddockOptions; pkgs.xorg.libXcursor
inherit ghcPackages; pkgs.xorg.libXinerama
}; pkgs.libGLU
default = pkgs.callPackage ./package.nix { ];
ghcOptions = releaseGhcOptions; inputsFrom = [
inherit haddockOptions; self.packages.${system}.default
inherit ghcPackages; ];
}; };
}; };
}; };

38
hs-game.cabal Normal file
View File

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

View File

@@ -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"];
};
}

View File

@@ -208,7 +208,7 @@ applyToTuples f (x, y) (a, b) = (f x a, f y b)
updateCursorPos :: Double -> Double -> Model -> Model updateCursorPos :: Double -> Double -> Model -> Model
updateCursorPos x y model = updateCursorPos x y model =
let 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 in
if pyth < 16 then if pyth < 16 then
model model

View File

@@ -7,7 +7,7 @@
- Maintainer : Matrix @Andromeda:tchncs.de - Maintainer : Matrix @Andromeda:tchncs.de
- Stability : Experimental - Stability : Experimental
-} -}
module Game (main) where module Main (main) where
import Game.Internal.Types import Game.Internal.Types
import Game.Internal import Game.Internal