Compiling HashLink on macOS Apple Silicon

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:

arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

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:

HL/JIT 1.12.0 (c)2015-2020 Haxe Foundation
  Usage : hl [--debug <port>] [--debug-wait] <file>

Hopefully, this helps someone else!

11 Likes

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.

succesfully built 1.13 version on m1 mac! thanks!
without CFLAGS and LIBFLAGS renaming everything worked perfectly.

boroda$ ./hl
HL/JIT 1.13.0 (c)2015-2022 Haxe Foundation
  Usage : hl [--debug <port>] [--debug-wait] <file>

Has there been any progress in making the VSCode debugger work on Apple Silicon now that HashLink compiles flawlessly on that architecture?

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).

  1. Open a NEW terminal, check the current architecture by typing:
    arch
    Will say something like arm64

  2. 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

  3. 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:

mkdir hl_i386
cd hl_i386
  1. Install the Intel version of Homebrew, as above:

arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

  1. Get the last HashLink source:
    git clone https://github.com/HaxeFoundation/hashlink.git

5b. Enter the folder

cd hashlink

  1. Build hash link (as above):
arch -x86_64 /usr/local/bin/brew bundle
arch -x86_64 make
  1. 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");
    }
}
  1. Also create this file:
    nano compile.hxml

8b. Add this content:

-cp src
-lib heaps
-lib hlsdl
-hl hello.hl
-main Main
  1. Compile it:

haxe --hl hello8.hl --main Main

  1. 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!

  1. You can also disable rosetta from the terminal shortcut.

  2. And maybe edit the PATH to use the new hl. And remove the “hello world” related files if you did as me :slight_smile:

That’s it! Not very clean, but it works :smiley:

1 Like

I forgot to mention that building HL gives some warnings, but worry not, it still works as a charm :wink:

macbook pro m1 sonoma 14.6.1:
brew install hashlink/Brewfile at master · HaxeFoundation/hashlink · GitHub
then clone hashlink
then make and make install


look like is fine

You may encounter such a problem. I tried to change to arch -x86_64

I am having trouble at step 6. Despite running “arch -x86_64 make” libraries are still being fetched from opt/homebrew

this happened to me, when I closed the terminal to open a new one with rosetta I needed to quit the terminal program, not just close

[solved] I seem to be having issues

running ./hl shows:

Usage : hl [–debug ] [–debug-wait]

but arch -x86_64 make shows:

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

Thanks all!