Skip to content

Commit

Permalink
feat(#34): raygui nix support, raygui example
Browse files Browse the repository at this point in the history
  • Loading branch information
Anut-py committed Jan 30, 2024
1 parent edaa5a5 commit 9b81b92
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 44 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# Cabal output
dist-newstyle/

# Nix output
result

# Miscellaneous development files (scratch files)
other/

# IDE files
.vscode/
hie.yaml
18 changes: 13 additions & 5 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ mkDerivation, base, containers, exceptions, lens, lib, libGL
, libX11, libXcursor, libXext, libXi, libXinerama, libXrandr, raylib, ...
{ mkDerivation, base, containers, exceptions, lens, template-haskell, text, bytestring
, lib, libGL, libX11, libXcursor, libXext, libXi, libXinerama, libXrandr, raylib, raygui, ...
}:
mkDerivation {
pname = "h-raylib";
Expand All @@ -8,11 +8,19 @@ mkDerivation {
isLibrary = true;
isExecutable = true;
configureFlags = [
"-fplatform-nixos"
"-f-detect-platform -fplatform-nixos"
];
libraryHaskellDepends = [ base containers exceptions lens ];
libraryHaskellDepends = [ base containers exceptions lens template-haskell text bytestring ];
librarySystemDepends = [
libGL libX11 libXcursor libXext libXi libXinerama libXrandr raylib
libGL
libX11
libXcursor
libXext
libXi
libXinerama
libXrandr
raylib
raygui
];
description = "Raylib bindings for Haskell";
license = lib.licenses.asl20;
Expand Down
18 changes: 13 additions & 5 deletions default.nix.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ mkDerivation, base, containers, exceptions, lens, lib, libGL
, libX11, libXcursor, libXext, libXi, libXinerama, libXrandr, raylib, ...
{ mkDerivation, base, containers, exceptions, lens, template-haskell, text, bytestring
, lib, libGL, libX11, libXcursor, libXext, libXi, libXinerama, libXrandr, raylib, raygui, ...
}:
mkDerivation {
pname = "h-raylib";
Expand All @@ -8,11 +8,19 @@ mkDerivation {
isLibrary = true;
isExecutable = true;
configureFlags = [
"-fplatform-nixos"
"-f-detect-platform -fplatform-nixos"
];
libraryHaskellDepends = [ base containers exceptions lens ];
libraryHaskellDepends = [ base containers exceptions lens template-haskell text bytestring ];
librarySystemDepends = [
libGL libX11 libXcursor libXext libXi libXinerama libXrandr raylib
libGL
libX11
libXcursor
libXext
libXi
libXinerama
libXrandr
raylib
raygui
];
description = "Raylib bindings for Haskell";
license = lib.licenses.asl20;
Expand Down
48 changes: 32 additions & 16 deletions devtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,23 +145,31 @@ if (process.argv.includes("-u") || process.argv.includes("--nix-update")) {
log(logLevel.INFO, "Using nix path: " + nixPath);
log(logLevel.INFO, "Using git path: " + gitPath);

log(logLevel.VERB, "Fetching git revision");
log(logLevel.VERB, "Fetching git revisions");

const gitOutput = exec(`cd raylib && ${gitPath} rev-parse HEAD`);
const revision = gitOutput.split("\n")[0];
const raylibGitOutput = exec(`cd raylib && ${gitPath} rev-parse HEAD`);
const raylibRevision = raylibGitOutput.split("\n")[0];

log(logLevel.VERB, "Found raylib revision: " + raylibRevision);

const rayguiGitOutput = exec(`cd raygui && ${gitPath} rev-parse HEAD`);
const rayguiRevision = rayguiGitOutput.split("\n")[0];

log(logLevel.VERB, "Found raygui revision: " + rayguiRevision);

log(logLevel.VERB, "Found revision: " + revision);
log(logLevel.VERB, "Fetching h-raylib version");
log(logLevel.INFO, "h-raylib version " + hraylibVersion);

const flakeUpdated = readFileSync(
const flakeNixRaw = readFileSync(
path.join(__dirname, "flake.nix")
).includes(revision);
);

const flakeUpdatedRaylib = flakeNixRaw.includes(`rev = "${raylibRevision}"`);
const flakeUpdatedRaygui = flakeNixRaw.includes(`rev = "${rayguiRevision}"`);
const defaultUpdated = readFileSync(
path.join(__dirname, "default.nix")
).includes(hraylibVersion);
).includes(`version = "${hraylibVersion}"`);

if (flakeUpdated && defaultUpdated) {
if (flakeUpdatedRaylib && flakeUpdatedRaygui && defaultUpdated) {
log(logLevel.INFO, "The flake is already up to date");
process.exitCode = 0;
return;
Expand All @@ -173,12 +181,17 @@ if (process.argv.includes("-u") || process.argv.includes("--nix-update")) {
force: true
});

if (!flakeUpdated) {
if (!flakeUpdatedRaylib || !flakeUpdatedRaygui) {
log(logLevel.INFO, "Prefetching with nix, this might take a while");

const { hash } = JSON.parse(
const { raylibHash } = JSON.parse(
exec(
`${nixPath} flake prefetch github:raysan5/raylib/${raylibRevision} --extra-experimental-features nix-command --extra-experimental-features flakes --json`
)
);
const { rayguiHash } = JSON.parse(
exec(
`${nixPath} flake prefetch github:raysan5/raylib/${revision} --extra-experimental-features nix-command --extra-experimental-features flakes --json`
`${nixPath} flake prefetch github:raysan5/raygui/${rayguiRevision} --extra-experimental-features nix-command --extra-experimental-features flakes --json`
)
);

Expand All @@ -193,8 +206,10 @@ if (process.argv.includes("-u") || process.argv.includes("--nix-update")) {
path.join(__dirname, "flake.nix.template")
)
.toString()
.replace("REVISION", revision)
.replace("HASH", hash);
.replace("RAYLIB_REVISION", raylibRevision)
.replace("RAYLIB_HASH", raylibHash)
.replace("RAYGUI_REVISION", rayguiRevision)
.replace("RAYGUI_HASH", rayguiHash);
writeFileSync(path.join(__dirname, "flake.nix"), flakeTemplate);

log(logLevel.INFO, "Successfully updated flake.nix");
Expand Down Expand Up @@ -239,7 +254,7 @@ if (process.argv.includes("-u") || process.argv.includes("--nix-update")) {
) {
diffWithRemote("raylib");
} else if (
process.argv.includes("-g") ||
process.argv.includes("-gd") ||
process.argv.includes("--raygui-diff")
) {
diffWithRemote("raygui");
Expand Down Expand Up @@ -316,7 +331,8 @@ This script contains useful tools for h-raylib development
--raylib-diff
--nix-update
--raygui-diff Diff the local raygui source with the latest remote code
-gd Diff the local raygui source with the latest remote code
--raygui-diff
-p Package the cabal project and run the examples
--package
Expand Down
28 changes: 28 additions & 0 deletions examples/raygui-suite/src/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{-# OPTIONS -Wall #-}
module Main where

import Raylib.Core (clearBackground)
import Raylib.Core.Text (drawText)

Check warning on line 5 in examples/raygui-suite/src/Main.hs

View workflow job for this annotation

GitHub Actions / GHC 9.8 on ubuntu-latest

The import of ‘Raylib.Core.Text’ is redundant

Check warning on line 5 in examples/raygui-suite/src/Main.hs

View workflow job for this annotation

GitHub Actions / GHC 9.2 on ubuntu-latest

The import of ‘Raylib.Core.Text’ is redundant

Check warning on line 5 in examples/raygui-suite/src/Main.hs

View workflow job for this annotation

GitHub Actions / GHC 9.8 on windows-latest

The import of ‘Raylib.Core.Text’ is redundant

Check warning on line 5 in examples/raygui-suite/src/Main.hs

View workflow job for this annotation

GitHub Actions / GHC 9.2 on windows-latest

The import of ‘Raylib.Core.Text’ is redundant

Check warning on line 5 in examples/raygui-suite/src/Main.hs

View workflow job for this annotation

GitHub Actions / GHC 9.8 on macos-latest

The import of ‘Raylib.Core.Text’ is redundant
import Raylib.Util (drawing, whileWindowOpen_, withWindow)
import Raylib.Util.Colors (lightGray, rayWhite)

Check warning on line 7 in examples/raygui-suite/src/Main.hs

View workflow job for this annotation

GitHub Actions / GHC 9.8 on ubuntu-latest

The import of ‘lightGray’

Check warning on line 7 in examples/raygui-suite/src/Main.hs

View workflow job for this annotation

GitHub Actions / GHC 9.2 on ubuntu-latest

The import of ‘lightGray’

Check warning on line 7 in examples/raygui-suite/src/Main.hs

View workflow job for this annotation

GitHub Actions / GHC 9.8 on windows-latest

The import of ‘lightGray’

Check warning on line 7 in examples/raygui-suite/src/Main.hs

View workflow job for this annotation

GitHub Actions / GHC 9.2 on windows-latest

The import of ‘lightGray’

Check warning on line 7 in examples/raygui-suite/src/Main.hs

View workflow job for this annotation

GitHub Actions / GHC 9.8 on macos-latest

The import of ‘lightGray’
import Raylib.Util.GUI (guiLabel, guiSetStyleTextSize)
import Raylib.Types (Rectangle (Rectangle))

main :: IO ()
main = do
withWindow
1000
800
"raylib [raygui] test suite"
60
( \_ -> do
guiSetStyleTextSize 20
whileWindowOpen_
( \_ -> drawing
( do
clearBackground rayWhite

guiLabel (Rectangle 20 20 200 20) "raygui test suite"
) >> return ()
) ()
)
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 14 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,26 @@
(self: super: {
raylib = super.raylib.overrideAttrs (old: {
patches = [];
version = "5.0.0";
src = self.fetchFromGitHub {
owner = "raysan5";
repo = "raylib";
rev = "40f3df5b865eee0cd87a9e4e1347cb04c87841f8";
sha256 = "sha256-yJndpOz1DM9jmroZf5A+82uZ8f6TM+Qraidc9qetvbc=";
};
postFixup = ''
cp ../src/*.h $out/include/
'';
postFixup = "cp ../src/*.h $out/include/";
});
raygui = super.stdenv.mkDerivation { # A bit of a hack to get raygui working
name = "raygui";
src = self.fetchFromGitHub {
owner = "raysan5";
repo = "raygui";
rev = "45e7f967e62088b9fec02ac38c07d4b67d6466b0";
sha256 = "sha256-rt3W8hVAnq4WCnnMFj4sVOq0UjlkglHTKvtMye4w+TA=";
};
nativeBuildInputs = [];
postFixup = "mkdir -p $out/include/ && cp ./src/raygui.h $out/include/";
};
})
];
};
Expand All @@ -43,7 +53,6 @@
buildInputs = with pkgs; [
stdenv.cc
ghc

glfw
cabal-install
xorg.libXinerama
Expand All @@ -52,6 +61,7 @@
xorg.libXi
xorg.libXext
raylib
raygui
];
};
}
Expand Down
22 changes: 16 additions & 6 deletions flake.nix.template
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,26 @@
(self: super: {
raylib = super.raylib.overrideAttrs (old: {
patches = [];
version = "5.0.0";
src = self.fetchFromGitHub {
owner = "raysan5";
repo = "raylib";
rev = "REVISION";
sha256 = "HASH";
rev = "RAYLIB_REVISION";
sha256 = "RAYLIB_HASH";
};
postFixup = ''
cp ../src/*.h $out/include/
'';
postFixup = "cp ../src/*.h $out/include/";
});
raygui = super.stdenv.mkDerivation { # A bit of a hack to get raygui working
name = "raygui";
src = self.fetchFromGitHub {
owner = "raysan5";
repo = "raygui";
rev = "RAYGUI_REVISION";
sha256 = "RAYGUI_HASH";
};
nativeBuildInputs = [];
postFixup = "mkdir -p $out/include/ && cp ./src/raygui.h $out/include/";
};
})
];
};
Expand All @@ -43,7 +53,6 @@
buildInputs = with pkgs; [
stdenv.cc
ghc

glfw
cabal-install
xorg.libXinerama
Expand All @@ -52,6 +61,7 @@
xorg.libXi
xorg.libXext
raylib
raygui
];
};
}
Expand Down
15 changes: 11 additions & 4 deletions h-raylib.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ extra-source-files:
raylib/**/*.c
raylib/**/*.h
raylib/**/*.m
raygui/src/*.h

source-repository head
type: git
Expand Down Expand Up @@ -170,6 +171,12 @@ executable basic-rlgl
hs-source-dirs: examples/basic-rlgl/src
main-is: Main.hs

-- raygui
executable raygui-suite
import: example-options
hs-source-dirs: examples/raygui-suite/src
main-is: Main.hs

library
exposed-modules:
Raylib.Core
Expand Down Expand Up @@ -201,8 +208,8 @@ library
, exceptions >=0.10.4 && <0.10.8
, lens >=4.0 && <5.2.4
, template-haskell >=2.17.0.0 && <2.22.0.0
, text
, bytestring
, text >=2.0 && <2.2
, bytestring >=0.11.0 && <0.13

hs-source-dirs: src
default-language: Haskell2010
Expand Down Expand Up @@ -236,7 +243,7 @@ library
if impl(ghc <9.4.1)
extra-libraries: gcc_eh

elif (flag(platform-linux) || (flag(detect-platform) && os(linux)))
elif ((flag(platform-linux) || (flag(detect-platform) && os(linux))) || flag(platform-nixos))
extra-libraries:
GL
c
Expand All @@ -262,7 +269,7 @@ library
pthread

elif flag(platform-nixos)
pkgconfig-depends: raylib
pkgconfig-depends: raylib, raygui

else

Expand Down
5 changes: 4 additions & 1 deletion run-all-examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ then
then
cabal clean
fi
cabal build -j
cabal build all -j
fi

# core
Expand All @@ -41,3 +41,6 @@ cabal run basic-audio

# rlgl
cabal run basic-rlgl

# raygui
cabal run raygui-suite

0 comments on commit 9b81b92

Please # to comment.