This is a comprehensive guide on how to build hashlink from source for M1 mac and using it to compile your heaps.io game on windows and mac. This does not run .hl, rather, making a heaps project runnable on M1 mac by exporting it to a c project and using gcc to build / compile it.
Before we can use any hashlink related command, we need to build it from source. There's no (not that i know of) easy way to get hashlink other than building it directly from source. So here it goes
- Clone hashlink repo Go to this link : https://github.com/HaxeFoundation/hashlink and clone the repository to one of your folders, preferably named "hashlink"
- Brew bundle
Make sure you have brew installed, open up your terminal and
cdto your hashlink folder (e.gcd Documents/hashlink), then, runbrew bundleto install the necessary files - Modifying makefile
Modify your
Makefileusing your favourite text editor like this:- remove
-msse2and-mfpmath=ssefromCFLAGS - add
-I /opt/homebrew/opt/openal-soft/include -I /opt/homebrew/include/SDL2 -I /opt/homebrew/opt/jpeg-turbo/include -I /opt/homebrew/opt/libpng/include -I /opt/homebrew/opt/libvorbis/include -I /opt/homebrew/opt/libogg/include -I /opt/homebrew/opt/mbedtls@2/include -I /opt/homebrew/opt/libuv/includeto yourCFLAGS - Set your
LIBFLAGSto-L /opt/homebrew/opt/openal-soft/lib -L/opt/homebrew/lib -L/opt/homebrew/opt/jpeg-turbo/lib -L/opt/homebrew/opt/libpng/lib -L/opt/homebrew/opt/libvorbis/lib -L/opt/homebrew/opt/libogg/lib -L/opt/homebrew/opt/mbedtls@2/lib -L/opt/homebrew/opt/libuv/lib - Comment out
# HL_DEBUG = include/mdbg/mdbg.o include/mdbg/mach_excServer.o include/mdbg/mach_excUser.oand# LIB += ${HL_DEBUG} - If you want, you can download the makefile i used in the asset above, or just go here (Untested)
- remove
- Back on your terminal, run
make libhl && make libs, This will give you:libhl.dylib,fmt.hdll,mysql.hdll,openal.hdll,sdl.hdll,ssl.hdll,ui.hdllanduv.hdll - You can also try to use the files from my repository here (Untested)
- Congratulation, you have finished building hashlink libraries, go to the next step
- Go to your heaps project, or create a new one
- Create a new
.hxmlfile, in this case i name itmacos_c.hxml - In your new
.hxmlfile, paste this-cp src -lib heaps -lib hlsdl -hl build/macos/main.c -main Main
- in your project folder, run
haxe macos_c.hxml, if you encounter aError: Library hashlink is not installedandError: Build failed, That's absolutely normal and is part of the process - This will create a new folder
build/macosthat is filled with the generated C project - Copy your
libhl.dylib,fmt.hdll,mysql.hdll,openal.hdll,sdl.hdll,ssl.hdll,ui.hdllanduv.hdllfrom step 1, and paste it to your newbuild/macosfolder - run
cd build/macosand after that, run this codegcc -O3 -o main main.c -lhl -I[/path/to/hashlink/src] -I. -L. fmt.hdll mysql.hdll sdl.hdll openal.hdll ssl.hdll ui.hdll uv.hdll
- To test out your game, run
./mainonbuild/macosfolder
To make the process of compiling and running your game repeatedly easier, i've created a simple script to automate the gcc stuff
- Download macos_c_compile and macos_c_compile_n_run from this repository, and inside you will find
#!/bin/bash cd build/macos gcc -O3 -o main main.c -lhl -I/PATH/TO/HASHLINK/SRC/ -I. -L. fmt.hdll mysql.hdll sdl.hdll openal.hdll ssl.hdll ui.hdll uv.hdll
- Replace
-I/PATH/TO/HASHLINK/SRC/with your src folder of the hashlink that you've built in step 1 - Do this for both
macos_c_compileandmacos_c_compile_n_run - Make sure you have pasted all the
.dyliband.hdllin yourbuild/macosfolder - To compile your game, run
sh macos_c_compile - To compile and run your game, run
sh macos_c_compile_n_run