Skip to content

Commit

Permalink
working Heaps Game on MacOS
Browse files Browse the repository at this point in the history
  • Loading branch information
MadMcCrow committed Jul 6, 2024
1 parent 3ad0e59 commit 59c1434
Show file tree
Hide file tree
Showing 20 changed files with 78 additions and 99 deletions.
17 changes: 0 additions & 17 deletions flake.lock

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

6 changes: 1 addition & 5 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@
url = "github:HeapsIO/heaps";
flake = false;
};
# formatter
formatter = {
url = "github:HaxeCheckstyle/haxe-formatter";
flake = false;
};
# raylib source code
raylib = {
url = "github:Raysan5/raylib?ref=refs/tags/5.0";
Expand Down Expand Up @@ -76,6 +71,7 @@
demos = pkgs.callPackage ./demo ({ inherit inputs; } // packages);
in {
legacyPackages."${system}" = packages // demos;
devShell."${system}" = pkgs.callPackage ./pkgs/shell.nix packages;
# checks."${system}" = demos;
# TODO : checks and dev shell
};
Expand Down
2 changes: 1 addition & 1 deletion pkgs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
builtins.foldl' (x: y: lib.recursiveUpdate x (y (x // { inherit inputs; }))) { }
(map (x: (args: callPackage x args)) [
./haxe
./hxcpp
./format
./hashlink
./heaps
./hxcpp
./dox
./haxefmt
./raylib
Expand Down
2 changes: 1 addition & 1 deletion pkgs/dox/generic.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ version, inputs, lib, haxe, ... }:
haxe.buildHaxelib {
libname = "dox";
pname = "dox";
inherit version;
src = inputs.dox;
meta = {
Expand Down
23 changes: 7 additions & 16 deletions pkgs/hashlink/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,11 @@
# hashlink-latest is a virtual machine that can be targeted
# when building haxe code
{ stdenv, buildEnv, callPackage, inputs, haxe, ... }@args:
let
version = "1.14";
# hashlink-latest is different depending on the platform
hl = (if stdenv.isDarwin then
callPackage ./hl-darwin.nix
else
callPackage ./hl.nix) (args // { inherit version; });
in {
hashlink = hl;
#buildEnv {
#name = "hashlink-latest";
#paths = [
# (import ./hlsdl { inherit haxe hl; })
# (import ./hlopenal { inherit haxe hl; })
# ];
#};
let version = "1.14";
in rec {
# three packages
hashlink = callPackage (if stdenv.isDarwin then ./hl-darwin.nix else ./hl.nix)
(args // { inherit version; });
hlsdl = callPackage ./hlsdl.nix (args // { inherit haxe hashlink; });
hlopenal = callPackage ./hlopenal.nix (args // { inherit haxe hashlink; });
}
10 changes: 5 additions & 5 deletions pkgs/hashlink/hl-darwin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ let
builtins.concatStringsSep "," (map (x: "${x}/${dir}") objc);
in [ "CPATH=${concatObjc "include"}" "LIBRARY_PATH=${concatObjc "lib"}" ];
# emulation for m1 macOS
pkgs_eml = import inputs.nixpkgs { system = "x86_64-darwin"; };
pkgs_eml = import inputs.nixpkgs { system = "x86_64-darwin"; };
# implementation :
in pkgs_eml.hashlink.overrideAttrs (finalAttrs : previousAttrs: {
in pkgs_eml.hashlink.overrideAttrs (finalAttrs: previousAttrs: {
inherit version;
src = inputs.hashlink;
buildInputs = previousAttrs.buildInputs ++ [ libpng ] ++ objc;
makeFlags = previousAttrs.makeFlags ++ ObjCmakeFlags;
postFixup = previousAttrs.postFixup + ''
# install_name_tool -add_rpath $out/lib $out/bin/hl
# '';
postFixup = previousAttrs.postFixup + ''
# install_name_tool -add_rpath $out/lib $out/bin/hl
# '';
postInstall = ''
${haxe.installHaxelib {
pname = "${finalAttrs.pname}";
Expand Down
15 changes: 9 additions & 6 deletions pkgs/hashlink/hlopenal.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# openal library for hashlink-latest
{ haxe, hl }:
# openal library for hashlink
{ haxe, hashlink, ... }:
haxe.buildHaxelib {
version = hl.version;
pname = "openal";
src = "${hl.src}/libs/openal";
meta = hl.meta // { description = "openal support for hashlink-latest"; };
version = hashlink.version;
pname = "hlopenal";
src = "${hashlink.src}/libs/openal";
meta = {
inherit (hashlink.meta) license homepage;
description = "openal support for hashlink";
};
}
11 changes: 7 additions & 4 deletions pkgs/hashlink/hlsdl.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# HLSDL library for hl
{ haxe, hl }:
{ haxe, hashlink, ... }:
haxe.buildHaxelib {
version = hl.version;
version = hashlink.version;
pname = "hlsdl";
src = "${hl.src}/libs/sdl";
meta = hl.meta // { description = "sdl2 support for hl"; };
src = "${hashlink.src}/libs/sdl";
meta = {
inherit (hashlink.meta) license homepage;
description = "sdl2 support for hashlink";
};
}
1 change: 0 additions & 1 deletion pkgs/haxe/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
let
haxe = callPackage ./generic.nix {
version = "4.3.4"; # using something else than a number may break packages
src = inputs.haxe;
};
in { haxe = haxe // (callPackage ./lib.nix { inherit haxe; }); }
4 changes: 2 additions & 2 deletions pkgs/haxe/generic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
{ version, src, stdenv, lib, fetchurl, haxe, ocaml-ng, zlib, pcre2, neko
, mbedtls_2, darwin, ... }:
haxe.overrideAttrs (previousAttrs: {
inherit version src;
buildInputs = [ zlib pcre2 neko mbedtls_2 ]
inherit version;
buildInputs = previousAttrs.buildInputs ++ [ zlib pcre2 neko mbedtls_2 ]
++ (with ocaml-ng.ocamlPackages_4_14; [
ocaml
findlib
Expand Down
14 changes: 8 additions & 6 deletions pkgs/haxefmt/default.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{ callPackage, writeShellApplication, inputs, haxe, ... }: rec {
formatter = callPackage ./generic.nix {
inherit haxe;
src = inputs.formatter;
version = "1.15.0";
};
{ callPackage, fetchFromGitHub, writeShellApplication, inputs, haxe, ...
}@args: rec {
# haxelib :
formatter = callPackage ./generic.nix (args // rec {
version = "1.16.0";
sha256 = "sha256-1m4jtZn38dJplH+qG2izirxkn4Cc9pAxv01lJZetd8I=";
});

# command to run in a shell-env
haxefmt = writeShellApplication {
name = "haxefmt";
Expand Down
4 changes: 2 additions & 2 deletions pkgs/haxefmt/generic.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ lib, haxe, src, version, ... }:
{ lib, src, haxe, version, ... }:
haxe.buildHaxelib {
inherit src version;
pname = "haxe-formatter";
pname = "formatter";
meta = {
homepage = "https://github.com/HaxeCheckstyle/haxe-formatter";
description = "A Haxe tool to format haxe code";
Expand Down
4 changes: 2 additions & 2 deletions pkgs/heaps/default.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# heaps/default.nix
# heaps.io is a "game engine" written in haxe
{ callPackage, inputs, hashlink, ... }@args:
{ callPackage, inputs, ... }@args:
let
heaps = callPackage ./generic.nix (args // {
src = inputs.heaps;
version = "2.0.0";
});
in { heaps = heaps // (callPackage ./lib.nix (args // {inherit heaps;})); }
in { heaps = heaps // (callPackage ./lib.nix (args // { inherit heaps; })); }
5 changes: 3 additions & 2 deletions pkgs/heaps/generic.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# heaps/generic.nix
# Build heaps games with nix
# TODO : remove function mkGame from module (move to separate "lib" module)
{ src, version, haxePackages, haxe, format, hashlink, SDL2, openal, ... }:
{ src, version, haxePackages, haxe, format, hashlink, hlsdl, hlopenal, SDL2
, openal, ... }:
haxe.buildHaxelib {
inherit src version;
pname = "heaps";
buildInputs = [ format hashlink SDL2 openal ];
buildInputs = [ format hashlink SDL2 openal hlsdl hlopenal ];
meta = haxePackages.heaps.meta;
}
14 changes: 4 additions & 10 deletions pkgs/heaps/lib.nix
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# heaps/lib.nix
# command to simplify building heaps games on nix
{ lib, stdenv, haxe, hashlink, heaps, ... }: {
buildHeapsGame =
{ compileHxml ? "compile.hxml", ... }@args:
{ lib, stdenv, haxe, format, hashlink, hlopenal, hlsdl, heaps, ... }: {
buildHeapsGame = { compileHxml ? "compile.hxml", ... }@args:
let
name = args.pname or args.name;
# disable HL/C on MacOS M1
DoHLC = if stdenv.isDarwin then "false" else "true";
in stdenv.mkDerivation (args // {
# build inputs
buildInputs = (args.buildInputs or [ ]);
nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [haxe hashlink heaps];
nativeBuildInputs = (args.nativeBuildInputs or [ ])
++ [ haxe format hashlink hlopenal hlsdl heaps ];
# copy source and the hxml
unpackPhase = ''
cp -r $src/* ./
Expand All @@ -20,8 +20,6 @@
${haxe}/bin/haxe ${compileHxml}
OUTHL=$(cat ${compileHxml} | grep '^-hl *[[:graph:]]*.hl' || true)
OUTHL=$(echo $OUTHL | sed 's/-hl[[:space:]]*//g')
ls -la ./build
edefe
OUTC=$(cat ${compileHxml} | grep '^-hl *[[:graph:]]*.c' || true)
OUTC=$(echo $OUTC | sed 's/-hl[[:space:]]*//g')
# build HL/C
Expand All @@ -38,14 +36,10 @@
mkdir -p $out/bin $out/lib
# hl bytecode
echo $OUTHL
ls -la build
defef
if [ -f "$OUTHL" ]; then
cp $OUTHL $out/lib/$(basename $OUTHL)
echo "${hashlink}/bin/hl $out/lib/$(basename $OUTHL)" > $out/bin/${name};
chmod +x $out/bin/${name};
ls $out/bin -la
efergdtg
fi
# native C
if [ -f "$OUTC" ] && ${DoHLC}; then
Expand Down
14 changes: 10 additions & 4 deletions pkgs/raylib/default.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# hxcpp/default.nix
# hxcpp is the cpp exporter for haxe
{ callPackage, inputs, ... }:
{ callPackage, inputs, haxe, ... }:
let
raylib = callPackage ./raylib.nix { inherit inputs; };
raylib-hx = callPackage ./raylib-hx.nix { inherit inputs raylib; };
lib = callPackage ./lib.nix { inherit inputs raylib raylib-hx; };
raylib = callPackage ./raylib.nix {
inherit inputs;
version = "5.0";
};
raylib-hx = callPackage ./raylib-hx.nix {
inherit inputs raylib haxe;
version = "5.0.0";
};
lib = callPackage ./lib.nix { inherit inputs raylib raylib-hx haxe; };
in {
inherit raylib;
raylib-hx = raylib-hx // lib;
Expand Down
6 changes: 3 additions & 3 deletions pkgs/raylib/lib.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{ raylib, raylib-hx, haxe, ... }: {
{ stdenv, raylib, raylib-hx, haxe, ... }: {
buildRaylibHxGame = { src, buildHxml ? "Build.hxml", ... }@args:
pkgs.stdenv.mkDerivation ({
stdenv.mkDerivation ({
inherit src;
unpackPhase = ''
cp -r $src/* ./
'';
# build with haxe compiler
buildPhase = ''
${haxe}/bin/haxe ${compileHxml}
${haxe}/bin/haxe ${buildHxml}
'';
} // args);
}
2 changes: 1 addition & 1 deletion pkgs/raylib/raylib-hx.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ stdenvNoCC.mkDerivation {
fi
${
haxe.installHaxelib {
libname = "raylib-hx";
pname = "raylib-hx";
files = "*";
inherit version;
}
Expand Down
11 changes: 5 additions & 6 deletions pkgs/raylib/raylib.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# raylib/raylib.nix
# raylib source code for raylib-hx
{ raylib, inputs, ... }: {
raylib = raylib.overrideAttrs (previousAttrs: {
version = "5.0";
src = inputs.raylib;
});
}
{ raylib, inputs, ... }:
raylib.overrideAttrs (previousAttrs: {
version = "5.0";
src = inputs.raylib;
})
12 changes: 7 additions & 5 deletions pkgs/shell.nix
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
# make shell with every thing
{ mkShell, haxe, hashlink-latest, format, hxcpp, heaps, formatter, haxefmt, dox, raylib
, raylib-hx, neko, ... }:
{ mkShell, haxe, format, hxcpp, hashlink, hlsdl, hlopenal, heaps, formatter
, haxefmt, dox, raylib, raylib-hx, neko, ... }:
mkShell {
buildInputs = [
haxe
hashlink-latest
format
neko
hxcpp
format
hashlink
hlsdl
hlopenal
heaps
formatter
haxefmt
dox
raylib
raylib-hx
neko
];
}

0 comments on commit 59c1434

Please sign in to comment.