Skip to content

Commit

Permalink
Support for MacOS (#3)
Browse files Browse the repository at this point in the history
* WIP embed resources

* Dev Update:
- MacOS support
- Flake template
- Documentation

* fix heaps shell

* dev build on linux

* hl builds on Mac M1

* hl runs on Mac M1

* minor cleanup

* Add mention to people who helped

* Add github action check
  • Loading branch information
MadMcCrow committed Nov 8, 2023
1 parent fbc3f9c commit 48ed022
Show file tree
Hide file tree
Showing 15 changed files with 472 additions and 230 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Check

on:
push:
branches: [main]
pull_request:

jobs:
check:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
name: checkout repository
- uses: DeterminateSystems/nix-installer-action@main
name: install nix
- uses: DeterminateSystems/magic-nix-cache-action@main
name: use nix cache
- uses: DeterminateSystems/flake-checker-action@v4
name: check flake lock
- run: nix flake check
name: run compilation checks
45 changes: 11 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,23 @@
# Haxix

a flake to build and run games made with [heaps.io](https://heaps.io/)
A flake to build and run games made with [heaps.io](https://heaps.io/) and possibly other haxe game engines in the future.

# Usage
## Usage

Add this to your flake
See the flake [template](template/flake.nix) for a example on how to use haxix in your own projects.

```nix
{
inputs = {
haxix.url = "github:MadMcCrow/haxix";
# not mandatory but should work just fine :
# haxix.inputs.nixpkgs.follows = "nixpkgs";
...
};
## TODO

outputs = {self, nixpkgs, haxix, ...} : {
packages."x86_64-linux" = {
default = haxix.lib."x86_64-linux".heaps.buildGame {
name = "my-game";
src = self; # or the folder containing the src folder
version = "0.0.1-alpha";
debug = false; # set to true to have debug symbols
release = false; # set to true for compiled to C
};
};
};
}
See [TODO.md](docs/TODO.md). these are the most likely things to be added to the project.

```
## Contribute

# TODO
Any [contribution](docs/CONTRIBUTING.md) welcome. You can contribute on features, documentation, or bug fixes.

- [ ] support packaging resources
- [ ] support other haxe game engines
- [ ] cache build output
- [ ] add flake checks
- [ ] add flake templates
## Licence

# Contribute
Licensed under [MIT](Licence.md)

Any contribution welcome.
## Authors

# Licence
Licensed under [MIT](Licence.md)
See [AUTHORS](docs/AUTHORS.md) for the complete list of people who helped make haxix.
10 changes: 10 additions & 0 deletions docs/AUTHORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Contributors:

[Noé Perard-Gayot](https://github.com/MadMcCrow) - Original flake, maintainer
[Beshoy Kamel](https://github.com/bwkam) - Latest Haxe, and hashlink implementation

# Special Thanks to :
- the nix community and its [unofficial discord](https://discord.gg/NJZ83pdM)
- the haxe community and it's [discord](https://discord.gg/UqzaWntA) :
- Zeta
- logololol
10 changes: 10 additions & 0 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Contributing

## Request support, report a bug, or ask for a feature

Please open an [Issue](https://github.com/MadMcCrow/haxix/issues).

## Propose Changes, Add a feature or improvement

Please open a [PR](https://github.com/MadMcCrow/haxix/pulls).
PRs are the best way of contributing, as I can merge them easily.
14 changes: 14 additions & 0 deletions docs/TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# DONE :

- build and run Heaps games on linux
- build wih latest Haxe, Heaps, etc.
- MacOS (darwin) support
- M1 support (no native heaps game, because HL cannot be built in arm64)
- package haxelibs

# TODO :
- [ ] Other Haxe game engines
- [ ] Godot-Haxe
- [ ] OpenFL
- [ ] Auto-Update through Github Action
- [ ] Clean, remove `_latest` from package names
45 changes: 31 additions & 14 deletions flake.lock

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

70 changes: 46 additions & 24 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
inputs = {
# latest nixpkgs
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";

# MacOS support
nixpkgs-darwin.url = "github:NixOS/nixpkgs/nixpkgs-23.05-darwin";

# haxe : the language
haxe = {
type = "git";
Expand All @@ -29,43 +33,61 @@
};
};

outputs = { self, nixpkgs, ... }@inputs:
outputs = { self, ... }@inputs:
let
# multiplatform support
# only tested on x86_64 linux
systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" ];
forAllSystems = function:
nixpkgs.lib.genAttrs systems
(system: function (import nixpkgs { inherit system; }));
systems = [
"x86_64-linux"
# "aarch64-linux" <- not supported yet
"aarch64-darwin"
"x86_64-darwin"
];
forAllSystems = f: inputs.nixpkgs.lib.genAttrs systems f;

mkAllSystems = set:
forAllSystems (pkgs: builtins.mapAttrs (name: value: value pkgs) set);
# import functions:
haxix = system: (import ./nix { inherit inputs system; });

# sub modules
haxe = pkgs: (import nix/haxe.nix { inherit inputs pkgs; });
heaps = pkgs: (import nix/heaps.nix { inherit inputs pkgs; });

# the game itself
demo = pkgs:
(heaps pkgs).buildGame {
# an example of a game
demo = system:
(haxix system).heaps.mkGame {
name = "helloworld";
src = ./demo;
version = "0.0.1-alpha";
debug = false;
release = false;
native = false;
};

in {
# expose our heaps and haxe functions
lib = mkAllSystems { inherit heaps haxe; };

# add our demo
packages = mkAllSystems rec {
inherit demo;
default = demo;
};
# template for heaps projects :
templates.default = {
path = ./template;
description = "A simple haxe game project";
welcomeText = "";
};

# expose functions :
lib = forAllSystems (system: {
mkHaxelib = (haxix system).haxelib.mkHaxelib;
mkHeapsGame = (haxix system).heaps.mkGame;
mkHeapsShell = (haxix system).heaps.mkShell;
});

# All important packages and the demo
packages = forAllSystems (system: {
haxe = (haxix system).haxe.haxe_latest;
hashlink = (haxix system).hashlink.hashlink_latest;
demo = demo system;
});

# checks
# TODO : improve to only build minimal checks
checks = forAllSystems (system: {
demo = demo system;
});

# shell for the demo
devShells = mkAllSystems { default = pkgs: (heaps pkgs).mkShell (demo pkgs); };
devShells = forAllSystems
(system: { default = (haxix system).heaps.mkShell (demo system); });
};
}
25 changes: 25 additions & 0 deletions nix/darwin/hashlink.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# darwin/hashlink.nix
# Hashlink interpreter for haxe, on MacOS.
# only intel Mac supported, uses rosetta to run on M1
pkgs :
let
# we need objective-C
objc = with pkgs.darwin; [ apple_sdk_11_0.objc4 libobjc ];
# we support platform
meta = pkgs.hashlink.meta // { platforms = pkgs.lib.platforms.darwin; };
# make Flags to detect objective C
ObjCmakeFlags = let
concatObjc = dir:
builtins.concatStringsSep "," (map (x: "${x}/${dir}") objc);
in [ "CPATH=${concatObjc "include"}" "LIBRARY_PATH=${concatObjc "lib"}" ];

# implementation :
in (finalAttrs: previousAttrs:{
inherit meta;
buildInputs = (previousAttrs.buildInputs or []) ++ objc;
makeFlags = (previousAttrs.makeFlags or []) ++ ObjCmakeFlags;
postFixup = (previousAttrs.postFixup or "") +
''
install_name_tool -add_rpath $out/lib $out/bin/hl
'';
})
52 changes: 52 additions & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# default.nix
# expose every function/derivations here
# also detect linux/MacOS and give the correct version
{ inputs, system }:
with builtins;
let
inherit (inputs.nixpkgs.lib) platforms;

systemSwitch = linux: darwin:
if elem system platforms.darwin then darwin
else if elem system platforms.linux then linux
else throw "unsupported system";

# nixpkgs : support MacOS
nixpkgs = systemSwitch inputs.nixpkgs inputs.nixpkgs-darwin;
pkgs = import nixpkgs { system = systemSwitch "x86_64-linux" "x86_64-darwin"; };

# haxe language and compiler
# does not build in aaarch64-darwin
haxe = import ./haxe.nix {
inherit pkgs;
inherit (inputs) haxe;
};

# a way to install haxelibs
haxelib = import ./haxelib.nix { inherit pkgs; };

# format library
format = import ./format.nix {
inherit pkgs;
inherit (inputs) haxe_format;
};

# hashlink interpreter
# does not build in aaarch64-darwin
hashlink = import ./hashlink.nix {
inherit pkgs;
inherit haxelib;
inherit (inputs) hashlink;
};

# Heaps game engine
# does not build in aaarch64-darwin because of hashlink
heaps = import ./heaps.nix {
inherit pkgs haxelib;
inherit (inputs) heaps;
inherit (haxe) haxe_latest;
inherit (format) format_latest;
inherit (hashlink) hashlink_latest;
};

in { inherit haxe hashlink heaps format; }
Loading

0 comments on commit 48ed022

Please sign in to comment.