The current instructions to build HashLink on macOS don’t work on new Apple Silicon CPUs. However, I think that I’ve figured out how build for x86_64 on Apple Silicon.
First, install the Intel version of Homebrew using the following command:
You can have both Apple Silicon and Intel versions of Homebrew installed at the same time because the Apple Silicon version uses /opt/homebrew and the Intel version uses /usr/local/.
Once you get the right version of Homebrew, you need to run slightly different commands when building HashLink.
When the HashLink build instructions say to run brew bundle, you must run it with the Intel version (you might not need the arch -x86_64 part of this command, but I used it to be safe)
arch -x86_64 /usr/local/bin/brew bundle
Then, when running make, you must add arch -x86_64 before it (the arch part definitely not optional on this command) to ensure that it compiles for Intel instead of Apple Silicon.
arch -x86_64 make
When it builds successfully, you can run ./hl to verify that it worked. Here’s the output that I see:
Howdy hello! In case anybody else runs into an issue with this - the instructions here worked, but you may also need to modify CFLAGS and LIBFLAGS in the Makefile to reference /usr/local/Homebrew instead of /usr/local, since Homebrew may have placed the files inside a subdirectory.
Hi! I also managed to build hl for my Mac: MacBook Air with M1 processor, macOS Sonoma OS (14.5). I’m leaving here for posterity, full steps, compiled from other sources as well (since those needed to be adjusted for Sonoma anyway).
Please note that this setup works after I already have a regular version of homebrew installed, and a hl compiled (that does NOT work), however, this way is easier because you don’t need to make any edits to flags (as @cpimhoff is saying above).
Open a NEW terminal, check the current architecture by typing: arch
Will say something like arm64
We need to make it say “i386”. Now, since we can’t duplicate the terminal shortcut in Sonoma, as other older tutorials say, all we can do is close this terminal, right-click the terminal shortcut (from Finder > Applications > Utilities > Terminal, select “Get info”. We’ll see a pop-up with a checkbox that says “Open using Rosetta”, mark it as checked, close this pop-up, and double-click it to open a new terminal. Now, when we type “arch” again, should say i386
Navigate to the desired new install folder (I just installed it at the default path, which is user home (“~”), not ideal, but seems to work fine), create a new folder (I’m using hl_i386, but you can use anything you want), then enter it:
Get the last HashLink source: git clone https://github.com/HaxeFoundation/hashlink.git
5b. Enter the folder
cd hashlink
Build hash link (as above):
arch -x86_64 /usr/local/bin/brew bundle
arch -x86_64 make
Create Hello World example (right in this folder, not cool, but this is how I did it): nano Main.hx
7b. Add this content to the new file:
class Main {
static public function main():Void {
// Single line comment
trace("Hello World");
}
}
Also create this file: nano compile.hxml
8b. Add this content:
-cp src
-lib heaps
-lib hlsdl
-hl hello.hl
-main Main
Compile it:
haxe --hl hello8.hl --main Main
Run it. Make sure to use THIS new path for hl, my mistake was that I was trying to run it using hl hello8.hl which was WRONG, because I already had a different HashLink on my system (the wrong one) and it was using it, even if I was in the proper folder, where the new hl was installed! Seems like PATH on a Mac comes before the current folder. So the proper instruction was:
./hl hello8.hl
Which prints “Hello World”. Finally!
You can also disable rosetta from the terminal shortcut.
And maybe edit the PATH to use the new hl. And remove the “hello world” related files if you did as me
When building HashLink from source, you must run make codesign_osx before installing.
so i ran arch -x86_64 make codesign_osx which shows a bunch of successful looking stuff followed by 1 key imported.
but lime setup hashlink still tells me to run make codesign_osx again. I also tried make codesign_osx without arch -x86_64, just in case. Was I supposed to sign this in an earlier step?
Is steps 7+ just verifying that it works, or is that needed?
Edit: Talked to Josh in discord:
Lime always says that when you have a custom HL_PATH
it doesn’t check if it’s signed or anything
The actual issue was that dragging the hashlink folder into terminal for the lime setup hashlink path adds a space which was used in the path. I removed the space and i can compile hl now