add library as git submodule, wayland, window shows

This commit is contained in:
mtgmonkey
2025-12-10 21:12:56 +01:00
parent 5e2d2b89c8
commit ab69702910
7 changed files with 53 additions and 14070 deletions

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "lib/RGFW"]
path = lib/RGFW
url = https://github.com/ColleagueRiley/RGFW

View File

@@ -1,6 +1,7 @@
{
inputs = {
nixpkgs.url = "nixpkgs/nixpkgs-unstable";
self.submodules = true;
};
outputs = {nixpkgs, ...}: let
system = "x86_64-linux";
@@ -47,10 +48,6 @@
ghcPackages = p: [
];
buildDeps = [
pkgs.pkg-config
pkgs.wayland-protocols
pkgs.wayland-scanner
pkgs.egl-wayland
pkgs.libGL
pkgs.libxkbcommon
@@ -60,6 +57,12 @@
pkgs.xorg.libXi
pkgs.xorg.libXrandr
];
runtimeDeps = [
pkgs.makeWrapper
pkgs.pkg-config
pkgs.wayland-protocols
pkgs.wayland-scanner
];
in {
packages.${system} = {
debug = pkgs.callPackage ./package.nix {
@@ -67,24 +70,28 @@
haddockOptions = noHaddockOptions;
inherit ghcPackages;
inherit buildDeps;
inherit runtimeDeps;
};
release = pkgs.callPackage ./package.nix {
ghcOptions = releaseGhcOptions;
haddockOptions = noHaddockOptions;
inherit ghcPackages;
inherit buildDeps;
inherit runtimeDeps;
};
docs = pkgs.callPackage ./package.nix {
ghcOptions = "--version";
inherit haddockOptions;
inherit ghcPackages;
inherit buildDeps;
inherit runtimeDeps;
};
default = pkgs.callPackage ./package.nix {
ghcOptions = releaseGhcOptions;
inherit haddockOptions;
inherit ghcPackages;
inherit buildDeps;
inherit runtimeDeps;
};
};
};

1
lib/RGFW Submodule

Submodule lib/RGFW added at b7bd582eb3

14040
lib/RGFW.h

File diff suppressed because it is too large Load Diff

16
lib/RGFW_HS.h Normal file
View File

@@ -0,0 +1,16 @@
#ifndef RGFW_HS // avoid repeated imports
#define RGFW_HS
// TODO add actual include logic
#define RGFW_IMPLEMENTATION
#define RGFW_DEBUG
#define RGFW_X11
#define RGFW_WAYLAND
#define RGFW_OPENGL
#define Time X11Time // fixes namespace clash with GHC when building with Nix
#include "RGFW/RGFW.h"
#undef Time
#endif RGFW_HS

View File

@@ -1,5 +1,6 @@
{
buildDeps,
runtimeDeps,
haskellPackages,
lib,
pkgs,
@@ -9,7 +10,7 @@
ghcPackages,
...
}:
stdenv.mkDerivation {
stdenv.mkDerivation rec {
pname = "hs-rgfw";
version = "0.1.0";
src = ./.;
@@ -17,11 +18,11 @@ stdenv.mkDerivation {
[
(haskellPackages.ghcWithPackages ghcPackages)
]
++ buildDeps;
++ buildDeps ++ runtimeDeps;
buildInputs =
[
]
++ buildDeps;
++ runtimeDeps;
configurePhase = ''
export PKG_CONFIG_PATH=/run/current-system/sw/lib/pkgconfig
@@ -43,7 +44,7 @@ stdenv.mkDerivation {
'';
buildPhase = ''
mkdir src/lib
cp lib/* src/lib/
cp -r lib/* src/lib/
cp ccode/*.c ./
ghc ${ghcOptions} ./src/Main.hs -o ./Main $(pkg-config --cflags --libs gl wayland-client wayland-egl wayland-cursor xkbcommon x11 xcursor xrandr xi) -I./headers/ $(ls *.c)
mkdir ./docs
@@ -53,6 +54,7 @@ stdenv.mkDerivation {
mkdir -p $out/bin
cp ./Main $out/bin/hs-rgfw
cp ./docs $out/docs -r
wrapProgram "$out/bin/${meta.mainProgram}" --prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath buildInputs}"
'';
meta = {

View File

@@ -21,25 +21,19 @@ main = do
800
600
$ mkWindowFlags
[ WindowCenter
, WindowNoResize
[ WindowNoResize
, WindowOpenGL
, WindowFullscreen
]
)
let loop = do
putStrLn $ show window
putStrLn
$ show
$ mkWindowFlags
[ WindowCenter
, WindowNoResize
, WindowOpenGL
]
let loop ctr = do
shouldClose <- rgfwWindowShouldClose window
if 0 == shouldClose
then return ()
else loop
loop
if 0 /= shouldClose
then return shouldClose
else loop $ ctr + 1
exitCode <- loop 0
putStrLn $ show exitCode
return ()
--------------------------------------------------------------------------------
-- Haskell-ier abstractions
@@ -107,15 +101,15 @@ type RGFWwindowFlags = Word32
type RGFWbool = CUInt
foreign import capi "lib/RGFW.h RGFW_createWindow" rgfwCreateWindow
:: CString
-> Int32
-> Int32
-> Int32
-> Int32
foreign import capi "lib/RGFW_HS.h RGFW_createWindow" rgfwCreateWindow
:: Ptr CChar
-> CInt
-> CInt
-> CInt
-> CInt
-> RGFWwindowFlags
-> IO RGFWwindowPtr
foreign import capi "lib/RGFW.h RGFW_window_shouldClose" rgfwWindowShouldClose
foreign import capi "lib/RGFW_HS.h RGFW_window_shouldClose" rgfwWindowShouldClose
:: RGFWwindowPtr
-> IO RGFWbool